22 |
|
int lineNum = 0; // keeps track of the line number |
23 |
|
int n_atoms; // the number of atoms |
24 |
|
int i,j; // loop counters |
25 |
+ |
int isFirst; |
26 |
|
|
27 |
|
char read_buffer[2000]; /*the line buffer for reading */ |
28 |
|
char *foo; /*the pointer to the current string token */ |
48 |
|
char cosCorr1[30]; |
49 |
|
char cosCorr2[30]; |
50 |
|
|
50 |
– |
|
51 |
– |
|
51 |
|
program_name = argv[0]; /*save the program name in case we need it*/ |
52 |
|
|
53 |
|
for( i = 1; i < argc; i++){ |
180 |
|
exit(8); |
181 |
|
} |
182 |
|
|
183 |
< |
// create the array of frames |
183 |
> |
// create and initialize the array of frames |
184 |
|
|
185 |
|
dumpArray = (struct xyz_frame*)calloc( nFrames, |
186 |
|
sizeof( struct xyz_frame ) ); |
187 |
+ |
for( i=0; i<nFrames; i++ ){ |
188 |
+ |
dumpArray[i].nAtoms = 0; |
189 |
+ |
dumpArray[i].time = 0.0; |
190 |
+ |
dumpArray[i].boxX = 0.0; |
191 |
+ |
dumpArray[i].boxY = 0.0; |
192 |
+ |
dumpArray[i].boxZ = 0.0; |
193 |
+ |
dumpArray[i].r = NULL; |
194 |
+ |
dumpArray[i].v = NULL; |
195 |
+ |
dumpArray[i].names = NULL; |
196 |
+ |
} |
197 |
|
|
198 |
|
// read the frames |
199 |
|
|
200 |
|
printf( "Reading the frames into the coordinate arrays..." ); |
201 |
|
fflush( stdout ); |
202 |
|
|
203 |
+ |
isFirst = 1; |
204 |
|
for(j =0; j<nFrames; j++ ){ |
205 |
|
|
206 |
|
// read the number of atoms |
213 |
|
|
214 |
|
dumpArray[j].r = |
215 |
|
(struct coords *)calloc(n_atoms, sizeof(struct coords)); |
216 |
+ |
|
217 |
+ |
if( isFirst ) { |
218 |
+ |
dumpArray[0].names = |
219 |
+ |
(atomID *)calloc( n_atoms, sizeof(atomID) ); |
220 |
+ |
isFirst = 0; |
221 |
+ |
} |
222 |
|
|
223 |
|
if( calcMuCorr || calcCosCorr ){ |
224 |
|
dumpArray[j].v = |
225 |
|
(struct vect *)calloc(n_atoms, sizeof(struct vect)); |
226 |
+ |
printf( " (Note: reading in vectors)... " ); |
227 |
+ |
fflush( stdout ); |
228 |
|
} |
229 |
|
|
230 |
|
//read the time and the box sizes |
278 |
|
exit(8); |
279 |
|
} |
280 |
|
|
281 |
< |
strcpy(dumpArray[j].r[i].name, foo); /*copy the atom name */ |
281 |
> |
strcpy(dumpArray[0].names[i], foo); /*copy the atom name */ |
282 |
|
|
283 |
|
foo = strtok(NULL, " ,;\t"); |
284 |
|
if(foo == NULL){ |
411 |
|
fflush(stdout); |
412 |
|
} |
413 |
|
|
396 |
– |
|
414 |
|
return 0; |
415 |
|
|
416 |
|
} |