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 _cmdline.parse(argc, argv);
144
145 _database = database.getValue();
146
147 if (table.getValue() == "Theory") {
148
149 _table = PAHdb::Database::Theory;
150 } else if (table.getValue() == "Experiment") {
151
152 _table = PAHdb::Database::Experiment;
153 } else if (table.getValue() == "Anharmonic") {
154
155 _table = PAHdb::Database::Anharmonic;
156 }
157
158 _host = host.getValue();
159
160 _username = username.getValue();
161
162 _password = password.getValue();
163
164 _port = port.getValue();
165
166 _compress = compress.getValue();
167
168 _timeout = timeout.getValue();
169
170 _socket = socket.getValue();
171
172 _databaseversion = databaseversion.getValue();
173
174 _output = output.getValue();
175
176 _input = input.getValue();
177
178 std::string_view tmp = ids.getValue();
179
180 std::string strvalue;
181
182 auto it = tmp.begin();
183
184 int ivalue;
185
186 char *endp;
187
188 while (true) {
189
190 if (*it == ',' || it == tmp.end()) {
191
192 ivalue = strtol(strvalue.c_str(), &endp, 10);
193
194 if (strvalue.size() == 0 || *endp != '\0') {
195
196 throw(Exception(std::string(
197 "PARSE ERROR: Argument (--ids)\n Value '" + strvalue +
198 "' does not meet constraint: integer")));
199 }
200
201 _ids.push_back(ivalue);
202
203 strvalue.clear();
204 } else {
205
206 strvalue += *it;
207 }
208
209 if (it == tmp.end()) {
210
211 break;
212 }
213 ++it;
214 };
215
216 tmp = plotsize.getValue();
217
218 it = tmp.begin();
219
220 size_t i = 0;
221
222 while (i < 2) {
223
224 if (*it == ',' || it == tmp.end()) {
225
226 ivalue = strtol(strvalue.c_str(), &endp, 10);
227
228 if (strvalue.size() == 0 || *endp != '\0') {
229
230 throw(Exception(std::string(
231 "PARSE ERROR: Argument (--plotsize)\n Value '" +
232 strvalue + "' does not meet constraint: int")));
233 }
234
235 _plotsize[i++] = ivalue;
236
237 strvalue.clear();
238 } else {
239
240 strvalue += *it;
241 }
242
243 if (it == tmp.end()) {
244
245 break;
246 }
247 ++it;
248 };
249
250 if (_plotsize.size() != 2) {
251
252 throw(Exception(
253 (std::string(
254 "PARSE ERROR: Argument (--plotsize)\n Value '") +
255 tmp.data() + "' does not meet constraint: two integers")));
256 }
257
258 if (model.getValue() == "ZeroKelvin") {
259
260 _model = Parameters::Arg::ZeroKelvin;
261 } else if (model.getValue() == "FixedTemperature") {
262
263 _model = Parameters::Arg::FixedTemperature;
264 } else if (model.getValue() == "Temperature") {
265
266 _model = Parameters::Arg::Temperature;
267 }
268
269 else if (model.getValue() == "Cascade") {
270
271 _model = Parameters::Arg::Cascade;
272 }
273
274 if (tool.getValue() == "CoAdd") {
275
276 _tool = Parameters::Arg::CoAdd;
277 } else if (tool.getValue() == "Stack") {
278
279 _tool = Parameters::Arg::Stack;
280 } else if (tool.getValue() == "TemperatureStack") {
281
282 _tool = Parameters::Arg::TemperatureStack;
283 }
284
285 else if (tool.getValue() == "CompareExperimentWithTheory") {
286
287 _tool = Parameters::Arg::CompareExperimentWithTheory;
288 } else if (tool.getValue() == "SpectralFit") {
289 _tool = Parameters::Arg::SpectralFit;
290 }
291
292 if (profile.getValue() == "Lorentzian") {
293
294 _profile = Parameters::Arg::Lorentzian;
295 } else if (profile.getValue() == "Gaussian") {
296
297 _profile = Parameters::Arg::Gaussian;
298 } else if (profile.getValue() == "Drude") {
299
300 _profile = Parameters::Arg::Drude;
301 }
302
303 _fwhm = fwhm.getValue();
304
305 _shift = shift.getValue();
306
307 _energy = energy.getValue();
308
309 _temperature = temperature.getValue();
310
311 double dvalue;
312
313 tmp = temperatures.getValue();
314
315 if (tmp.size() > 0) {
316
317 it = tmp.begin();
318
319 while (true) {
320
321 if (*it == ',' || it == tmp.end()) {
322
323 dvalue = strtod(strvalue.c_str(), &endp);
324
325 if (strvalue.size() == 0 || *endp != '\0') {
326
327 throw(Exception(
328 std::string("PARSE ERROR: Argument (--temperatures)\n "
329 " Value '" +
330 strvalue + "' does not meet constraint: double")));
331 }
332
333 _temperatures.push_back(dvalue);
334
335 strvalue.clear();
336 } else {
337
338 strvalue += *it;
339 }
340
341 if (it == tmp.end()) {
342
343 break;
344 }
345 ++it;
346 };
347 }
348
349 tmp = weights.getValue();
350
351 if (tmp.size() > 0) {
352
353 it = tmp.begin();
354
355 while (true) {
356
357 if (*it == ',' || it == tmp.end()) {
358
359 dvalue = strtod(strvalue.c_str(), &endp);
360
361 if (strvalue.size() == 0 || *endp != '\0') {
362
363 throw(Exception(std::string(
364 "PARSE ERROR: Argument (--weights)\n Value '" +
365 strvalue + "' does not meet constraint: double")));
366 }
367
368 _weights.push_back(dvalue);
369
370 strvalue.clear();
371 } else {
372
373 strvalue += *it;
374 }
375
376 if (it == tmp.end()) {
377
378 break;
379 }
380 ++it;
381 };
382 } else {
383
384 _weights = std::vector<double>(_ids.size(), 1.0);
385 }
386
387 tmp = plotlimits.getValue();
388
389 it = tmp.begin();
390
391 i = 0;
392
393 while (i < 2) {
394
395 if (*it == ',' || it == tmp.end()) {
396
397 dvalue = strtod(strvalue.c_str(), &endp);
398
399 if (strvalue.size() == 0 || *endp != '\0') {
400
401 throw(Exception(std::string(
402 "PARSE ERROR: Argument (--plotlimits)\n Value '" +
403 strvalue + "' does not meet constraint: double")));
404 }
405
406 _plotlimits[i++] = dvalue;
407
408 strvalue.clear();
409 } else {
410
411 strvalue += *it;
412 }
413
414 if (it == tmp.end()) {
415
416 break;
417 }
418 ++it;
419 };
420
421 if (_plotlimits.size() != 2) {
422
423 throw(Exception(
424 std::string(
425 "PARSE ERROR: Argument (--plotlimits)\n Value '") +
426 tmp.data() + "' does not meet constraint: two doubles"));
427 }
428
429 if (units.getValue() == "Frequency")
430 _units = Parameters::Arg::Frequency;
431 else if (units.getValue() == "Wavelength")
432 _units = Parameters::Arg::Wavelength;
433
434 _invplotlimits = _plotlimits;
435
436 _invplotlimits.at(0) = 1e4 / _plotlimits.at(0);
437
438 _invplotlimits.at(1) = 1e4 / _plotlimits.at(1);
439
440 _x11 = x11.getValue();
441
442 _png = !nopng.getValue();
443
444 _jpeg = jpeg.getValue();
445
446 _postscript = postscript.getValue();
447 } catch (const TCLAP::ArgException &e) {
448
449 throw(Exception(e.what()));
450 }
451}

Since FY2019 the NASA Ames PAH IR Spectroscopic Database is being supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics - The NASA Ames PAH IR Spectroscopic Database".
Since FY2023 the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Rd 2 directed Work Package at NASA Ames.
© Copyright 2021-2025, Christiaan Boersma