/** \file parsing.cpp * * Declarations of various class functions for the parsing of value files. * */ // ======================================= INCLUDES ========================================== #include "helpers.hpp" #include "parser.hpp" // ======================================= FUNCTIONS ========================================== /** Test if given filename can be opened. * \param filename name of file * \return given file exists */ #ifdef HAVE_INLINE inline bool FilePresent(const char *filename) #else bool FilePresent(const char *filename) #endif { ifstream input; input.open(filename, ios::in); if (input == NULL) { cout << endl << "Unable to open " << filename << ", is the directory correct?" << endl; return false; } input.close(); return true; }; /** Test the given parameters. * \param argc argument count * \param **argv arguments array * \return given inputdir is valid */ bool TestParams(int argc, char **argv) { ifstream input; stringstream line; line << argv[1] << FRAGMENTPREFIX << KEYSETFILE; return FilePresent(line.str().c_str()); }; // ======================================= CLASS MatrixContainer ============================= /** Constructor of MatrixContainer class. */ MatrixContainer::MatrixContainer() { Matrix = NULL; Indices = NULL; Header = NULL; MatrixCounter = 0; RowCounter = NULL; ColumnCounter = 0; }; /** Destructor of MatrixContainer class. */ MatrixContainer::~MatrixContainer() { if (Matrix != NULL) { for(int i=0;i> Header; //cout << line.str() << endl; ColumnCounter=0; while (!line.eof()) { strcpy(filename,"@"); line >> filename; if (filename[0] != '@') ColumnCounter++; } //cout << line.str() << endl; //cout << "ColumnCounter: " << ColumnCounter << endl; // scan rest for number of rows/lines RowCounter[i]=-1; // counts one line too much while (!input.eof()) { input.getline(filename, 1023); //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl; RowCounter[i]++; // then line was not last MeanForce if (strncmp(filename,"MeanForce", 9) == 0) { break; } } cout << "RowCounter[" << i << "]: " << RowCounter[i] << endl; Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]"); input.clear(); input.seekg(ios::beg); for (int m=0;m<=skiplines;m++) input.getline(Header, 1023); // skip header line.str(Header); for(int k=0;k> filename; strncpy(Header, line.str().c_str(), 1023); for(int j=0;j> filename; for(int k=0;(k> Matrix[i][j][k]; //cout << " " << setprecision(2) << Matrix[i][j][k];; } //cout << endl; } Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]"); for(int j=0;j RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ]) { cerr << "Current force index " << m << " is greater than " << RowCounter[ KeySet.OrderSet[Order][CurrentFragment] ] << "!" << endl; return false; } if (Order == SubOrder) { // equal order is always copy from Energies for(int l=0;l1) && (RowCounter >= 1)) //cout << "Fragments[ KeySet.OrderSet[" << i << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << RowCounter[0]-1 << "][" << 1 << "] = " << Fragments[ KeySet.OrderSet[Order][CurrentFragment] ][RowCounter[0]-1][1] << endl; } } else { //cout << "Fragment " << KeySet.OrderSet[SubOrder][j] << " is not contained in fragment " << KeySet. KeySet.OrderSet[Order][CurrentFragment] << "." << endl; } } } //cout << "Final Fragments[ KeySet.OrderSet[" << Order << "][" << CurrentFragment << "]=" << KeySet.OrderSet[Order][CurrentFragment] << " ][" << KeySet.AtomCounter[0]-1 << "][" << 1 << "] = " << Fragments[ KeySet.OrderSet[Order][CurrentFragment] ][KeySet.AtomCounter[0]-1][1] << endl; } return true; }; /** Writes the summed total fragment terms \f$F_{ij}\f$ to file. * \param *name inputdir * \param *prefix prefix before \a EnergySuffix * \return file was written */ bool MatrixContainer::WriteTotalFragments(const char *name, const char *prefix) { ofstream output; char *FragmentNumber = NULL; cout << "Writing fragment files." << endl; for(int i=0;i RowCounter[MatrixCounter]) { cerr << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl; return false; } if (j != -1) for(int k=2;k> KeySets[i][j]; cout << " " << KeySets[i][j]; } cout << endl; } input.close(); return true; }; /** Parse many body terms, associating each fragment to a certain bond order. * \return parsing succesful */ bool KeySetsContainer::ParseManyBodyTerms() { int Counter; cout << "Creating Fragment terms." << endl; // scan through all to determine order Order=0; for(int i=0;i Order) Order = Counter; } cout << "Found Order is " << Order << "." << endl; // scan through all to determine fragments per order FragmentsPerOrder = (int *) Malloc(sizeof(int)*Order, "KeySetsContainer::ParseManyBodyTerms: *FragmentsPerOrder"); for(int i=0;i FragmentCounter) || (SmallerSet > FragmentCounter)) // index out of bounds return false; for(int i=0;i