// File: /workspace/github_cpp_makefile_star2_O1/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 $0x2a8, %rsp            # imm = 0x2A8
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x9a23
movq %rax, 0x8(%rbx)
movq 0x18(%rbx), %rax
cmpq %rax, 0x20(%rbx)
je 0x9a31
movq %rax, 0x20(%rbx)
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x9a3f
movq %rax, 0x38(%rbx)
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x9a4d
movq %rax, 0x50(%rbx)
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x6640
leaq 0xa0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x92a3
movq 0xa0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0xc0(%rsp,%rax)
je 0x9e81
leaq 0xa0(%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 0x35a1a(%rip), %rsi     # 0x3f4e8
movq %r14, %rdi
callq 0x6100
testl %eax, %eax
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movslq %r12d, %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
cvttsd2si 0x18(%rax), %eax
sete %cl
movl %eax, 0x48(%rsp)
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
movq %r15, 0x80(%rsp)
movb %cl, 0xf(%rsp)
je 0x9b2a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x9b39
leaq 0x30(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xc822
movq %r14, 0x78(%rsp)
movq %r12, 0x28(%rsp)
leal 0x1(%r12), %r15d
movslq %r15d, %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r12, %rcx
cmpq %rbp, %rcx
jbe 0x9be8
leaq (,%rbp,8), %rcx
leaq (%rcx,%rcx,2), %r14
leaq 0x48(%rsp), %r13
movq (%rax,%r14), %rax
movsd 0x18(%rax), %xmm0
movq 0x38(%rsp), %rsi
xorps %xmm1, %xmm1
cvtsi2sdl -0x4(%rsi), %xmm1
ucomisd %xmm1, %xmm0
jne 0x9b9e
jnp 0x9bc7
cvttsd2si %xmm0, %eax
movl %eax, 0x48(%rsp)
cmpq 0x40(%rsp), %rsi
je 0x9bba
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x9bc7
leaq 0x30(%rsp), %rdi
movq %r13, %rdx
callq 0xc822
incq %rbp
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
addq $0x18, %r14
cmpq %rcx, %rbp
jb 0x9b80
movl 0x28(%rsp), %eax
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
cmpq %rax, %rdx
jbe 0x9d7a
leaq 0x18(%rbx), %rdx
movq %rdx, 0x98(%rsp)
leaq 0x30(%rbx), %rdx
movq %rdx, 0x90(%rsp)
leaq 0x48(%rbx), %rdx
movq %rdx, 0x88(%rsp)
xorl %esi, %esi
movb 0xf(%rsp), %dl
movb %dl, %sil
leaq 0x35862(%rip), %rdx     # 0x3f4a0
movsd (%rdx,%rsi,8), %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0x48(%rsp), %r14
leaq (%rax,%rax,2), %rbp
movq (%rcx,%rbp,8), %rdx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x9c75
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x9c7d
movq %rbx, %rdi
callq 0xbf7a
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x9caf
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x9cbf
movq 0x98(%rsp), %rdi
movq %r14, %rdx
callq 0x744a
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd 0x10(%rax), %xmm0
mulsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x9cf1
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x9d01
movq 0x90(%rsp), %rdi
movq %r14, %rdx
callq 0x744a
movq 0x10(%rsp), %rax
movq (%rax,%rbp,8), %rax
movl %r13d, %ecx
movq 0x30(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sdl (%rdx,%rcx,4), %xmm0
cmpneqsd 0x18(%rax), %xmm0
movq %xmm0, %rax
subl %eax, %r13d
leal 0x1(%r13), %eax
movl %eax, 0x48(%rsp)
movq 0x50(%rbx), %rsi
cmpq 0x58(%rbx), %rsi
je 0x9d46
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x50(%rbx)
jmp 0x9d56
movq 0x88(%rsp), %rdi
movq %r14, %rdx
callq 0xc822
movl %r15d, %eax
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incl %r15d
cmpq %rax, %rdx
ja 0x9c51
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x3, %rsi
movq 0x80(%rsp), %rax
movq (%rax), %rdx
leaq 0x35755(%rip), %rdi     # 0x3f4ec
xorl %eax, %eax
callq 0x6050
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
leaq 0x48(%rsp), %rdi
callq 0xbb1a
movq 0x70(%rsp), %rsi
leaq 0x35793(%rip), %rdi     # 0x3f54f
xorl %eax, %eax
callq 0x6050
movl 0x70(%rsp), %eax
movl %eax, 0xf8(%rbx)
leaq 0x35714(%rip), %rsi     # 0x3f4e8
movq 0x78(%rsp), %rdi
callq 0x6100
testl %eax, %eax
jne 0x9e28
movq 0x491af(%rip), %r14     # 0x52f98
leaq 0x35863(%rip), %rsi     # 0x3f653
movl $0x30, %edx
movq %r14, %rdi
callq 0x64a0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x6430
movsbl %al, %esi
movq 0x4917d(%rip), %rdi     # 0x52f98
callq 0x6030
movq %rax, %rdi
callq 0x6300
movq (%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x100(%rbx)
leaq 0x48(%rsp), %rdi
callq 0xbe66
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9e58
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
leaq 0xa0(%rsp), %rdi
callq 0x60e0
leaq 0x10(%rsp), %rdi
callq 0xbacc
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rsi
leaq 0x3563d(%rip), %rdi     # 0x3f4c8
xorl %eax, %eax
callq 0x6050
movl $0x1, %edi
callq 0x64e0
jmp 0x9ec1
jmp 0x9ec1
movq %rax, %rbx
jmp 0x9ee8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xbe66
jmp 0x9ec4
jmp 0x9ec1
movq %rax, %rbx
jmp 0x9edb
jmp 0x9ec1
jmp 0x9ec1
jmp 0x9ec1
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x9edb
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
leaq 0xa0(%rsp), %rdi
callq 0x60e0
leaq 0x10(%rsp), %rdi
callq 0xbacc
movq %rbx, %rdi
callq 0x6710