Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/parser.cpp

    rad011c 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.