// File: /workspace/github_cpp_makefile_star2_O1/j-faria[P]kima/src/Data.cpp
// Function: Data::load(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, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
void Data::load(const std::string filename, const std::string units, 
                int skip, const vector<string>& indicators)
{

  data_t data;

  // Empty the vectors
  t.clear();
  y.clear();
  sig.clear();
  
  // check for indicator correlations and store stuff
  int nempty = count(indicators.begin(), indicators.end(), "");
  number_indicators = indicators.size() - nempty;
  indicator_correlations = number_indicators > 0;
  indicator_names = indicators;
  indicator_names.erase(
    std::remove( indicator_names.begin(), indicator_names.end(), "" ), 
    indicator_names.end() );


  // Empty the indicator vectors as well
  actind.clear();
  actind.resize(number_indicators);
  for (int n = 0; n < number_indicators; n++)
    actind[n].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 = false;
  number_instruments = 1;


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

  for (size_t n = 0; 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 (indicator_correlations)
      {
        j = 0;
        for (size_t i = 0; i < number_indicators + nempty; i++)
        {
          if (indicators[i] == "")
            continue; // skip column
          else
          {
            actind[j].push_back(data[n][3+i] * factor);
            j++;
          }
        }
      }
  
    }
  
  // epoch for the mean anomaly, by default the time of the first observation
  M0_epoch = t[0];


  // subtract means from activity indicators
  if (indicator_correlations)
  {
    double mean;
    for (auto& i: actind){ // use auto& instead of auto to modify i
      mean = std::accumulate(i.begin(), i.end(), 0.0) / y.size();
      std::for_each(i.begin(), i.end(), [mean](double& d) { d -= mean;});
    }
  }

  // How many points did we read?
  printf("# Loaded %zu data points from file %s\n", t.size(), filename.c_str());
  // Did we read activity indicators? how many?
  if(indicator_correlations){
    printf("# Loaded %zu observations of %zu activity indicators: ", 
           actind[0].size(), actind.size());
    for (const auto i: indicators){
      if (i != ""){
        printf("'%s'", i.c_str());
        (i != indicators.back()) ? cout << ", " : cout << " ";
      }
    }
    cout << endl;
  }
  // What are the units?
  if(units == "kms")
    printf("# Multiplied all RVs by 1000; units are now m/s.\n");

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %r8, (%rsp)
movl %ecx, 0x30(%rsp)
movq %rdx, %rbp
movq %rdi, %r13
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x936d
movq %rax, 0x8(%r13)
movq 0x18(%r13), %rax
cmpq %rax, 0x20(%r13)
je 0x937b
movq %rax, 0x20(%r13)
movq %rsi, 0x68(%rsp)
movq 0x30(%r13), %rax
cmpq %rax, 0x38(%r13)
je 0x938e
movq %rax, 0x38(%r13)
movq (%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r15
xorl %r14d, %r14d
cmpq %r15, %rbx
je 0x93c3
leaq 0x366f9(%rip), %r12     # 0x3faa1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6100
cmpl $0x1, %eax
adcq $0x0, %r14
addq $0x20, %rbx
cmpq %r15, %rbx
jne 0x93a8
movq (%rsp), %rsi
movq 0x8(%rsi), %rax
subq (%rsi), %rax
shrq $0x5, %rax
subl %r14d, %eax
movl %eax, 0x7c(%r13)
testl %eax, %eax
setg 0x78(%r13)
leaq 0x80(%r13), %rbx
movq %rbx, %rdi
callq 0xb916
movq 0x80(%r13), %rdi
movq 0x88(%r13), %rsi
leaq 0x3669d(%rip), %rdx     # 0x3faa1
callq 0xc483
movq 0x88(%r13), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xc5d0
leaq 0x60(%r13), %rbx
movq 0x60(%r13), %rsi
movq %rbx, %rdi
callq 0xc696
movslq 0x7c(%r13), %rsi
movq %rbx, 0x70(%rsp)
movq %rbx, %rdi
callq 0xba90
movslq 0x7c(%r13), %rcx
testq %rcx, %rcx
movq 0x68(%rsp), %rbx
jle 0x9475
movq 0x70(%rsp), %rax
movq (%rax), %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movq (%rax,%rdx), %rsi
cmpq %rsi, 0x8(%rax,%rdx)
je 0x946c
movq %rsi, 0x8(%rax,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x945c
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x6640
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x92a3
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0xb0(%rsp,%rax)
je 0x9975
leaq 0x90(%rsp), %rdi
callq 0x60a0
leaq 0x98(%r13), %rdi
movq %rbx, %rsi
callq 0x6210
leaq 0xd0(%r13), %rdi
movq %rbp, %rsi
callq 0x6210
movl 0x30(%rsp), %ebx
movl %ebx, 0xf0(%r13)
movb $0x0, 0xf4(%r13)
movq %r13, 0x8(%rsp)
movl $0x1, 0xf8(%r13)
leaq 0x35fdd(%rip), %rsi     # 0x3f4e8
movq %rbp, 0x60(%rsp)
movq %rbp, %rdi
callq 0x6100
xorl %ecx, %ecx
testl %eax, %eax
sete %dl
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x9714
movq 0x8(%rsp), %rsi
leaq 0x18(%rsi), %rdi
movq %rdi, 0x80(%rsp)
addq $0x30, %rsi
movq %rsi, 0x78(%rsp)
movb %dl, %cl
leaq 0x35f4e(%rip), %rdx     # 0x3f4a0
movsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movslq %ebx, %rcx
movq %rcx, 0x30(%rsp)
xorl %r12d, %r12d
movq %r14, %rcx
movslq %ecx, %r14
negl %ecx
movq %rcx, 0x88(%rsp)
cmpq 0x30(%rsp), %r12
jb 0x96e9
leaq (%r12,%r12,2), %r13
movq (%rax,%r13,8), %rdx
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x95ac
movsd (%rdx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x95b4
movq %rbx, %rdi
callq 0xbf7a
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x95e6
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x95f8
movq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x744a
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd 0x10(%rax), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x962a
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x9639
movq 0x78(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x744a
cmpb $0x1, 0x78(%rbx)
jne 0x96e9
movq 0x8(%rsp), %rax
movq 0x88(%rsp), %rcx
cmpl %ecx, 0x7c(%rax)
je 0x96e9
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r15d, %r15d
movq (%rsp), %rax
movq (%rax), %rdi
addq %rbp, %rdi
leaq 0x36430(%rip), %rsi     # 0x3faa1
callq 0x6100
testl %eax, %eax
je 0x96cd
movslq %ebx, %rax
movq 0x70(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd 0x18(%rax,%r15,8), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x96c1
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x96cb
leaq 0x40(%rsp), %rdx
callq 0x744a
incl %ebx
incq %r15
movq 0x8(%rsp), %rax
movslq 0x7c(%rax), %rax
addq %r14, %rax
addq $0x20, %rbp
cmpq %rax, %r15
jb 0x9660
incq %r12
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rcx, %r12
jb 0x9578
movq 0x8(%rsp), %r14
movq (%r14), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x100(%r14)
cmpb $0x0, 0x78(%r14)
movq 0x60(%rsp), %rbx
movq 0x68(%rsp), %r9
je 0x97c0
movq 0x60(%r14), %rcx
movq 0x68(%r14), %rdx
cmpq %rdx, %rcx
je 0x97c0
movq 0x20(%r14), %rsi
subq 0x18(%r14), %rsi
sarq $0x3, %rsi
movq %rsi, %xmm1
punpckldq 0x358ac(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x358b4(%rip), %xmm1    # 0x3f020
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq (%rcx), %rsi
movq 0x8(%rcx), %rdi
xorpd %xmm1, %xmm1
cmpq %rdi, %rsi
je 0x9799
movq %rsi, %r8
addsd (%r8), %xmm1
addq $0x8, %r8
cmpq %rdi, %r8
jne 0x978b
cmpq %rdi, %rsi
je 0x97b7
divsd %xmm0, %xmm1
movsd (%rsi), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rsi)
addq $0x8, %rsi
cmpq %rdi, %rsi
jne 0x97a2
addq $0x18, %rcx
cmpq %rdx, %rcx
jne 0x9778
movq 0x8(%r14), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movq (%r9), %rdx
leaq 0x35d17(%rip), %rdi     # 0x3f4ec
xorl %eax, %eax
callq 0x6050
cmpb $0x1, 0x78(%r14)
jne 0x992d
movq 0x60(%r14), %rax
movq 0x68(%r14), %rdx
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rdx
leaq 0x35cfd(%rip), %rdi     # 0x3f513
xorl %eax, %eax
callq 0x6050
movq (%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r13
cmpq %r13, %r14
je 0x98f9
leaq 0x50(%rsp), %r12
leaq 0x40(%rsp), %rbx
leaq 0x3625f(%rip), %r15     # 0x3faa1
movq %r12, 0x40(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0xbeb6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6100
testl %eax, %eax
je 0x98d5
movq 0x40(%rsp), %rsi
leaq 0x35cd6(%rip), %rdi     # 0x3f54a
xorl %eax, %eax
callq 0x6050
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq 0x48(%rsp), %rdx
movl $0x2, %ebp
cmpq -0x18(%rax), %rdx
jne 0x98bf
testq %rdx, %rdx
je 0x98b1
movq -0x20(%rax), %rsi
movq 0x40(%rsp), %rdi
callq 0x6470
leaq 0x3e7de(%rip), %rsi     # 0x4808b
testl %eax, %eax
jne 0x98c6
movl $0x1, %ebp
leaq 0x35ce6(%rip), %rsi     # 0x3f5a3
jmp 0x98c6
leaq 0x3e7c5(%rip), %rsi     # 0x4808b
movq 0x496cb(%rip), %rdi     # 0x52f98
movq %rbp, %rdx
callq 0x64a0
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x98ec
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6460
addq $0x20, %r14
cmpq %r13, %r14
jne 0x9842
movq 0x49698(%rip), %rdi     # 0x52f98
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x6430
movq 0x60(%rsp), %rbx
movsbl %al, %esi
movq 0x49678(%rip), %rdi     # 0x52f98
callq 0x6030
movq %rax, %rdi
callq 0x6300
leaq 0x35bb4(%rip), %rsi     # 0x3f4e8
movq %rbx, %rdi
callq 0x6100
testl %eax, %eax
jne 0x994c
leaq 0x35d0c(%rip), %rdi     # 0x3f653
callq 0x65f0
leaq 0x90(%rsp), %rdi
callq 0x60e0
leaq 0x10(%rsp), %rdi
callq 0xbacc
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rsi
leaq 0x35b49(%rip), %rdi     # 0x3f4c8
xorl %eax, %eax
callq 0x6050
movl $0x1, %edi
callq 0x64e0
jmp 0x9998
jmp 0x9998
jmp 0x9998
jmp 0x99c3
movq %rax, %rbx
jmp 0x99d3
jmp 0x99c3
jmp 0x99c3
jmp 0x99c3
jmp 0x99c3
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x99c6
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6460
jmp 0x99c6
jmp 0x99c3
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x60e0
leaq 0x10(%rsp), %rdi
callq 0xbacc
movq %rbx, %rdi
callq 0x6710
nop