![]() |
ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
|
00001 #include "MassTable.h" 00002 00003 00004 MassTable::MassTable(string filename, VerbosePrinter * toRegister) 00005 { 00006 registerListener(toRegister); 00007 vPrint(4,"Creating mass table from file %s.\n", filename.c_str()); 00008 FILE * myFile; 00009 myFile = fopen(filename.c_str(),"r"); 00010 if(myFile==NULL) 00011 perror("The opened file is null"); 00012 char line[200]; 00013 vector<string> fileContent; 00014 while (fgets(line,200, myFile)!=NULL) 00015 { 00016 string myString(line); 00017 fileContent.push_back(myString); 00018 } 00019 vector<string>::iterator it = fileContent.begin(); 00020 for(int i = 0; i<40 && it!=fileContent.end(); i++) 00021 ++it; 00022 while(it!=fileContent.end()) 00023 { 00024 myMasses.push_back(MassObject(*(it++))); 00025 } 00026 if(myFile!=NULL) 00027 fclose(myFile); 00028 vPrint(4,"Done creating mass table.\n"); 00029 return; 00030 } 00031 00032 list<MassObject> MassTable::getMassObjects() const 00033 { 00034 return myMasses; 00035 } 00036 00037 const MassObject MassTable::getMassObject(Nukleid toGet) const 00038 { 00039 vPrint(13, "Now searching through %d masstable entries.\n",myMasses.size()); 00040 for(list<MassObject>::const_iterator it = myMasses.begin(); it!=myMasses.end(); it++) 00041 { 00042 if(it->getNukleid()==toGet) 00043 return (*it); 00044 } 00045 throw DataFileException("The requested nucleid was not found in the masstable: " + toGet.toString() + " Probable cause: incorrect or missing masstable."); 00046 } 00047 00048 const MassObject MassTable::getMassObject(unsigned short int Z, unsigned short int A) const 00049 { 00050 for(list<MassObject>::const_iterator it = myMasses.begin(); it!=myMasses.end(); it++) 00051 { 00052 if(it->getNukleid().getA()==A && it->getNukleid().getZ()==Z) 00053 return (*it); 00054 } 00055 throw DataFileException("The requested nucleid was not found. "); 00056 }