Changeset 375dcf for molecuilder/src/parser.cpp
- Timestamp:
- Jun 27, 2008, 9:14:58 PM (17 years ago)
- 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)
- File:
-
- 1 edited
-
molecuilder/src/parser.cpp (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/parser.cpp
rd7b1bf r375dcf 10 10 #include "parser.hpp" 11 11 12 // include config.h 13 #ifdef HAVE_CONFIG_H 14 #include <config.h> 15 #endif 16 12 17 // ======================================= FUNCTIONS ========================================== 13 18 14 19 /** Test if given filename can be opened. 15 20 * \param filename name of file 21 * \param test true - no error message, false - print error 16 22 * \return given file exists 17 23 */ 18 #ifdef HAVE_INLINE 19 inline bool FilePresent(const char *filename) 20 #else 21 bool FilePresent(const char *filename) 22 #endif 24 bool FilePresent(const char *filename, bool test) 23 25 { 24 26 ifstream input; … … 26 28 input.open(filename, ios::in); 27 29 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; 29 32 return false; 30 33 } … … 44 47 45 48 line << argv[1] << FRAGMENTPREFIX << KEYSETFILE; 46 return FilePresent(line.str().c_str() );49 return FilePresent(line.str().c_str(), false); 47 50 }; 48 51 … … 89 92 90 93 /** 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 91 104 * \param *name directory with files 92 105 * \param *prefix prefix of each matrix file … … 131 144 stringstream line; 132 145 FragmentNumber = FixedDigitNumber(MatrixCounter, i); 146 file.str(" "); 133 147 if (i != MatrixCounter) 134 line << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix << suffix;148 file << name << FRAGMENTPREFIX << FragmentNumber << "/" << prefix << suffix; 135 149 else 136 line << name << prefix << suffix;150 file << name << prefix << suffix; 137 151 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; 140 154 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; 142 156 return false; 143 157 } 158 144 159 // skip some initial lines 145 160 for (int m=skiplines+1;m--;) 146 161 input.getline(Header, 1023); 162 147 163 // scan header for number of columns 148 164 line.str(Header); … … 159 175 //cout << line.str() << endl; 160 176 //cout << "ColumnCounter: " << ColumnCounter << endl; 177 161 178 // scan rest for number of rows/lines 162 179 RowCounter[i]=-1; // counts one line too much … … 169 186 } 170 187 } 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.; 191 218 } 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 } 197 222 input.close(); 198 223 } … … 430 455 stringstream line; 431 456 432 cout << "Parsing force indices ." << endl;457 cout << "Parsing force indices for " << MatrixCounter << " matrices." << endl; 433 458 Indices = (int **) Malloc(sizeof(int *)*(MatrixCounter+1), "ForceMatrix::ParseIndices: **Indices"); 434 459 line << name << FRAGMENTPREFIX << FORCESFILE; … … 446 471 Indices[i] = (int *) Malloc(sizeof(int)*RowCounter[i], "ForceMatrix::ParseIndices: *Indices[]"); 447 472 FragmentNumber = FixedDigitNumber(MatrixCounter, i); 448 cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";473 //cout << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:"; 449 474 Free((void **)&FragmentNumber, "ForceMatrix::ParseIndices: *FragmentNumber"); 450 475 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) { 451 476 line >> Indices[i][j]; 452 cout << " " << Indices[i][j];453 } 454 cout << endl;477 //cout << " " << Indices[i][j]; 478 } 479 //cout << endl; 455 480 } 456 481 Indices[MatrixCounter] = (int *) Malloc(sizeof(int)*RowCounter[MatrixCounter], "ForceMatrix::ParseIndices: *Indices[]"); … … 568 593 569 594 cout << "Creating Fragment terms." << endl; 570 // scan through all to determine order595 // scan through all to determine maximum order 571 596 Order=0; 572 597 for(int i=FragmentCounter;i--;) {
Note:
See TracChangeset
for help on using the changeset viewer.
