// File: 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
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movq %rsi, -0x2e8(%rbp)
movq %rdx, -0x2f8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x15680
movq -0x2f0(%rbp), %rdi
callq 0x156c0
movq -0x2f0(%rbp), %rdi
addq $0x18, %rdi
callq 0x156c0
movq -0x2f0(%rbp), %rdi
addq $0x30, %rdi
callq 0x156c0
movq -0x2f0(%rbp), %rdi
addq $0x48, %rdi
callq 0x16090
movq -0x2e8(%rbp), %rsi
leaq -0x240(%rbp), %rdi
movl $0x8, %edx
callq 0x6770
jmp 0x11d62
leaq -0x240(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x111f0
jmp 0x11d74
movq -0x240(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x240(%rbp,%rax), %rdi
callq 0x68c0
movb %al, -0x2f9(%rbp)
jmp 0x11d94
movb -0x2f9(%rbp), %al
testb $0x1, %al
jne 0x11df7
jmp 0x11da0
movq -0x2e8(%rbp), %rdi
callq 0x61e0
movq %rax, %rsi
leaq 0xa5712(%rip), %rdi     # 0xb74c8
xorl %eax, %eax
callq 0x6050
jmp 0x11dbf
movl $0x1, %edi
callq 0x65d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x1234c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x12340
leaq -0x240(%rbp), %rdi
callq 0x60d0
jmp 0x11e05
movq -0x2e8(%rbp), %rsi
movq -0x2f0(%rbp), %rdi
addq $0x98, %rdi
callq 0x6030
jmp 0x11e21
movq -0x2f8(%rbp), %rsi
movq -0x2f0(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6030
jmp 0x11e3d
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0xf0(%rax)
movb $0x1, 0xf4(%rax)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x258(%rbp)
leaq 0xa5675(%rip), %rsi     # 0xb74e8
callq 0x15d50
movb %al, -0x2fa(%rbp)
jmp 0x11e80
movb -0x2fa(%rbp), %al
testb $0x1, %al
jne 0x11e8c
jmp 0x11e9c
movsd 0xa561c(%rip), %xmm0    # 0xb74b0
movsd %xmm0, -0x258(%rbp)
leaq -0x270(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x15660
movl $0x0, -0x274(%rbp)
movslq -0x1c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x3, %esi
callq 0xc6a0
movq -0x308(%rbp), %rdi
cvttsd2si (%rax), %eax
movl %eax, -0x278(%rbp)
leaq -0x278(%rbp), %rsi
callq 0x160b0
jmp 0x11ef2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x310(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x15d80
movq %rax, %rcx
movq -0x310(%rbp), %rax
cmpq %rcx, %rax
jae 0x11fe4
movq -0x280(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x3, %esi
callq 0xc6a0
movsd (%rax), %xmm0
movsd %xmm0, -0x318(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x160e0
movsd -0x318(%rbp), %xmm0
cvtsi2sdl (%rax), %xmm1
ucomisd %xmm1, %xmm0
jne 0x11f76
jp 0x11f76
jmp 0x11fcb
movq -0x280(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x3, %esi
callq 0xc6a0
cvttsd2si (%rax), %eax
movl %eax, -0x284(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x284(%rbp), %rsi
callq 0x160b0
jmp 0x11fb2
jmp 0x11fcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
jmp 0x12334
jmp 0x11fcd
movq -0x280(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x280(%rbp)
jmp 0x11f01
movl -0x1c(%rbp), %eax
movl %eax, -0x288(%rbp)
movl -0x288(%rbp), %eax
movq %rax, -0x320(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x15d80
movq %rax, %rcx
movq -0x320(%rbp), %rax
cmpq %rcx, %rax
jae 0x1219d
movl -0x288(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc6a0
movq -0x2f0(%rbp), %rdi
movq %rax, %rsi
callq 0x15700
jmp 0x12044
movq -0x2f0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x328(%rbp)
movl -0x288(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x1, %esi
callq 0xc6a0
movq -0x328(%rbp), %rdi
movsd (%rax), %xmm0
movsd -0x258(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x290(%rbp)
leaq -0x290(%rbp), %rsi
callq 0x77e0
jmp 0x120a1
movq -0x2f0(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x330(%rbp)
movl -0x288(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x2, %esi
callq 0xc6a0
movq -0x330(%rbp), %rdi
movsd (%rax), %xmm0
movsd -0x258(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x298(%rbp)
leaq -0x298(%rbp), %rsi
callq 0x77e0
jmp 0x120fe
movl -0x288(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x3, %esi
callq 0xc6a0
movsd (%rax), %xmm0
movsd %xmm0, -0x338(%rbp)
movslq -0x274(%rbp), %rsi
leaq -0x270(%rbp), %rdi
callq 0x16120
movsd -0x338(%rbp), %xmm0
cvtsi2sdl (%rax), %xmm1
ucomisd %xmm1, %xmm0
jne 0x12151
jp 0x12151
jmp 0x12160
movl -0x274(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274(%rbp)
movq -0x2f0(%rbp), %rdi
addq $0x48, %rdi
movl -0x274(%rbp), %eax
incl %eax
movl %eax, -0x29c(%rbp)
leaq -0x29c(%rbp), %rsi
callq 0x160b0
jmp 0x12187
jmp 0x12189
movl -0x288(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x288(%rbp)
jmp 0x11fed
movq -0x2f0(%rbp), %rdi
callq 0x7c90
movq -0x2e8(%rbp), %rdi
movq %rax, -0x340(%rbp)
callq 0x61e0
movq -0x340(%rbp), %rsi
movq %rax, %rdx
leaq 0xa531f(%rip), %rdi     # 0xb74ec
xorl %eax, %eax
callq 0x6050
jmp 0x121d6
movq -0x2f0(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x348(%rbp)
callq 0x16140
movq -0x348(%rbp), %rdi
movq %rax, -0x2d8(%rbp)
callq 0x16170
movq %rax, -0x2e0(%rbp)
movq -0x2d8(%rbp), %rsi
movq -0x2e0(%rbp), %rdx
leaq -0x2d0(%rbp), %rdi
callq 0x161a0
jmp 0x12223
leaq -0x2d0(%rbp), %rdi
callq 0x16220
movq %rax, %rsi
leaq 0xa5348(%rip), %rdi     # 0xb7581
xorl %eax, %eax
callq 0x6050
jmp 0x12242
leaq -0x2d0(%rbp), %rdi
callq 0x16220
movq -0x2f8(%rbp), %rdi
movq %rax, %rcx
movq -0x2f0(%rbp), %rax
movl %ecx, 0xf8(%rax)
leaq 0xa527c(%rip), %rsi     # 0xb74e8
callq 0x15d50
movb %al, -0x349(%rbp)
jmp 0x12279
movb -0x349(%rbp), %al
testb $0x1, %al
jne 0x12285
jmp 0x122d8
movq 0x107d0c(%rip), %rdi    # 0x119f98
leaq 0xa531a(%rip), %rsi     # 0xb75ad
callq 0x64f0
movq %rax, -0x358(%rbp)
jmp 0x122a1
movq -0x358(%rbp), %rdi
movq 0x107c69(%rip), %rsi    # 0x119f18
callq 0x6530
jmp 0x122b6
jmp 0x122d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x248(%rbp)
movl %eax, -0x24c(%rbp)
leaq -0x2d0(%rbp), %rdi
callq 0x16240
jmp 0x12334
movq -0x2f0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc6a0
movq %rax, %rcx
movq -0x2f0(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x100(%rax)
leaq -0x2d0(%rbp), %rdi
callq 0x16240
leaq -0x270(%rbp), %rdi
callq 0x16260
leaq -0x240(%rbp), %rdi
callq 0x6130
leaq -0x38(%rbp), %rdi
callq 0x16030
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
leaq -0x270(%rbp), %rdi
callq 0x16260
leaq -0x240(%rbp), %rdi
callq 0x6130
leaq -0x38(%rbp), %rdi
callq 0x16030
movq -0x248(%rbp), %rdi
callq 0x6830
nopw %cs:(%rax,%rax)