48 sp.
comp[symbol] = atoms;
57 std::string s,
int linenum = -1)
59 string msg =
"illegal number: "+s;
64 void CKParser::checkSpeciesName(std::string spname)
66 if (spname.size() <= 0) {
67 string sss =
"Empty for string name";
68 throw CK_SyntaxError(*m_log, sss, m_line);
70 char first = spname[0];
72 string sss =
"First char of string name is number";
73 throw CK_SyntaxError(*m_log, sss, m_line);
76 string sss =
"First char of string name is white space";
77 throw CK_SyntaxError(*m_log, sss, m_line);
81 static std::string d2e(std::string s)
87 for (n = 0; n < sz; n++) {
91 }
else if (ch ==
'd') {
98 static double de_atof(std::string s)
102 double rval = atof(r.c_str());
106 static double getNumberFromString(std::string s)
110 int sz =
static_cast<int>(s.size());
112 for (
int n = 0; n < sz; n++) {
114 if (!inexp && (ch ==
'E' || ch ==
'e' || ch ==
'D' || ch ==
'd')) {
116 }
else if (ch ==
'+' || ch ==
'-') {
117 if (n > 0 && (s[n-1] !=
'E' && s[n-1]
118 !=
'e' && s[n-1] !=
'd' && s[n-1] !=
'D')) {
121 }
else if (ch !=
'.' && (ch < '0' || ch >
'9')) {
128 static int de_atoi(std::ostream& log, std::string s,
int line = -1)
130 double val = getNumberFromString(s);
131 int ival = (int) val;
132 double val2 = (double) ival;
133 if (fabs(val - val2) >= 0.00001 * (val + val2)) {
134 string sss =
"de_atoi: Conversion of int failed: " + s;
135 throw CK_SyntaxError(log, sss, line);
156 bool CKParser::readNASA9ThermoSection(std::vector<string>& names,
158 int& optionFlag, std::ostream& log)
163 string defaultDate=
"";
164 int nsp =
static_cast<int>(names.size());
172 "In NASA9 parser. However, we expect a different file format",
178 bool getAllSpecies = (nsp > 0 &&
match(names[0],
"<ALL>"));
184 map<string, int> dup;
192 already_read =
false;
196 readNASA9ThermoRecord(spec);
200 if (spec.
name ==
"<END>") {
205 if (dup[spec.
name] == 2) {
206 log <<
"Warning: more than one THERMO record for "
207 <<
"species " << spec.
name << endl;
208 log <<
"Record at line " << m_line
209 <<
" of " << m_ckfilename <<
" ignored." << endl;
217 if (!already_read && (getAllSpecies
218 || (find(names.begin(), names.end(), spec.
name)
224 species[spec.
name] = spec;
227 log << endl <<
"found species " << spec.
name;
228 log <<
" at line " << m_line
229 <<
" of " << m_ckfilename;
233 names.push_back(spec.
name);
234 nsp =
static_cast<int>(names.size());
249 void CKParser::readNASA9ThermoRecord(
Species& sp)
268 getCKLine(s, comment);
271 putCKLine(s, comment);
276 string nameid = s.substr(0,18);
277 getTokens(nameid, static_cast<int>(nameid.size()), toks);
279 }
while (nToks == 0);
283 size_t nt = s.size();
284 sp.m_commentsRef = s.substr(18, nt-18);
291 "Illegal number of tokens for string name", m_line);
293 checkSpeciesName(sp.
name);
298 getCKLine(s, comment);
301 "Size of second line is too small", m_line);
304 string sN = s.substr(0,2);
307 string refDataCode = s.substr(3,6);
310 for (
int i = 0; i < 5; i++) {
311 string elementSym =
"";
313 if (s[iloc] !=
' ') {
314 if (s[iloc+1] !=
' ') {
315 elementSym = s.substr(iloc,2);
317 elementSym = s.substr(iloc,1);
319 }
else if (s[iloc+1] !=
' ') {
320 elementSym = s.substr(iloc+1,1);
322 double atoms = de_atof(s.substr(iloc+2,6));
328 sp.
phase = s.substr(50,2);
331 string molecWeight = s.substr(52, 13);
334 string Hf298_Jgmol = s.substr(65, 15);
336 vector_fp* coeffs_ptr;
339 coeffs_ptr =
new vector_fp(9);
340 vector_fp& coeffs = *coeffs_ptr;
343 getCKLine(s, comment);
346 "Size of third line is too small", m_line);
349 string sTlow = s.substr(0, 11);
350 double tLow = de_atof(sTlow);
352 string sTHigh = s.substr(11, 11);
353 double tHigh = de_atof(sTHigh);
355 string sNCoeff = s.substr(22, 1);
356 int nCoeff = de_atoi(*m_log, sNCoeff);
361 string sTCoeff1 = s.substr(24, 5);
362 double TCoeff1 = de_atof(sTCoeff1);
363 if (TCoeff1 != -2.0) {
367 string sTCoeff2 = s.substr(29, 5);
368 double TCoeff2 = de_atof(sTCoeff2);
369 if (TCoeff2 != -1.0) {
373 string sTCoeff3 = s.substr(34, 5);
374 double TCoeff3 = de_atof(sTCoeff3);
375 if (TCoeff3 != 0.0) {
379 string sTCoeff4 = s.substr(39, 5);
380 double TCoeff4 = de_atof(sTCoeff4);
381 if (TCoeff4 != 1.0) {
385 string sTCoeff5 = s.substr(44, 5);
386 double TCoeff5 = de_atof(sTCoeff5);
387 if (TCoeff5 != 2.0) {
391 string sTCoeff6 = s.substr(49, 5);
392 double TCoeff6 = de_atof(sTCoeff6);
393 if (TCoeff6 != 3.0) {
397 string sTCoeff7 = s.substr(54, 5);
398 double TCoeff7 = de_atof(sTCoeff7);
399 if (TCoeff7 != 4.0) {
403 string sHf298mHF0 = s.substr(65, 15);
406 getCKLine(s, comment);
409 "Size of third line is too small", m_line);
412 numstr = s.substr(0, 16);
413 cf = getNumberFromString(numstr);
419 numstr = s.substr(16, 16);
420 cf = getNumberFromString(numstr);
426 numstr = s.substr(32, 16);
427 cf = getNumberFromString(numstr);
433 numstr = s.substr(48, 16);
434 cf = getNumberFromString(numstr);
440 numstr = s.substr(64, 16);
441 cf = getNumberFromString(numstr);
448 getCKLine(s, comment);
451 "Size of fourth line is too small", m_line);
454 numstr = s.substr(0, 16);
455 cf = getNumberFromString(numstr);
461 numstr = s.substr(16, 16);
462 cf = getNumberFromString(numstr);
468 numstr = s.substr(48, 16);
469 cf = getNumberFromString(numstr);
475 numstr = s.substr(64, 16);
476 cf = getNumberFromString(numstr);
483 sp.minTemps.push_back(tLow);
484 sp.maxTemps.push_back(tHigh);
486 sp.region_coeffs.push_back(coeffs_ptr);