![]() |
ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
|
00001 #include "Main.h" 00002 00003 using namespace std; 00004 int main(int argc, char *argv[]) 00005 { 00006 list<CommandLineArgument> myArguments; 00007 myArguments.push_back(CommandLineArgument("file",1)); 00008 myArguments.push_back(CommandLineArgument("bLimits",2)); 00009 myArguments.push_back(CommandLineArgument("bBranch",1)); 00010 myArguments.push_back(CommandLineArgument("gBranch",1)); 00011 myArguments.push_back(CommandLineArgument("v",1)); //verbose. 00012 myArguments.push_back(CommandLineArgument("i",0)); 00013 myArguments.push_back(CommandLineArgument("gList",0)); 00014 myArguments.push_back(CommandLineArgument("iList",0)); 00015 myArguments.push_back(CommandLineArgument("cList",0)); 00016 myArguments.push_back(CommandLineArgument("texList",0)); 00017 myArguments.push_back(CommandLineArgument("t",1)); 00018 myArguments.push_back(CommandLineArgument("tLimits",2)); 00019 myArguments.push_back(CommandLineArgument("help",0)); 00020 CommandLineInterpreter * myInterpreter = new CommandLineInterpreter(argc, argv, myArguments); 00021 if(!myInterpreter->readFlaggedCommand("help").empty()) 00022 { 00023 printf("The following arguments are valid:\n"); 00024 printf(" -file <filename> Specifies output file.\n"); 00025 printf(" -bLimits <lower limit> <upper limit> Specifies limiting Beta decay times.\n"); 00026 printf(" -bBranch <branch strength> Specifies minimum branch strength for a beta decay branch.\n"); 00027 printf(" -gBranch <branch strength> Specifies minimum branch strength for a gamma decay.\n"); 00028 printf(" -v <verbose level> Specifies how verbose the output should be.\n The larger verbose level, the more information will be dumped to the terminal during execution.\n"); 00029 printf(" -i Interactive session.\n"); 00030 printf(" -gList Create a list of gamma energies instead of normal output.\n"); 00031 printf(" -iList Create a list of isomers instead of normal output.\n"); 00032 printf(" -cList Create a list of nuclides suitable for chart view.\n"); 00033 printf(" -texList Create a list of nuclides suitable for the report.\n"); 00034 00035 printf(" -tLimits Time limits for the isomers in case of the iList parameter.\n"); 00036 printf(" -t <number of threads> specifies number of threads to use for loading data, default is 5."); 00037 printf(" -help Displays this help message.\n"); 00038 return 0; 00039 } 00040 00041 if(argc<2 || !(myInterpreter->readFlaggedCommand("i").empty())) 00042 { 00043 int verbosityLevel = 0; 00044 if(myInterpreter->readFlaggedCommand("v").size()==1) 00045 verbosityLevel = atoi((myInterpreter->readFlaggedCommand("v").front()).c_str()); 00046 unsigned int nbrOfThreads = 5; 00047 if(myInterpreter->readFlaggedCommand("t").size()==1) 00048 nbrOfThreads = atoi((myInterpreter->readFlaggedCommand("t").front()).c_str()); 00049 int retval = proceed_interact(verbosityLevel, nbrOfThreads); 00050 delete myInterpreter; 00051 myInterpreter = NULL; 00052 return retval; 00053 } 00054 int retval = proceed_nointeract(myInterpreter); 00055 delete myInterpreter; 00056 myInterpreter = NULL; 00057 return retval; 00058 } 00059 00060 00061 int proceed_interact(int verbosityLevel, unsigned int nbrOfThreads) 00062 { 00063 VerbosePrinter * myVerbosePrinter = new VerbosePrinter(verbosityLevel); 00064 myVerbosePrinter->print(1,"Creating ENSDF object.\n"); 00065 ENSDFProcessor * myProcessor = new ENSDFProcessor(ENSDF_DIR, MASSTABLE_DIR, myVerbosePrinter, nbrOfThreads); 00066 00067 int thisVariableIsOnlyUsedToAvoidCompilerWarnings = 0; 00068 char proceed = 'Y'; 00069 do 00070 { 00071 double min=1E-3, max=1, betabranch=0.1, gammabranch=0.1; 00072 printf("\nPlease enter query parameters.\n"); 00073 printf("Minimum time for beta decay (s): "); 00074 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf("%lg",&min); 00075 printf("Maximum time for beta decay (s): "); 00076 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf("%lg",&max); 00077 printf("Minimum beta branch strength (%%): "); 00078 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf("%lg", &betabranch); 00079 printf("Minimum gamma branch strength (%%): "); 00080 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf("%lg",&gammabranch); 00081 char * myD = new char[200]; 00082 printf("Enter output file name: "); fflush(stdin); 00083 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf("%s",myD); 00084 00085 string fileString(myD); 00086 00087 myVerbosePrinter->print(1,"Running query\n"); 00088 myProcessor->runBetaGammaQuery(min, max, betabranch, gammabranch, fileString); 00089 00090 fflush(stdin); 00091 printf("Do you want to run another query? [Y/N] "); 00092 thisVariableIsOnlyUsedToAvoidCompilerWarnings=scanf(" %c", &proceed); 00093 fflush(stdin); 00094 }while(proceed=='Y' || proceed=='y'); 00095 delete myProcessor; 00096 myProcessor = NULL; 00097 delete myVerbosePrinter; 00098 myVerbosePrinter = NULL; 00099 return 0; 00100 } 00101 00102 00103 int proceed_nointeract(CommandLineInterpreter * myInterpreter) 00104 { 00105 int verbosityLevel = 0; 00106 if(myInterpreter->readFlaggedCommand("v").size()==1) 00107 verbosityLevel = atoi((myInterpreter->readFlaggedCommand("v").front()).c_str()); 00108 00109 00110 VerbosePrinter * myVerbosePrinter = new VerbosePrinter(verbosityLevel); 00111 00112 unsigned int nbrOfThreads = 5; 00113 if(myInterpreter->readFlaggedCommand("t").size()==1) 00114 { 00115 nbrOfThreads = atoi((myInterpreter->readFlaggedCommand("t").front()).c_str()); 00116 myVerbosePrinter->print(8,"Number of threads: %d.\n",nbrOfThreads); 00117 } 00118 else 00119 { 00120 myVerbosePrinter->print(8,"Number of threads not specified, the default number %d was set.\n", nbrOfThreads); 00121 } 00122 00123 00124 00125 if(myInterpreter->readFlaggedCommand("file").size()!=1) 00126 throw CommandLineException("File not properly specified.\n"); 00127 string myFile = myInterpreter->readFlaggedCommand("file").front(); 00128 if(myFile.size()<2) 00129 throw CommandLineException("Invalid file name specified.\n"); 00130 00131 myVerbosePrinter->print(1,"Creating ENSDF object.\n"); 00132 ENSDFProcessor * myProcessor = new ENSDFProcessor(ENSDF_DIR, MASSTABLE_DIR, myVerbosePrinter, nbrOfThreads); 00133 00134 myVerbosePrinter->print(1,"Running query\n"); 00135 if(!myInterpreter->readFlaggedCommand("iList").empty()) 00136 { 00137 if(myInterpreter->readFlaggedCommand("tLimits").size()!=2) 00138 throw CommandLineException("Decay time limits not properly specified.\n"); 00139 double tLower = atof(((myInterpreter->readFlaggedCommand("tLimits"))[0]).c_str()); 00140 double tUpper = atof(((myInterpreter->readFlaggedCommand("tLimits"))[1]).c_str()); 00141 00142 myProcessor->runIsomerQuery(tLower, tUpper, myFile); 00143 } 00144 else 00145 { 00146 if(myInterpreter->readFlaggedCommand("bLimits").size()!=2) 00147 throw CommandLineException("Beta limits not properly specified.\n"); 00148 double bLowerLimit = atof(((myInterpreter->readFlaggedCommand("bLimits"))[0]).c_str()); 00149 double bUpperLimit = atof(((myInterpreter->readFlaggedCommand("bLimits"))[1]).c_str()); 00150 00151 if(myInterpreter->readFlaggedCommand("gBranch").size()!=1) 00152 throw CommandLineException("Gamma branch not properly specified.\n"); 00153 double gBranch = atof(myInterpreter->readFlaggedCommand("gBranch").front().c_str()); 00154 00155 if(!myInterpreter->readFlaggedCommand("gList").empty()) 00156 { 00157 myProcessor->runBetaGammaQuery_GenerateGammaList(bLowerLimit, bUpperLimit, gBranch, myFile); 00158 } 00159 else if(!myInterpreter->readFlaggedCommand("cList").empty()) 00160 { 00161 myProcessor->runBetaGammaQuery_GenerateChartList(bLowerLimit, bUpperLimit, gBranch, myFile); 00162 } 00163 else if(!myInterpreter->readFlaggedCommand("texList").empty()) 00164 { 00165 myProcessor->runBetaGammaQuery_GenerateTexList(bLowerLimit, bUpperLimit, gBranch, myFile); 00166 } 00167 else 00168 { 00169 if(myInterpreter->readFlaggedCommand("bBranch").size()!=1) 00170 throw CommandLineException("Beta branch not properly specified.\n"); 00171 double bBranch = atof(myInterpreter->readFlaggedCommand("bBranch").front().c_str()); 00172 myProcessor->runBetaGammaQuery(bLowerLimit, bUpperLimit, bBranch, gBranch, myFile); 00173 } 00174 } 00175 delete myProcessor; 00176 myProcessor = NULL; 00177 delete myVerbosePrinter; 00178 myVerbosePrinter = NULL; 00179 return 0; 00180 }