--- trunk/tcProps/readWrite.c 2004/02/18 21:20:51 1058 +++ trunk/tcProps/readWrite.c 2004/02/19 21:10:06 1060 @@ -17,8 +17,8 @@ FILE* inFile; int nFrames; double *frameTimes; FILE* inFile; +char* inName; - struct linkedPos{ fpos_t *myPos; @@ -39,9 +39,9 @@ void openFile( char* inName ){ void setU( double q[4], double u[3] ); void normalizeQ( double q[4] ); -void openFile( char* inName ){ +void openFile( void ){ - inFile = fopen(inName); + inFile = fopen(inName, "r"); if(inFile ==NULL){ fprintf(stderr, "Error opening file \"%s\"\n", @@ -59,7 +59,7 @@ int setFrames( void ){ fileOpen = 0; } -int setFrames( void ){ +void setFrames( void ){ int i,j,k; struct linkedPos* headPos; @@ -81,21 +81,22 @@ int setFrames( void ){ nFrames = 0; headPos = (struct linkedPos*)malloc(sizeof(struct linkedPos)); currPos = headPos; + + currPT = (fpos_t *)malloc(sizeof(fpos_t)); + fgetpos(inFile, currPT); + + fgets( readBuffer, sizeof( readBuffer ), inFile ); + lineNum++; + if( feof( inFile ) ){ + fprintf( stderr, + "File \"%s\" ended unexpectedly at line %d\n", + inName, + lineNum ); + exit(0); + } + while( !feof( inFile ) ){ - currPT = (fpos_t *)malloc(sizeof(fpos_t)); - fgetpos(inFile, currPT); - - fgets( readBuffer, sizeof( readBuffer ), inFile ); - lineNum++; - if( feof( inFile ) ){ - fprintf( stderr, - "File \"%s\" ended unexpectedly at line %d\n", - inName, - lineNum ); - exit(0); - } - currPos->next = (struct linkedPos*)malloc(sizeof(struct linkedPos)); currPos = currPos->next; currPos->myPos = currPT; @@ -229,6 +230,12 @@ int setFrames( void ){ exit(0); } } + + currPT = (fpos_t *)malloc(sizeof(fpos_t)); + fgetpos(inFile, currPT); + + fgets( readBuffer, sizeof( readBuffer ), inFile ); + lineNum++; } // allocate the static position array @@ -303,7 +310,7 @@ void readFrame(int theFrame, struct atomCoord* atoms, if( !fileOpen ){ fprintf( stderr, - "File is closed, cannot read frame %d.\n" + "File is closed, cannot read frame %d.\n", theFrame ); exit(0); } @@ -311,7 +318,7 @@ void readFrame(int theFrame, struct atomCoord* atoms, // access the frame framePos = posArray[theFrame].myPos; - fsetPos( inFile, framePos ); + fsetpos( inFile, framePos ); for(j=0;j<3;j++){ for(k=0;k<3;k++){ @@ -370,6 +377,13 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, void parseDumpLine( char readLine[BUFFER_SIZE], int i, struct atomCoord* atoms ){ + + const int nLipAtoms = NL_ATOMS; + const int nBonds = NBONDS; + const int nLipids = NLIPIDS; + const int nSSD = NSSD; + const int nAtoms = nLipAtoms * nLipids + nSSD; + char* foo; double q[4]; @@ -384,7 +398,7 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, case HEAD: if( strcmp(foo, "HEAD") ){ fprintf( stderr, - "Atom %s does not match master array type \"HEAD\".\n" + "Atom %s does not match master array type \"HEAD\".\n", foo ); exit(0); } @@ -393,7 +407,7 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, case CH: if( strcmp(foo, "CH") ){ fprintf( stderr, - "Atom %s does not match master array type \"CH\".\n" + "Atom %s does not match master array type \"CH\".\n", foo ); exit(0); } @@ -402,7 +416,7 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, case CH2: if( strcmp(foo, "CH2") ){ fprintf( stderr, - "Atom %s does not match master array type \"CH2\".\n" + "Atom %s does not match master array type \"CH2\".\n", foo ); exit(0); } @@ -411,7 +425,7 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, case CH3: if( strcmp(foo, "CH3") ){ fprintf( stderr, - "Atom %s does not match master array type \"CH3\".\n" + "Atom %s does not match master array type \"CH3\".\n", foo ); exit(0); } @@ -420,7 +434,7 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, case SSD: if( strcmp(foo, "SSD") ){ fprintf( stderr, - "Atom %s does not match master array type \"SSD\".\n" + "Atom %s does not match master array type \"SSD\".\n", foo ); exit(0); } @@ -505,10 +519,10 @@ void parseDumpLine( char readLine[BUFFER_SIZE], int i, foo = strtok(NULL, " ,;\t"); if(foo == NULL){ - sprintf(painCave.errMsg, - "error in reading quaternion 0 from %s\n" - "natoms = %d, i = %d\n", - inName, nAtoms, i ); + fprintf( stderr, + "error in reading quaternion 0 from %s\n" + "natoms = %d, i = %d\n", + inName, nAtoms, i ); exit(0); } q[0] = atof( foo ); @@ -555,6 +569,7 @@ void setU( double the_q[4], double u[3] ){ double q0Sqr, q1Sqr, q2Sqr, q3Sqr; double A[3][3]; double rb[3]; + int i,j,k; // initialize the axis