// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x43e0
movq %r14, %rdi
callq 0x4510
movq %rax, 0x48(%rbx)
movq %rdx, 0x50(%rbx)
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x43e0
leaq 0x4e04(%rip), %rsi      # 0x3c57a
movq %rbx, %rdi
callq 0x40e0
testl %eax, %eax
je 0x3779f
leaq 0x58bf(%rip), %rsi      # 0x3d048
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40e0
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x399d6
movq %rax, %r15
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
leaq 0x58(%rbx), %rdi
movq 0x60(%rbx), %rdx
movl $0x4, %r8d
xorl %esi, %esi
movq %r15, %rcx
callq 0x4470
movl 0x4(%r15), %eax
movl %eax, 0x78(%rbx)
movl 0x8(%r15), %eax
movl %eax, 0x7c(%rbx)
movl 0xc(%r15), %eax
movl %eax, 0x80(%rbx)
movl 0x10(%r15), %eax
movl %eax, 0x84(%rbx)
movl 0x14(%r15), %eax
movl %eax, 0x88(%rbx)
testl %eax, %eax
jle 0x37851
movq 0x3b87db(%rip), %r12    # 0x3efff0
leaq 0x57ae(%rip), %rsi      # 0x3cfca
movl $0x31, %edx
movq %r12, %rdi
callq 0x4340
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl 0x20(%r15), %eax
movl %eax, 0x90(%rbx)
movl 0x24(%r15), %eax
movl %eax, 0x94(%rbx)
movss 0x28(%r15), %xmm0
movss %xmm0, 0x98(%rbx)
movl 0x2c(%r15), %eax
movl %eax, 0x9c(%rbx)
movl 0x30(%r15), %eax
movl %eax, 0xa0(%rbx)
movl 0x34(%r15), %eax
movl %eax, 0xa4(%rbx)
movl 0x38(%r15), %eax
movl %eax, 0xa8(%rbx)
movl 0x50(%r15), %eax
movl %eax, 0xac(%rbx)
movl $0x4, %esi
movq %r15, %rdi
callq 0x42e0
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movq %r14, 0x10(%rsp)
movq %r14, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x39bd4
movl 0x38(%rbx), %edx
movl (%r12), %ecx
addl %edx, %ecx
addl $0x8, %ecx
movl %ecx, 0x38(%rbx)
movq %rax, 0x8(%rsp)
movsbq (%rax), %r13
leaq 0xb0(%rbx), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1fc0e
testq %r13, %r13
jle 0x37934
movq 0x8(%rsp), %r12
addq $0x4, %r12
shlq $0x5, %r13
xorl %r14d, %r14d
movq (%rbp), %rdi
movq 0x8(%rdi,%r14), %rdx
addq %r14, %rdi
movl $0x50, %r8d
xorl %esi, %esi
movq %r12, %rcx
callq 0x4470
addq $0x50, %r12
addq $0x20, %r14
cmpq %r14, %r13
jne 0x3790b
movl $0x1, %esi
movq 0x8(%rsp), %rdi
callq 0x42e0
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x399d6
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 0x379d2
callq 0x2557c
cmpl 0xc8(%rbx), %eax
je 0x379d2
movq 0x3b865a(%rip), %r12    # 0x3efff0
leaq 0x565f(%rip), %rsi      # 0x3cffc
movl $0x1c, %edx
movq %r12, %rdi
callq 0x4340
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl $0x4, %esi
movq %r15, %rdi
callq 0x42e0
cmpl $0x0, 0x94(%rbx)
jle 0x37a64
leaq 0x4(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x399d6
movq %rax, %r14
movl 0x38(%rbx), %eax
movl (%r12), %ecx
addl %ecx, %eax
addl $0x8, %eax
movl %eax, 0x38(%rbx)
movq 0x3b85d9(%rip), %r15    # 0x3efff0
leaq 0x55fb(%rip), %rsi      # 0x3d019
movl $0x2e, %edx
movq %r15, %rdi
callq 0x4340
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x42a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
testq %r14, %r14
je 0x37a64
movl $0x4, %esi
movq %r14, %rdi
callq 0x42e0
cmpb $0x1, 0x30(%rbx)
jne 0x37a72
movq %rbx, %rdi
callq 0x37a98
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop