// File: atfrank[P]PCASA/lib/Trajectory.cpp
// Function: Trajectory::writeFrame(std::basic_ofstream<char, std::char_traits<char>>&, Trajectory*)
void Trajectory::writeFrame(std::ofstream &trjout, Trajectory *ftrjin){
  double *dbuffer;
  float *xbuffer;
  float *ybuffer;
  float *zbuffer;
  unsigned int i;
  int length;
  Molecule *mol;

  //crystal
  if (this->getQCrystal() > 0){
    double pbc[ftrjin->pb.size()];
    for(i=0; i< ftrjin->pb.size(); i++){
      pbc[i]=ftrjin->pb.at(i);
    }
    dbuffer=&pbc[0];
    length=sizeof(double)*ftrjin->pb.size();
    writeFortran(trjout, dbuffer, length);
  }

  if (this->getMolecule() == NULL){
    float x[ftrjin->x.size()];
    float y[ftrjin->y.size()];
    float z[ftrjin->z.size()];

    for(i=0; i< ftrjin->x.size(); i++){
      x[i]=ftrjin->x.at(i);
      y[i]=ftrjin->y.at(i);
      z[i]=ftrjin->z.at(i);
    } 

    length=sizeof(float)*ftrjin->x.size();

    xbuffer=&x[0];
    ybuffer=&y[0];
    zbuffer=&z[0];

    writeFortran(trjout, xbuffer, length);
    writeFortran(trjout, ybuffer, length);
    writeFortran(trjout, zbuffer, length);
  
  }
  else{
    mol=this->getMolecule();
    float x[mol->getNAtom()];
    float y[mol->getNAtom()];
    float z[mol->getNAtom()];

    for(i=0; i< mol->getNAtom(); i++){
      x[i]=mol->getAtom(i)->getX();
      y[i]=mol->getAtom(i)->getY();
      z[i]=mol->getAtom(i)->getZ();
    }

    length=sizeof(float)*mol->getNAtom();

    xbuffer=&x[0];
    ybuffer=&y[0];
    zbuffer=&z[0];

    writeFortran(trjout, xbuffer, length);
    writeFortran(trjout, ybuffer, length);
    writeFortran(trjout, zbuffer, length);

  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x72750
cmpl $0x0, %eax
jle 0x741f4
movq -0x18(%rbp), %rdi
addq $0xe8, %rdi
callq 0x17a60
movq %rax, %rcx
movq %rcx, %rax
movq %rsp, %rdx
movq %rdx, -0x50(%rbp)
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
addq $0xe8, %rdi
callq 0x17a60
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x741b3
movq -0x18(%rbp), %rdi
addq $0xe8, %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x16f90
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movsd (%rcx), %xmm0
movl -0x3c(%rbp), %ecx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x74154
movq -0xa8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0xe8, %rdi
callq 0x17a60
movq -0xa0(%rbp), %rdi
shlq $0x3, %rax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74ee0
movq -0x50(%rbp), %rax
movq %rax, %rsp
movq -0xa0(%rbp), %rdi
callq 0x745f0
cmpq $0x0, %rax
jne 0x743f9
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x412e0
movq %rsp, %rcx
movq %rcx, -0x60(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x412e0
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
callq 0x412e0
movq %rax, %rcx
movq %rcx, %rax
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x412e0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
jae 0x7436a
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x75210
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movss (%rcx), %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x18(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x75210
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movss (%rcx), %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x18(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
movl -0x3c(%rbp), %eax
movl %eax, %esi
callq 0x75210
movq %rax, %rcx
movq -0xb8(%rbp), %rax
movss (%rcx), %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x742ae
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x412e0
movq -0xc8(%rbp), %rdx
movq -0xc0(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
movq -0xb8(%rbp), %rax
shlq $0x2, %rsi
movl %esi, -0x40(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0x60(%rbp), %rax
movq %rax, %rsp
jmp 0x745e2
movq -0xa0(%rbp), %rdi
callq 0x745f0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x44a80
movl %eax, %eax
movq %rsp, %rcx
movq %rcx, -0x80(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xe8(%rbp)
movq %rcx, %rsp
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rdi
callq 0x44a80
movl %eax, %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xe0(%rbp)
movq %rcx, %rsp
movq %rax, -0x90(%rbp)
movq -0x48(%rbp), %rdi
callq 0x44a80
movl %eax, %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xd8(%rbp)
movq %rcx, %rsp
movq %rax, -0x98(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xec(%rbp)
movq -0x48(%rbp), %rdi
callq 0x44a80
movl %eax, %ecx
movl -0xec(%rbp), %eax
cmpl %ecx, %eax
jae 0x7455e
movq -0x48(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x43580
movq %rax, %rdi
callq 0x1fa60
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movsd (%rcx), %xmm0
cvtsd2ss %xmm0, %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x43580
movq %rax, %rdi
callq 0x1fa80
movq %rax, %rcx
movq -0xe0(%rbp), %rax
movsd (%rcx), %xmm0
cvtsd2ss %xmm0, %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x43580
movq %rax, %rdi
callq 0x1faa0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movsd (%rcx), %xmm0
cvtsd2ss %xmm0, %xmm0
movl -0x3c(%rbp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x744a1
movq -0x48(%rbp), %rdi
callq 0x44a80
movq -0xe8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
movq -0xa0(%rbp), %rdi
movl %eax, %esi
movq -0xd8(%rbp), %rax
movl %esi, %esi
shlq $0x2, %rsi
movl %esi, -0x40(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x74f40
movq -0x80(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)