1 |
+ |
#define _FILE_OFFSET_BITS 64 |
2 |
+ |
|
3 |
|
#include <stdio.h> |
4 |
|
#include <stdlib.h> |
5 |
|
|
6 |
|
|
7 |
|
#include "params.h" |
8 |
|
#include "tcProps.h" |
9 |
+ |
#include "readWrite.h" |
10 |
+ |
#include "scdCorr.h" |
11 |
|
|
12 |
|
|
13 |
+ |
#define VERSION_MAJOR 0 |
14 |
+ |
#define VERSION_MINOR 1 |
15 |
+ |
|
16 |
+ |
char *programName; /*the name of the program */ |
17 |
+ |
void usage(void); |
18 |
+ |
|
19 |
|
int main( int argC, char *argV[] ){ |
20 |
|
|
21 |
|
// list of 'a priori' constants |
22 |
|
|
23 |
< |
const int nLipAtoms = 19; |
24 |
< |
const int nBonds = 18; |
25 |
< |
const int nLipids = NLIPIDS; |
26 |
< |
const int nSSD = NSSD; |
27 |
< |
const int nAtoms = nLipAtoms * nLipids + nSSD; |
23 |
> |
const int nLipAtoms = NL_ATOMS; |
24 |
> |
const int nBonds = NBONDS; |
25 |
> |
const int nLipids = NLIPIDS; |
26 |
> |
const int nSSD = NSSD; |
27 |
> |
const int nAtoms = nLipAtoms * nLipids + nSSD; |
28 |
> |
|
29 |
> |
// different needed variables |
30 |
|
|
31 |
|
struct atomCoord atoms[nAtoms]; |
32 |
+ |
int i,j,k; |
33 |
+ |
char* inName; |
34 |
+ |
int nFrames; |
35 |
+ |
|
36 |
+ |
char* outPrefix; // the output prefix |
37 |
+ |
char currentFlag; // used in parsing the flags |
38 |
+ |
int done = 0; // multipurpose boolean |
39 |
+ |
int havePrefix; // boolean for the output prefix |
40 |
+ |
char* conversionCheck; |
41 |
+ |
int conversionError; |
42 |
+ |
int optionError; |
43 |
+ |
char* pair1; |
44 |
+ |
char* pair2; |
45 |
+ |
int scdCorr; |
46 |
+ |
double startTime; |
47 |
|
|
48 |
+ |
// system initialization |
49 |
|
|
50 |
+ |
isScanned = 0; |
51 |
+ |
fileOpen = 0; |
52 |
+ |
nFrames = 0; |
53 |
+ |
frameTimes = NULL; |
54 |
|
|
55 |
< |
int i,j,k; |
55 |
> |
outPrefix = NULL; |
56 |
> |
inName = NULL; |
57 |
|
|
58 |
+ |
conversionError = 0; |
59 |
+ |
optionError = 0; |
60 |
+ |
havePrefix = 0; |
61 |
+ |
scdCorr = 0; |
62 |
+ |
startTime = 0.0; |
63 |
+ |
|
64 |
+ |
|
65 |
+ |
// parse the command line |
66 |
+ |
|
67 |
+ |
programName = argV[0]; /*save the program name in case we need it*/ |
68 |
+ |
|
69 |
+ |
for( i = 1; i < argC; i++){ |
70 |
+ |
|
71 |
+ |
if(argV[i][0] =='-'){ |
72 |
+ |
|
73 |
+ |
// parse the option |
74 |
+ |
|
75 |
+ |
if(argV[i][1] == '-' ){ |
76 |
+ |
|
77 |
+ |
// parse long word options |
78 |
+ |
|
79 |
+ |
if( !strcmp( argV[i], "--gofr" ) ){ |
80 |
+ |
|
81 |
+ |
i++; |
82 |
+ |
if( i>=argC ){ |
83 |
+ |
fprintf( stderr, |
84 |
+ |
"\n" |
85 |
+ |
"not enough arguments for --gofr\n"); |
86 |
+ |
usage(); |
87 |
+ |
exit(0); |
88 |
+ |
} |
89 |
+ |
pair1 = argV[i]; |
90 |
+ |
|
91 |
+ |
i++; |
92 |
+ |
if( i>=argC ){ |
93 |
+ |
fprintf( stderr, |
94 |
+ |
"\n" |
95 |
+ |
"not enough arguments for --gofr\n"); |
96 |
+ |
usage(); |
97 |
+ |
exit(0); |
98 |
+ |
} |
99 |
+ |
pair2 = argV[i]; |
100 |
+ |
|
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
else if( !strcmp( argV[i], "--gofrTheta" ) ){ |
104 |
+ |
|
105 |
+ |
i++; |
106 |
+ |
if( i>=argC ){ |
107 |
+ |
fprintf( stderr, |
108 |
+ |
"\n" |
109 |
+ |
"not enough arguments for --gofrTheta\n"); |
110 |
+ |
usage(); |
111 |
+ |
exit(0); |
112 |
+ |
} |
113 |
+ |
pair1 = argV[i]; |
114 |
+ |
|
115 |
+ |
i++; |
116 |
+ |
if( i>=argC ){ |
117 |
+ |
fprintf( stderr, |
118 |
+ |
"\n" |
119 |
+ |
"not enough arguments for --gofrTheta\n"); |
120 |
+ |
usage(); |
121 |
+ |
exit(0); |
122 |
+ |
} |
123 |
+ |
pair2 = argV[i]; |
124 |
+ |
|
125 |
+ |
} |
126 |
+ |
|
127 |
+ |
else if( !strcmp( argV[i], "--gofrOmega" ) ){ |
128 |
+ |
|
129 |
+ |
i++; |
130 |
+ |
if( i>=argC ){ |
131 |
+ |
fprintf( stderr, |
132 |
+ |
"\n" |
133 |
+ |
"not enough arguments for --gofrOmega\n"); |
134 |
+ |
usage(); |
135 |
+ |
exit(0); |
136 |
+ |
} |
137 |
+ |
pair1 = argV[i]; |
138 |
+ |
|
139 |
+ |
i++; |
140 |
+ |
if( i>=argC ){ |
141 |
+ |
fprintf( stderr, |
142 |
+ |
"\n" |
143 |
+ |
"not enough arguments for --gofrOmega\n"); |
144 |
+ |
usage(); |
145 |
+ |
exit(0); |
146 |
+ |
} |
147 |
+ |
pair2 = argV[i]; |
148 |
+ |
|
149 |
+ |
} |
150 |
+ |
|
151 |
+ |
else if( !strcmp( argV[i], "--version") ){ |
152 |
+ |
|
153 |
+ |
printf("\n" |
154 |
+ |
"tcProps version %d.%d\n" |
155 |
+ |
"\n", |
156 |
+ |
VERSION_MAJOR, VERSION_MINOR ); |
157 |
+ |
exit(0); |
158 |
+ |
|
159 |
+ |
} |
160 |
+ |
|
161 |
+ |
else if( !strcmp( argV[i], "--help") ){ |
162 |
+ |
|
163 |
+ |
usage(); |
164 |
+ |
exit(0); |
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
// anything else is an error |
168 |
+ |
|
169 |
+ |
else{ |
170 |
+ |
fprintf( stderr, |
171 |
+ |
"Invalid option \"%s\"\n", argV[i] ); |
172 |
+ |
usage(); |
173 |
+ |
exit(0); |
174 |
+ |
} |
175 |
+ |
} |
176 |
+ |
|
177 |
+ |
else{ |
178 |
+ |
|
179 |
+ |
// parse single character options |
180 |
+ |
|
181 |
+ |
done =0; |
182 |
+ |
j = 1; |
183 |
+ |
currentFlag = argV[i][j]; |
184 |
+ |
while( (currentFlag != '\0') && (!done) ){ |
185 |
+ |
|
186 |
+ |
switch(currentFlag){ |
187 |
+ |
|
188 |
+ |
case 'o': |
189 |
+ |
// -o <prefix> => the output prefix. |
190 |
+ |
|
191 |
+ |
j++; |
192 |
+ |
currentFlag = argV[i][j]; |
193 |
+ |
|
194 |
+ |
if( currentFlag != '\0' ) optionError = 1; |
195 |
+ |
|
196 |
+ |
if( optionError ){ |
197 |
+ |
fprintf( stderr, |
198 |
+ |
"\n" |
199 |
+ |
"The -o flag should end an option sequence.\n" |
200 |
+ |
" example: -r <outname> *NOT* -or <outname>\n" ); |
201 |
+ |
usage(); |
202 |
+ |
exit(0); |
203 |
+ |
} |
204 |
+ |
|
205 |
+ |
i++; |
206 |
+ |
if( i>=argC ){ |
207 |
+ |
fprintf( stderr, |
208 |
+ |
"\n" |
209 |
+ |
"not enough arguments for -o\n"); |
210 |
+ |
usage(); |
211 |
+ |
exit(0); |
212 |
+ |
} |
213 |
+ |
|
214 |
+ |
outPrefix = argV[i]; |
215 |
+ |
if( outPrefix[0] == '-' ) optionError = 1; |
216 |
+ |
|
217 |
+ |
if( optionError ){ |
218 |
+ |
fprintf( stderr, |
219 |
+ |
"\n" |
220 |
+ |
"\"%s\" is not a valid out prefix/name.\n" |
221 |
+ |
"Out prefix/name should not begin with a dash.\n", |
222 |
+ |
outPrefix ); |
223 |
+ |
usage(); |
224 |
+ |
exit(0); |
225 |
+ |
} |
226 |
+ |
|
227 |
+ |
havePrefix = 1; |
228 |
+ |
done = 1; |
229 |
+ |
break; |
230 |
+ |
|
231 |
+ |
case 'l': |
232 |
+ |
// -l <double> set <double> to the maxLength |
233 |
+ |
|
234 |
+ |
haveMaxLength = true; |
235 |
+ |
j++; |
236 |
+ |
currentFlag = argV[i][j]; |
237 |
+ |
|
238 |
+ |
if( currentFlag != '\0' ) optionError = 1; |
239 |
+ |
|
240 |
+ |
if( optionError ){ |
241 |
+ |
fprintf( stderr, |
242 |
+ |
"\n" |
243 |
+ |
"The -l flag should end an option sequence.\n" |
244 |
+ |
" example: -sl <double> *NOT* -ls <double>\n" ); |
245 |
+ |
usage(); |
246 |
+ |
exit(0); |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
i++; |
250 |
+ |
if( i>=argC ){ |
251 |
+ |
fprintf( stderr, |
252 |
+ |
"\n" |
253 |
+ |
"not enough arguments for -l\n"); |
254 |
+ |
usage(); |
255 |
+ |
exit(0); |
256 |
+ |
} |
257 |
+ |
|
258 |
+ |
maxLength = atof( argV[i] ); |
259 |
+ |
|
260 |
+ |
done = 1; |
261 |
+ |
|
262 |
+ |
break; |
263 |
+ |
|
264 |
+ |
case 't': |
265 |
+ |
// -t <double> set <double> to the startTime |
266 |
+ |
|
267 |
+ |
j++; |
268 |
+ |
currentFlag = argV[i][j]; |
269 |
+ |
|
270 |
+ |
if( currentFlag != '\0' ) optionError = 1; |
271 |
+ |
|
272 |
+ |
if( optionError ){ |
273 |
+ |
fprintf( stderr, |
274 |
+ |
"\n" |
275 |
+ |
"The -t flag should end an option sequence.\n" |
276 |
+ |
" example: -st <double> *NOT* -ts <double>\n" ); |
277 |
+ |
usage(); |
278 |
+ |
exit(0); |
279 |
+ |
} |
280 |
+ |
|
281 |
+ |
i++; |
282 |
+ |
if( i>=argC ){ |
283 |
+ |
fprintf( stderr, |
284 |
+ |
"\n" |
285 |
+ |
"not enough arguments for -t\n"); |
286 |
+ |
usage(); |
287 |
+ |
exit(0); |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
startTime = atof( argV[i] ); |
291 |
+ |
done = 1; |
292 |
+ |
break; |
293 |
+ |
|
294 |
+ |
case 's': |
295 |
+ |
// -s turn on separate output files |
296 |
+ |
|
297 |
+ |
scdCorr = 1; |
298 |
+ |
break; |
299 |
+ |
|
300 |
+ |
|
301 |
+ |
default: |
302 |
+ |
|
303 |
+ |
sprintf(painCave.errMsg, |
304 |
+ |
"\n" |
305 |
+ |
"Bad option \"-%c\"\n", currentFlag); |
306 |
+ |
usage(); |
307 |
+ |
exit(0); |
308 |
+ |
} |
309 |
+ |
j++; |
310 |
+ |
currentFlag = argV[i][j]; |
311 |
+ |
} |
312 |
+ |
} |
313 |
+ |
} |
314 |
+ |
|
315 |
+ |
else{ |
316 |
+ |
|
317 |
+ |
if( inName != NULL ){ |
318 |
+ |
fprintf( stderr, |
319 |
+ |
"Error at \"%s\", program does not currently support\n" |
320 |
+ |
"more than one input dump file.\n" |
321 |
+ |
"\n", |
322 |
+ |
argV[i]); |
323 |
+ |
usage(); |
324 |
+ |
exit(0); |
325 |
+ |
} |
326 |
+ |
|
327 |
+ |
inName = argV[i]; |
328 |
+ |
|
329 |
+ |
} |
330 |
+ |
} |
331 |
+ |
|
332 |
+ |
if( inName == NULL ){ |
333 |
+ |
fprintf( stderr, |
334 |
+ |
"Error, dump file is needed to run.\n" ); |
335 |
+ |
usage(); |
336 |
+ |
exit(0); |
337 |
+ |
} |
338 |
+ |
|
339 |
+ |
|
340 |
|
// initialize the arrays |
341 |
|
|
342 |
|
for(i=0;i<nLipids;i++){ |
343 |
|
|
344 |
|
atoms[nLipAtoms*i+0].type = HEAD; |
345 |
+ |
atoms[nLipAtoms*i+0].u[0] = 0.0; |
346 |
+ |
atoms[nLipAtoms*i+0].u[1] = 0.0; |
347 |
+ |
atoms[nLipAtoms*i+0].u[2] = 1.0; |
348 |
+ |
|
349 |
|
|
350 |
|
atoms[nLipAtoms*i+1].type = CH2; |
351 |
|
|
384 |
|
atoms[nLipAtoms*i+18].type = CH3; |
385 |
|
} |
386 |
|
|
387 |
< |
for(i=;i<nAtoms;i++){ |
387 |
> |
for(i=(nLipAtoms*nLipids);i<nAtoms;i++){ |
388 |
|
atoms[i].type = SSD; |
389 |
+ |
atoms[i].u[0] = 0.0; |
390 |
+ |
atoms[i].u[1] = 0.0; |
391 |
+ |
atoms[i].u[2] = 1.0; |
392 |
|
} |
393 |
+ |
|
394 |
+ |
// read and set the frames |
395 |
+ |
|
396 |
+ |
openFile( inName ); |
397 |
+ |
|
398 |
+ |
fprintf( stdout, |
399 |
+ |
"\n" |
400 |
+ |
"Counting the number of frames in \"%s\"...", |
401 |
+ |
inName ); |
402 |
+ |
fflush(stdout); |
403 |
+ |
|
404 |
+ |
setFrames( inName ); |
405 |
+ |
|
406 |
+ |
fprintf( stdout, |
407 |
+ |
"done.\n" |
408 |
+ |
"nFrames = %d\n.", |
409 |
+ |
nFrames ); |
410 |
+ |
fflush(stdout); |
411 |
+ |
|
412 |
+ |
if(scdCorr){ |
413 |
+ |
|
414 |
+ |
fprintf ( stdout, |
415 |
+ |
"Calculating the Scd correlation\n" ); |
416 |
+ |
fflush( stdout ); |
417 |
+ |
|
418 |
+ |
calcScdCorr( startTime ); |
419 |
+ |
} |
420 |
+ |
|
421 |
+ |
|
422 |
+ |
} |
423 |
+ |
|
424 |
+ |
|
425 |
+ |
/*************************************************************************** |
426 |
+ |
* prints out the usage for the command line arguments, then exits. |
427 |
+ |
***************************************************************************/ |
428 |
+ |
|
429 |
+ |
void usage(){ |
430 |
+ |
(void)fprintf(stdout, |
431 |
+ |
"\n" |
432 |
+ |
"The proper usage is: %s [options] <input_file>\n" |
433 |
+ |
"\n" |
434 |
+ |
"Options:\n" |
435 |
+ |
"\n" |
436 |
+ |
" short:\n" |
437 |
+ |
" ------\n" |
438 |
+ |
" -o <name> The output prefix\n" |
439 |
+ |
" -t <time> Set the start time for correlations\n" |
440 |
+ |
" -l <maxLength> set the maximum value of r\n" |
441 |
+ |
" *Defaults to 1/2 smallest length of first frame.\n" |
442 |
+ |
" -s Calculate the Scd chain correlation.\n" |
443 |
+ |
"\n" |
444 |
+ |
" long:\n" |
445 |
+ |
" -----\n" |
446 |
+ |
" --gofr <atom1> <atom2> g(r) for atom1 and atom2\n" |
447 |
+ |
" --gofrTheta <atom1> <atom2> g(r, theta) for atom1 and atom2\n" |
448 |
+ |
" --gofrOmega <atom1> <atom2> g(r, omega) for atom1 and atom2\n" |
449 |
+ |
" --version displays the version number\n" |
450 |
+ |
" --help displays this help message.\n" |
451 |
+ |
|
452 |
+ |
"\n" |
453 |
+ |
"\n", |
454 |
+ |
programName); |
455 |
+ |
} |