ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
Record.cpp
Go to the documentation of this file.
00001 #include "Record.h"
00002 #include <iostream>
00003 
00004 Record::Record(list<string> cardArg) 
00005 {
00006   if(!cardArg.empty())
00007     {
00008       myCard = cardArg;
00009       myNukleid = Nukleid(myCard.front().substr(0,5));
00010     }
00011 }
00012 
00013 Record::~Record() 
00014 {
00015   //nothing to do here...
00016 }
00017 
00018 Nukleid Record::getNukleid() const
00019 {
00020   return myNukleid;
00021 }
00022 
00023 list<string> Record::getCardStrings() const
00024 {
00025   return myCard;
00026 }
00027 
00028 double Record::cardToDouble(int startPos, int endPos)
00029 {
00030   if(!myCard.empty())
00031     {
00032       string data = myCard.front().substr(startPos-1, endPos-startPos+1);
00033       const char* dataCString = data.c_str();
00034       double number = atof(dataCString);
00035       return number;
00036     }
00037   else
00038     {
00039       throw DataFileException("Empty card string.\n");
00040     }
00041 }
00042 
00043 string Record::trimString(string toTrim)
00044 {
00045   int ptrStart = -1;
00046   int ptrStop = toTrim.size();
00047   while(toTrim[++ptrStart]==' ');
00048   while(toTrim[--ptrStop]==' ');
00049   return toTrim.substr(ptrStart,ptrStop-ptrStart+1);
00050 }
00051 
00052 // returns -1 if the nucleid is stable and 0 if no half life is given
00053 double Record::parseHalfLife(int startPos, int endPos)
00054 {
00055   string tempStr = myCard.front().substr(startPos-1, endPos-startPos+1);
00056   string halfLifeStr = trimString(tempStr);
00057 
00058 
00059   if (halfLifeStr.substr(0,5).compare("STABLE") == 0)                   // the strings are equal
00060     return -1;
00061   unsigned int i = 0;
00062   for (i = 0; i < halfLifeStr.length(); i++)
00063     {
00064       if (!((halfLifeStr.at(i) <= '9' && halfLifeStr.at(i) >= '0') || halfLifeStr.at(i) == '.'))
00065         break;
00066     }
00067   if(halfLifeStr.size()<i+2)
00068     return -3;
00069   string numberStr = halfLifeStr.substr(0, i);
00070   const char* numberCString = numberStr.c_str();
00071   double number = atof(numberCString);
00072   if(halfLifeStr.size()>i+2)
00073     {
00074       string unit = halfLifeStr.substr(i+1, 2);
00075       if (unit.compare("Y ") == 0)
00076         number *= 365*24*60*60;
00077       else if (unit.compare("D ") == 0)
00078         number *= 60*60*24;
00079       else if (unit.compare("H ") == 0)
00080         number *= 60*60;
00081       else if (unit.compare("M ") == 0)
00082         number *= 60;
00083       else if (unit.compare("S ") == 0)
00084         number *= 1;
00085       else if (unit.compare("MS") == 0)
00086         number *= 1E-3;
00087       else if (unit.compare("US") == 0)
00088         number *= 1E-6;
00089       else if (unit.compare("NS") == 0)
00090         number *= 1E-9;
00091       else if (unit.compare("PS") == 0)
00092         number *= 1E-12;
00093       else if (unit.compare("FS") == 0)
00094         number *= 1E-15;
00095       else if (unit.compare("AS") == 0)
00096         number *= 1E-18;
00097       else
00098         return -2;
00099     }
00100   else if(halfLifeStr.size()>i+1)
00101     {
00102       string unit = halfLifeStr.substr(i+1, 1);
00103       if (unit.compare("Y") == 0)
00104         number *= 365*24*60*60;
00105       else if (unit.compare("D") == 0)
00106         number *= 60*60*24;
00107       else if (unit.compare("H") == 0)
00108         number *= 60*60;
00109       else if (unit.compare("M") == 0)
00110         number *= 60;
00111       else if (unit.compare("S") == 0)
00112         number *= 1;
00113       else
00114         return -5;
00115     }
00116   else
00117     {
00118       number = - 1339;
00119     }
00121   return number;
00122 }
 All Classes Files Functions Variables Enumerations Enumerator Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark