--- trunk/src/io/Globals.cpp 2004/09/24 16:27:58 3 +++ trunk/src/io/Globals.cpp 2005/04/15 22:04:00 507 @@ -1,3 +1,44 @@ +/* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Acknowledgement of the program authors must be made in any + * publication of scientific results based in part on use of the + * program. An acceptable form of acknowledgement is citation of + * the article in which the program was described (Matthew + * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher + * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented + * Parallel Simulation Engine for Molecular Dynamics," + * J. Comput. Chem. 26, pp. 252-271 (2005)) + * + * 2. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 3. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + */ + #include #include #include @@ -10,7 +51,7 @@ /* * The following section lists all of the defined tokens for the - * gloabal assignment statements. All are prefixed with a G_ to avoid + * global assignment statements. All are prefixed with a G_ to avoid * stepping on any previously defined enumerations. * * NOTE: tokens start at 1, 0 is a resrved token number @@ -71,6 +112,10 @@ #define G_THERM_INT_LAMBDA 50 #define G_THERM_INT_K 51 #define G_FORCEFIELD_VARIANT 52 +#define G_FORCEFIELD_FILENAME 53 +#define G_THERM_INT_DIST_SPRING 54 +#define G_THERM_INT_THETA_SPRING 55 +#define G_THERM_INT_OMEGA_SPRING 56 Globals::Globals(){ initalize(); @@ -78,12 +123,6 @@ Globals::~Globals(){ Globals::~Globals(){ int i; - - for( i=0; imatch( lhs ); + + CommandMapType::iterator iter; + std::string keyword(lhs); + iter = command_table.find(keyword); + if (iter != command_table.end()) { + token = iter->second; + } if( token ){ @@ -1205,14 +1249,14 @@ int Globals::globalAssign( event* the_event ){ switch( the_type ){ case STRING: - strcpy(zconsForcePolicy, the_event->evt.asmt.rhs.sval); + strcpy(zconsForcePolicy, the_event->evt.asmt.rhs.sval); - for(int i = 0; zconsForcePolicy[i] != '\0'; i++) - { - zconsForcePolicy[i] = toupper(zconsForcePolicy[i]); - } + for(int i = 0; zconsForcePolicy[i] != '\0'; i++) + { + zconsForcePolicy[i] = toupper(zconsForcePolicy[i]); + } have_zcons_force_policy = 1; - return 1; + return 1; break; case DOUBLE: @@ -1389,13 +1433,13 @@ int Globals::globalAssign( event* the_event ){ case STRING: the_event->err_msg = - strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not a double or int.\n" ); + strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not an int.\n" ); return 1; break; case DOUBLE: - minimizer_writefrq= the_event->evt.asmt.rhs.dval; - have_minimizer_writefrq = 1; + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not an int.\n" ); return 1; break; @@ -1505,13 +1549,13 @@ int Globals::globalAssign( event* the_event ){ case STRING: the_event->err_msg = - strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not a double or int.\n" ); + strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not an int.\n" ); return 1; break; case DOUBLE: - minimizer_ls_maxiteration = the_event->evt.asmt.rhs.dval; - have_minimizer_ls_maxiteration = 1; + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not an int.\n" ); return 1; break; @@ -1563,21 +1607,21 @@ int Globals::globalAssign( event* the_event ){ switch( the_type ){ case STRING: - the_event->err_msg = + the_event->err_msg = strdup( "Error in parsing meta-data file!\n\tseed is not a string.\n" ); return 0; - return 0; + return 0; break; case DOUBLE: - have_seed = 1; - seed = (int)the_event->evt.asmt.rhs.dval; + have_seed = 1; + seed = (int)the_event->evt.asmt.rhs.dval; return 1; break; case INT: - have_seed = 1; - seed = the_event->evt.asmt.rhs.ival ; + have_seed = 1; + seed = the_event->evt.asmt.rhs.ival ; return 1; break; @@ -1681,7 +1725,8 @@ int Globals::globalAssign( event* the_event ){ return 0; break; } - break; + break; + case G_FORCEFIELD_VARIANT: if( the_type == STRING ){ strcpy( forcefield_variant, the_event->evt.asmt.rhs.sval ); @@ -1691,8 +1736,108 @@ int Globals::globalAssign( event* the_event ){ the_event->err_msg = strdup( "Error in parsing meta-data file!\n\tforceFieldVariant was not a string assignment.\n" ); + return 0; + break; + // add more token cases here. + + case G_FORCEFIELD_FILENAME: + if( the_type == STRING ){ + strcpy( forcefield_filename, the_event->evt.asmt.rhs.sval ); + have_forcefield_filename = 1; + return 1; + } + + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tforceFieldFileName was not a string assignment.\n" ); return 0; break; + + case G_THERM_INT_DIST_SPRING: + switch( the_type ){ + + case STRING: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst is not a double or int.\n" ); + return 1; + break; + + case DOUBLE: + therm_int_dist_spring = the_event->evt.asmt.rhs.dval; + have_dist_spring_constant = 1; + return 1; + break; + + case INT: + therm_int_dist_spring = (double)the_event->evt.asmt.rhs.dval; + have_dist_spring_constant = 1; + return 1; + break; + + default: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst unrecognized.\n" ); + return 0; + break; + } + break; + + case G_THERM_INT_THETA_SPRING: + switch( the_type ){ + + case STRING: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst is not a double or int.\n" ); + return 1; + break; + + case DOUBLE: + therm_int_theta_spring = the_event->evt.asmt.rhs.dval; + have_theta_spring_constant = 1; + return 1; + break; + + case INT: + therm_int_theta_spring = (double)the_event->evt.asmt.rhs.dval; + have_theta_spring_constant = 1; + return 1; + break; + + default: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst unrecognized.\n" ); + return 0; + break; + } + break; + + case G_THERM_INT_OMEGA_SPRING: + switch( the_type ){ + + case STRING: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst is not a double or int.\n" ); + return 1; + break; + + case DOUBLE: + therm_int_omega_spring = the_event->evt.asmt.rhs.dval; + have_omega_spring_constant = 1; + return 1; + break; + + case INT: + therm_int_omega_spring = (double)the_event->evt.asmt.rhs.dval; + have_omega_spring_constant = 1; + return 1; + break; + + default: + the_event->err_msg = + strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst unrecognized.\n" ); + return 0; + break; + } + break; // add more token cases here. } } @@ -1784,46 +1929,3 @@ int Globals::globalEnd( event* the_event ){ return 1; } -int Globals::hash( char* text ){ - - register unsigned short int i = 0; // loop counter - int key = 0; // the hash key - - while( text[i] != '\0' ){ - - key = ( ( key << hash_shift ) + text[i] ) % hash_size; - - i++; - } - - if( key < 0 ){ - - // if the key is less than zero, we've had an overflow error - - sprintf( painCave.errMsg, - "There has been an overflow error in the Globals' hash key."); - painCave.isFatal = 1; - simError(); -#ifdef IS_MPI - if( painCave.isEventLoop ){ - if( worldRank == 0 ) mpiInterfaceExit(); - } -#endif //is_mpi - } - - return key; -} - -void Globals::addHash( char* text, int token ){ - - int key; - LinkedCommand* the_element; - - the_element = new LinkedCommand; - the_element->setValues( text, token ); - - key = hash( text ); - - the_element->setNext( command_table[key] ); - command_table[key] = the_element; -}