1 |
mmeineke |
495 |
#include <cstdlib> |
2 |
|
|
#include <cstdio> |
3 |
|
|
#include <cstring> |
4 |
|
|
|
5 |
|
|
#include "simError.h" |
6 |
|
|
|
7 |
mmeineke |
498 |
#include "bilayerSys.hpp" |
8 |
|
|
|
9 |
mmeineke |
495 |
// quick case asignments |
10 |
|
|
|
11 |
|
|
#define BILAYER 1 |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
char* program_name; |
15 |
|
|
void usage(void); |
16 |
|
|
|
17 |
|
|
|
18 |
|
|
int main( int argc, char* argv[]){ |
19 |
|
|
|
20 |
|
|
int i,j,k; |
21 |
|
|
int sysType; |
22 |
|
|
int done, have_prefix, isRandom; |
23 |
|
|
char current_flag; |
24 |
|
|
char* out_prefix; |
25 |
|
|
char* in_name; |
26 |
mmeineke |
498 |
|
27 |
|
|
sysBuildInfo info; |
28 |
mmeineke |
495 |
|
29 |
|
|
// initialize simError |
30 |
|
|
initSimError(); |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
program_name = argv[0]; /*save the program name in case we need it*/ |
34 |
|
|
sysType = -1; |
35 |
|
|
have_prefix = 0; |
36 |
|
|
isRandom = 0; |
37 |
|
|
in_name = NULL; |
38 |
|
|
for( i = 1; i < argc; i++){ |
39 |
|
|
|
40 |
|
|
if(argv[i][0] =='-'){ |
41 |
|
|
|
42 |
|
|
// parse the option |
43 |
|
|
|
44 |
|
|
if(argv[i][1] == '-' ){ |
45 |
|
|
|
46 |
|
|
// parse long word options |
47 |
|
|
|
48 |
|
|
if( !strcmp( argv[i], "--bilayer" ) ){ |
49 |
|
|
if( sysType > 0 ){ |
50 |
|
|
sprintf( painCave.errMsg, |
51 |
|
|
"You cannot specify more than one system to build.\n" ); |
52 |
|
|
painCave.isFatal = 0; |
53 |
|
|
simError(); |
54 |
|
|
usage(); |
55 |
|
|
} |
56 |
|
|
sysType = BILAYER; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
else{ |
60 |
|
|
sprintf( painCave.errMsg, |
61 |
|
|
"Invalid option \"%s\"\n", argv[i] ); |
62 |
|
|
painCave.isFatal = 0; |
63 |
|
|
simError(); |
64 |
|
|
usage(); |
65 |
|
|
} |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
else{ |
69 |
|
|
|
70 |
|
|
// parse single character options |
71 |
|
|
|
72 |
|
|
done =0; |
73 |
|
|
j = 1; |
74 |
|
|
current_flag = argv[i][j]; |
75 |
|
|
while( (current_flag != '\0') && (!done) ){ |
76 |
|
|
|
77 |
|
|
switch(current_flag){ |
78 |
|
|
|
79 |
|
|
case 'o': |
80 |
|
|
// -o <prefix> => the output prefix. |
81 |
|
|
|
82 |
|
|
i++; |
83 |
|
|
out_prefix = argv[i]; |
84 |
|
|
have_prefix = 1; |
85 |
|
|
done = 1; |
86 |
|
|
break; |
87 |
|
|
|
88 |
|
|
case 'h': |
89 |
|
|
// -h => give the usage |
90 |
|
|
|
91 |
|
|
usage(); |
92 |
|
|
break; |
93 |
|
|
|
94 |
|
|
case 'r': |
95 |
|
|
// toggle random |
96 |
|
|
|
97 |
|
|
isRandom = 1;; |
98 |
|
|
break; |
99 |
|
|
|
100 |
|
|
default: |
101 |
|
|
sprintf(painCave.errMsg, |
102 |
mmeineke |
498 |
"Bad option \"-%c\"\n", current_flag); |
103 |
mmeineke |
495 |
painCave.isFatal = 0; |
104 |
|
|
simError(); |
105 |
|
|
usage(); |
106 |
|
|
} |
107 |
|
|
j++; |
108 |
|
|
current_flag = argv[i][j]; |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
else{ |
114 |
|
|
|
115 |
|
|
if( in_name != NULL ){ |
116 |
|
|
sprintf( painCave.errMsg, |
117 |
|
|
"Error at \"%s\", program does not support\n" |
118 |
|
|
"more than one input file.\n" |
119 |
|
|
"\n", |
120 |
|
|
argv[i]); |
121 |
|
|
painCave.isFatal = 0; |
122 |
|
|
simError(); |
123 |
|
|
usage(); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
in_name = argv[i]; |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
if(in_name == NULL){ |
131 |
mmeineke |
498 |
sprintf( painCave.errMsg, |
132 |
|
|
"No input bass file was specified.\n"); |
133 |
|
|
painCave.isFatal = 0; |
134 |
|
|
simError(); |
135 |
mmeineke |
495 |
usage(); |
136 |
|
|
} |
137 |
mmeineke |
498 |
|
138 |
|
|
if( sysType < 0 ){ |
139 |
|
|
sprintf( painCave.errMsg, |
140 |
|
|
"No system type was specified.\n"); |
141 |
|
|
painCave.isFatal = 0; |
142 |
|
|
simError(); |
143 |
|
|
usage(); |
144 |
|
|
} |
145 |
mmeineke |
495 |
|
146 |
|
|
|
147 |
mmeineke |
498 |
// if no output prefix is given default to "donkey". |
148 |
|
|
|
149 |
|
|
if( !have_prefix ){ |
150 |
|
|
out_prefix = strdup( "donkey" ); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
info.in_name = in_name; |
154 |
|
|
info.out_prefix = out_prefix; |
155 |
|
|
info.isRandom = isRandom; |
156 |
mmeineke |
495 |
|
157 |
mmeineke |
498 |
// switch the system type |
158 |
|
|
|
159 |
|
|
switch( sysType ){ |
160 |
|
|
|
161 |
|
|
case BILAYER: |
162 |
|
|
|
163 |
|
|
buildBilayer( info ); |
164 |
|
|
break; |
165 |
|
|
|
166 |
|
|
default: |
167 |
|
|
sprintf( painCave.errMsg, |
168 |
|
|
"Unknown system type: %d\n", sysType ); |
169 |
|
|
painCave.isFatal = 1; |
170 |
|
|
simError(); |
171 |
|
|
} |
172 |
mmeineke |
495 |
|
173 |
|
|
return 0; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
|
177 |
|
|
/*************************************************************************** |
178 |
|
|
* prints out the usage for the command line arguments, then exits. |
179 |
|
|
***************************************************************************/ |
180 |
|
|
|
181 |
|
|
void usage(){ |
182 |
|
|
(void)fprintf(stdout, |
183 |
|
|
"The proper usage is: %s [options] <input bass>\n" |
184 |
|
|
"\n" |
185 |
|
|
"Options:\n" |
186 |
|
|
"\n" |
187 |
|
|
" short:\n" |
188 |
|
|
" ------\n" |
189 |
|
|
" -h Display this message\n" |
190 |
|
|
" -o <prefix> The output prefix\n" |
191 |
|
|
" -r toggle the random option\n" |
192 |
|
|
"\n" |
193 |
|
|
" long:\n" |
194 |
|
|
" -----\n" |
195 |
|
|
" --bilayer Tries to build a basic bilayer with the specified number\n" |
196 |
|
|
" of lipids in the input bass file. The bilayer will be\n" |
197 |
|
|
" surrounded by the number of solvent molecules given\n" |
198 |
|
|
" in the bass file.\n" |
199 |
|
|
" -note: combined with \"-r\" the simulation will start in\n" |
200 |
|
|
" an FCC lattice with randomly assigned latice\n" |
201 |
mmeineke |
498 |
" sites for all atoms involved.\n" |
202 |
mmeineke |
495 |
"\n" |
203 |
|
|
"\n", |
204 |
|
|
program_name); |
205 |
|
|
exit(8); |
206 |
|
|
} |