// File: Luthaf[P]zeopp/networkio.cc
// Function: writeToV1(char*, ATOM_NETWORK*)
bool writeToV1(char * filename, ATOM_NETWORK *cell){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .v1 output file " << filename << endl;
    //cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout << "Writing atom network information to " << filename << "\n";

    // Write information about the unit cell
    output << "Unit cell vectors:" << "\n";
    output.precision(8);
    output << "va= " << cell->v_a.x << " " << cell->v_a.y << " " << cell->v_a.z << "\n";
    output << "vb= " << cell->v_b.x << " " << cell->v_b.y << " " << cell->v_b.z << "\n";
    output << "vc= " << cell->v_c.x << " " << cell->v_c.y << " " << cell->v_c.z << "\n";
    output << cell->numAtoms << "\n";

    // Write information about each atom
    vector <ATOM> ::iterator iter = cell->atoms.begin();
    while(iter != cell->atoms.end()){
      output << iter->type << " " << iter->x << " " << iter->y << " " << iter->z << "\n";
      iter++;
    }
  }
  output.close();
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x228(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x5660
movq -0x258(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x10, %edx
callq 0x54b0
jmp 0x561cd
leaq -0x228(%rbp), %rdi
callq 0x58b0
movb %al, -0x259(%rbp)
jmp 0x561e1
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x56271
jmp 0x561f1
movq 0x21cdf8(%rip), %rdi    # 0x272ff0
leaq 0x19d60a(%rip), %rsi    # 0x1f3809
callq 0x5540
movq %rax, -0x268(%rbp)
jmp 0x5620d
movq -0x268(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x270(%rbp)
jmp 0x56226
movq -0x270(%rbp), %rdi
movq 0x21cd64(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0x5623b
movb $0x0, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
jmp 0x5671a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5150
jmp 0x56734
movq 0x21cd48(%rip), %rdi    # 0x272fc0
leaq 0x19d324(%rip), %rsi    # 0x1f35a3
callq 0x5540
movq %rax, -0x278(%rbp)
jmp 0x5628d
movq -0x278(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x280(%rbp)
jmp 0x562a6
movq -0x280(%rbp), %rdi
leaq 0x1a3371(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x562bb
leaq -0x218(%rbp), %rdi
leaq 0x19d567(%rip), %rsi    # 0x1f3830
callq 0x5540
movq %rax, -0x288(%rbp)
jmp 0x562d7
movq -0x288(%rbp), %rdi
leaq 0x1a3340(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x562ec
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
movl $0x8, %esi
callq 0xf930
jmp 0x5630b
leaq -0x218(%rbp), %rdi
leaq 0x19d52a(%rip), %rsi    # 0x1f3843
callq 0x5540
movq %rax, -0x290(%rbp)
jmp 0x56327
movq -0x290(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x38(%rax), %xmm0
callq 0x5980
movq %rax, -0x298(%rbp)
jmp 0x56345
movq -0x298(%rbp), %rdi
leaq 0x1a5f5b(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2a0(%rbp)
jmp 0x56361
movq -0x2a0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x40(%rax), %xmm0
callq 0x5980
movq %rax, -0x2a8(%rbp)
jmp 0x5637f
movq -0x2a8(%rbp), %rdi
leaq 0x1a5f21(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2b0(%rbp)
jmp 0x5639b
movq -0x2b0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x48(%rax), %xmm0
callq 0x5980
movq %rax, -0x2b8(%rbp)
jmp 0x563b9
movq -0x2b8(%rbp), %rdi
leaq 0x1a325e(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x563ce
leaq -0x218(%rbp), %rdi
leaq 0x19d46c(%rip), %rsi    # 0x1f3848
callq 0x5540
movq %rax, -0x2c0(%rbp)
jmp 0x563ea
movq -0x2c0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x50(%rax), %xmm0
callq 0x5980
movq %rax, -0x2c8(%rbp)
jmp 0x56408
movq -0x2c8(%rbp), %rdi
leaq 0x1a5e98(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2d0(%rbp)
jmp 0x56424
movq -0x2d0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x58(%rax), %xmm0
callq 0x5980
movq %rax, -0x2d8(%rbp)
jmp 0x56442
movq -0x2d8(%rbp), %rdi
leaq 0x1a5e5e(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x2e0(%rbp)
jmp 0x5645e
movq -0x2e0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x60(%rax), %xmm0
callq 0x5980
movq %rax, -0x2e8(%rbp)
jmp 0x5647c
movq -0x2e8(%rbp), %rdi
leaq 0x1a319b(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56491
leaq -0x218(%rbp), %rdi
leaq 0x19d3ae(%rip), %rsi    # 0x1f384d
callq 0x5540
movq %rax, -0x2f0(%rbp)
jmp 0x564ad
movq -0x2f0(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
callq 0x5980
movq %rax, -0x2f8(%rbp)
jmp 0x564cb
movq -0x2f8(%rbp), %rdi
leaq 0x1a5dd5(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x300(%rbp)
jmp 0x564e7
movq -0x300(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x70(%rax), %xmm0
callq 0x5980
movq %rax, -0x308(%rbp)
jmp 0x56505
movq -0x308(%rbp), %rdi
leaq 0x1a5d9b(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x310(%rbp)
jmp 0x56521
movq -0x310(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x78(%rax), %xmm0
callq 0x5980
movq %rax, -0x318(%rbp)
jmp 0x5653f
movq -0x318(%rbp), %rdi
leaq 0x1a30d8(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56554
leaq -0x218(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x110(%rax), %esi
callq 0x58d0
movq %rax, -0x320(%rbp)
jmp 0x56573
movq -0x320(%rbp), %rdi
leaq 0x1a30a4(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x56588
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd0f0
movq %rax, -0x240(%rbp)
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
callq 0xd160
movq %rax, -0x248(%rbp)
leaq -0x240(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0xd120
testb $0x1, %al
jne 0x565d2
jmp 0x566fc
leaq -0x218(%rbp), %rax
movq %rax, -0x330(%rbp)
leaq -0x240(%rbp), %rdi
callq 0xd190
movq -0x330(%rbp), %rdi
movq %rax, %rsi
addq $0x40, %rsi
callq 0x5480
movq %rax, -0x328(%rbp)
jmp 0x56608
movq -0x328(%rbp), %rdi
leaq 0x1a5c98(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x338(%rbp)
jmp 0x56624
leaq -0x240(%rbp), %rdi
callq 0xd190
movq -0x338(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x5980
movq %rax, -0x340(%rbp)
jmp 0x56649
movq -0x340(%rbp), %rdi
leaq 0x1a5c57(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x348(%rbp)
jmp 0x56665
leaq -0x240(%rbp), %rdi
callq 0xd190
movq -0x348(%rbp), %rdi
movsd 0x8(%rax), %xmm0
callq 0x5980
movq %rax, -0x350(%rbp)
jmp 0x5668b
movq -0x350(%rbp), %rdi
leaq 0x1a5c15(%rip), %rsi    # 0x1fc2ae
callq 0x5540
movq %rax, -0x358(%rbp)
jmp 0x566a7
leaq -0x240(%rbp), %rdi
callq 0xd190
movq -0x358(%rbp), %rdi
movsd 0x10(%rax), %xmm0
callq 0x5980
movq %rax, -0x360(%rbp)
jmp 0x566cd
movq -0x360(%rbp), %rdi
leaq 0x1a2f4a(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x566e2
leaq -0x240(%rbp), %rdi
xorl %esi, %esi
callq 0xd220
movq %rax, -0x250(%rbp)
jmp 0x5659f
jmp 0x566fe
leaq -0x228(%rbp), %rdi
callq 0x50a0
jmp 0x5670c
movb $0x1, -0x1(%rbp)
movl $0x1, -0x238(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
movq -0x230(%rbp), %rdi
callq 0x58f0