#include "input_par.h" #include using namespace std; /***********************************************/ /* Create input_par: open the file for reading */ /* Throw a string if the file can't be open */ /***********************************************/ input_par::input_par(char *name) : file_name_(name), line_no_(1) { if(!name || (name[0]==0)) { throw ((string) "ERROR : blank file name for parameter file!"); } par_file_.open(name); if(!par_file_.good()) { throw ((string) "ERROR : Can't open parameter file "+name); } } /******************************************************/ /* Get the next paramater from the parameter file */ /* Read one word then compare it to the Name supplied */ /* Read the double Value that follows and put it in v */ /* The line must be of the form: */ /* Name Value */ /* Throw a string on error */ /******************************************************/ void input_par::get(char *Name,double &v) { // Check that the parameter name is correct check_par_name(Name); // Read the value that follows : an int par_file_ >> v; // Increment the line no ++line_no_; } /******************************************************/ /* Get the next paramater from the parameter file */ /* Read one word then compare it to the Name supplied */ /* Read the int Value that follows and put it in v */ /* The line must be of the form: */ /* Name Value */ /* Throw a string on error */ /******************************************************/ void input_par::get(char *Name,int &v) { // Check that the parameter name is correct check_par_name(Name); // Read the value that follows : a double par_file_ >> v; // Increment the line no ++line_no_; } /******************************************************/ /* Get the next paramater from the parameter file */ /* Read one word then compare it to the Name supplied */ /* Read the string Value that follows and put it in v */ /* No space is allowed in the string value! */ /* The line must be of the form: */ /* Name Value */ /* Throw a string on error */ /******************************************************/ void input_par::get(char *Name,char *v) { // Check that the parameter name is correct check_par_name(Name); // Read the value that follows : a string par_file_ >> v; // Increment the line no ++line_no_; } /*******************************************************/ /* Check the paramater name: */ /* Read one word then compare it to the Name supplied */ /* The line in the parameter file must be of the form: */ /* Name Value */ /* Throw a string if the parameter Name does not match */ /*******************************************************/ void input_par::check_par_name(char *Name) { string s; char Buff[40]; par_file_ >> s; // Check that the parameter name is correct if(s != Name) { sprintf(Buff,"%d",line_no_); throw ((string)"Error line "+Buff+" in parameter file "+file_name_+ "\n Line "+Buff+" : invalid parameter "+s+" when expecting "+Name); } }