// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
pushq $0x2
popq %rdx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x4420
movq %r15, %rdi
callq 0x4530
movq %rax, 0x48(%rbx)
movq %rdx, 0x50(%rbx)
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4420
leaq 0x49b6(%rip), %rsi      # 0x2e502
movq %rbx, %rdi
callq 0x4100
testl %eax, %eax
je 0x29b75
leaq 0x5429(%rip), %rsi      # 0x2ef88
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4100
xorl %r14d, %r14d
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x2b80a
movq %rax, %r13
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
leaq 0x58(%rbx), %rdi
pushq $0x4
popq %rdx
movq %r13, %rsi
callq 0x4400
movl 0x4(%r13), %eax
movl %eax, 0x78(%rbx)
movl 0x8(%r13), %eax
movl %eax, 0x7c(%rbx)
movl 0xc(%r13), %eax
movl %eax, 0x80(%rbx)
movl 0x10(%r13), %eax
movl %eax, 0x84(%rbx)
movl 0x14(%r13), %eax
movl %eax, 0x88(%rbx)
testl %eax, %eax
jle 0x29bf9
movq 0x3bb40b(%rip), %rdi    # 0x3e4ff0
leaq 0x531e(%rip), %rsi      # 0x2ef0a
callq 0x4300
movq %rax, %rdi
callq 0x4180
movl 0x20(%r13), %eax
movl %eax, 0x90(%rbx)
movl 0x24(%r13), %eax
movl %eax, 0x94(%rbx)
movss 0x28(%r13), %xmm0
movss %xmm0, 0x98(%rbx)
movl 0x2c(%r13), %eax
movl %eax, 0x9c(%rbx)
movl 0x30(%r13), %eax
movl %eax, 0xa0(%rbx)
movl 0x34(%r13), %eax
movl %eax, 0xa4(%rbx)
movl 0x38(%r13), %eax
movl %eax, 0xa8(%rbx)
movl 0x50(%r13), %eax
movl %eax, 0xac(%rbx)
pushq $0x4
popq %rsi
movq %r13, 0x18(%rsp)
movq %r13, %rdi
callq 0x4330
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r15, 0x20(%rsp)
movq %r15, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x2b9f0
movq %rax, %rbp
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
movsbq (%rbp), %r12
leaq 0xb0(%rbx), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1707a
movq %rbp, 0x10(%rsp)
addq $0x4, %rbp
testb %r12b, %r12b
cmovlel %r14d, %r12d
movzbl %r12b, %r15d
shll $0x5, %r15d
pushq $0x50
popq %r12
cmpq %r14, %r15
je 0x29cdd
movq (%r13), %rdi
addq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x4400
addq $0x20, %r14
addq $0x50, %rbp
jmp 0x29cbc
pushq $0x1
popq %rsi
movq 0x10(%rsp), %rdi
callq 0x4330
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rcx
callq 0x2b80a
movq %rax, %r15
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
movl (%r15), %eax
movl %eax, 0xc8(%rbx)
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x29d53
callq 0x1b6a8
cmpl 0xc8(%rbx), %eax
je 0x29d53
movq 0x3bb2b1(%rip), %rdi    # 0x3e4ff0
leaq 0x51f6(%rip), %rsi      # 0x2ef3c
callq 0x4300
movq %rax, %rdi
callq 0x4180
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x4330
cmpl $0x0, 0x94(%rbx)
jle 0x29dba
leaq 0xc(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2b80a
movq %rax, %r14
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
movq 0x3bb25a(%rip), %rdi    # 0x3e4ff0
leaq 0x51bc(%rip), %rsi      # 0x2ef59
callq 0x4300
movq %rax, %rdi
callq 0x4180
testq %r14, %r14
je 0x29dba
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x4330
cmpb $0x1, 0x30(%rbx)
jne 0x29dc8
movq %rbx, %rdi
callq 0x29dee
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop