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

    //For each corner in abc, get the coords in xyz
    vector<Point> corners; Point p;
    p = cell->abc_to_xyz(0, 0, 0); corners.push_back(p);
    p = cell->abc_to_xyz(0, 0, 1); corners.push_back(p);
    p = cell->abc_to_xyz(0, 1, 0); corners.push_back(p);
    p = cell->abc_to_xyz(0, 1, 1); corners.push_back(p);
    p = cell->abc_to_xyz(1, 0, 0); corners.push_back(p);
    p = cell->abc_to_xyz(1, 0, 1); corners.push_back(p);
    p = cell->abc_to_xyz(1, 1, 0); corners.push_back(p);
    p = cell->abc_to_xyz(1, 1, 1); corners.push_back(p);
    // Write header, information about the cell, and footer
    output << "# vtk DataFile Version 2.0\nvtk format representation of unit cell boundary\nASCII\nDATASET POLYDATA\nPOINTS 8 double\n";
    for(int i=0; i<8; i++) output << corners.at(i)[0] << " " << corners.at(i)[1] << " " << corners.at(i)[2] << "\n";
    output << "LINES 12 36\n2 0 1\n2 0 2\n2 1 3\n2 2 3\n2 4 5\n2 4 6\n2 5 7\n2 6 7\n2 0 4\n2 1 5\n2 2 6\n2 3 7\n";
  }
  output.close();
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x4540
pushq $0x10
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4410
leaq 0xd8(%rsp), %rdi
callq 0x4130
movb %al, 0x7(%rsp)
testb %al, %al
je 0x23e64
movq 0x12c43f(%rip), %rdi    # 0x14ffc0
leaq 0xd9bb5(%rip), %rsi     # 0xfd73d
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0xde9df(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x63c46
leaq 0x8(%rsp), %rdi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r14, %rsi
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd844d(%rip), %xmm2    # 0xfc058
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r14, %rsi
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd8412(%rip), %xmm1    # 0xfc058
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
movq %r14, %rsi
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd83d7(%rip), %xmm1    # 0xfc058
xorps %xmm0, %xmm0
movq %r14, %rsi
movaps %xmm1, %xmm2
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd839c(%rip), %xmm0    # 0xfc058
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r14, %rsi
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd8361(%rip), %xmm0    # 0xfc058
xorps %xmm1, %xmm1
movq %r14, %rsi
movaps %xmm0, %xmm2
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd8326(%rip), %xmm0    # 0xfc058
xorps %xmm2, %xmm2
movq %r14, %rsi
movaps %xmm0, %xmm1
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x8(%rsp), %rdi
movsd 0xd82eb(%rip), %xmm0    # 0xfc058
movq %r14, %rsi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x3f0e6
movq 0x18(%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, 0x10(%rsi)
movups 0x8(%rsp), %xmm0
movaps %xmm0, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2468e
leaq 0x68(%rsp), %rdi
leaq 0xd99b8(%rip), %rsi     # 0xfd75f
callq 0x4480
xorl %r15d, %r15d
leaq 0x20(%rsp), %r12
leaq 0xe0757(%rip), %r13     # 0x104512
pushq $0x2
popq %rbx
leaq 0xde7b9(%rip), %r14     # 0x10257e
cmpq $0x8, %r15
je 0x23e8c
movq %r12, %rdi
movq %r15, %rsi
callq 0x246b4
movq %rax, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
leaq 0x68(%rsp), %rdi
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movq %rax, %rbp
movq %r12, %rdi
movq %r15, %rsi
callq 0x246b4
movq %rax, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbp, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x4480
movq %rax, %rbp
movq %r12, %rdi
movq %r15, %rsi
callq 0x246b4
movq %rax, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbp, %rdi
callq 0x46c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x4480
incq %r15
jmp 0x23dc5
movq 0x12c185(%rip), %rdi    # 0x14fff0
leaq 0xd98a3(%rip), %rsi     # 0xfd715
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movq %rax, %rdi
callq 0x4230
jmp 0x23eb1
leaq 0xd993f(%rip), %rsi     # 0xfd7d2
leaq 0x68(%rsp), %rdi
callq 0x4480
leaq 0x20(%rsp), %rdi
callq 0xb83e
leaq 0x58(%rsp), %rdi
callq 0x4080
leaq 0x58(%rsp), %rdi
callq 0x4120
movb 0x7(%rsp), %al
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
jmp 0x23ee8
movq %rax, %rbx
jmp 0x23ef5
jmp 0x23ee8
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xb83e
leaq 0x58(%rsp), %rdi
callq 0x4120
movq %rbx, %rdi
callq 0x4780