--- trunk/src/io/Globals.cpp 2005/10/14 14:18:02 666 +++ trunk/src/io/Globals.cpp 2005/10/17 03:06:29 674 @@ -50,6 +50,7 @@ #include "io/mpiBASS.h" #endif // is_mpi +#include "io/ParamConstraint.hpp" #define DefineParameter(NAME,KEYWORD) \ NAME.setKeyword(KEYWORD); \ @@ -63,6 +64,9 @@ NAME.setKeyword(KEYWORD); NAME.setOptional(true); NAME.setDefaultValue(DEFAULTVALUE); \ parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); +#define CheckParameter(NAME, CONSTRAINT) \ + if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) { sprintf(painCave.errMsg,"Error in checking %s : should be %s\n",NAME.getKeyword().c_str(),(CONSTRAINT).getConstraintDescription().c_str()); painCave.isFatal = 1; painCave.severity = OOPSE_ERROR; simError();} } + Globals::Globals(){ DefineParameter(ForceField, "forceField") @@ -137,36 +141,42 @@ int Globals::globalAssign( event* the_event ){ } int Globals::globalAssign( event* the_event ){ - + char errorMessage[65535]; int key; - int token; interface_assign_type the_type = the_event->evt.asmt.asmt_type; char* lhs = the_event->evt.asmt.lhs; std::string keyword(lhs); - bool result; + bool result = false; - + /**@todo fix memory leak */ ParamMap::iterator i =parameters_.find(keyword); if (i != parameters_.end()) { if( the_type == STRING ){ result = i->second->setData(std::string(the_event->evt.asmt.rhs.sval)); if (!result ) { - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a string.\n", keyword.c_str() ); + sprintf(errorMessage, "Error in parsing %s: expect %s, but get a string \"%s\".\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.sval); + the_event->err_msg = strdup(errorMessage); } } else if( the_type == DOUBLE ){ result = i->second->setData(the_event->evt.asmt.rhs.dval); if (!result ) - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be a double.\n", keyword.c_str() ); + sprintf(errorMessage, "Error in parsing %s: expect %s, but get a double %f.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.dval ); + the_event->err_msg = strdup(errorMessage); } else if (the_type == INT ){ result = i->second->setData(the_event->evt.asmt.rhs.ival); if (!result ) - sprintf(the_event->err_msg, "Error in parsing meta-data file!\n\t%s must be an int.\n", keyword.c_str() ); + sprintf(errorMessage, "Error in parsing %s: expect %s, but get an int %d.\n", keyword.c_str(), i->second->getParamType().c_str(), the_event->evt.asmt.rhs.ival ); + the_event->err_msg = strdup(errorMessage); } else { - + sprintf(errorMessage, "Internal error of parser\n"); + the_event->err_msg = strdup(errorMessage); } + } else { + sprintf(errorMessage, "%s is an unrecognized keyword\n", keyword.c_str() ); + the_event->err_msg = strdup(errorMessage); } if (keyword == "nComponents" && getNComponents() > 0) { @@ -325,6 +335,67 @@ char* Globals::checkMe( void ){ } } + CheckParameter(ForceField, isNotEmpty()); + CheckParameter(NComponents,isPositive()); + CheckParameter(TargetTemp, isPositive()); + CheckParameter(Ensemble, isEqualIgnoreCase(std::string("NVE")) || isEqualIgnoreCase(std::string("NVT")) || + isEqualIgnoreCase(std::string("NPTi")) || isEqualIgnoreCase(std::string("NPTf"))|| + isEqualIgnoreCase(std::string("NPTxyz")) ); + + CheckParameter(Dt, isPositive()); + CheckParameter(RunTime, isPositive()); + CheckParameter(InitialConfig, isNotEmpty()); + CheckParameter(FinalConfig, isNotEmpty()); + CheckParameter(NMol, isPositive()); + CheckParameter(Density, isPositive()); + CheckParameter(Box, isPositive()); + CheckParameter(BoxX, isPositive()); + CheckParameter(BoxY, isPositive()); + CheckParameter(BoxZ, isPositive()); + CheckParameter(SampleTime, isNonNegative()); + CheckParameter(ResetTime, isNonNegative()); + CheckParameter(StatusTime, isNonNegative()); + CheckParameter(CutoffRadius, isPositive()); + CheckParameter(SwitchingRadius, isNonNegative()); + CheckParameter(Dielectric, isPositive()); + CheckParameter(ThermalTime, isNonNegative()); + CheckParameter(TargetPressure, isPositive()); + CheckParameter(TauThermostat, isPositive()); + CheckParameter(TauBarostat, isPositive()); + CheckParameter(ZconsTime, isPositive()); + CheckParameter(NZconstraints, isPositive()); + CheckParameter(ZconsTol, isPositive()); + //CheckParameter(ZconsForcePolicy,); + CheckParameter(Seed, isPositive()); + CheckParameter(Minimizer, isEqualIgnoreCase(std::string("SD")) || isEqualIgnoreCase(std::string("CG"))); + CheckParameter(MinimizerMaxIter, isPositive()); + CheckParameter(MinimizerWriteFrq, isPositive()); + CheckParameter(MinimizerStepSize, isPositive()); + CheckParameter(MinimizerFTol, isPositive()); + CheckParameter(MinimizerGTol, isPositive()); + CheckParameter(MinimizerLSTol, isPositive()); + CheckParameter(MinimizerLSMaxIter, isPositive()); + CheckParameter(ZconsGap, isPositive()); + CheckParameter(ZconsFixtime, isPositive()); + CheckParameter(ThermodynamicIntegrationLambda, isPositive()); + CheckParameter(ThermodynamicIntegrationK, isPositive()); + CheckParameter(ForceFieldVariant, isNotEmpty()); + CheckParameter(ForceFieldFileName, isNotEmpty()); + CheckParameter(ThermIntDistSpringConst, isPositive()); + CheckParameter(ThermIntThetaSpringConst, isPositive()); + CheckParameter(ThermIntOmegaSpringConst, isPositive()); + CheckParameter(SurfaceTension, isPositive()); + CheckParameter(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("UNDAMPED_WOLF")) || isEqualIgnoreCase(std::string("DAMPED_WOLF")) || isEqualIgnoreCase(std::string("REACTION_FIELD")) ); + CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); + //CheckParameter(StatFileFormat,); + //CheckParameter(MixingRule,); + CheckParameter(OrthoBoxTolerance, isPositive()); + CheckParameter(ThermIntDistSpringConst, isPositive()); + CheckParameter(ThermIntThetaSpringConst, isPositive()); + CheckParameter(ThermIntOmegaSpringConst, isPositive()); + CheckParameter(DampingAlpha,isPositive()); + CheckParameter(SkinThickness, isPositive()); + //@todo memory leak if( have_err ) return strdup( err.c_str() );