// File: atfrank[P]PCASA/lib/Trajectory.cpp
// Function: Trajectory::readHeader(std::basic_ifstream<char, std::char_traits<char>>&)
void Trajectory::readHeader(std::ifstream &trjin){
  binbuf *buffer;
  char *cbuffer;
  int length;
  int i;

  buffer=NULL;
  cbuffer=NULL;

  trjin.seekg(0, std::ios::end);
  this->setLastPos(trjin.tellg());

  trjin.seekg(0, std::ios::beg);

  if (format.compare("CHARMM") == 0){
    buffer=readFortran(trjin, buffer, length);
    this->setHdrSize(this->getHdrSize()+length+sizeof(int)*2);

    //HDR
    hdr.assign(buffer[0].c,4);

    //ICNTRL 1-20
    nframe=buffer[1].i;
    npriv=buffer[2].i;
    nsavc=buffer[3].i;
    nstep=buffer[4].i;
    qvelocity=buffer[5].i;
    if (qvelocity > 0){
      std::cerr << "Error: Velocity reading has yet to be implemented" << std::endl;
    }
  
    dof=buffer[8].i;
    nfixed=buffer[9].i;
  
    tstep=buffer[10].f;
    
    qcrystal=buffer[11].i;
    q4d=buffer[12].i;
    qcharge=buffer[13].i;
    qcheck=buffer[14].i;
    
    version=buffer[20].i;

    if (buffer != NULL){
      delete buffer;
    }

    //Title
    cbuffer=readFortran(trjin, cbuffer, length);
    this->setHdrSize(this->getHdrSize()+length+sizeof(int)*2);
    int ntitle=cbuffer[0];
    title.resize(ntitle);
    for (i=0; i< ntitle; i++){
      title[i].assign(cbuffer+sizeof(int)+i*80,80);
    }

    if (cbuffer != NULL){
      delete cbuffer;
    }
    

    //NATOM
    buffer=readFortran(trjin, buffer, length);
    this->setHdrSize(this->getHdrSize()+length+sizeof(int)*2);
    natom=buffer[0].i;
    if (mol != NULL && static_cast<int>(mol->getNAtom()) != natom){
      std::cerr << "Error: Atom number mismatch!" << std::endl;
    }

    if (buffer != NULL){
      delete buffer;
    }

    //FIXED
    if (nfixed > 0){
      buffer=readFortran(trjin, buffer, length);
      this->setHdrSize(this->getHdrSize()+length+sizeof(int)*2);
      std::cerr << "Warning: Fixed atoms has yet to be implemented" << std::endl;
      //for (i=0; i< length; i++){
      //  std::cerr << buffer[i].i << ":";
      //  fixinx.push_back(buffer[i].i);
      //}

      if (buffer != NULL){
        delete buffer;
      }
    }

    if (this->getShow() == true){
      this->showHeader();
    } 
  }
  else if (format.compare("AMBER") == 0){
    
  }
  else{
    //Do nothing
  }

}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x68(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x55e0
movq 0x68(%rsp), %rdi
callq 0x5700
movq 0x20(%rsp), %rdi
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
leaq 0x40(%rsp), %rsi
callq 0x71ab0
movq 0x68(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x55e0
movq 0x20(%rsp), %rdi
leaq 0xae3a(%rip), %rsi      # 0x7c4d6
callq 0x5140
cmpl $0x0, %eax
jne 0x71a84
movq 0x20(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x74b20
movq 0x20(%rsp), %rdi
movq %rax, 0x60(%rsp)
callq 0x71b00
movq 0x20(%rsp), %rdi
addl 0x54(%rsp), %eax
movl %eax, %eax
addq $0x8, %rax
movl %eax, 0x3c(%rsp)
leaq 0x3c(%rsp), %rsi
callq 0x71ae0
movq 0x20(%rsp), %rdi
addq $0x58, %rdi
movq 0x60(%rsp), %rsi
movl $0x4, %edx
callq 0x55c0
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %rcx
movl 0x4(%rcx), %ecx
movl %ecx, 0x78(%rax)
movq 0x60(%rsp), %rcx
movl 0x8(%rcx), %ecx
movl %ecx, 0x7c(%rax)
movq 0x60(%rsp), %rcx
movl 0xc(%rcx), %ecx
movl %ecx, 0x80(%rax)
movq 0x60(%rsp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x84(%rax)
movq 0x60(%rsp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x88(%rax)
cmpl $0x0, 0x88(%rax)
jle 0x71777
movq 0x3c9894(%rip), %rdi    # 0x43aff0
leaq 0xb75f(%rip), %rsi      # 0x7cec2
callq 0x53f0
movq %rax, %rdi
movq 0x3c9836(%rip), %rsi    # 0x43afa8
callq 0x5460
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %rcx
movl 0x20(%rcx), %ecx
movl %ecx, 0x90(%rax)
movq 0x60(%rsp), %rcx
movl 0x24(%rcx), %ecx
movl %ecx, 0x94(%rax)
movq 0x60(%rsp), %rcx
movss 0x28(%rcx), %xmm0
movss %xmm0, 0x98(%rax)
movq 0x60(%rsp), %rcx
movl 0x2c(%rcx), %ecx
movl %ecx, 0x9c(%rax)
movq 0x60(%rsp), %rcx
movl 0x30(%rcx), %ecx
movl %ecx, 0xa0(%rax)
movq 0x60(%rsp), %rcx
movl 0x34(%rcx), %ecx
movl %ecx, 0xa4(%rax)
movq 0x60(%rsp), %rcx
movl 0x38(%rcx), %ecx
movl %ecx, 0xa8(%rax)
movq 0x60(%rsp), %rcx
movl 0x50(%rcx), %ecx
movl %ecx, 0xac(%rax)
cmpq $0x0, 0x60(%rsp)
je 0x71819
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x71817
movq 0x18(%rsp), %rdi
movl $0x4, %esi
callq 0x5420
jmp 0x71819
movq 0x20(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x74dc0
movq 0x20(%rsp), %rdi
movq %rax, 0x58(%rsp)
callq 0x71b00
movq 0x20(%rsp), %rdi
addl 0x54(%rsp), %eax
movl %eax, %eax
addq $0x8, %rax
movl %eax, 0x38(%rsp)
leaq 0x38(%rsp), %rsi
callq 0x71ae0
movq 0x20(%rsp), %rdi
movq 0x58(%rsp), %rax
movsbl (%rax), %eax
movl %eax, 0x34(%rsp)
addq $0xb0, %rdi
movslq 0x34(%rsp), %rsi
callq 0x385d0
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x718d5
movq 0x20(%rsp), %rdi
addq $0xb0, %rdi
movslq 0x50(%rsp), %rsi
callq 0x9020
movq %rax, %rdi
movq 0x58(%rsp), %rsi
addq $0x4, %rsi
imull $0x50, 0x50(%rsp), %eax
cltq
addq %rax, %rsi
movl $0x50, %edx
callq 0x55c0
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x71888
cmpq $0x0, 0x58(%rsp)
je 0x718fe
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x718fc
movq 0x10(%rsp), %rdi
movl $0x1, %esi
callq 0x5420
jmp 0x718fe
movq 0x20(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x74b20
movq 0x20(%rsp), %rdi
movq %rax, 0x60(%rsp)
callq 0x71b00
movq 0x20(%rsp), %rdi
addl 0x54(%rsp), %eax
movl %eax, %eax
addq $0x8, %rax
movl %eax, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x71ae0
movq 0x20(%rsp), %rax
movq 0x60(%rsp), %rcx
movl (%rcx), %ecx
movl %ecx, 0xc8(%rax)
cmpq $0x0, 0x28(%rax)
je 0x71999
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0x44a80
movq 0x20(%rsp), %rcx
cmpl 0xc8(%rcx), %eax
je 0x71999
movq 0x3c9672(%rip), %rdi    # 0x43aff0
leaq 0xb56f(%rip), %rsi      # 0x7cef4
callq 0x53f0
movq %rax, %rdi
movq 0x3c9614(%rip), %rsi    # 0x43afa8
callq 0x5460
cmpq $0x0, 0x60(%rsp)
je 0x719c2
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x719c0
movq 0x8(%rsp), %rdi
movl $0x4, %esi
callq 0x5420
jmp 0x719c2
movq 0x20(%rsp), %rax
cmpl $0x0, 0x94(%rax)
jle 0x71a64
movq 0x20(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x54(%rsp), %rcx
callq 0x74b20
movq 0x20(%rsp), %rdi
movq %rax, 0x60(%rsp)
callq 0x71b00
movq 0x20(%rsp), %rdi
addl 0x54(%rsp), %eax
movl %eax, %eax
addq $0x8, %rax
movl %eax, 0x2c(%rsp)
leaq 0x2c(%rsp), %rsi
callq 0x71ae0
movq 0x3c95d0(%rip), %rdi    # 0x43aff0
leaq 0xb4ea(%rip), %rsi      # 0x7cf11
callq 0x53f0
movq %rax, %rdi
movq 0x3c9572(%rip), %rsi    # 0x43afa8
callq 0x5460
cmpq $0x0, 0x60(%rsp)
je 0x71a62
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x71a60
movq (%rsp), %rdi
movl $0x4, %esi
callq 0x5420
jmp 0x71a62
jmp 0x71a64
movq 0x20(%rsp), %rdi
callq 0x71b10
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x71a82
movq 0x20(%rsp), %rdi
callq 0x71b20
jmp 0x71aa0
movq 0x20(%rsp), %rdi
leaq 0xb4b0(%rip), %rsi      # 0x7cf40
callq 0x5140
cmpl $0x0, %eax
jne 0x71a9c
jmp 0x71a9e
jmp 0x71a9e
jmp 0x71aa0
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)