// File: 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
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movq %rsi, -0x398(%rbp)
movq %rdx, -0x390(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x388(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x15680
movq -0x388(%rbp), %rdi
callq 0x156c0
movq -0x388(%rbp), %rdi
addq $0x18, %rdi
callq 0x156c0
movq -0x388(%rbp), %rdi
addq $0x30, %rdi
callq 0x156c0
movq -0x28(%rbp), %rdi
callq 0x15830
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
callq 0x15860
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq 0xa676c(%rip), %rdx     # 0xb7a91
callq 0x157e0
movq %rax, -0x380(%rbp)
jmp 0x11333
movq -0x380(%rbp), %rax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
callq 0x15890
movq -0x388(%rbp), %rdi
movl -0x44(%rbp), %ecx
subl %ecx, %eax
movl %eax, 0x7c(%rdi)
movl 0x7c(%rdi), %eax
testl %eax, %eax
setg 0x78(%rdi)
movq -0x28(%rbp), %rsi
subq $-0x80, %rdi
callq 0x158b0
jmp 0x1136d
movq -0x388(%rbp), %rdi
subq $-0x80, %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x15be0
movq -0x3a8(%rbp), %rdi
movq %rax, -0x80(%rbp)
callq 0x15c10
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq 0xa66e4(%rip), %rdx     # 0xb7a91
callq 0x15b90
movq %rax, -0x3a0(%rbp)
jmp 0x113bb
movq -0x3a0(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x15c40
movq -0x388(%rbp), %rdi
subq $-0x80, %rdi
callq 0x15c10
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x15c40
movq -0x3a8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0x15b00
movq %rax, -0x3b0(%rbp)
jmp 0x1141d
movq -0x388(%rbp), %rdi
movq -0x3b0(%rbp), %rax
movq %rax, -0xa0(%rbp)
addq $0x60, %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x15c80
movq -0x388(%rbp), %rax
movq -0x3b8(%rbp), %rdi
movslq 0x7c(%rax), %rsi
callq 0x15ca0
jmp 0x1145b
movl $0x0, -0xa4(%rbp)
movq -0x388(%rbp), %rcx
movl -0xa4(%rbp), %eax
cmpl 0x7c(%rcx), %eax
jge 0x114b8
movq -0x388(%rbp), %rdi
addq $0x60, %rdi
movslq -0xa4(%rbp), %rsi
callq 0x15d30
movq %rax, %rdi
callq 0x156c0
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x11465
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x11c53
movq -0x398(%rbp), %rsi
leaq -0x2b0(%rbp), %rdi
movl $0x8, %edx
callq 0x6770
jmp 0x114d2
leaq -0x2b0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x111f0
jmp 0x114e4
movq -0x2b0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2b0(%rbp,%rax), %rdi
callq 0x68c0
movb %al, -0x3b9(%rbp)
jmp 0x11504
movb -0x3b9(%rbp), %al
testb $0x1, %al
jne 0x1154a
jmp 0x11510
movq -0x398(%rbp), %rdi
callq 0x61e0
movq %rax, %rsi
leaq 0xa5fa2(%rip), %rdi     # 0xb74c8
xorl %eax, %eax
callq 0x6050
jmp 0x1152f
movl $0x1, %edi
callq 0x65d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x11c47
leaq -0x2b0(%rbp), %rdi
callq 0x60d0
jmp 0x11558
movq -0x398(%rbp), %rsi
movq -0x388(%rbp), %rdi
addq $0x98, %rdi
callq 0x6030
jmp 0x11574
movq -0x390(%rbp), %rsi
movq -0x388(%rbp), %rdi
addq $0xd0, %rdi
callq 0x6030
jmp 0x11590
movq -0x390(%rbp), %rdi
movq -0x388(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, 0xf0(%rax)
movb $0x0, 0xf4(%rax)
movl $0x1, 0xf8(%rax)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x2b8(%rbp)
leaq 0xa5f18(%rip), %rsi     # 0xb74e8
callq 0x15d50
movb %al, -0x3ba(%rbp)
jmp 0x115dd
movb -0x3ba(%rbp), %al
testb $0x1, %al
jne 0x115e9
jmp 0x115f9
movsd 0xa5ebf(%rip), %xmm0    # 0xb74b0
movsd %xmm0, -0x2b8(%rbp)
movq $0x0, -0x2c8(%rbp)
movq -0x2c8(%rbp), %rax
movq %rax, -0x3c8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x15d80
movq %rax, %rcx
movq -0x3c8(%rbp), %rax
cmpq %rcx, %rax
jae 0x11854
movq -0x2c8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jae 0x11643
jmp 0x1183d
movq -0x2c8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc6a0
movq -0x388(%rbp), %rdi
movq %rax, %rsi
callq 0x15700
jmp 0x11670
movq -0x388(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x3d0(%rbp)
movq -0x2c8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x1, %esi
callq 0xc6a0
movq -0x3d0(%rbp), %rdi
movsd (%rax), %xmm0
movsd -0x2b8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x2d0(%rbp)
leaq -0x2d0(%rbp), %rsi
callq 0x77e0
jmp 0x116cc
movq -0x388(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x3d8(%rbp)
movq -0x2c8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movl $0x2, %esi
callq 0xc6a0
movq -0x3d8(%rbp), %rdi
movsd (%rax), %xmm0
movsd -0x2b8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x2d8(%rbp)
leaq -0x2d8(%rbp), %rsi
callq 0x77e0
jmp 0x11728
movq -0x388(%rbp), %rax
testb $0x1, 0x78(%rax)
je 0x1183b
movl $0x0, -0x2bc(%rbp)
movq $0x0, -0x2e0(%rbp)
movq -0x388(%rbp), %rcx
movq -0x2e0(%rbp), %rax
movl 0x7c(%rcx), %ecx
addl -0x44(%rbp), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x11839
movq -0x28(%rbp), %rdi
movq -0x2e0(%rbp), %rsi
callq 0x15db0
movq %rax, %rdi
leaq 0xa6309(%rip), %rsi     # 0xb7a91
callq 0x15d50
movb %al, -0x3d9(%rbp)
jmp 0x11795
movb -0x3d9(%rbp), %al
testb $0x1, %al
jne 0x117a1
jmp 0x117a3
jmp 0x11822
movq -0x388(%rbp), %rdi
addq $0x60, %rdi
movslq -0x2bc(%rbp), %rsi
callq 0x15d30
movq %rax, -0x3e8(%rbp)
movq -0x2c8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x15d30
movq %rax, %rdi
movq -0x2e0(%rbp), %rsi
addq $0x3, %rsi
callq 0xc6a0
movq -0x3e8(%rbp), %rdi
movsd (%rax), %xmm0
movsd -0x2b8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x2e8(%rbp)
leaq -0x2e8(%rbp), %rsi
callq 0x77e0
jmp 0x11811
movl -0x2bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2bc(%rbp)
jmp 0x11822
movq -0x2e0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2e0(%rbp)
jmp 0x1174e
jmp 0x1183b
jmp 0x1183d
movq -0x2c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2c8(%rbp)
jmp 0x11604
movq -0x388(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc6a0
movq %rax, %rcx
movq -0x388(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x100(%rax)
testb $0x1, 0x78(%rax)
je 0x119fa
movq -0x388(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x2f8(%rbp)
movq -0x2f8(%rbp), %rdi
callq 0x15dd0
movq %rax, -0x300(%rbp)
movq -0x2f8(%rbp), %rdi
callq 0x15e00
movq %rax, -0x308(%rbp)
leaq -0x300(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x15e30
testb $0x1, %al
jne 0x118d8
jmp 0x119f8
leaq -0x300(%rbp), %rdi
callq 0x15e70
movq %rax, -0x310(%rbp)
movq -0x310(%rbp), %rdi
callq 0x7890
movq %rax, -0x318(%rbp)
movq -0x310(%rbp), %rdi
callq 0x78c0
movq %rax, -0x320(%rbp)
movq -0x318(%rbp), %rdi
movq -0x320(%rbp), %rsi
xorps %xmm0, %xmm0
callq 0x15e90
movsd %xmm0, -0x3f0(%rbp)
jmp 0x11931
movq -0x388(%rbp), %rdi
addq $0x18, %rdi
callq 0x7c90
movsd -0x3f0(%rbp), %xmm0
movq %rax, %xmm1
movaps 0xa56bb(%rip), %xmm2    # 0xb7010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xa56bf(%rip), %xmm2    # 0xb7020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x2f0(%rbp)
movq -0x310(%rbp), %rdi
callq 0x7890
movq %rax, -0x328(%rbp)
movq -0x310(%rbp), %rdi
callq 0x78c0
movq %rax, -0x330(%rbp)
movsd -0x2f0(%rbp), %xmm0
movsd %xmm0, -0x338(%rbp)
movq -0x328(%rbp), %rdi
movq -0x330(%rbp), %rsi
movsd -0x338(%rbp), %xmm0
callq 0x11c70
movsd %xmm0, -0x3f8(%rbp)
jmp 0x119d7
movsd -0x3f8(%rbp), %xmm0
movsd %xmm0, -0x340(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x15ef0
jmp 0x118bc
jmp 0x119fa
movq -0x388(%rbp), %rdi
callq 0x7c90
movq -0x398(%rbp), %rdi
movq %rax, -0x400(%rbp)
callq 0x61e0
movq -0x400(%rbp), %rsi
movq %rax, %rdx
leaq 0xa5ac2(%rip), %rdi     # 0xb74ec
xorl %eax, %eax
callq 0x6050
jmp 0x11a33
movq -0x388(%rbp), %rax
testb $0x1, 0x78(%rax)
je 0x11bf0
movq -0x388(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x418(%rbp)
xorl %eax, %eax
movl %eax, -0x404(%rbp)
movl %eax, %esi
callq 0x15d30
movq %rax, %rdi
callq 0x7c90
movq -0x418(%rbp), %rdi
movq %rax, -0x410(%rbp)
callq 0x15d80
movq -0x410(%rbp), %rsi
movq %rax, %rdx
movl -0x404(%rbp), %eax
leaq 0xa5a7c(%rip), %rdi     # 0xb7513
callq 0x6050
jmp 0x11a9e
movq -0x28(%rbp), %rax
movq %rax, -0x348(%rbp)
movq -0x348(%rbp), %rdi
callq 0x15830
movq %rax, -0x350(%rbp)
movq -0x348(%rbp), %rdi
callq 0x15860
movq %rax, -0x358(%rbp)
leaq -0x350(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x15f10
testb $0x1, %al
jne 0x11aeb
jmp 0x11bd9
leaq -0x350(%rbp), %rdi
callq 0x15f50
movq %rax, %rsi
leaq -0x378(%rbp), %rdi
callq 0x6200
jmp 0x11b08
leaq 0xa5f82(%rip), %rsi     # 0xb7a91
leaq -0x378(%rbp), %rdi
callq 0x15f70
movb %al, -0x419(%rbp)
jmp 0x11b23
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x11b32
jmp 0x11bbc
leaq -0x378(%rbp), %rdi
callq 0x61e0
movq %rax, %rsi
leaq 0xa5a02(%rip), %rdi     # 0xb754a
xorl %eax, %eax
callq 0x6050
jmp 0x11b51
movq -0x28(%rbp), %rdi
callq 0x15fd0
movq %rax, %rsi
leaq -0x378(%rbp), %rdi
callq 0x15fa0
testb $0x1, %al
jne 0x11b6f
jmp 0x11b86
movq 0x108422(%rip), %rdi    # 0x119f98
leaq 0xba4c7(%rip), %rsi     # 0xcc044
callq 0x64f0
jmp 0x11b84
jmp 0x11b9d
movq 0x10840b(%rip), %rdi    # 0x119f98
leaq 0xa5a72(%rip), %rsi     # 0xb7606
callq 0x64f0
jmp 0x11b9b
jmp 0x11b9d
jmp 0x11bbc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x6948
jmp 0x11c47
leaq -0x378(%rbp), %rdi
callq 0x6948
leaq -0x350(%rbp), %rdi
callq 0x16010
jmp 0x11acf
movq 0x1083b8(%rip), %rdi    # 0x119f98
movq 0x108331(%rip), %rsi    # 0x119f18
callq 0x6530
jmp 0x11bee
jmp 0x11bf0
movq -0x390(%rbp), %rdi
leaq 0xa58ea(%rip), %rsi     # 0xb74e8
callq 0x15d50
movb %al, -0x41a(%rbp)
jmp 0x11c0b
movb -0x41a(%rbp), %al
testb $0x1, %al
jne 0x11c17
jmp 0x11c29
leaq 0xa5931(%rip), %rdi     # 0xb754f
xorl %eax, %eax
callq 0x6050
jmp 0x11c27
jmp 0x11c29
leaq -0x2b0(%rbp), %rdi
callq 0x6130
leaq -0x40(%rbp), %rdi
callq 0x16030
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
leaq -0x2b0(%rbp), %rdi
callq 0x6130
leaq -0x40(%rbp), %rdi
callq 0x16030
movq -0x60(%rbp), %rdi
callq 0x6830
nopw %cs:(%rax,%rax)