Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

global_params.cpp

Go to the documentation of this file.
00001 /*
00002  * ******** fete: From ENDF To ENDL *********
00003  * 
00004  * Copyright (c) 2006, The Regents of the University of California. 
00005  * All rights reserved.
00006  * 
00007  * Produced at the Lawrence Livermore National Laboratory. 
00008  * Written by David A. Brown, Gerry Hedstrom, Tony Hill
00009  * 
00010  * This file is part of fete v1.0  (UCRL-CODE-218718)
00011  * 
00012  * Please read the COPYING file for "Our Notice and GNU General 
00013  * Public License" in the root of this software distribution.  
00014  * 
00015  * This program is free software; you can redistribute it and/or modify 
00016  * it under the terms of the GNU General Public License (as published by 
00017  * the Free Software Foundation) version 2, dated June 1991. 
00018  * 
00019  * This program is distributed in the hope that it will be useful, 
00020  * but WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF 
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms 
00022  * and conditions of the GNU General Public License for more details. 
00023  * 
00024  * You should have received a copy of the GNU General Public License along 
00025  * with this program; if not, write to the Free Software Foundation, Inc., 
00026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00027  * 
00028  * $Revision: 1888 $
00029  * $Date: 2006-08-28 10:37:08 -0700 (Mon, 28 Aug 2006) $
00030  * $Author: dbrown $
00031  * $Id: global_params.cpp 1888 2006-08-28 17:37:08Z dbrown $
00032  * 
00033  * ******** fete: From ENDF To ENDL *********
00034  */
00035 
00036 //Implementation of the GlobalParameterClass
00037 
00038 #include "global_params.hpp"
00039 #include "convert.hpp"         // converting strings to numbers
00040 
00041 // *********** ss_link class ***********************
00042 // ----------- ss_link::print ---------------
00043 // print the data in a link
00044 void ss_link::print()
00045 {
00046   cout << "   " << x << "   " << y << endl;
00047 }
00048 
00049 // *********** ss_list class ***********************
00050 // ----------- ss_list::at ---------------
00051 // Function to get the link at "x"
00052 // Returns "false" if the entry is not found.
00053 bool ss_list::at(string x, ss_list::iterator& link)
00054 {
00055   for( link = begin(); 
00056        link != end();
00057        ++link )
00058   {
00059     if ( link->name( ) == x ) 
00060     {
00061       return true;
00062     }
00063   }
00064   return false;
00065 }
00066 
00067 // ----------- ss_list::print ---------------
00068 void ss_list::print()
00069 {
00070   for( ss_list::iterator link = begin(); 
00071        link != end();
00072        ++link)
00073   {
00074     link->print();
00075   }
00076   cout<<endl;
00077 }
00078 
00079 // *********** GlobalParameterClass class ***********************
00080 // ----------- GlobalParameterClass constructor ---------------
00081 //Default constructor loads the default Parameter list and then reads in the 
00082 //default parameter file and loads them into the Parameter list.
00083 GlobalParameterClass::GlobalParameterClass()   
00084 {
00085   // Here is the "standard" list of translation switches
00086   // Interpolation options
00087   set("tol_1d", 0.005);         //! accuracy of interpolation in 1-d lists
00088   set("cut_off_1d", 0.001);     //! don't impose tolerance below this value
00089   set("tol_2d", 0.015);         //! accuracy of interpolation in 2-d lists
00090   set("cut_off_2d", 0.003);     //! don't impose 2-d tolerance below this value
00091   set("dE_tol", 0.01);          //! minimum incident energy difference for 2-d lists
00092   // 3d list options
00093   set("num_mu_3d", 2);          //! number of mu values in 3-d lists is 2*num_mu_3d+1
00094   set("num_E_in_3d", 12);       //! number of incident energies for 3d expansion
00095   set("log_log_tol", 0.005);    //! relative error in converting log-log to lin-lin
00096   // MF=5 options
00097   set("num_mf5_bins", 32);      //! number of equiprobable energy bins
00098   set("mf5_shift", 0.00002);    //! amount by which the first distribution is above threshold
00099   set("mf5_tol", 0.00001);      //! energy tolerance in ENDF/B-VI files
00100   // Other options specific to one data type
00101   set("sum_inelastic", 0);      //! 0: use the mt51--mt91 individual inelastic data; 1: use the mt04 total inelastic data
00102   set("Kalbach_i10", 0);        //! if > 0, calculate the i=10 average energy
00103   set("split_gammas", 0);       //! if > 0, split discrete gammas from continuum
00104   set("skip_gammas", 0);        //! if > 0, skip the gamma data
00105   set("fission_Q", 1);          //! 0: use ENDF fission Q value; otherwise: subtract Q for delayed fission decays
00106   // General processing options
00107   set("skip_date", 1);          //! if == 1, don't bother processing eval date field
00108   set("translate_all", 1);      //! if == 1, attempt to translate all data, even if we normally would ignore it
00109   set("skip_logging", 0);       //! if == 1, don't log errors in documentation.txt file
00110   set("message_level",0);       //!three levels of messages - info, warn and severe
00111                                 // info = 0 (all messages written)
00112                                 // warn = 1 (only warnings and errors)
00113                                 // severe >=2 (errors only, these cause exits anyway!)
00114   set("endl_datafield_precision",8); //! 8 sig-figs in all endl data fields
00115   set("max_list_size", 500);    //! maximum length of a 1-d list
00116   set("Max_n_energy", 20.0);    //! maximum neutron energy for ENDL files
00117   set("Max_cp_energy", 30.0);   //! maximum charged particle energy for ENDL
00118   set("Max_g_energy", 30.0);    //! maximum gamma for ENDL files
00119   set("mf5_weight_tol", 0.001); //! tolerance on the total weight for mf5 models
00120   set("max_coulomb_mu", 0.94);  //! maximum mu for charged-particle scattering
00121   set("smallest_dE", 1.0e-16);  //! dE to use in widening a jump at E = 0
00122   set("jump_factor", 2.0);      //! factor of ENDL_EPSILON to use for jump width
00123   set("Min_n_energy", 1e-11); //! minimum incident neutron energy for ENDL files
00124 }
00125 // ----------- GlobalParameterClassss_link destructor --------
00126 //Default destructor.
00127 GlobalParameterClass::~GlobalParameterClass()  
00128 { 
00129 }
00130 // ----------- GlobalParameterClass::set ---------------
00131 //Sets the parameter values and creates a new parameter if one doesn't exist.
00132 void GlobalParameterClass::set(string gp, double gp_num)
00133 {
00134   //First thing we need to do is to strip all extraneous blanks from the string gp
00135   gp = tolower( remove_extra_blanks( gp ) );
00136   ostringstream gp_ostr; 
00137   gp_ostr <<  gp_num;
00138   string gp_val = gp_ostr.str();
00139   //We test for the existence of the parameter name in the list.
00140   //If it is new, we add a link.  If not, we reset the existing
00141   //value in the link to gp_val.
00142   ss_list::iterator SSlist;
00143 
00144   if ( Parameters.at(gp,SSlist) )
00145     {
00146       SSlist->value()=gp_val;  //reset the parameter value in this link
00147     }
00148   else
00149     {
00150       ss_link SSlink;
00151       SSlink.name() = gp;  //Load into link
00152       SSlink.value() = gp_val;
00153       Parameters.insert(Parameters.end(), SSlink); //Insert link into list
00154     }
00155 }
00156 // ----------- GlobalParameterClass::set ---------------
00157 //Sets the parameter values and creates a new parameter if one doesn't exist.
00158 void GlobalParameterClass::set(string gp, string gp_val)
00159 {
00160   //First thing we need to do is to strip all extraneous blanks from the strings
00161   gp     = remove_extra_blanks( gp );
00162   gp_val = remove_extra_blanks( gp_val );
00163   
00164   //We test for the existence of the parameter name in the list.
00165   //If it is new, we add a link.  If not, we reset the existing
00166   //value in the link to gp_val.
00167   ss_list::iterator SSlist;
00168 
00169   if ( Parameters.at(gp,SSlist) )
00170   {
00171       SSlist->value()=gp_val;  //reset the parameter value in this link
00172   }  
00173   else
00174   {
00175       ss_link SSlink;
00176       SSlink.name() = gp;  //Load into link
00177       SSlink.value() = gp_val;
00178       Parameters.insert(Parameters.end(), SSlink); //Insert link into list
00179   }
00180 }
00181 // ----------- GlobalParameterClass::print ---------------
00182 // Print utility
00183 void GlobalParameterClass::print( )
00184 {
00185   cout<<"Info : List of global parameters used in this translation:"<<endl;
00186   Parameters.print();
00187 }
00188 // ----------- GlobalParameterClass::read_command_line ---------------
00189 // Function used to parse the command line for parameters and settings
00190 string GlobalParameterClass::read_command_line(int argc, char* argv[] )
00191 {
00192   //First see if the user just wants help.  This is the only way to have a non-"-option value" pair
00193   string help1("-help"), help2("--help"), help3("-h");
00194   for( int j=1; j<argc; ++j)
00195   {
00196     string sarg(argv[j]);
00197     if( sarg == help1 || sarg == help2 || sarg == help3 )
00198     {
00199       cout << center(40*string("="),42) <<endl;
00200       cout << center("Help for fete.",40)<<endl;
00201       cout << center(40*string("="),42) <<endl;
00202       cout << "Usage: fete [-option1 value]"<<endl<<endl;
00203       cout << "To set the file to translate, use the -f option (e.g. fete -f fred.endf)  "<<endl;
00204       cout << "Other options are set by prepending '-' to the options listed below:"<<endl;
00205       Parameters.print();
00206       exit(1);
00207     }
00208   }
00209   
00210   //Next, we test the command line inputs for the "-" indicator on every other input
00211   for( int j=1; j<argc; j+=2 )
00212   {
00213     if ( argv[j][0] != '-' ) 
00214      { 
00215        cerr<<"fete Fatal Error GlobalParameterClass::read_command_line:"<<endl;
00216        cerr<<"    Unable to process command line."<<endl;
00217        cerr<<"    "<<argv[j]<<" is not a valid switch!"<<endl;
00218        exit(-10);
00219      }
00220     else
00221      {
00222        //Move the character array into string arrays
00223        spar[j] = argv[j]; 
00224        if (j+1<argc) spar[j+1]=argv[j+1];
00225       else spar[j+1]="";
00226      }
00227   };
00228 
00229   //Then we will loop through argv to see if the user wants to use a private input file
00230   //or an assortment of input files, each possibly overwriting earlier settings...
00231   string privateParameterFile("");
00232   for( int j=1; j<argc;j+=2 ) if( spar[j] == "-p" || spar[j] == "-param" ) privateParameterFile=spar[j+1];
00233   if (privateParameterFile!="")
00234   {
00235     cout<<"Info : Private parameter input file: "<<privateParameterFile<<endl;
00236     read_file( privateParameterFile );
00237   }  
00238   else 
00239   {
00240     //Now, we read in the standard input file, if it is there
00241     read_file("fete_options.inp");
00242   }
00243 
00244   //Now we loop through the argument list and set parameters listed on the command line
00245   //We perform this loop AFTER the user file so that the command line settings are
00246   //always used.
00247   for( int j=1; j<argc;j+=2 )
00248   {
00249     if( spar[j] != "-f" && spar[j] != "-file" && spar[j] != "-p" && spar[j] != "-param" ) //not a param file request
00250     {
00251       string pval = spar[j+1];
00252       string key = spar[j];
00253       key.erase(0,1);
00254       set(key,pval);
00255     }
00256   }
00257   
00258   //Then we will loop through argv to see if the user wants to use a different default ENDF file name
00259   for( int j=1; j<argc;j+=2 )
00260   {
00261     if( spar[j] == "-f" || spar[j] == "-file" )
00262     {
00263       cout<<"Info : ENDF input file: "<<spar[j+1]<<endl;
00264       string file = spar[j+1];
00265       return file;
00266     }
00267   }
00268   return "";
00269 }
00270 // ----------- GlobalParameterClass::read_file ---------------
00271 // Reads in a file and looks for parameter names and values...
00272 void GlobalParameterClass::read_file(string file)
00273 {
00274   string linebuff, origbuff;
00275   
00276   ifstream paramfile( file.c_str() );  //open the file
00277   
00278   if ( !paramfile )
00279     {
00280       cout<<"Info: GlobalParameterClass::read_file: There is no parameter file named: "<<file<<", using internal defaults"<<endl;
00281     }
00282   else
00283     {
00284       cout<<"Info : Reading the parameter file: "<<file<<" ..."<<endl;
00285       while( !paramfile.eof() )  //Read until end of file
00286     { 
00287       getline( paramfile, linebuff );  //Get a line
00288       origbuff=linebuff;     //Make a copy in case there's trouble
00289       linebuff = remove_extra_blanks( linebuff );  //remove extraneous blanks
00290       if( linebuff.find('#') <= linebuff.size() )  //loook for comment marker
00291         {
00292           linebuff = linebuff.erase(linebuff.find('#'),linebuff.size()); //erase
00293           linebuff=remove_extra_blanks( linebuff ); //new trailing blanks can show up
00294         }
00295 
00296       if( linebuff.size() > 0 ) //We are done with this line if it is blank
00297         {
00298           int nblanks=0; //counter for number of blanks left in string
00299           for( int i=0;i<linebuff.size();i++ )
00300         {
00301           if ( linebuff.at(i) == ' ' ) ++nblanks; //count the blanks
00302         }
00303           if( nblanks != 1 ) //There should be exactly one left (two words)
00304         {
00305           cerr
00306             <<"fete Fatal Error GlobalParameterClass::read_file: Could not parse the following line from "
00307             <<"the parameter file, "<<file<<endl;
00308           cerr<<origbuff<<endl;  //Show original line in file
00309           exit(-10);
00310         }
00311           else  //Looks like we have a winner!
00312         {
00313           string sparam 
00314             = linebuff.substr(0,linebuff.find(' ')); //load name
00315           string svalue 
00316             = linebuff.substr(linebuff.find(' ')+1,linebuff.size()); //load value
00317           set(sparam, svalue);
00318         }
00319         }
00320     }
00321     }
00322 }
00323 // ----------- GlobalParameterClass::Value ---------------
00324 // Returns the value of the requested parameter.
00325 double GlobalParameterClass::Value( string ParamName )
00326 {
00327   ss_list::iterator XYptr;
00328   string parm = tolower( ParamName );
00329   if( !Parameters.at(parm,XYptr) )
00330     {
00331       cerr<<"fete Fatal Error GlobalParameterClass::Value:"<<
00332         " no parameter called "<<ParamName<<" found!"<<endl;
00333       exit(-50);
00334     }
00335   return( static_cast<double>( stof(XYptr->value()) ) );
00336 }
00337 // ----------- GlobalParameterClass::Flag ---------------
00338 // Returns the string value of the parameter.
00339 string GlobalParameterClass::Flag( string ParamName )
00340 {
00341   ss_list::iterator XYptr;
00342   string parm = tolower( ParamName );
00343   if( !Parameters.at(parm,XYptr) )
00344     {
00345       cerr<<"fete Fatal Error GlobalParameterClass::Flag:"<<
00346         " no parameter called "<<ParamName<<" found!"<<endl;
00347       exit(-50);
00348     }
00349   return( XYptr->value() );
00350 }
00351 

Generated on Thu Sep 7 10:30:04 2006 for fete -- From ENDFB6 To ENDL by doxygen 1.3.4