ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/tcProps/readWrite.c
Revision: 1055
Committed: Mon Feb 16 21:50:34 2004 UTC (20 years, 4 months ago) by mmeineke
Content type: text/plain
File size: 4482 byte(s)
Log Message:
finished most of the actual dump scane.

File Contents

# User Rev Content
1 mmeineke 1052 #define _FILE_OFFSET_BITS 64
2    
3     #include <stdio.h>
4     #include <stdlib.h>
5     #include <sys/types.h>
6     #include <sys/stat.h>
7     #include <string.h>
8    
9     #include "params.h"
10     #include "tcProps.h"
11     #include "readWrite.h"
12    
13    
14 mmeineke 1053 #define BUFFER_SIZE 2000
15 mmeineke 1052 int isScanned;
16     FILE* inFile;
17    
18    
19     struct linkedPos{
20    
21     fpos_t *myPos;
22     double timeStamp;
23     double Hmat[3][3];
24     struct linkedPos* next;
25     };
26    
27     struct staticPos{
28    
29     fpos_t *myPos;
30     double timeStamp;
31     double Hmat[3][3];
32     };
33     struct staticPos* posArray;
34    
35    
36     void closeFile( void ){
37    
38     fclose( inFile );
39     }
40    
41     int setFrames( char* inFile ){
42    
43     int nFrames = 0;
44     int i,j,k;
45     struct linkedPos* headPos;
46     struct linkedPos* currPos;
47     fpos_t *currPT;
48 mmeineke 1053 char readBuffer[BUFFER_SIZE];
49 mmeineke 1055 char trash[BUFFER_SIZE];
50 mmeineke 1053 char* foo;
51     int lineNum = 0;
52    
53    
54 mmeineke 1052
55     inFile = fopen(inName);
56     if(inFile ==NULL){
57     fprintf(stderr,
58     "Error opening file \"%s\"\n",
59     inName);
60     exit(0);
61     }
62    
63    
64 mmeineke 1053 headPos = (struct linkedPos*)malloc(sizeof(struct linkedPos));
65 mmeineke 1055 currPos = headPos;
66 mmeineke 1052 while( !feof( inFile ) ){
67    
68 mmeineke 1053 currPT = (fpos_t *)malloc(sizeof(fpos_t));
69     fgetpos(inFile, currPT);
70    
71     fgets( readBuffer, sizeof( readBuffer ), inFile );
72     lineNum++;
73     if( feof( inFile ) ){
74     fprintf( stderr,
75     "File \"%s\" ended unexpectedly at line %d\n",
76     inName,
77     lineNum );
78     exit(0);
79     }
80    
81 mmeineke 1055 currPos->next = (struct linkedPos*)malloc(sizeof(struct linkedPos));
82     currPos = currPos->next;
83     currPos->myPos = currPT;
84     nFrames++;
85    
86 mmeineke 1053 i = atoi(readBuffer);
87 mmeineke 1055
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 mmeineke 1053
98    
99 mmeineke 1055 // parse the comment line
100    
101     foo = strtok(readBuffer, " ,;\t");
102    
103     if(foo == NULL){
104     fprintf(stderr,
105     "error in reading time from %s at line %d\n",
106     inName, lineNum );
107     exit(0);
108     }
109     currPos->timeStamp = atof( foo );
110    
111     // get the Hx vector
112    
113     foo = strtok(NULL, " ,;\t");
114     if(foo == NULL){
115     fprintf(stderr,
116     "error in reading Hx[0] from %s at line %d\n",
117     inName, lineNum );
118     exit(0);
119     }
120     currPos->Hmat[0][0] = atof( foo );
121    
122     foo = strtok(NULL, " ,;\t");
123     if(foo == NULL){
124     fprintf(stderr,
125     "error in reading Hx[1] from %s at line %d\n",
126     inName, lineNum );
127     exit(0);
128     }
129     currPos->Hmat[1][0] = atof( foo );
130    
131     foo = strtok(NULL, " ,;\t");
132     if(foo == NULL){
133     fprintf(stderr,
134     "error in reading Hx[2] from %s at line %d\n",
135     inName, lineNum );
136     exit(0);
137     }
138     currPos->Hmat[2][0] = atof( foo );
139    
140     // get the Hy vector
141    
142     foo = strtok(NULL, " ,;\t");
143     if(foo == NULL){
144     fprintf(stderr,
145     "error in reading Hy[0] from %s at line %d\n",
146     inName, lineNum );
147     exit(0);
148     }
149     currPos->Hmat[0][1] = atof( foo );
150    
151     foo = strtok(NULL, " ,;\t");
152     if(foo == NULL){
153     fprintf(stderr,
154     "error in reading Hy[1] from %s at line %d\n",
155     inName, lineNum );
156     exit(0);
157     }
158     currPos->Hmat[1][1] = atof( foo );
159    
160     foo = strtok(NULL, " ,;\t");
161     if(foo == NULL){
162     fprintf(stderr,
163     "error in reading Hy[2] from %s at line %d\n",
164     inName, lineNum );
165     exit(0);
166     }
167     currPos->Hmat[2][1] = atof( foo );
168    
169     // get the Hz vector
170    
171     foo = strtok(NULL, " ,;\t");
172     if(foo == NULL){
173     fprintf(stderr,
174     "error in reading Hz[0] from %s at line %d\n",
175     inName, lineNum );
176     exit(0);
177     }
178     currPos->Hmat[0][2] = atof( foo );
179    
180     foo = strtok(NULL, " ,;\t");
181     if(foo == NULL){
182     fprintf(stderr,
183     "error in reading Hz[1] from %s at line %d\n",
184     inName, lineNum );
185     exit(0);
186     }
187     currPos->Hmat[1][2] = atof( foo );
188    
189     foo = strtok(NULL, " ,;\t");
190     if(foo == NULL){
191     fprintf(stderr,
192     "error in reading Hz[2] from %s at line %d\n",
193     inName, lineNum );
194     exit(0);
195     }
196     currPos->Hmat[2][2] = atof( foo );
197    
198     // skip the atoms
199    
200     for(j=0; j<i; j++){
201    
202     fgets( readBuffer, sizeof( readBuffer ), inFile );
203     lineNum++;
204     if( feof( inFile ) ){
205     fprintf( stderr,
206     "File \"%s\" ended unexpectedly at line %d,"
207     " with atom %d\n",
208     inName,
209     lineNum,
210     j );
211     exit(0);
212     }
213     }
214 mmeineke 1053 }
215 mmeineke 1052
216     isScanned = 1;
217     return nFrames;
218     }