--- trunk/src/io/Globals.cpp 2005/10/17 00:51:16 673 +++ trunk/src/io/Globals.cpp 2005/11/02 20:36:25 710 @@ -65,9 +65,8 @@ parameters_.insert(std::make_pair(std::string(KEYWORD), &NAME)); #define CheckParameter(NAME, CONSTRAINT) \ - if (!NAME.empty()) { if (!(CONSTRAINT)(NAME.getData())) std::cout <<"Error in parsing " << NAME.getKeyword() << " : "<< (CONSTRAINT).getConstraintDescription() << std::endl; } + 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") @@ -122,8 +121,8 @@ Globals::Globals(){ DefineOptionalParameter(SurfaceTension, "surfaceTension"); DefineOptionalParameter(PrintPressureTensor, "printPressureTensor"); DefineOptionalParameter(ElectrostaticSummationMethod, "electrostaticSummationMethod"); + DefineOptionalParameter(ScreeningMethod, "screeningMethod"); DefineOptionalParameter(CutoffPolicy, "cutoffPolicy"); - DefineOptionalParameter(StatFileFormat, "statFileFormat"); DefineOptionalParameterWithDefaultValue(MixingRule, "mixingRule", "standard"); DefineOptionalParameterWithDefaultValue(UsePeriodicBoundaryConditions, "usePeriodicBoundaryConditions", true); @@ -138,11 +137,13 @@ Globals::Globals(){ DefineOptionalParameterWithDefaultValue(DampingAlpha, "dampingAlpha", 1.5); DefineOptionalParameterWithDefaultValue(CompressDumpFile, "compressDumpFile", 0); DefineOptionalParameterWithDefaultValue(SkinThickness, "skinThickness", 1.0); + DefineOptionalParameterWithDefaultValue(StatFileFormat, "statFileFormat", "TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY"); + } int Globals::globalAssign( event* the_event ){ - + char errorMessage[65535]; int key; interface_assign_type the_type = the_event->evt.asmt.asmt_type; char* lhs = the_event->evt.asmt.lhs; @@ -150,26 +151,34 @@ int Globals::globalAssign( event* the_event ){ 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 %s: expect %s, but get %s.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.sval); + 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 %s: expect %s, but get %f.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.dval ); + 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 %s: expect %s, but get %d.\n", keyword.c_str(), i->second->getParamType(), the_event->evt.asmt.rhs.ival ); + 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(the_event->err_msg, "%s is an unrecognized keyword\n", keyword.c_str() ); + 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) { @@ -334,7 +343,6 @@ char* Globals::checkMe( void ){ 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()); @@ -378,7 +386,8 @@ char* Globals::checkMe( void ){ 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(ElectrostaticSummationMethod, isEqualIgnoreCase(std::string("NONE")) || isEqualIgnoreCase(std::string("SHIFTED_POTENTIAL")) || isEqualIgnoreCase(std::string("SHIFTED_FORCE")) || isEqualIgnoreCase(std::string("REACTION_FIELD"))); + CheckParameter(ScreeningMethod, isEqualIgnoreCase(std::string("UNDAMPED")) || isEqualIgnoreCase(std::string("DAMPED"))); CheckParameter(CutoffPolicy, isEqualIgnoreCase(std::string("MIX")) || isEqualIgnoreCase(std::string("MAX")) || isEqualIgnoreCase(std::string("TRADITIONAL"))); //CheckParameter(StatFileFormat,); //CheckParameter(MixingRule,);