| 6 |  | * redistribute this software in source and binary code form, provided | 
| 7 |  | * that the following conditions are met: | 
| 8 |  | * | 
| 9 | < | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | < | *    publication of scientific results based in part on use of the | 
| 11 | < | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | < | *    the article in which the program was described (Matthew | 
| 13 | < | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | < | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | < | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | < | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | < | * | 
| 18 | < | * 2. Redistributions of source code must retain the above copyright | 
| 9 | > | * 1. Redistributions of source code must retain the above copyright | 
| 10 |  | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  | * | 
| 12 | < | * 3. Redistributions in binary form must reproduce the above copyright | 
| 12 | > | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 |  | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  | *    documentation and/or other materials provided with the | 
| 15 |  | *    distribution. | 
| 28 |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  | * such damages. | 
| 31 | + | * | 
| 32 | + | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | + | * research, please cite the appropriate papers when you publish your | 
| 34 | + | * work.  Good starting points are: | 
| 35 | + | * | 
| 36 | + | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 | + | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | + | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). | 
| 39 | + | * [4]  Vardeman & Gezelter, in progress (2009). | 
| 40 |  | */ | 
| 41 |  | #include <algorithm> | 
| 42 |  | #include <stack> | 
| 44 |  | #include "utils/Trim.hpp" | 
| 45 |  | #include "utils/simError.h" | 
| 46 |  |  | 
| 47 | < | namespace oopse { | 
| 47 | > | namespace OpenMD { | 
| 48 |  |  | 
| 49 |  | SectionParserManager::~SectionParserManager() { | 
| 50 |  | SectionParserManager::iterator i; | 
| 72 |  |  | 
| 73 |  | std::string line = trimLeftCopy(buffer); | 
| 74 |  | //a line begins with "//" is a comment line | 
| 75 | < | if ( line.empty() || (line.size() >= 2 && line[0] == '/' && line[1] == '/')) { | 
| 75 | > | if ( line.empty() || (line.size() >= 2 && line[0] == '/' | 
| 76 | > | && line[1] == '/') ) { | 
| 77 |  | continue; | 
| 78 |  | } else { | 
| 79 |  | StringTokenizer tokenizer(line); | 
| 85 |  | if (keyword == "begin") { | 
| 86 |  | std::string section = tokenizer.nextToken(); | 
| 87 |  | sectionNameStack.push(section); | 
| 88 | < |  | 
| 89 | < | i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), SameSectionParserFunctor(section)); | 
| 88 | > |  | 
| 89 | > | i = std::find_if(sectionParsers_.begin(), sectionParsers_.end(), | 
| 90 | > | SameSectionParserFunctor(section)); | 
| 91 |  | if (i == sectionParsers_.end()){ | 
| 92 | < | sprintf(painCave.errMsg, "SectionParserManager Error: Can not find corresponding section parser for %s\n", | 
| 93 | < | section.c_str()); | 
| 92 | > | sprintf(painCave.errMsg, | 
| 93 | > | "SectionParserManager Error: Can not find corresponding " | 
| 94 | > | "section parser for %s\n", | 
| 95 | > | section.c_str()); | 
| 96 |  | painCave.isFatal = 1; | 
| 97 |  | simError(); | 
| 98 |  | } else { | 
| 99 |  | if (i->isActive) { | 
| 100 | < | sprintf(painCave.errMsg, "SectionParserManager Error:find multiple %s section\n", | 
| 101 | < | section.c_str()); | 
| 102 | < | painCave.isFatal = 1; | 
| 103 | < | simError(); | 
| 100 | > | sprintf(painCave.errMsg, "SectionParserManager Error:find multiple %s " | 
| 101 | > | "section\n", | 
| 102 | > | section.c_str()); | 
| 103 | > | painCave.isFatal = 1; | 
| 104 | > | simError(); | 
| 105 |  | } else { | 
| 106 | < | i->isActive = true; | 
| 107 | < | i->lineNo = lineNo; | 
| 108 | < | i->offset = input.tellg(); | 
| 106 | > | i->isActive = true; | 
| 107 | > | i->lineNo = lineNo; | 
| 108 | > | i->offset = input.tellg(); | 
| 109 |  | } | 
| 110 |  | } | 
| 111 |  | } else if (keyword == "end") { | 
| 114 |  | sectionNameStack.pop(); | 
| 115 |  | } else { | 
| 116 |  | sprintf(painCave.errMsg, "SectionParserManager Error: begin %s and end %s does not match at line %d\n", | 
| 117 | < | sectionNameStack.top().c_str(), section.c_str(), lineNo); | 
| 117 | > | sectionNameStack.top().c_str(), section.c_str(), lineNo); | 
| 118 |  | painCave.isFatal = 1; | 
| 119 |  | simError(); | 
| 120 |  | } | 
| 121 | < |  | 
| 121 | > |  | 
| 122 |  | } else { | 
| 123 |  | continue; | 
| 124 |  | } | 
| 125 |  | } | 
| 126 |  | } | 
| 127 | < |  | 
| 127 | > |  | 
| 128 |  | } | 
| 129 | < |  | 
| 129 | > |  | 
| 130 |  | if (!sectionNameStack.empty()) { | 
| 131 |  | sprintf(painCave.errMsg, "SectionParserManager Error: stack is not empty\n"); | 
| 132 |  | painCave.isFatal = 1; | 
| 133 |  | simError(); | 
| 134 |  | } | 
| 135 | < |  | 
| 135 | > |  | 
| 136 |  | //invoke parser | 
| 137 |  | for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { | 
| 138 |  | if (i->isActive) { | 
| 139 | < | //C++ standard does not guarantee seekg  reset EOF, in that case, seekg will fail | 
| 140 | < | //It is always a good idea to call clear() before seek | 
| 141 | < | input.clear(); | 
| 142 | < | input.seekg(i->offset); | 
| 143 | < | (i->sectionParser)->parse(input, ff, i->lineNo); | 
| 139 | > | //C++ standard does not guarantee seekg  reset EOF, in that case, seekg will fail | 
| 140 | > | //It is always a good idea to call clear() before seek | 
| 141 | > | input.clear(); | 
| 142 | > | input.seekg(i->offset); | 
| 143 | > | (i->sectionParser)->parse(input, ff, i->lineNo); | 
| 144 | > | (i->sectionParser)->validateSection(); | 
| 145 |  | } | 
| 146 |  | } | 
| 147 |  |  | 
| 148 |  | } | 
| 149 | < |  | 
| 149 | > |  | 
| 150 |  | void SectionParserManager::push_front(SectionParser* sp) { | 
| 151 |  | SectionParserManager::iterator i; | 
| 152 |  | i = findSectionParser(sp->getSectionName()); | 
| 153 |  | if (i != sectionParsers_.end()) { | 
| 154 | < | std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; | 
| 154 | > | std::cerr << sp->getSectionName() << " section parser already exists" | 
| 155 | > | << std::endl; | 
| 156 |  | return; | 
| 157 |  | } | 
| 158 |  |  | 
| 163 |  | } else { | 
| 164 |  | context.priority = sectionParsers_.front().priority - priorityDifference_; | 
| 165 |  | } | 
| 166 | < |  | 
| 166 | > |  | 
| 167 |  | context.sectionParser = sp; | 
| 168 |  | context.lineNo = 0; | 
| 169 |  | context.offset = 0; | 
| 176 |  | SectionParserManager::iterator i; | 
| 177 |  | i = findSectionParser(sp->getSectionName()); | 
| 178 |  | if (i != sectionParsers_.end()) { | 
| 179 | < | std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; | 
| 179 | > | std::cerr << sp->getSectionName() << " section parser already exists" | 
| 180 | > | << std::endl; | 
| 181 |  | return; | 
| 182 |  | } | 
| 183 |  |  | 
| 201 |  | SectionParserManager::iterator i; | 
| 202 |  | i = findSectionParser(sp->getSectionName()); | 
| 203 |  | if (i != sectionParsers_.end()) { | 
| 204 | < | std::cerr << sp->getSectionName() << " section parser is alway existed" << std::endl; | 
| 204 | > | std::cerr << sp->getSectionName() << " section parser already exists" | 
| 205 | > | << std::endl; | 
| 206 |  | } | 
| 207 |  |  | 
| 208 |  | SectionParserContext context; | 
| 235 |  | SectionParserManager::iterator i; | 
| 236 |  | for (i = sectionParsers_.begin(); i != sectionParsers_.end(); ++i) { | 
| 237 |  | if (i->sectionParser->getSectionName() == sectionName) { | 
| 238 | < | break; | 
| 238 | > | break; | 
| 239 |  | } | 
| 240 |  | } | 
| 241 |  |  |