--- trunk/src/brains/SimCreator.cpp 2005/12/30 15:32:55 832 +++ trunk/src/brains/SimCreator.cpp 2006/05/17 21:51:42 963 @@ -46,7 +46,7 @@ * @time 13:51am * @version 1.0 */ - +#include #include #include #include @@ -147,37 +147,88 @@ Globals* SimCreator::parseFile(const std::string mdFil simParams = treeParser.walkTree(parser.getAST()); } + catch(antlr::MismatchedCharException& e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } catch(antlr::MismatchedTokenException &e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } catch(antlr::NoViableAltForCharException &e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } catch(antlr::NoViableAltException &e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } + catch(antlr::TokenStreamRecognitionException& e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } + catch(antlr::TokenStreamIOException& e) { - cerr<< "parser exception: " << e.getMessage() << endl; + sprintf(painCave.errMsg, + "parser exception: %s\n", + e.getMessage().c_str()); + painCave.isFatal = 1; + simError(); } + catch(antlr::TokenStreamException& e) { - cerr<< "parser exception: " << e.getMessage() << endl; + sprintf(painCave.errMsg, + "parser exception: %s\n", + e.getMessage().c_str()); + painCave.isFatal = 1; + simError(); } catch (antlr::RecognitionException& e) { - cerr<< "parser exception: " << e.getMessage() << " " << e.getFilename() << ":" << e.getLine() << " " << e.getColumn() << endl; + sprintf(painCave.errMsg, + "parser exception: %s %s:%d:%d\n", + e.getMessage().c_str(),e.getFilename().c_str(), e.getLine(), e.getColumn()); + painCave.isFatal = 1; + simError(); } catch (antlr::CharStreamException& e) { - cerr << "parser exception: " << e.getMessage() << endl; + sprintf(painCave.errMsg, + "parser exception: %s\n", + e.getMessage().c_str()); + painCave.isFatal = 1; + simError(); } - catch (exception& e) { - cerr << "parser exception: " << e.what() << endl; - } + catch (OOPSEException& e) { + sprintf(painCave.errMsg, + "%s\n", + e.getMessage().c_str()); + painCave.isFatal = 1; + simError(); + } + catch (std::exception& e) { + sprintf(painCave.errMsg, + "parser exception: %s\n", + e.what()); + painCave.isFatal = 1; + simError(); + } return simParams; } @@ -228,7 +279,8 @@ Globals* SimCreator::parseFile(const std::string mdFil //create SimInfo SimInfo * info = new SimInfo(ff, simParams); - //gather parameters (SimCreator only retrieves part of the parameters) + //gather parameters (SimCreator only retrieves part of the + //parameters) gatherParameters(info, mdFileName); //divide the molecules and determine the global index of molecules @@ -240,18 +292,23 @@ Globals* SimCreator::parseFile(const std::string mdFil createMolecules(info); - //allocate memory for DataStorage(circular reference, need to break it) + //allocate memory for DataStorage(circular reference, need to + //break it) info->setSnapshotManager(new SimSnapshotManager(info)); - //set the global index of atoms, rigidbodies and cutoffgroups (only need to be set once, the - //global index will never change again). Local indices of atoms and rigidbodies are already set by - //MoleculeCreator class which actually delegates the responsibility to LocalIndexManager. + //set the global index of atoms, rigidbodies and cutoffgroups + //(only need to be set once, the global index will never change + //again). Local indices of atoms and rigidbodies are already set + //by MoleculeCreator class which actually delegates the + //responsibility to LocalIndexManager. setGlobalIndex(info); - //Alought addExculdePairs is called inside SimInfo's addMolecule method, at that point - //atoms don't have the global index yet (their global index are all initialized to -1). - //Therefore we have to call addExcludePairs explicitly here. A way to work around is that - //we can determine the beginning global indices of atoms before they get created. + //Although addExcludePairs is called inside SimInfo's addMolecule + //method, at that point atoms don't have the global index yet + //(their global index are all initialized to -1). Therefore we + //have to call addExcludePairs explicitly here. A way to work + //around is that we can determine the beginning global indices of + //atoms before they get created. SimInfo::MoleculeIterator mi; Molecule* mol; for (mol= info->beginMolecule(mi); mol != NULL; mol = info->nextMolecule(mi)) { @@ -295,12 +352,12 @@ Globals* SimCreator::parseFile(const std::string mdFil #ifdef IS_MPI void SimCreator::divideMolecules(SimInfo *info) { - double numerator; - double denominator; - double precast; - double x; - double y; - double a; + RealType numerator; + RealType denominator; + RealType precast; + RealType x; + RealType y; + RealType a; int old_atoms; int add_atoms; int new_atoms; @@ -412,7 +469,7 @@ Globals* SimCreator::parseFile(const std::string mdFil // Pacc(x) = exp(- a * x) // where a = penalty / (average atoms per molecule) - x = (double)(new_atoms - nTarget); + x = (RealType)(new_atoms - nTarget); y = myRandom->rand(); if (y < exp(- a * x)) {