Changeset 4e855e for src/parser.cpp


Ignore:
Timestamp:
Feb 4, 2011, 6:56:38 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

BondGraph::LoadBondLengthTable() now accepts istream instead of const char *.

  • This has been quite a lot of work because the matrix parsing is involved.
  • Hence, the fix is not really clean, this should get fixed as soon as we deal with the BondGraph implementation.
  • This fixes ticket #130.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/parser.cpp

    rfd3788 r4e855e  
    2222
    2323#include <cstring>
     24#include <iomanip>
    2425
    2526#include "Helpers/helpers.hpp"
     
    158159 *    -# allocate matrix
    159160 *    -# loop over found column and row counts and parse in each entry
    160  * \param *name directory with files
     161 * \param &input input stream
    161162 * \param skiplines number of inital lines to skip
    162163 * \param skiplines number of inital columns to skip
     
    164165 * \return parsing successful
    165166 */
    166 bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr)
    167 {
    168   ifstream input;
     167bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr)
     168{
    169169  stringstream line;
    170170  string token;
    171171  char filename[1023];
    172172
    173   input.open(name, ios::in);
    174173  //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);
    177176    //performCriticalExit();
    178177    return false;
     
    190189  for(int k=skipcolumns;k--;)
    191190    line >> Header[MatrixNr];
    192   //Log() << Verbose(0) << line.str() << endl;
     191  Log() << Verbose(0) << line.str() << endl;
    193192  ColumnCounter[MatrixNr]=0;
    194193  while ( getline(line,token, '\t') ) {
     
    196195      ColumnCounter[MatrixNr]++;
    197196  }
    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;
    200199  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);
    202201    performCriticalExit();
    203202  }
     
    207206  while (!input.eof()) {
    208207    input.getline(filename, 1023);
    209     //Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
     208    Log() << Verbose(0) << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
    210209    RowCounter[MatrixNr]++; // then line was not last MeanForce
    211210    if (strncmp(filename,"MeanForce", 9) == 0) {
     
    213212    }
    214213  }
    215   //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
     214  Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from input stream." << endl;
    216215  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);
    218217    performCriticalExit();
    219218  }
     
    233232      input.getline(Header[MatrixNr], 1023);    // skip header
    234233    line.str(Header[MatrixNr]);
     234    Log() << Verbose(0) << "Header: " << line.str() << endl;
    235235    for(int k=skipcolumns;k--;)  // skip columns in header too
    236236      line >> filename;
     
    245245      input.getline(filename, 1023);
    246246      stringstream lines(filename);
    247       //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
     247      Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
    248248      for(int k=skipcolumns;k--;)
    249249        lines >> filename;
    250250      for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
    251251        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;
    253253      }
    254254      if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL)
     
    261261    DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl);
    262262  }
    263   input.close();
    264263  return true;
    265264};
     
    327326    file.str(" ");
    328327    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();
    330331      return false;
     332    }
     333    input.close();
    331334    delete[](FragmentNumber);
    332335  }
     
    628631    strncat(filename, prefix, 1023-strlen(filename));
    629632    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();
    631636  }
    632637  return status;
     
    764769    strncat(filename, prefix, 1023-strlen(filename));
    765770    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();
    767774  }
    768775 
     
    992999    strncat(filename, prefix, 1023-strlen(filename));
    9931000    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();
    9951004  }
    9961005
Note: See TracChangeset for help on using the changeset viewer.