NAPISD
PAHdb website C++ backend
Loading...
Searching...
No Matches
Parameters.cpp
1#include "Parameters.h"
2
3Parameters::Parameters()
4 : _cmdline(PROGRAM_DESCRIPTION, ' ', PROGRAM_VERSION) {}
5
6Parameters::Parameters(const int argc, const char *argv[])
7 : _cmdline(PROGRAM_DESCRIPTION, ' ', PROGRAM_VERSION) {
8
9 parse(argc, argv);
10}
11
12void Parameters::parse(const int argc, const char *argv[]) {
13
14 try {
15
16 TCLAP::ValueArg<std::string> database("", "database", "MySQL database",
17 false, "pahdb", "string", _cmdline);
18
19 std::vector<std::string> constraint{"Theory", "Experiment", "Anharmonic"};
20
21 TCLAP::ValuesConstraint<std::string> tableconstraint(constraint);
22
23 TCLAP::ValueArg<std::string> table("", "table", "MySQL table", false,
24 "Theory", &tableconstraint, _cmdline);
25
26 TCLAP::ValueArg<std::string> host("", "host", "MySQL host", false,
27 "localhost", "string", _cmdline);
28
29 TCLAP::ValueArg<std::string> username("", "username", "MySQL username",
30 false, "root", "string", _cmdline);
31
32 TCLAP::ValueArg<std::string> password("", "password", "MySQL password",
33 false, "root", "string", _cmdline);
34
35 TCLAP::ValueArg<int> port("", "port", "MySQL port", false, 3306, "integer",
36 _cmdline);
37
38 TCLAP::SwitchArg compress("", "compress", "MySQL compression", _cmdline);
39
40 TCLAP::ValueArg<int> timeout("", "timeout", "MySQL timeout", false, 60,
41 "integer", _cmdline);
42
43 TCLAP::ValueArg<std::string> socket("", "socket", "MySQL socket", false,
44 "/var/run/mysqld/mysqld.sock", "string",
45 _cmdline);
46
47 TCLAP::ValueArg<int> databaseversion("", "databaseversion",
48 "Database version", false, 99,
49 "integer", _cmdline);
50
51 TCLAP::ValueArg<std::string> output("", "output", "Output file", false,
52 "default", "string", _cmdline);
53
54 TCLAP::ValueArg<std::string> input("", "input", "Input file", false, "",
55 "string", _cmdline);
56
57 TCLAP::ValueArg<std::string> ids("", "ids", "Species identifier(s)", true,
58 "", "comma separeted list of integers",
59 _cmdline);
60
61 TCLAP::ValueArg<std::string> plotsize(
62 "", "plotsize", "Plot size", false, "650,325",
63 "comma separeted list of 2 integers", _cmdline);
64
65 constraint.clear();
66
67 constraint.clear();
68 constraint.insert(constraint.begin(), {"ZeroKelvin", "FixedTemperature",
69 "Temperature", "Cascade"});
70
71 TCLAP::ValuesConstraint<std::string> modelconstraint(constraint);
72
73 TCLAP::ValueArg<std::string> model("", "model", "Emission model", false,
74 "ZeroKelvin", &modelconstraint,
75 _cmdline);
76
77 constraint.clear();
78
79 constraint.insert(constraint.begin(),
80 {"CoAdd", "Stack", "TemperatureStack",
81 "CompareExperimentWithTheory", "SpectralFit"});
82
83 TCLAP::ValuesConstraint<std::string> toolconstraint(constraint);
84
85 TCLAP::ValueArg<std::string> tool("", "tool", "Tool", false, "CoAdd",
86 &toolconstraint, _cmdline);
87
88 constraint.clear();
89
90 constraint.insert(constraint.begin(), {"Lorentzian", "Gaussian", "Drude"});
91
92 TCLAP::ValuesConstraint<std::string> profileconstraint(constraint);
93
94 TCLAP::ValueArg<std::string> profile("", "profile", "Emission profile",
95 false, "Lorentzian",
96 &profileconstraint, _cmdline);
97
98 TCLAP::ValueArg<double> fwhm(
99 "", "fwhm", "Full-width-half-maximum for applied emission profile",
100 false, 15.0, "double", _cmdline);
101
102 TCLAP::ValueArg<double> shift("", "shift", "Spectral shift", false, 0.0,
103 "double", _cmdline);
104
105 TCLAP::ValueArg<double> energy("", "energy", "Energy for model [eV]", false,
106 5, "double", _cmdline);
107
108 TCLAP::ValueArg<double> temperature("", "temperature",
109 "Temperature for Blackbody [Kelvin]",
110 false, 550, "double", _cmdline);
111
112 TCLAP::ValueArg<std::string> temperatures(
113 "", "temperatures", "Temperatures for Blackbodies [Kelvin]", false,
114 "10,100,1000", "comma separeted list of doubles", _cmdline);
115
116 TCLAP::ValueArg<std::string> weights(
117 "", "weights", "Weights to apply for co-add", false, "",
118 "comma separated list of doubles", _cmdline);
119
120 TCLAP::ValueArg<std::string> plotlimits(
121 "", "plotlimits", "Plot limits", false, "7000,0",
122 "Comma separated list of two doubles", _cmdline);
123
124 constraint.clear();
125
126 constraint.insert(constraint.begin(), {"Frequency", "Wavelength"});
127
128 TCLAP::ValuesConstraint<std::string> unitsconstraint(constraint);
129
130 TCLAP::ValueArg<std::string> units("", "units", "Plot units", false,
131 "Frequency", &unitsconstraint, _cmdline);
132
133 TCLAP::SwitchArg x11("", "x11", "Output to screen", _cmdline, false);
134
135 TCLAP::SwitchArg nopng("", "nopng", "Disable output to PNG file", _cmdline,
136 false);
137
138 TCLAP::SwitchArg jpeg("", "jpeg", "Output to a JPEG file", _cmdline, false);
139
140 TCLAP::SwitchArg postscript("", "postscript", "Output to a Postscript file",
141 _cmdline, false);
142
143 TCLAP::SwitchArg pdf("", "pdf", "Output to a PDF file", _cmdline, false);
144
145 _cmdline.parse(argc, argv);
146
147 _database = database.getValue();
148
149 if (table.getValue() == "Theory") {
150
151 _table = PAHdb::Database::Theory;
152 } else if (table.getValue() == "Experiment") {
153
154 _table = PAHdb::Database::Experiment;
155 } else if (table.getValue() == "Anharmonic") {
156
157 _table = PAHdb::Database::Anharmonic;
158 }
159
160 _host = host.getValue();
161
162 _username = username.getValue();
163
164 _password = password.getValue();
165
166 _port = port.getValue();
167
168 _compress = compress.getValue();
169
170 _timeout = timeout.getValue();
171
172 _socket = socket.getValue();
173
174 _databaseversion = databaseversion.getValue();
175
176 _output = output.getValue();
177
178 _input = input.getValue();
179
180 std::string_view tmp = ids.getValue();
181
182 std::string strvalue;
183
184 auto it = tmp.begin();
185
186 int ivalue;
187
188 char *endp;
189
190 while (true) {
191
192 if (*it == ',' || it == tmp.end()) {
193
194 ivalue = strtol(strvalue.c_str(), &endp, 10);
195
196 if (strvalue.size() == 0 || *endp != '\0') {
197
198 throw(Exception(std::string(
199 "PARSE ERROR: Argument (--ids)\n Value '" + strvalue +
200 "' does not meet constraint: integer")));
201 }
202
203 _ids.push_back(ivalue);
204
205 strvalue.clear();
206 } else {
207
208 strvalue += *it;
209 }
210
211 if (it == tmp.end()) {
212
213 break;
214 }
215 ++it;
216 };
217
218 tmp = plotsize.getValue();
219
220 it = tmp.begin();
221
222 size_t i = 0;
223
224 while (i < 2) {
225
226 if (*it == ',' || it == tmp.end()) {
227
228 ivalue = strtol(strvalue.c_str(), &endp, 10);
229
230 if (strvalue.size() == 0 || *endp != '\0') {
231
232 throw(Exception(std::string(
233 "PARSE ERROR: Argument (--plotsize)\n Value '" +
234 strvalue + "' does not meet constraint: int")));
235 }
236
237 _plotsize[i++] = ivalue;
238
239 strvalue.clear();
240 } else {
241
242 strvalue += *it;
243 }
244
245 if (it == tmp.end()) {
246
247 break;
248 }
249 ++it;
250 };
251
252 if (_plotsize.size() != 2) {
253
254 throw(Exception(
255 (std::string(
256 "PARSE ERROR: Argument (--plotsize)\n Value '") +
257 tmp.data() + "' does not meet constraint: two integers")));
258 }
259
260 if (model.getValue() == "ZeroKelvin") {
261
262 _model = Parameters::Arg::ZeroKelvin;
263 } else if (model.getValue() == "FixedTemperature") {
264
265 _model = Parameters::Arg::FixedTemperature;
266 } else if (model.getValue() == "Temperature") {
267
268 _model = Parameters::Arg::Temperature;
269 }
270
271 else if (model.getValue() == "Cascade") {
272
273 _model = Parameters::Arg::Cascade;
274 }
275
276 if (tool.getValue() == "CoAdd") {
277
278 _tool = Parameters::Arg::CoAdd;
279 } else if (tool.getValue() == "Stack") {
280
281 _tool = Parameters::Arg::Stack;
282 } else if (tool.getValue() == "TemperatureStack") {
283
284 _tool = Parameters::Arg::TemperatureStack;
285 }
286
287 else if (tool.getValue() == "CompareExperimentWithTheory") {
288
289 _tool = Parameters::Arg::CompareExperimentWithTheory;
290 } else if (tool.getValue() == "SpectralFit") {
291 _tool = Parameters::Arg::SpectralFit;
292 }
293
294 if (profile.getValue() == "Lorentzian") {
295
296 _profile = Parameters::Arg::Lorentzian;
297 } else if (profile.getValue() == "Gaussian") {
298
299 _profile = Parameters::Arg::Gaussian;
300 } else if (profile.getValue() == "Drude") {
301
302 _profile = Parameters::Arg::Drude;
303 }
304
305 _fwhm = fwhm.getValue();
306
307 _shift = shift.getValue();
308
309 _energy = energy.getValue();
310
311 _temperature = temperature.getValue();
312
313 double dvalue;
314
315 tmp = temperatures.getValue();
316
317 if (tmp.size() > 0) {
318
319 it = tmp.begin();
320
321 while (true) {
322
323 if (*it == ',' || it == tmp.end()) {
324
325 dvalue = strtod(strvalue.c_str(), &endp);
326
327 if (strvalue.size() == 0 || *endp != '\0') {
328
329 throw(Exception(
330 std::string("PARSE ERROR: Argument (--temperatures)\n "
331 " Value '" +
332 strvalue + "' does not meet constraint: double")));
333 }
334
335 _temperatures.push_back(dvalue);
336
337 strvalue.clear();
338 } else {
339
340 strvalue += *it;
341 }
342
343 if (it == tmp.end()) {
344
345 break;
346 }
347 ++it;
348 };
349 }
350
351 tmp = weights.getValue();
352
353 if (tmp.size() > 0) {
354
355 it = tmp.begin();
356
357 while (true) {
358
359 if (*it == ',' || it == tmp.end()) {
360
361 dvalue = strtod(strvalue.c_str(), &endp);
362
363 if (strvalue.size() == 0 || *endp != '\0') {
364
365 throw(Exception(std::string(
366 "PARSE ERROR: Argument (--weights)\n Value '" +
367 strvalue + "' does not meet constraint: double")));
368 }
369
370 _weights.push_back(dvalue);
371
372 strvalue.clear();
373 } else {
374
375 strvalue += *it;
376 }
377
378 if (it == tmp.end()) {
379
380 break;
381 }
382 ++it;
383 };
384 } else {
385
386 _weights = std::vector<double>(_ids.size(), 1.0);
387 }
388
389 tmp = plotlimits.getValue();
390
391 it = tmp.begin();
392
393 i = 0;
394
395 while (i < 2) {
396
397 if (*it == ',' || it == tmp.end()) {
398
399 dvalue = strtod(strvalue.c_str(), &endp);
400
401 if (strvalue.size() == 0 || *endp != '\0') {
402
403 throw(Exception(std::string(
404 "PARSE ERROR: Argument (--plotlimits)\n Value '" +
405 strvalue + "' does not meet constraint: double")));
406 }
407
408 _plotlimits[i++] = dvalue;
409
410 strvalue.clear();
411 } else {
412
413 strvalue += *it;
414 }
415
416 if (it == tmp.end()) {
417
418 break;
419 }
420 ++it;
421 };
422
423 if (_plotlimits.size() != 2) {
424
425 throw(Exception(
426 std::string(
427 "PARSE ERROR: Argument (--plotlimits)\n Value '") +
428 tmp.data() + "' does not meet constraint: two doubles"));
429 }
430
431 if (units.getValue() == "Frequency")
432 _units = Parameters::Arg::Frequency;
433 else if (units.getValue() == "Wavelength")
434 _units = Parameters::Arg::Wavelength;
435
436 _invplotlimits = _plotlimits;
437
438 _invplotlimits.at(0) = 1e4 / _plotlimits.at(0);
439
440 _invplotlimits.at(1) = 1e4 / _plotlimits.at(1);
441
442 _x11 = x11.getValue();
443
444 _png = !nopng.getValue();
445
446 _jpeg = jpeg.getValue();
447
448 _postscript = postscript.getValue();
449
450 _pdf = pdf.getValue();
451 } catch (const TCLAP::ArgException &e) {
452
453 throw(Exception(e.what()));
454 }
455}

From FY2025 onward the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Round 3 directed Work Package at NASA Ames.
From FY2023-2025 the NASA Ames PAH IR Spectroscopic Database was supported through the Laboratory Astrophysics Round 2 directed Work Package at NASA Ames.
From FY2019-2022 the NASA Ames PAH IR Spectroscopic Database was supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics – The NASA Ames PAH IR Spectroscopic Database".
© Copyright 2021-2025, Christiaan Boersma