23 #ifndef GW_BASEENSDF_H
35 string BaseENSDF::BLANK =
" \n";
45 Position.second = key.
Position.second;
50 void BaseENSDF::DataSetKey::Clear()
57 Position.first = Position.second = CurrentPosition = 0;
60 void BaseENSDF::DataSetKey::Print(std::ostream &out)
const
62 out <<
"Nuclide " << Nuclide <<
" with id " << Dsid
63 <<
" at position " << Position.first <<
" " << Position.second <<
endl;
66 BaseENSDF::BaseENSDF()
70 BaseENSDF::~BaseENSDF() { Close(); }
72 bool BaseENSDF::IsRecord(
const char *r,
const char *t)
const
74 string id, type, record;
bool ok;
77 for (
int i = 0; i < RSIZE; i++ ) record += r[i];
79 id = record.substr(5,4); type = t;
81 if ( type ==
"IDENT" && (
id ==
" " ||
id ==
"1 ") ) {
82 if ( record != BLANK ) ok =
true;
85 if ( type ==
"Q-VALUE" &&
id ==
" Q " ) { ok =
true; }
86 if ( type ==
"LEVEL" &&
id ==
" L " ) { ok =
true; }
87 if ( type ==
"BETA" &&
id ==
" B " ) { ok =
true; }
88 if ( type ==
"EC" &&
id ==
" E " ) { ok =
true; }
89 if ( type ==
"ALPHA" &&
id ==
" A " ) { ok =
true; }
90 if ( type ==
"GAMMA" &&
id ==
" G " ) { ok =
true; }
92 if ( type ==
"END" && record == BLANK ) { ok =
true; }
96 string BaseENSDF::Nuclide(
const char *r)
const
99 for (
int i = 0; i < 5; i++ ) tmp += r[i];
return tmp;
101 string BaseENSDF::Dsid(
const char *r)
const
104 for (
int i = 9; i < 39; i++ ) tmp += r[i];
return tmp;
106 string BaseENSDF::Dsref(
const char *r)
const
109 for (
int i = 39; i < 65; i++ ) tmp += r[i];
return tmp;
111 string BaseENSDF::Pub(
const char *r)
const
114 for (
int i = 65; i < 74; i++ ) tmp += r[i];
return tmp;
117 string BaseENSDF::Date(
const char *r)
const
120 for (
int i = 74; i < 80; i++ ) tmp += r[i];
return tmp;
123 unsigned int BaseENSDF::IsDataSet(
const char *nuclide,
const char *datasetid)
const
125 unsigned int which = 0;
126 for (
unsigned int i = 0; i < fDataSets.size(); i++ ) {
127 if ( fDataSets[i].Dsid.find(datasetid) != string::npos
128 && fDataSets[i].Nuclide.find(nuclide) != string::npos ) which = i + 1;
133 bool BaseENSDF::NextRecord(
unsigned int whichdataset,
char *record)
135 bool ok =
true;
unsigned int realwhich;
138 if ( (0 < whichdataset) && (whichdataset < (fDataSets.size()+1)) ) {
140 realwhich = whichdataset - 1;
142 fDataSets[realwhich].CurrentPosition++;
143 if ( fDataSets[realwhich].CurrentPosition >= fDataSets[realwhich].Position.second )
146 Input.seekg(fDataSets[realwhich].CurrentPosition * RSIZE,ios::beg);
148 for (
int i = 0; i < RSIZE; i++) Input.get(record[i]);
157 bool BaseENSDF::FirstRecord(
unsigned int whichdataset,
char *record)
159 bool ok =
true;
unsigned int realwhich;
162 if ( (0 < whichdataset) && (whichdataset < (fDataSets.size()+1)) ) {
164 realwhich = whichdataset - 1;
166 fDataSets[realwhich].CurrentPosition = fDataSets[realwhich].Position.first;
167 Input.seekg(fDataSets[realwhich].CurrentPosition * RSIZE,ios::beg);
170 for (
int i = 0; i < RSIZE; i++) Input.get(record[i]);
178 bool BaseENSDF::Open(
const char *filename)
181 char record[RSIZE];
int read_record, read_good_record;
bool anew;
186 Input.open(filename);
188 anew =
false; read_record = read_good_record = 0;
189 if ( Input.is_open() ) {
193 ::memset(record,
'\0',81); std::string aline; getline(Input,aline);
194 if ( !Input && anew ==
true ) {
196 tmpkey.
Position.second = read_record;
197 fDataSets.push_back(tmpkey);
204 if ( aline.size() != 80 ) {
205 for (
size_t i = 0; i < RSIZE; i++)
206 record[i] = BLANK[i];
208 cerr <<
" NOT a record, break " << aline.size() <<
endl;
211 for (
size_t i = 0; i < aline.size(); i++)
212 record[i] = aline[i];
214 record[80] =
'\n'; read_record++;
222 if ( IsRecord(record,
"IDENT") && anew == false ) {
224 cerr <<
" A new Record is expected : " <<
endl;;
226 tmpkey.
Nuclide = Nuclide(record);
227 tmpkey.
Dsid = Dsid(record);
228 tmpkey.
Dsref = Dsref(record);
229 tmpkey.
Pub = Pub(record);
230 tmpkey.
Date = Date(record);
236 if ( IsRecord(record,
"END") && anew ==
true ) {
238 tmpkey.
Position.second = read_record; fDataSets.push_back(tmpkey);
240 tmpkey.
Clear(); anew =
false;
247 cout << fDataSets.size() <<
" datasets have been found in the ENSDF file " << filename <<
endl;
249 return Input.is_open();
295 void BaseENSDF::Close()
297 fDataSets.
clear(); Input.close(); Input.
clear();
300 void BaseENSDF::ls(std::ostream &out)
const
304 for (
unsigned int i = 0; i < fDataSets.size(); i++) {
305 out << fDataSets[i].Nuclide <<
" "
306 << fDataSets[i].Dsid <<
" "
308 <<
"from line " << fDataSets[i].Position.first <<
" to " << fDataSets[i].Position.second <<
" Current: "
309 << fDataSets[i].CurrentPosition <<
endl;
313 float BaseENSDF::GetCC(
const char *r)
318 for (
int i = 55; i < 62; i++ )
319 if ( r[i] !=
' ' ) tmp += r[i];
322 if (tmp.size() > 0 ) { istringstream estring(tmp); estring >> c; }
328 float BaseENSDF::GetDCC(
const char *r)
330 float dvalue, precision;
unsigned int i;
string tmp1, tmp2;
334 for (i = 55; i < 62; i++)
335 if ( r[i] !=
' ' ) tmp1 += r[i];
337 if ( tmp1.size() > 0 )
338 precision = GetPrecision(tmp1);
344 for (i = 62; i < 64; i++)
345 if ( r[i] !=
' ' ) tmp2 += r[i];
347 if ( tmp2.size() == 0 ||
348 tmp2 ==
"LT" || tmp2 ==
"GT" || tmp2 ==
"LE" ||
349 tmp2 ==
"GE" || tmp2 ==
"AP" || tmp2 ==
"CA" || tmp2 ==
"SY" ) dvalue = 0;
351 istringstream estring(tmp2);
352 estring >> dvalue; dvalue *= precision;
357 float BaseENSDF::GetMR(
const char *r)
362 for (
int i = 41; i < 49; i++ )
363 if ( r[i] !=
' ' ) tmp += r[i];
366 if (tmp.size() > 0 ) { istringstream estring(tmp); estring >> c; }
373 float BaseENSDF::GetDMR(
const char *r)
375 float dvalue, precision;
unsigned int i;
size_t l;
string tmp1, tmp2;
379 for (i = 41; i < 49; i++ )
380 if ( r[i] !=
' ' ) tmp1 += r[i];
382 if ( tmp1.size() > 0 )
383 precision = GetPrecision(tmp1);
388 for (i = 49; i < 55; i++ )
389 if ( r[i] !=
' ' ) tmp2 += r[i];
391 if ( (l = tmp2.find(
'+', 0 ) ) != string::npos
392 && (l = tmp2.find(
'-', 0 ) != string::npos ) ) {
396 if ( tmp2.size() > 0 ) {
397 istringstream estring(tmp2); estring >> dvalue;
401 return dvalue*precision;
405 float BaseENSDF::GetRI(
const char *r, std::string &s)
407 float value;
unsigned int i;
size_t l;
string tmp;
411 for (i = 21; i < 29; i++)
412 if ( r[i] !=
' ' ) tmp += r[i];
415 if ( (l = tmp.find(
'(', 0 ) ) != string::npos )
416 { s.insert(s.begin(),
'?'); tmp.erase(l,1); }
417 if ( (l = tmp.find(
')', 0 ) ) != string::npos )
418 { s.insert(s.begin(),
'?'); tmp.erase(l,1); }
420 if ( tmp.size() > 0 ) {
421 istringstream vstring(tmp); vstring >>
value;
428 float BaseENSDF::GetDRI(
const char *r)
430 float dvalue, precision;
unsigned int i;
string tmp1, tmp2;
434 for (i = 21; i < 29; i++)
435 if ( r[i] !=
' ' && r[i] !=
'(' && r[i] !=
')' ) tmp1 += r[i];
437 if ( tmp1.size() > 0 )
438 precision = GetPrecision(tmp1);
444 for (i = 29; i < 31; i++)
445 if ( r[i] !=
' ' ) tmp2 += r[i];
447 if ( tmp2.size() == 0 ||
448 tmp2 ==
"LT" || tmp2 ==
"GT" || tmp2 ==
"LE" ||
449 tmp2 ==
"GE" || tmp2 ==
"AP" || tmp2 ==
"CA" || tmp2 ==
"SY" ) dvalue = 0;
451 istringstream estring(tmp2);
452 estring >> dvalue; dvalue *= precision;
457 float BaseENSDF::GetTI(
const char *r, std::string &s)
459 float value;
unsigned int i;
size_t l;
string tmp;
463 for (i = 64; i < 74; i++)
464 if ( r[i] !=
' ' ) tmp += r[i];
467 if ( (l = tmp.find(
'(', 0 ) ) != string::npos )
468 { s.insert(s.begin(),
'?'); tmp.erase(l,1); }
469 if ( (l = tmp.find(
')', 0 ) ) != string::npos )
470 { s.insert(s.begin(),
'?'); tmp.erase(l,1); }
472 if ( tmp.size() > 0 ) {
473 istringstream vstring(tmp); vstring >>
value;
480 float BaseENSDF::GetDTI(
const char *r)
482 float dvalue, precision;
unsigned int i;
string tmp1, tmp2;
486 for (i = 64; i < 74; i++)
487 if ( r[i] !=
' ' && r[i] !=
'(' && r[i] !=
')' ) tmp1 += r[i];
489 if ( tmp1.size() > 0 )
490 precision = GetPrecision(tmp1);
496 for (i = 74; i < 76; i++)
497 if ( r[i] !=
' ' ) tmp2 += r[i];
499 if ( tmp2.size() == 0 ||
500 tmp2 ==
"LT" || tmp2 ==
"GT" || tmp2 ==
"LE" ||
501 tmp2 ==
"GE" || tmp2 ==
"AP" || tmp2 ==
"CA" || tmp2 ==
"SY" ) dvalue = 0;
503 istringstream estring(tmp2);
504 estring >> dvalue; dvalue *= precision;
509 float BaseENSDF::GetE(
const char *r, std::string &offset)
511 static char whichoffset[] =
"XYZUVWABCDEFGHIJKLMNOPQRST";
513 float energy;
unsigned int i;
size_t l;
string tmp;
517 for (i = 9; i < 19; i++) tmp += r[i];
521 for (i = 0; i < 26; i++) {
522 if ( (l = tmp.find(whichoffset[i],0 ) ) != string::npos )
523 { offset.insert(offset.begin(),whichoffset[i]); tmp.erase(l,1);
break; }
526 if ( (l = tmp.find(
'(', 0 ) ) != string::npos )
527 { offset.insert(offset.begin()+1,
'?'); tmp.erase(l,1); }
528 if ( (l = tmp.find(
')', 0 ) ) != string::npos )
529 { offset.insert(offset.begin()+1,
'?'); tmp.erase(l,1); }
531 if ( (l = tmp.find(
'+', 0 ) ) != string::npos ) { tmp.erase(l,1); }
534 if ( tmp.size() > 0 ) {
535 istringstream estring(tmp); estring >> energy;
537 if ( estring.fail() ) energy = 0.0;
544 float BaseENSDF::GetPrecision(std::string st)
546 float precision = 1.0;
int expo;
size_t l1,l2;
548 l1 = st.find(
'.'); l2 = st.find(
'E');
if ( l2 == string::npos ) l2 = st.find(
'e');
549 if ( l1 == string::npos ) {
550 if ( l2 == string::npos )
554 istringstream out(st); out >> expo; precision = pow(10.0,expo);
557 if ( l2 == string::npos ) {
558 int e = - (st.size() - l1 - 1); precision = pow(10.0,e);
562 istringstream out(st); out >> expo;
564 int e = - (l2 - l1 - 1) + expo; precision = pow(10.0,e);
567 if ( precision < 0 ) precision = -1.0 * precision;
572 float BaseENSDF::GetDE(
const char *r)
574 static char whichoffset[] =
"XYZUVWABCDEFGHIJKLMNOPQRST";
576 float denergy, precision;
unsigned int i;
size_t l;
string tmp1, tmp2;
580 for (i = 9; i < 19; i++)
581 if ( r[i] !=
' ' ) tmp1 += r[i];
584 for (i = 0; i < 26; i++) {
585 if ( (l = tmp1.find(whichoffset[i],0 ) ) != string::npos )
586 { tmp1.erase(l,1);
break; }
589 if ( (l = tmp1.find(
'(', 0 ) ) != string::npos )
591 if ( (l = tmp1.find(
')', 0 ) ) != string::npos )
594 if ( (l = tmp1.find(
'+', 0 ) ) != string::npos ) { tmp1.erase(l,1); }
596 if ( tmp1.size() > 0 )
597 precision = GetPrecision(tmp1);
603 for (i = 19; i < 21; i++)
604 if ( r[i] !=
' ' ) tmp2 += r[i];
606 if ( tmp2.size() == 0 ||
607 tmp2 ==
"LT" || tmp2 ==
"GT" || tmp2 ==
"LE" ||
608 tmp2 ==
"GE" || tmp2 ==
"AP" || tmp2 ==
"CA" || tmp2 ==
"SY" ) denergy = 0;
610 istringstream estring(tmp2);
611 estring >> denergy; denergy *= precision;
616 float BaseENSDF::GetT(
const char *r,
float &unit, std::string &option)
618 float t;
unsigned int i;
size_t l;
string tmp;
622 for (i = 39; i < 49; i++) tmp += r[i];
625 if ( (l = tmp.find(
'?', 0 ) ) != string::npos ) { tmp.erase(l,1); option =
"?"; }
627 if ( tmp.find(
"STABLE") != string::npos ) { t = 3.2E23; unit = 1; }
629 if ( tmp.find(
"Y") != string::npos ) { unit = 31622400; }
630 if ( tmp.find(
"D") != string::npos ) { unit = 86400; }
631 if ( tmp.find(
"H") != string::npos ) { unit = 3600; }
632 if ( tmp.find(
"M") != string::npos ) { unit = 60; }
633 if ( tmp.find(
"S") != string::npos ) { unit = 1; }
634 if ( tmp.find(
"MS") != string::npos ) { unit = 1E-3; }
635 if ( tmp.find(
"US") != string::npos ) { unit = 1E-6; }
636 if ( tmp.find(
"NS") != string::npos ) { unit = 1E-9; }
637 if ( tmp.find(
"PS") != string::npos ) { unit = 1E-12; }
638 if ( tmp.find(
"FS") != string::npos ) { unit = 1E-15; }
639 if ( tmp.find(
"AS") != string::npos ) { unit = 1E-18; }
641 if ( tmp.size() > 0 ) {
642 istringstream tmpstring(tmp);
643 tmpstring >> t; t *= unit;
644 if ( tmpstring.fail() ) { option =
"?"; t = 0.0; unit = 0.0; }
646 else { t = 0.0; unit = 0.0; }
652 float BaseENSDF::GetDT(
const char *r)
654 float dt, precision, unit;
unsigned int i;
size_t l;
string tmp1, tmp2;
658 if ( BaseENSDF::GetT(r,unit,tmp1) == 3.2E23 )
return 0.0;
661 for (i = 39; i < 49; i++) {
662 if ( r[i] !=
' ' ) tmp1 += r[i];
664 if ( ( l = tmp1.find(
"MS")) != string::npos ) { tmp1.erase(l,2); }
665 if ( ( l = tmp1.find(
"US")) != string::npos ) { tmp1.erase(l,2); }
666 if ( ( l = tmp1.find(
"NS")) != string::npos ) { tmp1.erase(l,2); }
667 if ( ( l = tmp1.find(
"PS")) != string::npos ) { tmp1.erase(l,2); }
668 if ( ( l = tmp1.find(
"FS")) != string::npos ) { tmp1.erase(l,2); }
669 if ( ( l = tmp1.find(
"AS")) != string::npos ) { tmp1.erase(l,2); }
670 if ( ( l = tmp1.find(
"Y") ) != string::npos ) { tmp1.erase(l,1); }
671 if ( ( l = tmp1.find(
"D") ) != string::npos ) { tmp1.erase(l,1); }
672 if ( ( l = tmp1.find(
"H") ) != string::npos ) { tmp1.erase(l,1); }
673 if ( ( l = tmp1.find(
"M") ) != string::npos ) { tmp1.erase(l,1); }
674 if ( ( l = tmp1.find(
"S") ) != string::npos ) { tmp1.erase(l,1); }
676 if ( (l = tmp1.find(
'?', 0 ) ) != string::npos ) { tmp1.erase(l,1); }
678 if ( tmp1.size() > 0 )
679 precision = GetPrecision(tmp1);
686 for (i = 49; i < 55; i++)
687 if ( r[i] !=
' ' ) tmp2 += r[i];
689 if ( tmp2.size() == 0 ||
690 tmp2 ==
"LT" || tmp2 ==
"GT" || tmp2 ==
"LE" ||
691 tmp2 ==
"GE" || tmp2 ==
"AP" || tmp2 ==
"CA" || tmp2 ==
"SY" ) dt = 0;
693 istringstream estring(tmp2); estring >> dt; dt = dt * precision * unit;
698 string BaseENSDF::GetJPI(
const char *r)
701 for (
int i = 21; i < 39; i++)
702 if ( r[i] !=
' ' ) tmp += r[i];
friend LogMessage & clear(LogMessage &)
others
void Print(std::ostream &) const
base classe to interface ENSDF (Evaluated Nuclear Structure Data File)
ADF::LogMessage & endl(ADF::LogMessage &log)
std::pair< int, int > Position