// File: Luthaf[P]zeopp/networkio.cc
// Function: readDLPFile(char*, ATOM_NETWORK*, bool)
bool readDLPFile(char *filename, ATOM_NETWORK *cell, bool radial){
  fstream input;
  char garbage[256];
  int i;
  input.open(filename);
  if(!input.is_open()){
    cout<< "Failed to open .dlp file " << filename << "\n";
    cout<<"Exiting ..." << "\n";
//    exit(1);
    return false;
  }
  else{
    cout  << "Reading input file " << filename << "\n";
    input.getline(garbage, 256);

    // Read and store information about the unit cell. While the
    // vector components are known, the side lengths and angles remain unknown
    input >> cell->v_a.x >> cell->v_a.y >> cell->v_a.z;
    input >> cell->v_b.x >> cell->v_b.y >> cell->v_b.z;
    input >> cell->v_c.x >> cell->v_c.y >> cell->v_c.z;

//    input >> cell->numAtoms;
    cell->initMatrices();

    //Recover information about unit cell angles and side lengths from
    //vector components. Essentially reverses the steps performed in
    //the initialize() method for ATOM_NETWORK instances as contained
    //in the file networkstorage.cc
    cell->a = cell->v_a.x;
    cell->b = sqrt(cell->v_b.x*cell->v_b.x+cell->v_b.y*cell->v_b.y);
    cell->c = sqrt(cell->v_c.x*cell->v_c.x+cell->v_c.y*cell->v_c.y+cell->v_c.z*cell->v_c.z);
    cell->beta = acos(cell->v_c.x/cell->c)*360.0/(2.0*PI);
    cell->gamma = acos(cell->v_b.x/cell->b)*360.0/(2.0*PI);
    cell->alpha = 360.0/(2*PI)*acos((cell->v_c.y/cell->c*sin(2.0*PI*cell->gamma/360.0))
				    +cos(2.0*PI/360.0*cell->gamma)*cos(2.0*PI/360.0*cell->beta));

    // Read and store information about each atom
    int numAtoms = 0;
    while(!input.eof()){
      ATOM newAtom;
      input >> newAtom.type;
      if(newAtom.type.empty())
	break;

      input.getline(garbage,256); // reading remaining data from a line

      input >> newAtom.x >> newAtom.y >> newAtom.z;
      input.getline(garbage,256); // read end of line

      Point newCoords = cell->xyz_to_abc (newAtom.x,newAtom.y,newAtom.z);
      newAtom.a_coord = newCoords[0]; newAtom.b_coord = newCoords[1]; newAtom.c_coord = newCoords[2];
      newAtom.a_coord = trans_to_origuc(newAtom.a_coord);
      newAtom.b_coord = trans_to_origuc(newAtom.b_coord);
      newAtom.c_coord = trans_to_origuc(newAtom.c_coord);
      newAtom.radius = lookupRadius(newAtom.type, radial);
      cell->atoms.push_back(newAtom);
      numAtoms++;
    }
    cell->numAtoms= numAtoms;

    input.close();
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5660
movq -0x10(%rbp), %rax
movq %rax, -0x430(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x47640
movl %eax, -0x424(%rbp)
jmp 0x53698
movl -0x424(%rbp), %edx
movq -0x430(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x54b0
jmp 0x536b3
leaq -0x230(%rbp), %rdi
callq 0x58b0
movb %al, -0x431(%rbp)
jmp 0x536c7
movb -0x431(%rbp), %al
testb $0x1, %al
jne 0x5377c
jmp 0x536d7
movq 0x21f8e2(%rip), %rdi    # 0x272fc0
leaq 0x19fe5c(%rip), %rsi    # 0x1f3541
callq 0x5540
movq %rax, -0x440(%rbp)
jmp 0x536f3
movq -0x440(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x448(%rbp)
jmp 0x5370c
movq -0x448(%rbp), %rdi
leaq 0x1a5f0b(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x53721
movq 0x21f898(%rip), %rdi    # 0x272fc0
leaq 0x19f4d4(%rip), %rsi    # 0x1f2c03
callq 0x5540
movq %rax, -0x450(%rbp)
jmp 0x5373d
movq -0x450(%rbp), %rdi
leaq 0x1a5eda(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x53752
movb $0x0, -0x1(%rbp)
movl $0x1, -0x348(%rbp)
jmp 0x53dde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x53df8
movq 0x21f83d(%rip), %rdi    # 0x272fc0
leaq 0x19fa0e(%rip), %rsi    # 0x1f3198
callq 0x5540
movq %rax, -0x458(%rbp)
jmp 0x53798
movq -0x458(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, -0x460(%rbp)
jmp 0x537b1
movq -0x460(%rbp), %rdi
leaq 0x1a5e66(%rip), %rsi    # 0x1f9625
callq 0x5540
jmp 0x537c6
leaq -0x230(%rbp), %rdi
leaq -0x330(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x51d0
jmp 0x537e0
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
leaq -0x230(%rbp), %rdi
callq 0x5420
movq %rax, -0x468(%rbp)
jmp 0x537fd
movq -0x468(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x40, %rsi
callq 0x5420
movq %rax, -0x470(%rbp)
jmp 0x5381a
movq -0x470(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x48, %rsi
callq 0x5420
jmp 0x53830
movq -0x18(%rbp), %rsi
addq $0x50, %rsi
leaq -0x230(%rbp), %rdi
callq 0x5420
movq %rax, -0x478(%rbp)
jmp 0x5384d
movq -0x478(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x58, %rsi
callq 0x5420
movq %rax, -0x480(%rbp)
jmp 0x5386a
movq -0x480(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x60, %rsi
callq 0x5420
jmp 0x53880
movq -0x18(%rbp), %rsi
addq $0x68, %rsi
leaq -0x230(%rbp), %rdi
callq 0x5420
movq %rax, -0x488(%rbp)
jmp 0x5389d
movq -0x488(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x70, %rsi
callq 0x5420
movq %rax, -0x490(%rbp)
jmp 0x538ba
movq -0x490(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x78, %rsi
callq 0x5420
jmp 0x538d0
movq -0x18(%rbp), %rdi
callq 0x966b0
jmp 0x538db
movq -0x18(%rbp), %rax
movsd 0x38(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x18(%rbp), %rax
movsd 0x50(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd 0x50(%rax), %xmm2
movq -0x18(%rbp), %rax
movsd 0x58(%rax), %xmm1
movq -0x18(%rbp), %rax
mulsd 0x58(%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x53f0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm1
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm2
movq -0x18(%rbp), %rax
movsd 0x70(%rax), %xmm0
movq -0x18(%rbp), %rax
mulsd 0x70(%rax), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x18(%rbp), %rax
movsd 0x78(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd 0x78(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x53f0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
movq -0x18(%rbp), %rax
divsd 0x18(%rax), %xmm0
callq 0x54f0
movsd 0x19f0fe(%rip), %xmm1   # 0x1f2a98
mulsd %xmm1, %xmm0
movsd 0x19f0fa(%rip), %xmm1   # 0x1f2aa0
divsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x18(%rbp), %rax
movsd 0x50(%rax), %xmm0
movq -0x18(%rbp), %rax
divsd 0x10(%rax), %xmm0
callq 0x54f0
movsd 0x19f0c6(%rip), %xmm1   # 0x1f2a98
mulsd %xmm1, %xmm0
movsd 0x19f0c2(%rip), %xmm1   # 0x1f2aa0
divsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x18(%rbp), %rax
movsd 0x70(%rax), %xmm0
movq -0x18(%rbp), %rax
divsd 0x18(%rax), %xmm0
movsd %xmm0, -0x498(%rbp)
movq -0x18(%rbp), %rax
movsd 0x19f08f(%rip), %xmm0   # 0x1f2aa0
mulsd 0x30(%rax), %xmm0
movsd 0x19f07a(%rip), %xmm1   # 0x1f2a98
divsd %xmm1, %xmm0
callq 0x5140
movsd %xmm0, -0x4a0(%rbp)
movq -0x18(%rbp), %rax
movsd 0x19f075(%rip), %xmm0   # 0x1f2ab0
mulsd 0x30(%rax), %xmm0
callq 0x5970
movsd %xmm0, -0x4a8(%rbp)
movq -0x18(%rbp), %rax
movsd 0x19f057(%rip), %xmm0   # 0x1f2ab0
mulsd 0x28(%rax), %xmm0
callq 0x5970
movsd -0x4a8(%rbp), %xmm1
movsd -0x4a0(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0x498(%rbp), %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x54f0
movaps %xmm0, %xmm1
movsd 0x19f00e(%rip), %xmm0   # 0x1f2aa8
mulsd %xmm1, %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movl $0x0, -0x34c(%rbp)
movq -0x230(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x230(%rbp,%rax), %rdi
callq 0x5960
movb %al, -0x4a9(%rbp)
jmp 0x53ad1
movb -0x4a9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x53ae2
jmp 0x53db0
leaq -0x3e8(%rbp), %rdi
callq 0x954b0
jmp 0x53af0
leaq -0x3a8(%rbp), %rsi
leaq -0x230(%rbp), %rdi
callq 0x56a0
jmp 0x53b05
leaq -0x3e8(%rbp), %rdi
addq $0x40, %rdi
callq 0x5850
testb $0x1, %al
jne 0x53b1b
jmp 0x53b41
movl $0x3, -0x348(%rbp)
jmp 0x53d65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
jmp 0x53da2
leaq -0x230(%rbp), %rdi
leaq -0x330(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x51d0
jmp 0x53b5b
leaq -0x230(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x5420
movq %rax, -0x4b8(%rbp)
jmp 0x53b77
movq -0x4b8(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x5420
movq %rax, -0x4c0(%rbp)
jmp 0x53b93
movq -0x4c0(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
callq 0x5420
jmp 0x53ba8
leaq -0x230(%rbp), %rdi
leaq -0x330(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x51d0
jmp 0x53bc2
movq -0x18(%rbp), %rsi
movsd -0x3e8(%rbp), %xmm0
movsd -0x3e0(%rbp), %xmm1
movsd -0x3d8(%rbp), %xmm2
leaq -0x400(%rbp), %rdi
callq 0x97360
jmp 0x53bec
leaq -0x400(%rbp), %rdi
xorl %esi, %esi
callq 0xe9d70
movq %rax, -0x4c8(%rbp)
jmp 0x53c03
movq -0x4c8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3d0(%rbp)
leaq -0x400(%rbp), %rdi
movl $0x1, %esi
callq 0xe9d70
movq %rax, -0x4d0(%rbp)
jmp 0x53c30
movq -0x4d0(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3c8(%rbp)
leaq -0x400(%rbp), %rdi
movl $0x2, %esi
callq 0xe9d70
movq %rax, -0x4d8(%rbp)
jmp 0x53c5d
movq -0x4d8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3c0(%rbp)
movsd -0x3d0(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0x4e0(%rbp)
jmp 0x53c87
movsd -0x4e0(%rbp), %xmm0
movsd %xmm0, -0x3d0(%rbp)
movsd -0x3c8(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0x4e8(%rbp)
jmp 0x53cae
movsd -0x4e8(%rbp), %xmm0
movsd %xmm0, -0x3c8(%rbp)
movsd -0x3c0(%rbp), %xmm0
callq 0xe9290
movsd %xmm0, -0x4f0(%rbp)
jmp 0x53cd5
movsd -0x4f0(%rbp), %xmm0
movsd %xmm0, -0x3c0(%rbp)
leaq -0x3a8(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5220
jmp 0x53cfa
movzbl -0x19(%rbp), %esi
andl $0x1, %esi
leaq -0x420(%rbp), %rdi
callq 0x466e0
movsd %xmm0, -0x4f8(%rbp)
jmp 0x53d17
movsd -0x4f8(%rbp), %xmm0
movsd %xmm0, -0x3b8(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x5300
movq -0x18(%rbp), %rdi
addq $0x2f0, %rdi            # imm = 0x2F0
leaq -0x3e8(%rbp), %rsi
callq 0xf190
jmp 0x53d4c
movl -0x34c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34c(%rbp)
movl $0x0, -0x348(%rbp)
leaq -0x3e8(%rbp), %rdi
callq 0xf200
movl -0x348(%rbp), %eax
testl %eax, %eax
je 0x53d7f
jmp 0x53d7d
jmp 0x53db0
jmp 0x53ab1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x340(%rbp)
movl %eax, -0x344(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x5300
leaq -0x3e8(%rbp), %rdi
callq 0xf200
jmp 0x53df8
movl -0x34c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x110(%rax)
leaq -0x230(%rbp), %rdi
callq 0x50a0
jmp 0x53dce
jmp 0x53dd0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x348(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x5150
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
leaq -0x230(%rbp), %rdi
callq 0x5150
movq -0x340(%rbp), %rdi
callq 0x58f0