ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/tcProps/readWrite.c
(Generate patch)

Comparing trunk/tcProps/readWrite.c (file contents):
Revision 1056 by mmeineke, Tue Feb 17 14:30:48 2004 UTC vs.
Revision 1060 by mmeineke, Thu Feb 19 21:10:06 2004 UTC

# Line 17 | Line 17 | FILE* inFile;
17   int nFrames;
18   double *frameTimes;
19   FILE* inFile;
20 + char* inName;
21  
21
22   struct linkedPos{
23    
24    fpos_t *myPos;
# Line 36 | Line 36 | void parseDumpLine( char readBuffer[BUFFER_SIZE], int
36  
37   void parseDumpLine( char readBuffer[BUFFER_SIZE], int index,
38                      struct atomCoord* atoms );
39 + void setU( double q[4], double u[3] );
40 + void normalizeQ( double q[4] );
41  
42 < void openFile( char* inName ){
42 > void openFile( void ){
43    
44 <  inFile = fopen(inName);
44 >  inFile = fopen(inName, "r");
45    if(inFile ==NULL){
46      fprintf(stderr,
47              "Error opening file \"%s\"\n",
# Line 57 | Line 59 | void closeFile( void ){
59    fileOpen = 0;
60   }
61  
62 < int setFrames( void ){
62 > void setFrames( void ){
63  
64    int i,j,k;
65    struct linkedPos* headPos;
# Line 79 | Line 81 | int setFrames( void ){
81    nFrames = 0;
82    headPos = (struct linkedPos*)malloc(sizeof(struct linkedPos));
83    currPos = headPos;
84 +
85 +  currPT = (fpos_t *)malloc(sizeof(fpos_t));
86 +  fgetpos(inFile, currPT);
87 +  
88 +  fgets( readBuffer, sizeof( readBuffer ), inFile );
89 +  lineNum++;
90 +  if( feof( inFile ) ){
91 +    fprintf( stderr,
92 +             "File \"%s\" ended unexpectedly at line %d\n",
93 +             inName,
94 +             lineNum );
95 +    exit(0);
96 +  }
97 +
98    while( !feof( inFile ) ){
99  
84    currPT = (fpos_t *)malloc(sizeof(fpos_t));
85    fgetpos(inFile, currPT);
86    
87    fgets( readBuffer, sizeof( readBuffer ), inFile );
88    lineNum++;
89    if( feof( inFile ) ){
90      fprintf( stderr,
91               "File \"%s\" ended unexpectedly at line %d\n",
92               inName,
93               lineNum );
94      exit(0);
95    }
96    
100      currPos->next = (struct linkedPos*)malloc(sizeof(struct linkedPos));
101      currPos = currPos->next;
102      currPos->myPos = currPT;      
# Line 227 | Line 230 | int setFrames( void ){
230          exit(0);
231        }
232      }
233 +
234 +    currPT = (fpos_t *)malloc(sizeof(fpos_t));
235 +    fgetpos(inFile, currPT);
236 +    
237 +    fgets( readBuffer, sizeof( readBuffer ), inFile );
238 +    lineNum++;
239    }
240    
241    // allocate the static position array
# Line 301 | Line 310 | void readFrame(int theFrame, struct atomCoord* atoms,
310    if( !fileOpen ){
311      
312      fprintf( stderr,
313 <             "File is closed, cannot read frame %d.\n"
313 >             "File is closed, cannot read frame %d.\n",
314               theFrame );
315      exit(0);
316    }
# Line 309 | Line 318 | void readFrame(int theFrame, struct atomCoord* atoms,
318    // access the frame
319    
320    framePos = posArray[theFrame].myPos;
321 <  fsetPos( inFile, framePos );
321 >  fsetpos( inFile, framePos );
322  
323    for(j=0;j<3;j++){
324      for(k=0;k<3;k++){
# Line 366 | Line 375 | void readFrame(int theFrame, struct atomCoord* atoms,
375    }
376   }
377  
378 < void parseDumpLine( char readLine[BUFFER_SIZE], int index,
378 > void parseDumpLine( char readLine[BUFFER_SIZE], int i,
379                      struct atomCoord* atoms ){
380 +  
381 +  const int nLipAtoms = NL_ATOMS;
382 +  const int nBonds    = NBONDS;
383 +  const int nLipids   = NLIPIDS;
384 +  const int nSSD      = NSSD;
385 +  const int nAtoms    = nLipAtoms * nLipids + nSSD;
386 +
387    char* foo;
388    double q[4];
389  
# Line 377 | Line 393 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
393    
394    // check the atom ID
395  
396 <  switch( atoms[index].type ){
396 >  switch( atoms[i].type ){
397      
398    case HEAD:
399      if( strcmp(foo, "HEAD") ){
400        fprintf( stderr,
401 <               "Atom %s does not match master array type \"HEAD\".\n"
401 >               "Atom %s does not match master array type \"HEAD\".\n",
402                 foo );
403        exit(0);
404      }
# Line 391 | Line 407 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
407    case CH:
408      if( strcmp(foo, "CH") ){
409        fprintf( stderr,
410 <               "Atom %s does not match master array type \"CH\".\n"
410 >               "Atom %s does not match master array type \"CH\".\n",
411                 foo );
412        exit(0);
413      }
# Line 400 | Line 416 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
416    case CH2:
417      if( strcmp(foo, "CH2") ){
418        fprintf( stderr,
419 <               "Atom %s does not match master array type \"CH2\".\n"
419 >               "Atom %s does not match master array type \"CH2\".\n",
420                 foo );
421        exit(0);
422      }
# Line 409 | Line 425 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
425    case CH3:
426      if( strcmp(foo, "CH3") ){
427        fprintf( stderr,
428 <               "Atom %s does not match master array type \"CH3\".\n"
428 >               "Atom %s does not match master array type \"CH3\".\n",
429                 foo );
430        exit(0);
431      }
# Line 418 | Line 434 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
434    case SSD:
435      if( strcmp(foo, "SSD") ){
436        fprintf( stderr,
437 <               "Atom %s does not match master array type \"SSD\".\n"
437 >               "Atom %s does not match master array type \"SSD\".\n",
438                 foo );
439        exit(0);
440      }
# Line 427 | Line 443 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
443    default:
444      fprintf(stderr,
445              "Atom %d is an unrecognized enumeration\n",
446 <            index );
446 >            i );
447      exit(0);
448    }
449    
# Line 437 | Line 453 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
453    if(foo == NULL){
454      fprintf( stderr,
455               "error in reading postition x from %s\n"
456 <             "natoms  = %d, index = %d\n",
457 <             inName, nAtoms, index );
456 >             "natoms  = %d, i = %d\n",
457 >             inName, nAtoms, i );
458      exit(0);
459    }
460    atoms[i].pos[0] = atof( foo );
# Line 447 | Line 463 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
463    if(foo == NULL){
464      fprintf( stderr,
465               "error in reading postition y from %s\n"
466 <             "natoms  = %d, index = %d\n",
467 <             inName, nAtoms, index );
466 >             "natoms  = %d, i = %d\n",
467 >             inName, nAtoms, i );
468      exit(0);
469    }
470    atoms[i].pos[1] = atof( foo );
# Line 457 | Line 473 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
473    if(foo == NULL){
474      fprintf( stderr,
475               "error in reading postition z from %s\n"
476 <             "natoms  = %d, index = %d\n",
477 <             inName, nAtoms, index );
476 >             "natoms  = %d, i = %d\n",
477 >             inName, nAtoms, i );
478      exit(0);
479    }
480    atoms[i].pos[2] = atof( foo );    
# Line 470 | Line 486 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
486    if(foo == NULL){
487      fprintf( stderr,
488               "error in reading velocity x from %s\n"
489 <             "natoms  = %d, index = %d\n",
490 <             inName, nAtoms, index );
489 >             "natoms  = %d, i = %d\n",
490 >             inName, nAtoms, i );
491      exit(0);
492    }
493    atoms[i].vel[0] = atof( foo );
# Line 480 | Line 496 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
496    if(foo == NULL){
497      fprintf( stderr,
498               "error in reading velocity y from %s\n"
499 <             "natoms  = %d, index = %d\n",
500 <             inName, nAtoms, index );
499 >             "natoms  = %d, i = %d\n",
500 >             inName, nAtoms, i );
501      exit(0);
502    }
503    atoms[i].vel[1] = atof( foo );
# Line 490 | Line 506 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
506    if(foo == NULL){
507      fprintf( stderr,
508               "error in reading velocity z from %s\n"
509 <             "natoms  = %d, index = %d\n",
510 <             inName, nAtoms, index );
509 >             "natoms  = %d, i = %d\n",
510 >             inName, nAtoms, i );
511      exit(0);
512    }
513    atoms[i].vel[2] = atof( foo );
# Line 503 | Line 519 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
519        
520      foo = strtok(NULL, " ,;\t");
521      if(foo == NULL){
522 <      sprintf(painCave.errMsg,
523 <              "error in reading quaternion 0 from %s\n"
524 <              "natoms  = %d, index = %d\n",
525 <              inName, nAtoms, index );
522 >      fprintf( stderr,
523 >               "error in reading quaternion 0 from %s\n"
524 >               "natoms  = %d, i = %d\n",
525 >               inName, nAtoms, i );
526        exit(0);
527      }
528      q[0] = atof( foo );
# Line 515 | Line 531 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
531      if(foo == NULL){
532        fprintf( stderr,
533                 "error in reading quaternion 1 from %s\n"
534 <               "natoms  = %d, index = %d\n",
535 <               inName, nAtoms, index );
534 >               "natoms  = %d, i = %d\n",
535 >               inName, nAtoms, i );
536        exit(0);
537      }
538      q[1] = atof( foo );
# Line 525 | Line 541 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
541      if(foo == NULL){
542        fprintf( stderr,
543                 "error in reading quaternion 2 from %s\n"
544 <               "natoms  = %d, index = %d\n",
545 <               inName, nAtoms, index );
544 >               "natoms  = %d, i = %d\n",
545 >               inName, nAtoms, i );
546        exit(0);
547      }
548      q[2] = atof( foo );
# Line 535 | Line 551 | void parseDumpLine( char readLine[BUFFER_SIZE], int in
551      if(foo == NULL){
552        fprintf( stderr,
553                 "error in reading quaternion 3 from %s\n"
554 <               "natoms  = %d, index = %d\n",
555 <               inName, nAtoms, index );
554 >               "natoms  = %d, i = %d\n",
555 >               inName, nAtoms, i );
556        exit(0);
557      }
558      q[3] = atof( foo );
559 +  
560 +    normalizeQ( q );
561 +
562 +    setU( q, atoms[i].u );
563    }
564 + }
565  
566  
567 + void setU( double the_q[4], double u[3] ){
568  
569 +  double q0Sqr, q1Sqr, q2Sqr, q3Sqr;
570 +  double A[3][3];
571 +  double rb[3];
572 +  int i,j,k;
573  
574 +  // initialize the axis
575  
576 +  rb[0] = 0.0;
577 +  rb[1] = 0.0;
578 +  rb[2] = 1.0;
579 +
580 +  // set the rotation matrix
581 +  
582 +  q0Sqr = the_q[0] * the_q[0];
583 +  q1Sqr = the_q[1] * the_q[1];
584 +  q2Sqr = the_q[2] * the_q[2];
585 +  q3Sqr = the_q[3] * the_q[3];
586 +  
587 +  A[0][0] = q0Sqr + q1Sqr - q2Sqr - q3Sqr;
588 +  A[0][1] = 2.0 * ( the_q[1] * the_q[2] + the_q[0] * the_q[3] );
589 +  A[0][2] = 2.0 * ( the_q[1] * the_q[3] - the_q[0] * the_q[2] );
590 +  
591 +  A[1][0]  = 2.0 * ( the_q[1] * the_q[2] - the_q[0] * the_q[3] );
592 +  A[1][1] = q0Sqr - q1Sqr + q2Sqr - q3Sqr;
593 +  A[1][2] = 2.0 * ( the_q[2] * the_q[3] + the_q[0] * the_q[1] );
594 +  
595 +  A[2][0] = 2.0 * ( the_q[1] * the_q[3] + the_q[0] * the_q[2] );
596 +  A[2][1] = 2.0 * ( the_q[2] * the_q[3] - the_q[0] * the_q[1] );
597 +  A[2][2] = q0Sqr - q1Sqr -q2Sqr +q3Sqr;
598 +
599 +  // perform the rotation
600 +  
601 +  for( i=0; i<3; i++ ){
602 +    u[i] = 0.0;
603 +    
604 +    for( j=0; j<3; j++ ){
605 +      u[i] += A[j][i] * rb[j];
606 +    }
607 +  }
608   }
609 +
610 + void normalizeQ( double q[4] ){
611 +  
612 +  double qSqr, qL;
613 +  int i;
614 +  
615 +  qSqr = 0.0;
616 +  for(i=0;i<4;i++)
617 +    qSqr += q[i] * q[i];
618 +  
619 +  for(i=0;i<4;i++)
620 +    q[i] /= qSqr;
621 + }
622 +      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines