ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/InitializeFromFile.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/InitializeFromFile.cpp (file contents):
Revision 447 by mmeineke, Thu Apr 3 20:21:54 2003 UTC vs.
Revision 670 by mmeineke, Thu Aug 7 21:47:18 2003 UTC

# Line 69 | Line 69 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
69   }
70  
71  
72 < void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){
72 > void InitializeFromFile :: readInit( SimInfo* the_simnfo ){
73  
74    int i, j, done, which_node, which_atom; // loop counter
75  
# Line 83 | Line 83 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
83    char *eof_test; // ptr to see when we reach the end of the file
84    char *parseErr;
85    int procIndex;
86 +  double currTime;
87 +  double boxMat[9];
88 +  double theBoxMat3[3][3];
89  
90 <  entry_plug = the_entry_plug;
90 >  simnfo = the_simnfo;
91  
92  
93   #ifndef IS_MPI
# Line 99 | Line 102 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
102  
103    n_atoms = atoi( read_buffer );
104  
105 <  Atom **atoms = entry_plug->atoms;
105 >  Atom **atoms = simnfo->atoms;
106    DirectionalAtom* dAtom;
107  
108 <  if( n_atoms != entry_plug->n_atoms ){
108 >  if( n_atoms != simnfo->n_atoms ){
109      sprintf( painCave.errMsg,
110               "Initialize from File error. %s n_atoms, %d, "
111               "does not match the BASS file's n_atoms, %d.\n",
112 <             c_in_name, n_atoms, entry_plug->n_atoms );
112 >             c_in_name, n_atoms, simnfo->n_atoms );
113      painCave.isFatal = 1;
114      simError();
115    }
116    
117 <  //read and toss the comment line
117 >  //read the box mat from the comment line
118    
119    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
120    if(eof_test == NULL){
# Line 121 | Line 124 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
124      simError();
125    }
126  
127 +  parseErr = parseBoxLine( read_buffer, boxMat, currTime );
128 +  if( parseErr != NULL ){
129 +    strcpy( painCave.errMsg, parseErr );
130 +    painCave.isFatal = 1;
131 +    simError();
132 +  }
133 +
134 +  for(i=0;i<3;i++)
135 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
136 +
137 +  simnfo->setBoxM( theBoxMat3 );
138 +  simnfo->setTime( currTime );
139 +
140 +
141    for( i=0; i < n_atoms; i++){
142      
143      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
# Line 140 | Line 157 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
157        strcpy( painCave.errMsg, parseErr );
158        painCave.isFatal = 1;
159        simError();
160 <    }    
160 >    }
161    }
162  
163  
# Line 170 | Line 187 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
187      
188      n_atoms = atoi( read_buffer );
189      
190 <    Atom **atoms = entry_plug->atoms;
190 >    Atom **atoms = simnfo->atoms;
191      DirectionalAtom* dAtom;
192  
193      // Check to see that the number of atoms in the intial configuration file is the
# Line 180 | Line 197 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
197        sprintf( painCave.errMsg,
198                 "Initialize from File error. %s n_atoms, %d, "
199                 "does not match the BASS file's n_atoms, %d.\n",
200 <               c_in_name, n_atoms, entry_plug->n_atoms );
200 >               c_in_name, n_atoms, simnfo->n_atoms );
201        haveError= 1;
202        simError();
203      }
204      
205 <    //read and toss the comment line
205 >    //read the boxMat from the comment line
206      
207      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
208      if(eof_test == NULL){
209        sprintf( painCave.errMsg,
210                 "error in reading commment in %s\n", c_in_name);
211 <      haveError= 1;
211 >      haveError = 1;
212        simError();
213      }
214 +    
215 +    parseErr = parseBoxLine( read_buffer, boxMat, currTime );
216 +    if( parseErr != NULL ){
217 +      strcpy( painCave.errMsg, parseErr );
218 +      haveError = 1;
219 +      simError();
220 +    }
221 +
222 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD );
223 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD );
224    
225      if(haveError) nodeZeroError();
226  
# Line 247 | Line 274 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
274      
275    } else {
276      
277 +    MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD);
278 +    MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
279 +
280      done = 0;
281      while (!done) {
282  
# Line 278 | Line 308 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
308      
309   // last  thing last, enable  fatalities.
310    painCave.isEventLoop = 0;
311 +
312 +  for(i=0;i<3;i++)
313 +    for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i];
314 +
315 +  simnfo->setBoxM( theBoxMat3 );
316 +  simnfo->setTime( currTime );
317 +
318    
319   #endif
320   }
# Line 286 | Line 323 | char* InitializeFromFile::parseDumpLine(char* readLine
323  
324    char *foo; // the pointer to the current string token
325    
326 <  double rx, ry, rz; // position place holders
327 <  double vx, vy, vz; // velocity placeholders
326 >  double pos[3]; // position place holders
327 >  double vel[3]; // velocity placeholders
328    double q[4]; // the quaternions
329    double jx, jy, jz; // angular velocity placeholders;
330    double qSqr, qLength; // needed to normalize the quaternion vector.
331    
332 <  Atom **atoms = entry_plug->atoms;
332 >  Atom **atoms = simnfo->atoms;
333    DirectionalAtom* dAtom;
334    
335    int j, n_atoms, atomIndex;
# Line 311 | Line 348 | char* InitializeFromFile::parseDumpLine(char* readLine
348      return strdup( painCave.errMsg );
349    }  
350   #else
351 <  n_atoms = entry_plug->n_atoms;
351 >  n_atoms = simnfo->n_atoms;
352    atomIndex = globalIndex;
353   #endif // is_mpi
354  
# Line 340 | Line 377 | char* InitializeFromFile::parseDumpLine(char* readLine
377               c_in_name, n_atoms, atomIndex );
378      return strdup( painCave.errMsg );
379    }
380 <  rx = atof( foo );
380 >  pos[0] = atof( foo );
381    
382    foo = strtok(NULL, " ,;\t");
383    if(foo == NULL){
# Line 350 | Line 387 | char* InitializeFromFile::parseDumpLine(char* readLine
387               c_in_name, n_atoms, atomIndex );
388      return strdup( painCave.errMsg );
389    }
390 <  ry = atof( foo );
390 >  pos[1] = atof( foo );
391      
392    foo = strtok(NULL, " ,;\t");
393    if(foo == NULL){
# Line 360 | Line 397 | char* InitializeFromFile::parseDumpLine(char* readLine
397               c_in_name, n_atoms, atomIndex );
398      return strdup( painCave.errMsg );
399    }
400 <  rz = atof( foo );    
400 >  pos[2] = atof( foo );    
401  
402  
403    // get the velocities
# Line 373 | Line 410 | char* InitializeFromFile::parseDumpLine(char* readLine
410               c_in_name, n_atoms, atomIndex );
411      return strdup( painCave.errMsg );
412    }
413 <  vx = atof( foo );
413 >  vel[0] = atof( foo );
414      
415    foo = strtok(NULL, " ,;\t");
416    if(foo == NULL){
# Line 383 | Line 420 | char* InitializeFromFile::parseDumpLine(char* readLine
420               c_in_name, n_atoms, atomIndex );
421      return strdup( painCave.errMsg );
422    }
423 <  vy = atof( foo );
423 >  vel[1] = atof( foo );
424      
425    foo = strtok(NULL, " ,;\t");
426    if(foo == NULL){
# Line 393 | Line 430 | char* InitializeFromFile::parseDumpLine(char* readLine
430               c_in_name, n_atoms, atomIndex );
431      return strdup( painCave.errMsg );
432    }
433 <  vz = atof( foo );
433 >  vel[2] = atof( foo );
434      
435      
436    // get the quaternions
# Line 495 | Line 532 | char* InitializeFromFile::parseDumpLine(char* readLine
532      
533    // add the positions and velocities to the atom
534      
535 <  atoms[atomIndex]->setX( rx );
536 <  atoms[atomIndex]->setY( ry );
537 <  atoms[atomIndex]->setZ( rz );
538 <    
539 <  atoms[atomIndex]->set_vx( vx );
540 <  atoms[atomIndex]->set_vy( vy );
541 <  atoms[atomIndex]->set_vz( vz );
535 >  atoms[atomIndex]->setPos( pos );
536 >  atoms[atomIndex]->setVel( vel );
537 >
538 >  return NULL;
539 > }
540 >
541 >
542 > char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9],
543 >                                       double &time ){
544 >
545 >  char *foo; // the pointer to the current string token
546 >  int j;
547 >
548 >  // set the string tokenizer
549 >  
550 >  foo = strtok(readLine, " ,;\t");
551 >  // set the timeToken.
552  
553 +  if(foo == NULL){
554 +    sprintf( painCave.errMsg,
555 +             "error in reading Time from %s\n",
556 +             c_in_name );
557 +    return strdup( painCave.errMsg );
558 +  }
559 +  time = atof( foo );
560 +
561 +  // get the Hx vector
562 +
563 +  foo = strtok(NULL, " ,;\t");
564 +  if(foo == NULL){
565 +    sprintf( painCave.errMsg,
566 +             "error in reading Hx[0] from %s\n",
567 +             c_in_name );
568 +    return strdup( painCave.errMsg );
569 +  }
570 +  boxMat[0] = atof( foo );
571 +  
572 +  foo = strtok(NULL, " ,;\t");
573 +  if(foo == NULL){
574 +    sprintf( painCave.errMsg,
575 +             "error in reading Hx[1] from %s\n",
576 +             c_in_name );
577 +    return strdup( painCave.errMsg );
578 +  }
579 +  boxMat[1] = atof( foo );
580 +    
581 +  foo = strtok(NULL, " ,;\t");
582 +  if(foo == NULL){
583 +    sprintf( painCave.errMsg,
584 +             "error in reading Hx[2] from %s\n",
585 +             c_in_name );
586 +    return strdup( painCave.errMsg );
587 +  }
588 +  boxMat[2] = atof( foo );    
589 +
590 +  // get the Hy vector
591 +
592 +  foo = strtok(NULL, " ,;\t");
593 +  if(foo == NULL){
594 +    sprintf( painCave.errMsg,
595 +             "error in reading Hy[0] from %s\n",
596 +             c_in_name );
597 +    return strdup( painCave.errMsg );
598 +  }
599 +  boxMat[3] = atof( foo );
600 +  
601 +  foo = strtok(NULL, " ,;\t");
602 +  if(foo == NULL){
603 +    sprintf( painCave.errMsg,
604 +             "error in reading Hy[1] from %s\n",
605 +             c_in_name );
606 +    return strdup( painCave.errMsg );
607 +  }
608 +  boxMat[4] = atof( foo );
609 +    
610 +  foo = strtok(NULL, " ,;\t");
611 +  if(foo == NULL){
612 +    sprintf( painCave.errMsg,
613 +             "error in reading Hy[2] from %s\n",
614 +             c_in_name );
615 +    return strdup( painCave.errMsg );
616 +  }
617 +  boxMat[5] = atof( foo );    
618 +
619 +  // get the Hz vector
620 +
621 +  foo = strtok(NULL, " ,;\t");
622 +  if(foo == NULL){
623 +    sprintf( painCave.errMsg,
624 +             "error in reading Hz[0] from %s\n",
625 +             c_in_name );
626 +    return strdup( painCave.errMsg );
627 +  }
628 +  boxMat[6] = atof( foo );
629 +  
630 +  foo = strtok(NULL, " ,;\t");
631 +  if(foo == NULL){
632 +    sprintf( painCave.errMsg,
633 +             "error in reading Hz[1] from %s\n",
634 +             c_in_name );
635 +    return strdup( painCave.errMsg );
636 +  }
637 +  boxMat[7] = atof( foo );
638 +    
639 +  foo = strtok(NULL, " ,;\t");
640 +  if(foo == NULL){
641 +    sprintf( painCave.errMsg,
642 +             "error in reading Hz[2] from %s\n",
643 +             c_in_name );
644 +    return strdup( painCave.errMsg );
645 +  }
646 +  boxMat[8] = atof( foo );    
647 +
648    return NULL;
649   }
650  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines