1 : |
agomez |
1 |
#include "maininfo.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "gadget.h" |
4 : |
|
|
#include "runid.h" |
5 : |
|
|
#include "global.h" |
6 : |
|
|
|
7 : |
|
|
void MainInfo::showCorrectUsage(char* error) {
|
8 : |
|
|
RUNID.Print(cerr);
|
9 : |
|
|
cerr << "\nError in command line value - unrecognised option " << error << endl
|
10 : |
|
|
<< "Common options are -l or -s, -i <filename> -o <filename>\n"
|
11 : |
|
|
<< "For more information try running Gadget with the -h switch\n";
|
12 : |
|
|
exit(EXIT_FAILURE);
|
13 : |
|
|
}
|
14 : |
|
|
|
15 : |
|
|
void MainInfo::showUsage() {
|
16 : |
|
|
RUNID.Print(cout);
|
17 : |
|
|
cout << "\nOptions for running Gadget:\n"
|
18 : |
|
|
<< " -l perform a likelihood (optimising) model run\n"
|
19 : |
|
|
<< " -s perform a single (simulation) model run\n"
|
20 : |
|
|
<< " -n perform a network run (using paramin)\n"
|
21 : |
|
|
<< " -v --version display version information and exit\n"
|
22 : |
|
|
<< " -h --help display this help screen and exit\n"
|
23 : |
agomez |
20 |
#ifdef _OPENMP
|
24 : |
|
|
<< " -parallel <option> run in parallel <option> == [spe, rep]. spe=speculative, rep=reproducible. Defaull spe\n"
|
25 : |
|
|
#endif
|
26 : |
agomez |
1 |
<< "\nOptions for specifying the input to Gadget models:\n"
|
27 : |
|
|
<< " -i <filename> read model parameters from <filename>\n"
|
28 : |
|
|
<< " -opt <filename> read optimising parameters from <filename>\n"
|
29 : |
|
|
<< " -main <filename> read model information from <filename>\n"
|
30 : |
|
|
<< " (default filename is 'main')\n"
|
31 : |
|
|
<< " -m <filename> read other commandline parameters from <filename>\n"
|
32 : |
|
|
<< "\nOptions for specifying the output from Gadget models:\n"
|
33 : |
|
|
<< " -p <filename> print final model parameters to <filename>\n"
|
34 : |
|
|
<< " (default filename is 'params.out')\n"
|
35 : |
|
|
<< " -o <filename> print likelihood output to <filename>\n"
|
36 : |
|
|
<< " -print <number> print -o output every <number> iterations\n"
|
37 : |
|
|
<< " -precision <number> set the precision to <number> in output files\n"
|
38 : |
|
|
<< "\nOptions for debugging Gadget models:\n"
|
39 : |
|
|
<< " -log <filename> print logging information to <filename>\n"
|
40 : |
|
|
<< " -printinitial <filename> print initial model information to <filename>\n"
|
41 : |
|
|
<< " -printfinal <filename> print final model information to <filename>\n"
|
42 : |
|
|
<< "\nFor more information see the Gadget web page at http://www.hafro.is/gadget\n\n";
|
43 : |
|
|
exit(EXIT_SUCCESS);
|
44 : |
|
|
}
|
45 : |
|
|
|
46 : |
|
|
MainInfo::MainInfo()
|
47 : |
agomez |
20 |
#ifdef _OPENMP
|
48 : |
|
|
: givenOptInfo(0), givenInitialParam(0), runoptimise(0), runparallel(0),
|
49 : |
|
|
#else
|
50 : |
|
|
: givenOptInfo(0), givenInitialParam(0), runoptimise(0),
|
51 : |
|
|
#endif
|
52 : |
agomez |
1 |
runstochastic(0), runnetwork(0), runprint(1), forceprint(0),
|
53 : |
|
|
printInitialInfo(0), printFinalInfo(0), printLogLevel(0), maxratio(0.95) {
|
54 : |
|
|
|
55 : |
|
|
char tmpname[10];
|
56 : |
|
|
strncpy(tmpname, "", 10);
|
57 : |
|
|
strcpy(tmpname, "main");
|
58 : |
|
|
|
59 : |
|
|
strOptInfoFile = NULL;
|
60 : |
|
|
strInitialParamFile = NULL;
|
61 : |
|
|
strPrintInitialFile = NULL;
|
62 : |
|
|
strPrintFinalFile = NULL;
|
63 : |
|
|
strMainGadgetFile = NULL;
|
64 : |
|
|
setMainGadgetFile(tmpname);
|
65 : |
|
|
}
|
66 : |
|
|
|
67 : |
|
|
MainInfo::~MainInfo() {
|
68 : |
|
|
if (strOptInfoFile != NULL) {
|
69 : |
|
|
delete[] strOptInfoFile;
|
70 : |
|
|
strOptInfoFile = NULL;
|
71 : |
|
|
}
|
72 : |
|
|
if (strInitialParamFile != NULL) {
|
73 : |
|
|
delete[] strInitialParamFile;
|
74 : |
|
|
strInitialParamFile = NULL;
|
75 : |
|
|
}
|
76 : |
|
|
if (strPrintInitialFile != NULL) {
|
77 : |
|
|
delete[] strPrintInitialFile;
|
78 : |
|
|
strPrintInitialFile = NULL;
|
79 : |
|
|
}
|
80 : |
|
|
if (strPrintFinalFile != NULL) {
|
81 : |
|
|
delete[] strPrintFinalFile;
|
82 : |
|
|
strPrintFinalFile = NULL;
|
83 : |
|
|
}
|
84 : |
|
|
if (strMainGadgetFile != NULL) {
|
85 : |
|
|
delete[] strMainGadgetFile;
|
86 : |
|
|
strMainGadgetFile = NULL;
|
87 : |
|
|
}
|
88 : |
ulcessvp |
11 |
if (seed != NULL) {
|
89 : |
|
|
delete[] seed;
|
90 : |
|
|
seed = NULL;
|
91 : |
|
|
}
|
92 : |
agomez |
1 |
}
|
93 : |
|
|
|
94 : |
|
|
void MainInfo::read(int aNumber, char* const aVector[]) {
|
95 : |
|
|
|
96 : |
|
|
if (aNumber == 1) {
|
97 : |
|
|
handle.logMessage(LOGWARN, "Warning - no command line options specified, using default values");
|
98 : |
|
|
return;
|
99 : |
|
|
}
|
100 : |
|
|
|
101 : |
ulcessvp |
11 |
seed = new unsigned[3];
|
102 : |
|
|
seed[0] = 0;
|
103 : |
|
|
seed[1] = 0;
|
104 : |
|
|
seed[2] = 0;
|
105 : |
agomez |
1 |
int k = 1;
|
106 : |
|
|
while (k < aNumber) {
|
107 : |
|
|
if (strcasecmp(aVector[k], "-l") == 0) {
|
108 : |
|
|
runoptimise = 1;
|
109 : |
|
|
|
110 : |
|
|
} else if (strcasecmp(aVector[k], "-n") == 0) {
|
111 : |
|
|
runnetwork = 1;
|
112 : |
|
|
|
113 : |
|
|
#ifndef GADGET_NETWORK
|
114 : |
|
|
handle.logMessage(LOGFAIL, "Error - Gadget cannot currently run in network mode for paramin\nGadget must be recompiled to enable the network communication");
|
115 : |
|
|
#endif
|
116 : |
|
|
|
117 : |
|
|
} else if (strcasecmp(aVector[k], "-s") == 0) {
|
118 : |
ulcessvp |
11 |
runstochastic = 1;
|
119 : |
agomez |
1 |
} else if (strcasecmp(aVector[k], "-m") == 0) {
|
120 : |
|
|
ifstream infile;
|
121 : |
|
|
CommentStream incomment(infile);
|
122 : |
|
|
if (k == aNumber - 1)
|
123 : |
|
|
this->showCorrectUsage(aVector[k]);
|
124 : |
|
|
k++;
|
125 : |
|
|
infile.open(aVector[k], ios::in);
|
126 : |
|
|
handle.checkIfFailure(infile, aVector[k]);
|
127 : |
|
|
if (infile.fail())
|
128 : |
|
|
this->showCorrectUsage(aVector[k]);
|
129 : |
|
|
this->read(incomment);
|
130 : |
|
|
infile.close();
|
131 : |
|
|
infile.clear();
|
132 : |
|
|
|
133 : |
|
|
} else if (strcasecmp(aVector[k], "-i") == 0) {
|
134 : |
|
|
if (k == aNumber - 1)
|
135 : |
|
|
this->showCorrectUsage(aVector[k]);
|
136 : |
|
|
k++;
|
137 : |
|
|
this->setInitialParamFile(aVector[k]);
|
138 : |
|
|
|
139 : |
|
|
} else if (strcasecmp(aVector[k], "-o") == 0) {
|
140 : |
|
|
if (k == aNumber - 1)
|
141 : |
|
|
this->showCorrectUsage(aVector[k]);
|
142 : |
|
|
k++;
|
143 : |
|
|
printinfo.setOutputFile(aVector[k]);
|
144 : |
|
|
|
145 : |
|
|
} else if (strcasecmp(aVector[k], "-p") == 0) {
|
146 : |
|
|
if (k == aNumber - 1)
|
147 : |
|
|
this->showCorrectUsage(aVector[k]);
|
148 : |
|
|
k++;
|
149 : |
|
|
printinfo.setParamOutFile(aVector[k]);
|
150 : |
|
|
|
151 : |
|
|
} else if (strcasecmp(aVector[k], "-forceprint") == 0) {
|
152 : |
|
|
forceprint = 1;
|
153 : |
|
|
|
154 : |
|
|
} else if (strcasecmp(aVector[k], "-co") == 0) {
|
155 : |
|
|
handle.logMessage(LOGFAIL, "The -co switch is no longer supported");
|
156 : |
agomez |
20 |
#ifdef _OPENMP
|
157 : |
|
|
} else if (strcasecmp(aVector[k], "-parallel") == 0) {
|
158 : |
|
|
handle.logMessage(LOGINFO, "--------parallel option ", aVector[k]);
|
159 : |
agomez |
1 |
if (k == aNumber - 1)
|
160 : |
|
|
this->showCorrectUsage(aVector[k]);
|
161 : |
|
|
k++;
|
162 : |
agomez |
20 |
this->setParallel(aVector[k]);
|
163 : |
|
|
#endif
|
164 : |
agomez |
1 |
|
165 : |
|
|
} else if (strcasecmp(aVector[k], "-printfinal") == 0) {
|
166 : |
|
|
if (k == aNumber - 1)
|
167 : |
|
|
this->showCorrectUsage(aVector[k]);
|
168 : |
|
|
k++;
|
169 : |
|
|
this->setPrintFinalFile(aVector[k]);
|
170 : |
|
|
|
171 : |
|
|
} else if (strcasecmp(aVector[k], "-main") == 0) {
|
172 : |
|
|
if (k == aNumber - 1)
|
173 : |
|
|
this->showCorrectUsage(aVector[k]);
|
174 : |
|
|
k++;
|
175 : |
|
|
this->setMainGadgetFile(aVector[k]);
|
176 : |
|
|
|
177 : |
|
|
} else if (strcasecmp(aVector[k], "-opt") == 0) {
|
178 : |
|
|
if (k == aNumber - 1)
|
179 : |
|
|
this->showCorrectUsage(aVector[k]);
|
180 : |
|
|
k++;
|
181 : |
|
|
this->setOptInfoFile(aVector[k]);
|
182 : |
|
|
|
183 : |
|
|
} else if ((strcasecmp(aVector[k], "-printlikelihood") == 0) || (strcasecmp(aVector[k], "-likelihoodprint") == 0)) {
|
184 : |
|
|
handle.logMessage(LOGFAIL, "The -printlikelihood switch is no longer supported\nSpecify a likelihoodprinter class in the model print file instead");
|
185 : |
|
|
|
186 : |
|
|
} else if (strcasecmp(aVector[k], "-printlikesummary") == 0) {
|
187 : |
|
|
handle.logMessage(LOGFAIL, "The -printlikesummary switch is no longer supported\nSpecify a likelihoodsummaryprinter class in the model print file instead");
|
188 : |
|
|
|
189 : |
|
|
} else if (strcasecmp(aVector[k], "-printonelikelihood") == 0) {
|
190 : |
|
|
handle.logMessage(LOGFAIL, "The -printonelikelihood switch is no longer supported\nSpecify a likelihoodprinter class in the model print file instead");
|
191 : |
|
|
|
192 : |
|
|
} else if ((strcasecmp(aVector[k], "-print") == 0) || (strcasecmp(aVector[k], "-print1") == 0)) {
|
193 : |
|
|
if (k == aNumber - 1)
|
194 : |
|
|
this->showCorrectUsage(aVector[k]);
|
195 : |
|
|
k++;
|
196 : |
|
|
printinfo.setPrintIteration(atoi(aVector[k]));
|
197 : |
|
|
|
198 : |
|
|
} else if (strcasecmp(aVector[k], "-precision") == 0) {
|
199 : |
|
|
if (k == aNumber - 1)
|
200 : |
|
|
this->showCorrectUsage(aVector[k]);
|
201 : |
|
|
k++;
|
202 : |
|
|
printinfo.setPrecision(atoi(aVector[k]));
|
203 : |
|
|
|
204 : |
|
|
} else if ((strcasecmp(aVector[k], "-v") == 0) || (strcasecmp(aVector[k], "--version") == 0)) {
|
205 : |
|
|
RUNID.Print(cout);
|
206 : |
|
|
exit(EXIT_SUCCESS);
|
207 : |
|
|
|
208 : |
|
|
} else if ((strcasecmp(aVector[k], "-h") == 0) || (strcasecmp(aVector[k], "--help") == 0)) {
|
209 : |
|
|
this->showUsage();
|
210 : |
|
|
|
211 : |
|
|
} else if (strcasecmp(aVector[k], "-log") == 0) {
|
212 : |
|
|
if (k == aNumber - 1)
|
213 : |
|
|
this->showCorrectUsage(aVector[k]);
|
214 : |
|
|
k++;
|
215 : |
|
|
handle.setLogFile(aVector[k]);
|
216 : |
|
|
printLogLevel = 5;
|
217 : |
|
|
|
218 : |
|
|
} else if (strcasecmp(aVector[k], "-nowarnings") == 0) {
|
219 : |
|
|
//handle.logMessage(LOGWARN, "The -nowarnings switch is no longer supported\nSpecify a logging level using the -loglevel <number> instead");
|
220 : |
|
|
printLogLevel = 1;
|
221 : |
|
|
|
222 : |
|
|
} else if (strcasecmp(aVector[k], "-loglevel") == 0) {
|
223 : |
|
|
if (k == aNumber - 1)
|
224 : |
|
|
this->showCorrectUsage(aVector[k]);
|
225 : |
|
|
k++;
|
226 : |
|
|
printLogLevel = atoi(aVector[k]);
|
227 : |
|
|
|
228 : |
|
|
} else if (strcasecmp(aVector[k], "-noprint") == 0) {
|
229 : |
|
|
//JMB disable model printing from the commandline
|
230 : |
|
|
runprint = 0;
|
231 : |
|
|
|
232 : |
|
|
} else if (strcasecmp(aVector[k], "-seed") == 0) {
|
233 : |
|
|
//JMB experimental setting of random number seed from the commandline
|
234 : |
|
|
//if the "seed" is also specified in the optinfo file then that will override
|
235 : |
|
|
//any seed that is specified on the commandline
|
236 : |
|
|
if (k == aNumber - 1)
|
237 : |
|
|
this->showCorrectUsage(aVector[k]);
|
238 : |
|
|
k++;
|
239 : |
ulcessvp |
11 |
seed[0] = atoi(aVector[k]);
|
240 : |
|
|
srand(seed[0]);
|
241 : |
ulcessvp |
12 |
//seedM = seed to set the metropolis acceptance in SA
|
242 : |
ulcessvp |
11 |
} else if (strcasecmp(aVector[k], "-seedM") == 0) {
|
243 : |
|
|
//JMB experimental setting of random number seed from the commandline
|
244 : |
|
|
//if the "seed" is also specified in the optinfo file then that will override
|
245 : |
|
|
//any seed that is specified on the commandline
|
246 : |
|
|
if (k == aNumber - 1)
|
247 : |
|
|
this->showCorrectUsage(aVector[k]);
|
248 : |
|
|
k++;
|
249 : |
|
|
seed[1] = atoi(aVector[k]);
|
250 : |
ulcessvp |
12 |
//seedP = seed to set the orden of evaluation of the parameter in SA
|
251 : |
ulcessvp |
11 |
} else if (strcasecmp(aVector[k], "-seedP") == 0) {
|
252 : |
|
|
//JMB experimental setting of random number seed from the commandline
|
253 : |
|
|
//if the "seed" is also specified in the optinfo file then that will override
|
254 : |
|
|
//any seed that is specified on the commandline
|
255 : |
|
|
if (k == aNumber - 1)
|
256 : |
|
|
this->showCorrectUsage(aVector[k]);
|
257 : |
|
|
k++;
|
258 : |
|
|
seed[2] = atoi(aVector[k]);
|
259 : |
|
|
|
260 : |
agomez |
1 |
} else if (strcasecmp(aVector[k], "-maxratio") == 0) {
|
261 : |
|
|
//JMB experimental setting of maximum ratio of stock consumed in one timestep
|
262 : |
|
|
if (k == aNumber - 1)
|
263 : |
|
|
this->showCorrectUsage(aVector[k]);
|
264 : |
|
|
k++;
|
265 : |
|
|
maxratio = atof(aVector[k]);
|
266 : |
|
|
|
267 : |
|
|
} else
|
268 : |
|
|
this->showCorrectUsage(aVector[k]);
|
269 : |
|
|
|
270 : |
|
|
k++;
|
271 : |
|
|
}
|
272 : |
ulcessvp |
11 |
|
273 : |
|
|
if (seed[0] == 0) {
|
274 : |
|
|
seed[0] = unsigned(time(NULL));
|
275 : |
|
|
if (seed[1] == 0)
|
276 : |
|
|
seed[1] = unsigned(time(NULL));
|
277 : |
|
|
if (seed[2] == 0)
|
278 : |
|
|
seed[2] = unsigned(time(NULL));
|
279 : |
|
|
} else {
|
280 : |
|
|
if (seed[1] == 0)
|
281 : |
|
|
seed[1] = seed[0];
|
282 : |
|
|
if (seed[2] == 0)
|
283 : |
|
|
seed[2] = seed[0];
|
284 : |
|
|
}
|
285 : |
|
|
|
286 : |
|
|
|
287 : |
|
|
|
288 : |
|
|
|
289 : |
agomez |
1 |
}
|
290 : |
|
|
|
291 : |
|
|
void MainInfo::checkUsage(const char* const inputdir, const char* const workingdir) {
|
292 : |
|
|
int check = 0;
|
293 : |
|
|
if (runnetwork)
|
294 : |
|
|
check = max(0, printLogLevel);
|
295 : |
|
|
else if (runstochastic)
|
296 : |
|
|
check = max(3, printLogLevel);
|
297 : |
|
|
else
|
298 : |
|
|
check = max(2, printLogLevel);
|
299 : |
|
|
handle.setLogLevel(check);
|
300 : |
|
|
|
301 : |
|
|
//JMB dont print output if doing a network run
|
302 : |
|
|
if (!runnetwork)
|
303 : |
|
|
RUNID.Print(cout);
|
304 : |
|
|
handle.logMessage(LOGINFO, "Starting Gadget from directory:", workingdir);
|
305 : |
|
|
handle.logMessage(LOGINFO, "using data from directory:", inputdir);
|
306 : |
|
|
handle.logMessage(LOGMESSAGE, ""); //write a blank line to the log file
|
307 : |
|
|
if (strcasecmp(inputdir, workingdir) != 0)
|
308 : |
|
|
handle.logMessage(LOGWARN, "Warning - working directory different from input directory");
|
309 : |
|
|
|
310 : |
|
|
if (runnetwork) {
|
311 : |
|
|
handle.logMessage(LOGINFO, "\n** Gadget running in network mode for Paramin **");
|
312 : |
|
|
if (printInitialInfo) {
|
313 : |
|
|
handle.logMessage(LOGINFO, "Warning - cannot print initial model information");
|
314 : |
|
|
printInitialInfo = 0;
|
315 : |
|
|
}
|
316 : |
|
|
if (printFinalInfo) {
|
317 : |
|
|
handle.logMessage(LOGINFO, "Warning - cannot print final model information");
|
318 : |
|
|
printFinalInfo = 0;
|
319 : |
|
|
}
|
320 : |
|
|
}
|
321 : |
|
|
|
322 : |
|
|
//JMB check to see if we can actually open required files ...
|
323 : |
|
|
ifstream tmpin;
|
324 : |
|
|
if (chdir(inputdir) != 0)
|
325 : |
|
|
handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
|
326 : |
|
|
if (givenInitialParam) {
|
327 : |
|
|
//JMB check to see that the input and output filenames are different
|
328 : |
|
|
//Otherwise Gadget will over-write the inputfile with a blank outputfile ...
|
329 : |
|
|
if (strcasecmp(strInitialParamFile, printinfo.getParamOutFile()) == 0)
|
330 : |
|
|
handle.logFileMessage(LOGFAIL, "the parameter input and output filenames are the same");
|
331 : |
|
|
|
332 : |
|
|
tmpin.open(strInitialParamFile, ios::in);
|
333 : |
|
|
handle.checkIfFailure(tmpin, strInitialParamFile);
|
334 : |
|
|
tmpin.close();
|
335 : |
|
|
tmpin.clear();
|
336 : |
|
|
}
|
337 : |
|
|
if (givenOptInfo) {
|
338 : |
|
|
tmpin.open(strOptInfoFile, ios::in);
|
339 : |
|
|
handle.checkIfFailure(tmpin, strOptInfoFile);
|
340 : |
|
|
tmpin.close();
|
341 : |
|
|
tmpin.clear();
|
342 : |
|
|
}
|
343 : |
|
|
ofstream tmpout;
|
344 : |
|
|
if (chdir(workingdir) != 0)
|
345 : |
|
|
handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
|
346 : |
|
|
if (printInitialInfo) {
|
347 : |
|
|
tmpout.open(strPrintInitialFile, ios::out);
|
348 : |
|
|
handle.checkIfFailure(tmpout, strPrintInitialFile);
|
349 : |
|
|
tmpout.close();
|
350 : |
|
|
tmpout.clear();
|
351 : |
|
|
}
|
352 : |
|
|
if (printFinalInfo) {
|
353 : |
|
|
tmpout.open(strPrintFinalFile, ios::out);
|
354 : |
|
|
handle.checkIfFailure(tmpout, strPrintFinalFile);
|
355 : |
|
|
tmpout.close();
|
356 : |
|
|
tmpout.clear();
|
357 : |
|
|
}
|
358 : |
|
|
printinfo.checkPrintInfo(runnetwork);
|
359 : |
|
|
|
360 : |
|
|
//JMB check the value of maxratio
|
361 : |
|
|
if ((maxratio < rathersmall) || (maxratio > 1.0)) {
|
362 : |
|
|
handle.logMessage(LOGWARN, "Warning - value of maxratio outside bounds", maxratio);
|
363 : |
|
|
maxratio = 0.95;
|
364 : |
|
|
}
|
365 : |
|
|
|
366 : |
|
|
if ((!runstochastic) && (runnetwork)) {
|
367 : |
|
|
handle.logMessage(LOGWARN, "\nWarning - Gadget for the paramin network should be used with -s option\nGadget will now set the -s switch to perform a simulation run");
|
368 : |
|
|
runstochastic = 1;
|
369 : |
|
|
}
|
370 : |
|
|
|
371 : |
|
|
if ((runstochastic) && (runoptimise)) {
|
372 : |
|
|
handle.logMessage(LOGWARN, "\nWarning - Gadget has been started with both the -s switch and the -l switch\nHowever, it is not possible to do both a simulation run and a likelihood run!\nGadget will perform only the simulation run (and ignore the -l switch)");
|
373 : |
|
|
runoptimise = 0;
|
374 : |
|
|
}
|
375 : |
|
|
|
376 : |
|
|
if ((!runstochastic) && (!runoptimise)) {
|
377 : |
|
|
handle.logMessage(LOGWARN, "\nWarning - Gadget has been started without either the -s switch or the -l switch\nGadget will now set the -s switch to perform a simulation run");
|
378 : |
|
|
runstochastic = 1;
|
379 : |
|
|
}
|
380 : |
|
|
|
381 : |
|
|
handle.setRunOptimise(runoptimise);
|
382 : |
|
|
if ((printLogLevel == 1) && (!runoptimise))
|
383 : |
|
|
handle.logMessage(LOGWARN, "\n** Gadget cannot disable warnings for a simulation run **");
|
384 : |
|
|
|
385 : |
|
|
if ((handle.checkLogFile()) && (runoptimise) && (printLogLevel >= 5))
|
386 : |
|
|
handle.logMessage(LOGWARN, "\n** logging model information from a Gadget optimisation is not recommended **");
|
387 : |
|
|
|
388 : |
|
|
if ((handle.checkLogFile()) && (runnetwork))
|
389 : |
|
|
handle.logMessage(LOGWARN, "\n** logging model information from a Gadget network run is not recommended **");
|
390 : |
|
|
|
391 : |
|
|
//check the printing options
|
392 : |
|
|
if (forceprint)
|
393 : |
|
|
handle.logMessage(LOGMESSAGE, "\nPrinting model output has been enabled from the command line");
|
394 : |
|
|
if (!runprint)
|
395 : |
|
|
handle.logMessage(LOGMESSAGE, "\nPrinting model output has been disabled from the command line");
|
396 : |
|
|
|
397 : |
|
|
check = runprint;
|
398 : |
|
|
if (runnetwork)
|
399 : |
|
|
check = 0;
|
400 : |
|
|
else if ((runoptimise) && (!forceprint))
|
401 : |
|
|
check = 0;
|
402 : |
|
|
runprint = check;
|
403 : |
|
|
|
404 : |
|
|
handle.logMessage(LOGMESSAGE, ""); //write blank line to log file
|
405 : |
|
|
}
|
406 : |
|
|
|
407 : |
|
|
void MainInfo::read(CommentStream& infile) {
|
408 : |
|
|
int dummy = 0;
|
409 : |
|
|
char text[MaxStrLength];
|
410 : |
|
|
strncpy(text, "", MaxStrLength);
|
411 : |
|
|
infile >> ws;
|
412 : |
|
|
while (!infile.eof()) {
|
413 : |
|
|
infile >> text >> ws;
|
414 : |
|
|
|
415 : |
|
|
if (strcasecmp(text, "-i") == 0) {
|
416 : |
|
|
infile >> text >> ws;
|
417 : |
|
|
this->setInitialParamFile(text);
|
418 : |
|
|
} else if (strcasecmp(text, "-o") == 0) {
|
419 : |
|
|
infile >> text >> ws;
|
420 : |
|
|
printinfo.setOutputFile(text);
|
421 : |
|
|
} else if (strcasecmp(text, "-co") == 0) {
|
422 : |
|
|
handle.logMessage(LOGFAIL, "The -co switch is no longer supported");
|
423 : |
|
|
} else if (strcasecmp(text, "-p") == 0) {
|
424 : |
|
|
infile >> text >> ws;
|
425 : |
|
|
printinfo.setParamOutFile(text);
|
426 : |
|
|
} else if (strcasecmp(text, "-main") == 0) {
|
427 : |
|
|
infile >> text >> ws;
|
428 : |
|
|
this->setMainGadgetFile(text);
|
429 : |
|
|
} else if (strcasecmp(text, "-printinitial") == 0) {
|
430 : |
|
|
infile >> text >> ws;
|
431 : |
|
|
this->setPrintInitialFile(text);
|
432 : |
|
|
} else if (strcasecmp(text, "-printfinal") == 0) {
|
433 : |
|
|
infile >> text >> ws;
|
434 : |
|
|
this->setPrintFinalFile(text);
|
435 : |
agomez |
20 |
#ifdef _OPENMP
|
436 : |
|
|
} else if (strcasecmp(text, "-parallel") == 0) {
|
437 : |
|
|
infile >> text >> ws;
|
438 : |
|
|
handle.logMessage(LOGINFO, "--------parallel option 222 ", text);
|
439 : |
|
|
this->setParallel(text);
|
440 : |
|
|
#endif
|
441 : |
agomez |
1 |
} else if (strcasecmp(text, "-opt") == 0) {
|
442 : |
|
|
infile >> text >> ws;
|
443 : |
|
|
this->setOptInfoFile(text);
|
444 : |
|
|
} else if (strcasecmp(text, "-forceprint") == 0) {
|
445 : |
|
|
forceprint = 1;
|
446 : |
|
|
} else if (strcasecmp(text, "-noprint") == 0) {
|
447 : |
|
|
runprint = 0;
|
448 : |
|
|
} else if ((strcasecmp(text, "-print") == 0) || (strcasecmp(text, "-print1") == 0)) {
|
449 : |
|
|
infile >> dummy >> ws;
|
450 : |
|
|
printinfo.setPrintIteration(dummy);
|
451 : |
|
|
} else if (strcasecmp(text, "-precision") == 0) {
|
452 : |
|
|
infile >> dummy >> ws;
|
453 : |
|
|
printinfo.setPrecision(dummy);
|
454 : |
|
|
} else if (strcasecmp(text, "-log") == 0) {
|
455 : |
|
|
infile >> text >> ws;
|
456 : |
|
|
handle.setLogFile(text);
|
457 : |
|
|
printLogLevel = 5;
|
458 : |
|
|
} else if (strcasecmp(text, "-nowarnings") == 0) {
|
459 : |
|
|
printLogLevel = 1;
|
460 : |
|
|
} else if (strcasecmp(text, "-loglevel") == 0) {
|
461 : |
|
|
infile >> printLogLevel >> ws;
|
462 : |
|
|
} else if (strcasecmp(text, "-seed") == 0) {
|
463 : |
|
|
infile >> dummy >> ws;
|
464 : |
|
|
srand(dummy);
|
465 : |
|
|
} else if (strcasecmp(text, "-maxratio") == 0) {
|
466 : |
|
|
infile >> maxratio >> ws;
|
467 : |
|
|
} else if (strcasecmp(text, "-printlikesummary") == 0) {
|
468 : |
|
|
handle.logMessage(LOGWARN, "The -printlikesummary switch is no longer supported\nSpecify a likelihoodsummaryprinter class in the model print file instead");
|
469 : |
|
|
} else if (strcasecmp(text, "-printlikelihood") == 0) {
|
470 : |
|
|
handle.logMessage(LOGWARN, "The -printlikelihood switch is no longer supported\nSpecify a likelihoodprinter class in the model print file instead");
|
471 : |
|
|
} else if (strcasecmp(text, "-printonelikelihood") == 0) {
|
472 : |
|
|
handle.logMessage(LOGWARN, "The -printonelikelihood switch is no longer supported\nSpecify a likelihoodprinter class in the model print file instead");
|
473 : |
|
|
} else
|
474 : |
|
|
this->showCorrectUsage(text);
|
475 : |
|
|
}
|
476 : |
|
|
}
|
477 : |
|
|
|
478 : |
|
|
void MainInfo::setPrintInitialFile(char* filename) {
|
479 : |
|
|
if (strPrintInitialFile != NULL) {
|
480 : |
|
|
delete[] strPrintInitialFile;
|
481 : |
|
|
strPrintInitialFile = NULL;
|
482 : |
|
|
}
|
483 : |
|
|
strPrintInitialFile = new char[strlen(filename) + 1];
|
484 : |
|
|
strcpy(strPrintInitialFile, filename);
|
485 : |
|
|
printInitialInfo = 1;
|
486 : |
|
|
}
|
487 : |
|
|
|
488 : |
|
|
void MainInfo::setPrintFinalFile(char* filename) {
|
489 : |
|
|
if (strPrintFinalFile != NULL) {
|
490 : |
|
|
delete[] strPrintFinalFile;
|
491 : |
|
|
strPrintFinalFile = NULL;
|
492 : |
|
|
}
|
493 : |
|
|
strPrintFinalFile = new char[strlen(filename) + 1];
|
494 : |
|
|
strcpy(strPrintFinalFile, filename);
|
495 : |
|
|
printFinalInfo = 1;
|
496 : |
|
|
}
|
497 : |
agomez |
20 |
#ifdef _OPENMP
|
498 : |
|
|
void MainInfo::setParallel(char* filename) {
|
499 : |
|
|
if (!strcasecmp(filename,"spe")){
|
500 : |
|
|
runparallel=1;
|
501 : |
|
|
handle.logMessage(LOGINFO, "--------parallel speculative ", filename);
|
502 : |
|
|
return;
|
503 : |
|
|
}
|
504 : |
|
|
if (!strcasecmp(filename,"rep")){
|
505 : |
|
|
handle.logMessage(LOGINFO, "--------parallel reproducible ", filename);
|
506 : |
|
|
runparallel=2;
|
507 : |
|
|
return;
|
508 : |
|
|
}
|
509 : |
|
|
this->showCorrectUsage("opt");
|
510 : |
|
|
|
511 : |
|
|
}
|
512 : |
|
|
#endif
|
513 : |
agomez |
1 |
|
514 : |
|
|
void MainInfo::setMainGadgetFile(char* filename) {
|
515 : |
|
|
if (strMainGadgetFile != NULL) {
|
516 : |
|
|
delete[] strMainGadgetFile;
|
517 : |
|
|
strMainGadgetFile = NULL;
|
518 : |
|
|
}
|
519 : |
|
|
strMainGadgetFile = new char[strlen(filename) + 1];
|
520 : |
|
|
strcpy(strMainGadgetFile, filename);
|
521 : |
|
|
}
|
522 : |
|
|
|
523 : |
|
|
void MainInfo::setInitialParamFile(char* filename) {
|
524 : |
|
|
if (strInitialParamFile != NULL) {
|
525 : |
|
|
delete[] strInitialParamFile;
|
526 : |
|
|
strInitialParamFile = NULL;
|
527 : |
|
|
}
|
528 : |
|
|
strInitialParamFile = new char[strlen(filename) + 1];
|
529 : |
|
|
strcpy(strInitialParamFile, filename);
|
530 : |
|
|
givenInitialParam = 1;
|
531 : |
|
|
}
|
532 : |
|
|
|
533 : |
|
|
void MainInfo::setOptInfoFile(char* filename) {
|
534 : |
|
|
if (strOptInfoFile != NULL) {
|
535 : |
|
|
delete[] strOptInfoFile;
|
536 : |
|
|
strOptInfoFile = NULL;
|
537 : |
|
|
}
|
538 : |
|
|
strOptInfoFile = new char[strlen(filename) + 1];
|
539 : |
|
|
strcpy(strOptInfoFile, filename);
|
540 : |
|
|
givenOptInfo = 1;
|
541 : |
|
|
}
|