Ignore:
Timestamp:
Jun 27, 2008, 9:14:58 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
74baec
Parents:
d7b1bf
git-author:
Frederik Heber <heber@…> (06/27/08 21:12:52)
git-committer:
Frederik Heber <heber@…> (06/27/08 21:14:58)
Message:

introduced shieldings to analyzer and joiner

both now handle pcp.sigma_all...csv files just as pcp.forces.all. Therefore the data format in pcp/perturbed.c was adapted a bit, as we need a header.
periodentafel.hpp got periodentafel and element class from molecules.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/parser.cpp

    rd7b1bf r375dcf  
    1010#include "parser.hpp"
    1111
     12// include config.h
     13#ifdef HAVE_CONFIG_H
     14#include <config.h>
     15#endif
     16
    1217// ======================================= FUNCTIONS ==========================================
    1318
    1419/** Test if given filename can be opened.
    1520 * \param filename name of file
     21 * \param test true - no error message, false - print error
    1622 * \return given file exists
    1723 */
    18 #ifdef HAVE_INLINE
    19 inline bool FilePresent(const char *filename)
    20 #else
    21 bool FilePresent(const char *filename)
    22 #endif
     24bool FilePresent(const char *filename, bool test)
    2325{
    2426  ifstream input;
     
    2628  input.open(filename, ios::in);
    2729  if (input == NULL) {
    28     cout << endl << "Unable to open " << filename << ", is the directory correct?" << endl;
     30    if (!test)
     31      cout << endl << "Unable to open " << filename << ", is the directory correct?" << endl;
    2932    return false;
    3033  }
     
    4447
    4548  line << argv[1] << FRAGMENTPREFIX << KEYSETFILE;
    46   return FilePresent(line.str().c_str());
     49  return FilePresent(line.str().c_str(), false);
    4750};
    4851
     
    8992
    9093/** Parsing a number of matrices.
     94 * -# First, count the number of matrices by counting lines in KEYSETFILE
     95 * -# Then,
     96 *    -# construct the fragment number
     97 *    -# open the matrix file
     98 *    -# skip some lines (\a skiplines)
     99 *    -# scan header lines for number of columns
     100 *    -# scan lines for number of rows
     101 *    -# allocate matrix
     102 *    -# loop over found column and row counts and parse in each entry
     103 * -# Finally, allocate one additional matrix (\a MatrixCounter) containing combined or temporary values
    91104 * \param *name directory with files
    92105 * \param *prefix prefix of each matrix file
     
    131144    stringstream line;
    132145    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
     146    file.str(" ");
    133147    if (i != MatrixCounter) 
    134       line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix << suffix;
     148      file << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix << suffix;
    135149    else
    136       line << name << prefix << suffix;
     150      file << name << prefix << suffix;
    137151    Free((void **)&FragmentNumber, "MatrixContainer::ParseMatrix: *FragmentNumber");
    138     input.open(line.str().c_str(), ios::in);
    139     //cout << "Opening " << line.str() << " ... "  << input << endl;
     152    input.open(file.str().c_str(), ios::in);
     153    //cout << "Opening " << file.str() << " ... "  << input << endl;
    140154    if (input == NULL) {
    141       cerr << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
     155      cerr << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
    142156      return false;
    143157    }
     158   
    144159    // skip some initial lines
    145160    for (int m=skiplines+1;m--;)
    146161      input.getline(Header, 1023);
     162   
    147163    // scan header for number of columns
    148164    line.str(Header);
     
    159175    //cout << line.str() << endl;
    160176    //cout << "ColumnCounter: " << ColumnCounter << endl;
     177   
    161178    // scan rest for number of rows/lines
    162179    RowCounter[i]=-1;    // counts one line too much
     
    169186      }
    170187    }
    171     cout << "RowCounter[" << i << "]: " << RowCounter[i] << endl;
    172     Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]");
    173     input.clear();
    174     input.seekg(ios::beg);
    175     for (int m=skiplines+1;m--;)
    176       input.getline(Header, 1023);    // skip header
    177     line.str(Header);
    178     for(int k=skipcolumns;k--;)  // skip columns in header too
    179       line >> filename;
    180     strncpy(Header, line.str().c_str(), 1023); 
    181     for(int j=0;j<RowCounter[i];j++) {
    182       Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]");
    183       input.getline(filename, 1023);
    184       stringstream lines(filename);
    185       //cout << "Matrix at level " << j << ":";// << filename << endl;
    186       for(int k=skipcolumns;k--;)
    187         lines >> filename;
    188       for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) {
    189         lines >> Matrix[i][j][k];
    190         //cout << " " << setprecision(2) << Matrix[i][j][k];;
     188    //cout << "RowCounter[" << i << "]: " << RowCounter[i] << " from file " << file.str() << "." << endl;
     189   
     190    // allocate matrix if it's not zero dimension in one direction
     191    if ((ColumnCounter > 0) && (RowCounter[i] > -1)) {
     192      Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]");
     193   
     194      // parse in each entry for this matrix
     195      input.clear();
     196      input.seekg(ios::beg);
     197      for (int m=skiplines+1;m--;)
     198        input.getline(Header, 1023);    // skip header
     199      line.str(Header);
     200      for(int k=skipcolumns;k--;)  // skip columns in header too
     201        line >> filename;
     202      strncpy(Header, line.str().c_str(), 1023); 
     203      for(int j=0;j<RowCounter[i];j++) {
     204        Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]");
     205        input.getline(filename, 1023);
     206        stringstream lines(filename);
     207        //cout << "Matrix at level " << j << ":";// << filename << endl;
     208        for(int k=skipcolumns;k--;)
     209          lines >> filename;
     210        for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) {
     211          lines >> Matrix[i][j][k];
     212          //cout << " " << setprecision(2) << Matrix[i][j][k];;
     213        }
     214        //cout << endl;
     215        Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]");
     216        for(int j=ColumnCounter;j--;)
     217          Matrix[i][ RowCounter[i] ][j] = 0.;
    191218      }
    192       //cout << endl;
    193     }
    194     Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]");
    195     for(int j=ColumnCounter;j--;)
    196       Matrix[i][ RowCounter[i] ][j] = 0.;
     219    } else {
     220      cerr << "ERROR: Matrix nr. " << i << " has column and row count of (" << ColumnCounter << "," << RowCounter[i] << "), could not allocate nor parse!" << endl;
     221    }
    197222    input.close();
    198223  }
     
    430455  stringstream line;
    431456 
    432   cout << "Parsing force indices." << endl;
     457  cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
    433458  Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "ForceMatrix::ParseIndices: **Indices");
    434459  line << name << FRAGMENTPREFIX << FORCESFILE;
     
    446471    Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]");
    447472    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    448     cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
     473    //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
    449474    Free((void **)&FragmentNumber, "ForceMatrix::ParseIndices: *FragmentNumber");
    450475    for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
    451476      line >> Indices[i][j];
    452       cout << " " << Indices[i][j];
    453     }
    454     cout << endl;
     477      //cout << " " << Indices[i][j];
     478    }
     479    //cout << endl;
    455480  }
    456481  Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]");
     
    568593 
    569594  cout << "Creating Fragment terms." << endl;
    570   // scan through all to determine order
     595  // scan through all to determine maximum order
    571596  Order=0;
    572597  for(int i=FragmentCounter;i--;) {
Note: See TracChangeset for help on using the changeset viewer.