// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkio.cc
// Function: writeToCIF(char*, ATOM_NETWORK*)
bool writeToCIF(char *filename,  ATOM_NETWORK *cell){
  fstream output;
  output.open(filename, fstream::out);
  if(!output.is_open()){
    cerr << "Error: Failed to open .cif output file " << filename << endl;
	//cerr << "Exiting ..." << "\n";
    //exit(1);
    return false;
  }
  else{
    cout   << "Writing atom network information to " << filename << "\n";
    //output << "data_" << origname << endl; //we need this data_(name) line otherwise the cif file will not be considered valid in some software packages
    //Instead of supplying argument to write data_..., using timestamp with number of atoms in the structure
    string formula = get_formula(cell);
    string time_stamp = get_timestamp();
    output << "data_" << formula << "_" << time_stamp << endl;
    output << "#******************************************" << endl;
    output << "#" << endl;
    output << "# CIF file created by Zeo++" << endl;
    output << "# Zeo++ is an open source package to" << endl;
    output << "# analyze microporous materials" << endl;
    output << "#" << endl;
    output << "#*******************************************" << "\n\n";
    output << "_cell_length_a\t\t" << cell->a << "   " << endl;     //  removed (0)
    output << "_cell_length_b\t\t" << cell->b << "   " << endl;
    output << "_cell_length_c\t\t" << cell->c << "   " << endl;
    output << "_cell_angle_alpha\t\t" << cell->alpha << "   " << endl;
    output << "_cell_angle_beta\t\t" << cell->beta << "   " << endl;
    output << "_cell_angle_gamma\t\t" << cell->gamma << "   \n\n";
    output << "_symmetry_space_group_name_H-M\t\t" << "'P1'" << endl;
    output << "_symmetry_Int_Tables_number\t\t" << "1" << endl;
    output << "_symmetry_cell_setting\t\t";

    //Determine the Crystal System
    if (cell->alpha == 90 && cell->beta == 90 && cell->gamma == 90){
      if (cell->a == cell->b || cell->b == cell->c || cell->a == cell->c){
	      if (cell->a == cell->b && cell->b == cell->c){
	        output << "Isometric\n" << endl;
	      }
	      else {
	        output << "Tetragonal\n" << endl;
        }
      }
      else{
      	output << "Orthorhombic\n" << endl;
      }
    }
    else if(cell->alpha == cell->beta || cell->beta == cell->gamma || cell->alpha == cell->gamma){
      output << "Monoclinic\n" << endl;
    }
    else{
      output << "Triclinic\n" << endl;
    }

    output << "loop_" << endl;
    output << "_symmetry_equiv_pos_as_xyz" << endl;
    output << "'+x,+y,+z'\n" << endl;
    output << "loop_" << endl;
    output << "_atom_site_label" << endl;
    output << "_atom_site_type_symbol" << endl;
    output << "_atom_site_fract_x" << endl;
    output << "_atom_site_fract_y" << endl;
    output << "_atom_site_fract_z" << endl;
    for (unsigned int i=0; i<cell->atoms.size(); i++){
      ATOM *temp=&(cell->atoms.at(i));
      output << temp->specialID << "\t" << temp->type << "\t" << trans_to_origuc(temp->a_coord) << "\t" << trans_to_origuc(temp->b_coord) << "\t" << trans_to_origuc(temp->c_coord) << endl;
    }
    output.close();
    return true;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, 0x10(%rsp)
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, 0xf(%rsp)
testb %al, %al
je 0x22665
movq 0x12dcdb(%rip), %rdi    # 0x14ffc0
leaq 0xdb0de(%rip), %rsi     # 0xfd3ca
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
leaq 0xe027b(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x22097
leaq 0x18(%rsp), %rdi
callq 0x2223d
leaq 0x68(%rsp), %rdi
leaq 0xda8d1(%rip), %rsi     # 0xfcc01
callq 0x4480
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x43f0
leaq 0xda8bc(%rip), %rsi     # 0xfcc05
movq %rax, %rdi
callq 0x4480
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x43f0
movq %rax, %rdi
callq 0x4230
leaq 0xdb0f0(%rip), %rsi     # 0xfd45d
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xde098(%rip), %rsi     # 0x10041e
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0ea(%rip), %rsi     # 0xfd489
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0ed(%rip), %rsi     # 0xfd4a5
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0f9(%rip), %rsi     # 0xfd4ca
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xde034(%rip), %rsi     # 0x10041e
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0e7(%rip), %rsi     # 0xfd4ea
leaq 0x68(%rsp), %rdi
callq 0x4480
leaq 0xe1b87(%rip), %rsi     # 0x103f9b
movq %rax, %rdi
callq 0x4480
leaq 0xdb0f4(%rip), %rsi     # 0xfd517
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x8(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xda088(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0cb(%rip), %rsi     # 0xfd528
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xda04e(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb0a2(%rip), %rsi     # 0xfd539
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x18(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xda014(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb079(%rip), %rsi     # 0xfd54a
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x20(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xd9fda(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb053(%rip), %rsi     # 0xfd55e
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x28(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xd9fa0(%rip), %rsi     # 0xfc4ce
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb02c(%rip), %rsi     # 0xfd571
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rcx
movsd 0x30(%rcx), %xmm0
movq %rax, %rdi
callq 0x46c0
leaq 0xdb01d(%rip), %rsi     # 0xfd585
movq %rax, %rdi
callq 0x4480
leaq 0xdb014(%rip), %rsi     # 0xfd58b
leaq 0x68(%rsp), %rdi
callq 0x4480
leaq 0xdb024(%rip), %rsi     # 0xfd5ac
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb012(%rip), %rsi     # 0xfd5b1
leaq 0x68(%rsp), %rdi
callq 0x4480
leaq 0xdae5c(%rip), %rsi     # 0xfd40c
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdb008(%rip), %rsi     # 0xfd5cf
leaq 0x68(%rsp), %rdi
callq 0x4480
movq 0x10(%rsp), %rax
movsd 0x20(%rax), %xmm1
movsd 0x28(%rax), %xmm0
ucomisd 0xda528(%rip), %xmm1    # 0xfcb10
jne 0x22690
jp 0x22690
ucomisd 0xda514(%rip), %xmm0    # 0xfcb10
jne 0x22690
jp 0x22690
movq 0x10(%rsp), %rax
movsd 0x30(%rax), %xmm2
ucomisd 0xda4f6(%rip), %xmm2    # 0xfcb10
jne 0x22690
jp 0x22690
movq 0x10(%rsp), %rax
movsd 0x8(%rax), %xmm2
movsd 0x10(%rax), %xmm0
ucomisd %xmm0, %xmm2
movsd 0x18(%rax), %xmm1
leaq 0xdafb6(%rip), %rsi     # 0xfd5f3
jne 0x226ce
jp 0x226ce
ucomisd %xmm1, %xmm0
jne 0x226f0
jp 0x226f0
leaq 0xdaf88(%rip), %rsi     # 0xfd5e8
jmp 0x226f0
movq 0x12d984(%rip), %rdi    # 0x14fff0
leaq 0xdadc2(%rip), %rsi     # 0xfd435
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4480
movq %rax, %rdi
callq 0x4230
jmp 0x228e9
ucomisd %xmm0, %xmm1
jne 0x226a1
jp 0x226a1
leaq 0xdaf6e(%rip), %rsi     # 0xfd60d
jmp 0x226f0
movq 0x10(%rsp), %rax
movsd 0x30(%rax), %xmm2
ucomisd %xmm2, %xmm1
leaq 0xdaf63(%rip), %rax     # 0xfd619
leaq 0xdaf50(%rip), %rsi     # 0xfd60d
movq %rsi, %rcx
cmovneq %rax, %rcx
cmovpq %rax, %rcx
ucomisd %xmm2, %xmm0
jmp 0x226e8
ucomisd %xmm1, %xmm2
leaq 0xdaf26(%rip), %rax     # 0xfd5ff
movq %rsi, %rcx
cmovneq %rax, %rcx
cmovpq %rax, %rcx
ucomisd %xmm1, %xmm0
cmovneq %rcx, %rsi
cmovpq %rcx, %rsi
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda560(%rip), %rsi     # 0xfcc69
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda54d(%rip), %rsi     # 0xfcc6f
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xdaee9(%rip), %rsi     # 0xfd624
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda515(%rip), %rsi     # 0xfcc69
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda53e(%rip), %rsi     # 0xfccab
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda536(%rip), %rsi     # 0xfccbc
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda534(%rip), %rsi     # 0xfccd3
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda52e(%rip), %rsi     # 0xfcce6
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
leaq 0xda528(%rip), %rsi     # 0xfccf9
leaq 0x68(%rsp), %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
movq 0x10(%rsp), %rax
leaq 0x2f0(%rax), %r12
xorl %r13d, %r13d
movl $0x98, %r14d
leaq 0xdabf3(%rip), %rbp     # 0xfd3f2
movl %r13d, %r13d
movq 0x10(%rsp), %rcx
movq 0x2f8(%rcx), %rax
subq 0x2f0(%rcx), %rax
cqto
idivq %r14
cmpq %r13, %rax
jbe 0x228cb
movq %r12, %rdi
movq %r13, %rsi
callq 0xa73a
movq %rax, %rbx
movl 0x80(%rax), %esi
leaq 0x68(%rsp), %rdi
callq 0x4760
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4480
movq %rbx, %rsi
addq $0x40, %rsi
movq %rax, %rdi
callq 0x43f0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4480
movq %rax, %r15
movsd 0x18(%rbx), %xmm0
callq 0x6377f
movq %r15, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4480
movq %rax, %r15
movsd 0x20(%rbx), %xmm0
callq 0x6377f
movq %r15, %rdi
callq 0x46c0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4480
movq %rax, %r15
movsd 0x28(%rbx), %xmm0
callq 0x6377f
movq %r15, %rdi
callq 0x46c0
movq %rax, %rdi
callq 0x4230
incl %r13d
jmp 0x227ff
leaq 0x58(%rsp), %rdi
callq 0x4080
leaq 0x18(%rsp), %rdi
callq 0x4210
leaq 0x38(%rsp), %rdi
callq 0x4210
leaq 0x58(%rsp), %rdi
callq 0x4120
movb 0xf(%rsp), %al
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x22924
jmp 0x22910
movq %rax, %rbx
jmp 0x2292e
jmp 0x22917
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x4210
leaq 0x38(%rsp), %rdi
callq 0x4210
leaq 0x58(%rsp), %rdi
callq 0x4120
movq %rbx, %rdi
callq 0x4780