// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movl %ecx, %ebp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r14
xorpd %xmm0, %xmm0
andq $0x0, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x959a
movq %rax, 0x8(%r14)
movq 0x18(%r14), %rax
cmpq %rax, 0x20(%r14)
je 0x95a8
movq %rax, 0x20(%r14)
movq 0x30(%r14), %rax
cmpq %rax, 0x38(%r14)
je 0x95b6
movq %rax, 0x38(%r14)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
leaq 0x334c4(%rip), %rdx     # 0x3ca8d
callq 0xb9d0
movq %rax, %r12
movq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rax
subq (%rsi), %rax
shrq $0x5, %rax
subl %r12d, %eax
movl %eax, 0x7c(%r14)
testl %eax, %eax
setg 0x78(%r14)
leaq 0x80(%r14), %rbx
movq %rbx, %rdi
callq 0xb16e
movq 0x80(%r14), %rdi
movq 0x88(%r14), %rsi
leaq 0x3347a(%rip), %rdx     # 0x3ca8d
callq 0xbc39
movq 0x88(%r14), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb238
leaq 0x60(%r14), %rbx
movq %rbx, %rdi
callq 0xb23e
movslq 0x7c(%r14), %rsi
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0xb246
leaq 0x18(%r14), %rax
movq %rax, 0x58(%rsp)
leaq 0x30(%r14), %rax
movq %rax, 0x50(%rsp)
movl 0x7c(%r14), %edx
movq 0x60(%r14), %rax
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x18, %rdx, %rdx
cmpq %rcx, %rdx
je 0x9687
movq (%rax,%rcx), %rsi
cmpq %rsi, 0x8(%rax,%rcx)
je 0x9681
movq %rsi, 0x8(%rax,%rcx)
addq $0x18, %rcx
jmp 0x966c
leaq 0x90(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x6620
leaq 0x90(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x94ed
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0xb0(%rsp,%rax)
je 0x9a36
leaq 0x90(%rsp), %rdi
callq 0x60a0
leaq 0x98(%r14), %rdi
movq %r15, %rsi
callq 0x6210
leaq 0xd0(%r14), %rdi
movq 0x10(%rsp), %rsi
callq 0x6210
movl %ebp, 0xf0(%r14)
movb $0x0, 0xf4(%r14)
movl $0x1, 0xf8(%r14)
leaq 0x32dcc(%rip), %rsi     # 0x3c4e0
movq 0x10(%rsp), %rdi
callq 0xb27b
testb %al, %al
movq %r15, 0x48(%rsp)
jne 0x9731
movsd 0x32901(%rip), %xmm0    # 0x3c030
jmp 0x9739
movsd 0x32d67(%rip), %xmm0    # 0x3c4a0
movslq %ebp, %rax
movq %rax, 0x60(%rsp)
xorl %edi, %edi
movslq %r12d, %r13
movsd %xmm0, 0x18(%rsp)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rax, %rdi
jae 0x9862
movq %rdi, 0x40(%rsp)
cmpq 0x60(%rsp), %rdi
jb 0x9855
imulq $0x18, 0x40(%rsp), %rbx
movq (%rcx,%rbx), %rsi
movq %r14, %rdi
callq 0xb120
movq 0x20(%rsp), %rax
movq (%rax,%rbx), %rax
movsd 0x8(%rax), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0x58(%rsp), %rdi
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x71a2
movq 0x20(%rsp), %rax
movq (%rax,%rbx), %rax
movsd 0x10(%rax), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x71a2
cmpb $0x1, 0x78(%r14)
jne 0x9855
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebp, %ebp
movslq 0x7c(%r14), %rax
addq %r13, %rax
cmpq %rax, %r15
jae 0x9855
movq 0x8(%rsp), %rax
movq (%rax), %rdi
addq %r12, %rdi
leaq 0x33281(%rip), %rsi     # 0x3ca8d
callq 0xb27b
testb %al, %al
jne 0x984c
movslq %ebp, %rax
imulq $0x18, %rax, %rdi
movq 0x68(%rsp), %rax
addq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%rbx), %rax
movsd 0x18(%rax,%r15,8), %xmm0
mulsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x71a2
incl %ebp
incq %r15
addq $0x20, %r12
jmp 0x97ee
movq 0x40(%rsp), %rdi
incq %rdi
jmp 0x974c
movq (%r14), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x100(%r14)
cmpb $0x0, 0x78(%r14)
movq 0x48(%rsp), %r9
je 0x98f7
movq 0x20(%r14), %rdx
movq 0x60(%r14), %rcx
subq 0x18(%r14), %rdx
sarq $0x3, %rdx
movq %rdx, %xmm1
punpckldq 0x32775(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3277d(%rip), %xmm1    # 0x3c020
movq 0x68(%r14), %rdx
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
cmpq %rdx, %rcx
je 0x98f7
movq (%rcx), %rsi
movq 0x8(%rcx), %rdi
xorpd %xmm1, %xmm1
movq %rsi, %r8
cmpq %rdi, %r8
je 0x98d6
addsd (%r8), %xmm1
addq $0x8, %r8
jmp 0x98c6
divsd %xmm0, %xmm1
cmpq %rdi, %rsi
je 0x98f1
movsd (%rsi), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rsi)
addq $0x8, %rsi
jmp 0x98da
addq $0x18, %rcx
jmp 0x98b3
movq 0x8(%r14), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movq (%r9), %rdx
leaq 0x32bd8(%rip), %rdi     # 0x3c4e4
xorl %eax, %eax
callq 0x6040
cmpb $0x1, 0x78(%r14)
jne 0x99ec
movq 0x60(%r14), %rcx
movq 0x68(%r14), %rax
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
subq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq 0x32bc8(%rip), %rdi     # 0x3c50b
movq %rax, %rdx
xorl %eax, %eax
callq 0x6040
movq 0x8(%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
leaq 0x70(%rsp), %r15
leaq 0x33128(%rip), %r12     # 0x3ca8d
leaq 0x32c2f(%rip), %r13     # 0x3c59b
movq 0x5a625(%rip), %rbp     # 0x63f98
cmpq %r14, %rbx
je 0x99e0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x6550
movq %r15, %rdi
movq %r12, %rsi
callq 0xb288
testb %al, %al
je 0x99d2
movq 0x70(%rsp), %rsi
leaq 0x32ba4(%rip), %rdi     # 0x3c542
xorl %eax, %eax
callq 0x6040
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
addq $-0x20, %rsi
movq %r15, %rdi
callq 0xb292
testb %al, %al
movq %r13, %rsi
leaq 0x428c6(%rip), %rax     # 0x4c28c
cmovneq %rax, %rsi
movq %rbp, %rdi
callq 0x6430
movq %r15, %rdi
callq 0x6798
addq $0x20, %rbx
jmp 0x9973
movq 0x5a5b1(%rip), %rdi     # 0x63f98
callq 0x61c0
leaq 0x32aed(%rip), %rsi     # 0x3c4e0
movq 0x10(%rsp), %rdi
callq 0xb27b
testb %al, %al
je 0x9a0d
leaq 0x32c19(%rip), %rdi     # 0x3c621
callq 0x65e0
leaq 0x90(%rsp), %rdi
callq 0x60f0
leaq 0x20(%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 0x32a80(%rip), %rdi     # 0x3c4c0
xorl %eax, %eax
callq 0x6040
pushq $0x1
popq %rdi
callq 0x64b0
jmp 0x9a75
jmp 0x9a57
jmp 0x9a57
jmp 0x9a57
movq %rax, %rbx
jmp 0x9a85
jmp 0x9a75
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x6798
jmp 0x9a78
jmp 0x9a75
jmp 0x9a75
jmp 0x9a75
jmp 0x9a75
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x60f0
leaq 0x20(%rsp), %rdi
callq 0xb29c
movq %rbx, %rdi
callq 0x66e0
nop