// File: /workspace/github_cpp_makefile_star2_O2/j-faria[P]kima/src/Data.cpp
// Function: Data::load_multi(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void Data::load_multi(const std::string filename, const std::string units, int skip)
  {

  data_t data;

  // Empty the vectors
  t.clear();
  y.clear();
  sig.clear();
  obsi.clear();

  // Read the file into the data container
  ifstream infile( filename );
  infile >> data;

  // Complain if something went wrong.
  if (!infile.eof())
  {
    printf("Could not read data file (%s)!\n", filename.c_str());
    exit(1);
  }

  infile.close();

  datafile = filename;
  dataunits = units;
  dataskip = skip;
  datamulti = true;

  double factor = 1.;
  if(units == "kms") factor = 1E3;

  // the 4th column of the file identifies the instrument; can have "0"s
  // this is to make sure the obsi vector always starts at 1, to avoid
  // segmentation faults later
  vector<int> inst_id;
  int id = 0;

  inst_id.push_back(data[skip][3]);

  for (size_t n = skip+1; n < data.size(); n++)
  {
    if (data[n][3] != inst_id.back())
      inst_id.push_back(data[n][3]);
  }

  for (unsigned n = skip; n < data.size(); n++)
  {
    // if (n < skip) continue;
    t.push_back(data[n][0]);
    y.push_back(data[n][1] * factor);
    sig.push_back(data[n][2] * factor);

    if (data[n][3] != inst_id[id])
      id++;
    obsi.push_back(id+1);
  }

  // How many points did we read?
  printf("# Loaded %zu data points from file %s\n", t.size(), filename.c_str());

  // Of how many instruments?
  std::set<int> s( obsi.begin(), obsi.end() );
  printf("# RVs come from %zu different instruments.\n", s.size());
  number_instruments = s.size();
  
  if(units == "kms") 
    cout << "# Multiplied all RVs by 1000; units are now m/s." << endl;

  // epoch for the mean anomaly, by default the time of the first observation
  M0_epoch = t[0];

  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorpd %xmm0, %xmm0
andq $0x0, 0x10(%rsp)
movapd %xmm0, (%rsp)
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x9ad1
movq %rax, 0x8(%rbx)
movq 0x18(%rbx), %rax
cmpq %rax, 0x20(%rbx)
je 0x9adf
movq %rax, 0x20(%rbx)
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x9aed
movq %rax, 0x38(%rbx)
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x9afb
movq %rax, 0x50(%rbx)
leaq 0x90(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x6620
leaq 0x90(%rsp), %rdi
movq %rsp, %rsi
callq 0x94ed
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0xb0(%rsp,%rax)
je 0x9df2
leaq 0x90(%rsp), %rdi
callq 0x60a0
leaq 0x98(%rbx), %rdi
movq %r15, %rsi
callq 0x6210
leaq 0xd0(%rbx), %rdi
movq %r14, %rsi
callq 0x6210
movl %r12d, 0xf0(%rbx)
movb $0x1, 0xf4(%rbx)
leaq 0x32968(%rip), %rsi     # 0x3c4e0
movq %r14, %rdi
callq 0xb27b
testb %al, %al
jne 0x9b8e
movsd 0x324a4(%rip), %xmm0    # 0x3c030
jmp 0x9b96
movsd 0x3290a(%rip), %xmm0    # 0x3c4a0
movsd %xmm0, 0x18(%rsp)
movq %r15, 0x40(%rsp)
movq %r14, 0x38(%rsp)
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
andq $0x0, 0x10(%rdi)
movapd %xmm0, (%rdi)
movslq %r12d, %rax
movq (%rsp), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
cvttsd2si 0x18(%rax), %eax
leaq 0x60(%rsp), %rsi
movl %eax, (%rsi)
callq 0xbfb6
leaq 0x18(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x50(%rsp)
movq %rbx, %r14
leaq 0x48(%rbx), %rax
movq %rax, 0x48(%rsp)
leal 0x1(%r12), %eax
movslq %eax, %r13
imulq $0x18, %r13, %r15
pushq $0x18
popq %rbx
leaq 0x20(%rsp), %rbp
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
movq %rcx, %rax
subq %rsi, %rax
cqto
idivq %rbx
cmpq %rax, %r13
jae 0x9c5c
movq (%rsi,%r15), %rax
movsd 0x18(%rax), %xmm0
movq 0x28(%rsp), %rax
cvtsi2sdl -0x4(%rax), %xmm1
ucomisd %xmm1, %xmm0
jne 0x9c3e
jnp 0x9c53
cvttsd2si %xmm0, %eax
movl %eax, 0x60(%rsp)
movq %rbp, %rdi
leaq 0x60(%rsp), %rsi
callq 0xbfb6
incq %r13
addq $0x18, %r15
jmp 0x9c0a
xorl %r13d, %r13d
leaq 0x60(%rsp), %r15
movl %r12d, %r12d
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %rbx
cmpq %r12, %rax
jbe 0x9d20
imulq $0x18, %r12, %rbp
movq (%rsi,%rbp), %rsi
movq %r14, %rdi
callq 0xb120
movq (%rsp), %rax
movq (%rax,%rbp), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x71a2
movq (%rsp), %rax
movq (%rax,%rbp), %rax
movsd 0x10(%rax), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x71a2
movq (%rsp), %rax
movq (%rax,%rbp), %rax
movl %r13d, %ecx
movq 0x20(%rsp), %rdx
cvtsi2sdl (%rdx,%rcx,4), %xmm0
cmpneqsd 0x18(%rax), %xmm0
movq %xmm0, %rax
subl %eax, %r13d
leal 0x1(%r13), %eax
movl %eax, 0x60(%rsp)
movq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0xbfb6
incl %r12d
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
jmp 0x9c64
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
movq 0x40(%rsp), %rax
movq (%rax), %rdx
leaq 0x327aa(%rip), %rdi     # 0x3c4e4
xorl %eax, %eax
callq 0x6040
movq 0x48(%r14), %rsi
movq 0x50(%r14), %rdx
leaq 0x60(%rsp), %rdi
callq 0xb2be
movq 0x88(%rsp), %rsi
leaq 0x327e5(%rip), %rdi     # 0x3c547
xorl %eax, %eax
callq 0x6040
movl 0x88(%rsp), %eax
movl %eax, 0xf8(%r14)
leaq 0x32762(%rip), %rsi     # 0x3c4e0
movq 0x38(%rsp), %rdi
callq 0xb27b
testb %al, %al
je 0x9da7
movq 0x5a205(%rip), %rdi     # 0x63f98
leaq 0x32887(%rip), %rsi     # 0x3c621
callq 0x6430
movq %rax, %rdi
callq 0x61c0
movq (%r14), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x100(%r14)
leaq 0x60(%rsp), %rdi
callq 0xb4c6
leaq 0x20(%rsp), %rdi
callq 0xb5f6
leaq 0x90(%rsp), %rdi
callq 0x60f0
movq %rsp, %rdi
callq 0xb29c
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rsi
leaq 0x326c4(%rip), %rdi     # 0x3c4c0
xorl %eax, %eax
callq 0x6040
pushq $0x1
popq %rdi
callq 0x64b0
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xb4c6
jmp 0x9e33
jmp 0x9e30
jmp 0x9e30
movq %rax, %rbx
jmp 0x9e4a
movq %rax, %rbx
jmp 0x9e3d
jmp 0x9e30
jmp 0x9e30
jmp 0x9e30
jmp 0x9e30
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xb5f6
leaq 0x90(%rsp), %rdi
callq 0x60f0
movq %rsp, %rdi
callq 0xb29c
movq %rbx, %rdi
callq 0x66e0