Changeset 4e855e for src/parser.cpp
- Timestamp:
- Feb 4, 2011, 6:56:38 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- febef3
- Parents:
- fd3788
- git-author:
- Frederik Heber <heber@…> (02/04/11 18:54:12)
- git-committer:
- Frederik Heber <heber@…> (02/04/11 18:56:38)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/parser.cpp
rfd3788 r4e855e 22 22 23 23 #include <cstring> 24 #include <iomanip> 24 25 25 26 #include "Helpers/helpers.hpp" … … 158 159 * -# allocate matrix 159 160 * -# loop over found column and row counts and parse in each entry 160 * \param *name directory with files161 * \param &input input stream 161 162 * \param skiplines number of inital lines to skip 162 163 * \param skiplines number of inital columns to skip … … 164 165 * \return parsing successful 165 166 */ 166 bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr) 167 { 168 ifstream input; 167 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr) 168 { 169 169 stringstream line; 170 170 string token; 171 171 char filename[1023]; 172 172 173 input.open(name, ios::in);174 173 //Log() << Verbose(1) << "Opening " << name << " ... " << input << endl; 175 if (input == NULL) {176 DoeLog(1) && (eLog()<< Verbose(1) << endl << "MatrixContainer::ParseMatrix: Unable to open " << name << ", is the directory correct?" << endl);174 if (input.bad()) { 175 DoeLog(1) && (eLog()<< Verbose(1) << endl << "MatrixContainer::ParseMatrix: Unable to parse istream." << endl); 177 176 //performCriticalExit(); 178 177 return false; … … 190 189 for(int k=skipcolumns;k--;) 191 190 line >> Header[MatrixNr]; 192 //Log() << Verbose(0) << line.str() << endl;191 Log() << Verbose(0) << line.str() << endl; 193 192 ColumnCounter[MatrixNr]=0; 194 193 while ( getline(line,token, '\t') ) { … … 196 195 ColumnCounter[MatrixNr]++; 197 196 } 198 //Log() << Verbose(0) << line.str() << endl;199 //Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;197 Log() << Verbose(0) << line.str() << endl; 198 Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl; 200 199 if (ColumnCounter[MatrixNr] == 0) { 201 DoeLog(0) && (eLog()<< Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);200 DoeLog(0) && (eLog()<< Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from ostream." << endl); 202 201 performCriticalExit(); 203 202 } … … 207 206 while (!input.eof()) { 208 207 input.getline(filename, 1023); 209 //Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;208 Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl; 210 209 RowCounter[MatrixNr]++; // then line was not last MeanForce 211 210 if (strncmp(filename,"MeanForce", 9) == 0) { … … 213 212 } 214 213 } 215 //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;214 Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl; 216 215 if (RowCounter[MatrixNr] == 0) { 217 DoeLog(0) && (eLog()<< Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);216 DoeLog(0) && (eLog()<< Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl); 218 217 performCriticalExit(); 219 218 } … … 233 232 input.getline(Header[MatrixNr], 1023); // skip header 234 233 line.str(Header[MatrixNr]); 234 Log() << Verbose(0) << "Header: " << line.str() << endl; 235 235 for(int k=skipcolumns;k--;) // skip columns in header too 236 236 line >> filename; … … 245 245 input.getline(filename, 1023); 246 246 stringstream lines(filename); 247 //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;247 Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl; 248 248 for(int k=skipcolumns;k--;) 249 249 lines >> filename; 250 250 for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) { 251 251 lines >> Matrix[MatrixNr][j][k]; 252 //Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl;252 Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl; 253 253 } 254 254 if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL) … … 261 261 DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl); 262 262 } 263 input.close();264 263 return true; 265 264 }; … … 327 326 file.str(" "); 328 327 file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix; 329 if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i)) 328 std::ifstream input(file.str().c_str()); 329 if (!ParseMatrix(input, skiplines, skipcolumns, i)) { 330 input.close(); 330 331 return false; 332 } 333 input.close(); 331 334 delete[](FragmentNumber); 332 335 } … … 628 631 strncat(filename, prefix, 1023-strlen(filename)); 629 632 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 630 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 633 std::ifstream input(filename); 634 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 635 input.close(); 631 636 } 632 637 return status; … … 764 769 strncat(filename, prefix, 1023-strlen(filename)); 765 770 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 766 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 771 std::ifstream input(filename); 772 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 773 input.close(); 767 774 } 768 775 … … 992 999 strncat(filename, prefix, 1023-strlen(filename)); 993 1000 strncat(filename, suffix.c_str(), 1023-strlen(filename)); 994 ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter); 1001 std::ifstream input(filename); 1002 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); 1003 input.close(); 995 1004 } 996 1005
Note:
See TracChangeset
for help on using the changeset viewer.