// File: joraso[P]Glassius/Integration.cpp
// Function: Integrator::Run(double)
void Integrator::Run(double t){
    /* Advanced the integration for time=t. Records into an energy file AND a 
    trajectory file as it does. Does not themostate the system. */
    
    // Cycling indeces
    int m, n; int steps = int(t/dt);
    int cycles = int(steps/Nrecord);
    
    // Retrieving the system time
    time = System->Time();
    
    // Prepping output file
    std::ofstream energyfile;
    energyfile.open(efilename, std::ios::app);
    
    // File check-stop
    if(!energyfile.is_open()){
        cout << "Error opening energy file!" << endl;
        exit(1);
    }
    
    // Integrating
    for(m=0;m<cycles;m++){
        for(n=0;n<Nrecord;n++){Propigate();}
        energyfile << time << ", ";
        energyfile << System->KE() << ", ";
        energyfile << System->PE() << ", ";
        energyfile << System->TotalEnergy() << std::endl;
        if (recordtraj) {System->SaveTrajectory();};
    }
    
    // Closing the energy file
    energyfile.close();
    
    // Storing the system time
    System->setTime(time);
    
    return;
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x280(%rsp)
movsd %xmm0, 0x278(%rsp)
movq 0x280(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movsd 0x278(%rsp), %xmm0
movsd 0x18(%rcx), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x26c(%rsp)
movl 0x26c(%rsp), %eax
movl 0x28(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x268(%rsp)
movq 0x8(%rax), %rdi
callq 0x5d00
movq 0x48(%rsp), %rax
movsd %xmm0, 0x20(%rax)
leaq 0x68(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x21e0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdi
addq $0x30, %rsi
movl $0x1, %edx
callq 0x20a0
jmp 0x52c9
leaq 0x68(%rsp), %rdi
callq 0x20e0
movb %al, 0x47(%rsp)
jmp 0x52d9
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x5337
jmp 0x52e3
movq 0x6ce6(%rip), %rdi      # 0xbfd0
leaq 0x3f18(%rip), %rsi      # 0x9209
callq 0x2140
movq %rax, 0x38(%rsp)
jmp 0x52fd
movq 0x38(%rsp), %rdi
movq 0x6caf(%rip), %rsi      # 0xbfb8
callq 0x2150
jmp 0x5310
movl $0x1, %edi
callq 0x2170
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x21c0
jmp 0x54eb
movl $0x0, 0x274(%rsp)
movl 0x274(%rsp), %eax
cmpl 0x268(%rsp), %eax
jge 0x54b8
movl $0x0, 0x270(%rsp)
movq 0x48(%rsp), %rcx
movl 0x270(%rsp), %eax
cmpl 0x28(%rcx), %eax
jge 0x5397
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x5382
jmp 0x5384
movl 0x270(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x270(%rsp)
jmp 0x5361
movq 0x48(%rsp), %rax
movsd 0x20(%rax), %xmm0
leaq 0x68(%rsp), %rdi
callq 0x2240
movq %rax, 0x30(%rsp)
jmp 0x53b2
movq 0x30(%rsp), %rdi
leaq 0x3e66(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x53c5
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d10
movsd %xmm0, 0x28(%rsp)
jmp 0x53db
movsd 0x28(%rsp), %xmm0
leaq 0x68(%rsp), %rdi
callq 0x2240
movq %rax, 0x20(%rsp)
jmp 0x53f2
movq 0x20(%rsp), %rdi
leaq 0x3e26(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x5405
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d40
movsd %xmm0, 0x18(%rsp)
jmp 0x541b
movsd 0x18(%rsp), %xmm0
leaq 0x68(%rsp), %rdi
callq 0x2240
movq %rax, 0x10(%rsp)
jmp 0x5432
movq 0x10(%rsp), %rdi
leaq 0x3de6(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x5445
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d60
movsd %xmm0, 0x8(%rsp)
jmp 0x545b
movsd 0x8(%rsp), %xmm0
leaq 0x68(%rsp), %rdi
callq 0x2240
movq %rax, (%rsp)
jmp 0x5471
movq (%rsp), %rdi
movq 0x6b3c(%rip), %rsi      # 0xbfb8
callq 0x2150
jmp 0x5483
movq 0x48(%rsp), %rax
testb $0x1, 0x50(%rax)
je 0x54a0
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3cf0
jmp 0x549e
jmp 0x54a0
jmp 0x54a2
movl 0x274(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x274(%rsp)
jmp 0x5342
leaq 0x68(%rsp), %rdi
callq 0x21a0
jmp 0x54c4
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rdi
movsd 0x20(%rax), %xmm0
callq 0x5d80
jmp 0x54d9
leaq 0x68(%rsp), %rdi
callq 0x21c0
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x60(%rsp), %rdi
callq 0x2210
nopw %cs:(%rax,%rax)