Changeset 8f019c for src


Ignore:
Timestamp:
Aug 18, 2008, 8:35:11 AM (16 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:
f05407
Parents:
f3dc4c
Message:

Splitting MatrrixContainer::ParseMatrix in ParseMatrix

ParseMatrix just parses only a given matrix into a given part of the MatrixContainer::matrix array).
ParseFragmentMatrix calls ParseMatrix for a sequence of numbered files containing the matrices.
ForceMatrix::ParseFragmentMatrix overrides the routine from MatrixContainer in order to handle the parsing of the last and one ma
trix in a special way
EnergyMatrix::ParseFragmentMatrix overrides the routine from MatrixContainer in order to handle the parsing of the last and one matrix in a special way
Realloc() was fixed: ReAlloc would break if given oldptr is NULL, but now we simply switch to doing a malloc instead and only admonishing the wrong call to ReAlloc instead of Malloc
analyser.cpp and joiner.cpp have been adapted to these new calling schemes

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/analyzer.cpp

    rf3dc4c r8f019c  
    2929  ForceMatrix Shielding;
    3030  ForceMatrix ShieldingPAS;
    31   EnergyMatrix Time;
     31  MatrixContainer Time;
    3232  EnergyMatrix EnergyFragments;
    3333  EnergyMatrix HcorrectionFragments;
     
    5151  bool Hcorrected = true;
    5252  double norm;
    53   int counter;
    5453 
    5554  cout << "ANOVA Analyzer" << endl;
     
    8382 
    8483  // ------------- Parse through all Fragment subdirs --------
    85   if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix,0,0)) return 1;
    86   Hcorrected = Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX,0,0);
    87   if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix,0,0)) return 1;
    88   if (!Time.ParseFragmentMatrix(argv[1], dir, TimeSuffix, 10,1)) return 1;
     84  if (!Energy.ParseMatrix(argv[1], dir, EnergySuffix,0,0)) return 1;
     85  Hcorrected = Hcorrection.ParseMatrix(argv[1], "", HCORRECTIONSUFFIX,0,0);
     86  if (!Force.ParseMatrix(argv[1], dir, ForcesSuffix,0,0)) return 1;
     87  if (!Time.ParseMatrix(argv[1], dir, TimeSuffix, 10,1)) return 1;
    8988  if (periode != NULL) { // also look for PAS values
    90     if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
    91     if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
     89    if (!Shielding.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
     90    if (!ShieldingPAS.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
    9291  }
    9392
     
    112111 
    113112  // ---------- Parse fragment files created by 'joiner' into an array -------------
    114   if (!EnergyFragments.ParseFragmentMatrix(argv[1], dir, EnergyFragmentSuffix,0,0)) return 1;
    115   if (Hcorrected) HcorrectionFragments.ParseFragmentMatrix(argv[1], dir, HcorrectionFragmentSuffix,0,0);
    116   if (!ForceFragments.ParseFragmentMatrix(argv[1], dir, ForceFragmentSuffix,0,0)) return 1;
     113  if (!EnergyFragments.ParseMatrix(argv[1], dir, EnergyFragmentSuffix,0,0)) return 1;
     114  if (Hcorrected) HcorrectionFragments.ParseMatrix(argv[1], dir, HcorrectionFragmentSuffix,0,0);
     115  if (!ForceFragments.ParseMatrix(argv[1], dir, ForceFragmentSuffix,0,0)) return 1;
    117116  if (periode != NULL) { // also look for PAS values
    118     if (!ShieldingFragments.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
    119     if (!ShieldingPASFragments.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
     117    if (!ShieldingFragments.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
     118    if (!ShieldingPASFragments.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
    120119  }
    121120
     
    161160 
    162161  output << endl << "Total Times" << endl << "===============" << endl << Time.Header << endl;
     162  Time.SetLastMatrix(0., 0);
     163  for (int BondOrder=KeySet.Order;BondOrder--;)
     164    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
     165      for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
     166        for(int k=Time.ColumnCounter;k--;) {
     167          Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
     168        }
    163169  for(int j=0;j<Time.RowCounter[Time.MatrixCounter];j++) {
    164     for(int k=0;k<Time.ColumnCounter;k++) {
     170    for(int k=0;k<Time.ColumnCounter;k++)
    165171      output << scientific << Time.Matrix[ Time.MatrixCounter ][j][k] << "\t";
    166     }
    167172    output << endl;
    168173  }
    169174  output << endl;
    170175  output.close();
    171   for(int k=0;k<Time.ColumnCounter;k++)
    172     Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k] = Time.Matrix[ Time.MatrixCounter ][Time.RowCounter[Time.MatrixCounter]-1][k];
    173176
    174177  // +++++++++++++++ ANALYZING ++++++++++++++++++++++++++++++
     
    179182
    180183  // +++++++++++++++++++++++++++++++++++++++ Plotting Simtime vs Bond Order
    181   // +++++++++++++++++++++++++++++++++++++++ Plotting Delta Simtime vs Bond Order
    182184  if (!OpenOutputFile(output, argv[3], "SimTime-Order.dat" )) return false;
    183   if (!OpenOutputFile(output2, argv[3], "DeltaSimTime-Order.dat" )) return false;
    184   for(int j=Time.RowCounter[Time.MatrixCounter];j--;)
    185     for(int k=Time.ColumnCounter;k--;) {
    186       Time.Matrix[ Time.MatrixCounter ][j][k] = 0.;
    187     }
    188   counter = 0;
     185  Time.SetLastMatrix(0., 0);
    189186  output << "#Order\tFrag.No.\t" << Time.Header << endl;
    190   output2 << "#Order\tFrag.No.\t" << Time.Header << endl;
    191187  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    192188    for(int i=KeySet.FragmentsPerOrder[BondOrder];i--;)
     
    195191          Time.Matrix[ Time.MatrixCounter ][j][k] += Time.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k];
    196192        }
    197     counter += KeySet.FragmentsPerOrder[BondOrder];
    198     output << BondOrder+1 << "\t" << counter;
    199     output2 << BondOrder+1 << "\t" << counter;
    200     for(int k=0;k<Time.ColumnCounter;k++) {
    201       output << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k];
    202       if (fabs(Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k]) > MYEPSILON)
    203         output2 << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k] / Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter] ][k];
    204       else
    205         output2 << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][ Time.RowCounter[Time.MatrixCounter]-1 ][k];
    206     }
    207     output << endl;
    208     output2 << endl;
     193    output << BondOrder+1 << "\t" << KeySet.FragmentsPerOrder[BondOrder];
     194    for(int k=0;k<Time.ColumnCounter;k++)
     195      output << "\t" << scientific << Time.Matrix[ Time.MatrixCounter ][1][k];
     196    output << endl;
    209197  }
    210198  output.close();
    211   output2.close();
    212 
    213199
    214200  // +++++++++++++++++++++++++++++++++++++++ Plotting deviation in energy to full QM
  • src/helpers.cpp

    rf3dc4c r8f019c  
    7373  void *buffer = NULL;
    7474  if (OldPointer == NULL)
    75         cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl;
    76   buffer = (void *)realloc(OldPointer, size); // alloc
     75        //cout << Verbose(0) << "ReAlloc impossible - old is NULL: " << output << endl;
     76    buffer = (void *)malloc(size); // malloc
     77  else
     78    buffer = (void *)realloc(OldPointer, size); // realloc
    7779  if (buffer == NULL)
    7880    cout << Verbose(0) << "ReAlloc failed - new is NULL: " << output << endl;
  • src/joiner.cpp

    rf3dc4c r8f019c  
    6060 
    6161  // ------------- Parse through all Fragment subdirs --------
    62   if (!Energy.ParseMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
    63   Hcorrected = Hcorrection.ParseMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0);
    64   if (!Force.ParseMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
     62  if (!Energy.ParseFragmentMatrix(argv[1], dir, EnergySuffix, 0,0)) return 1;
     63  Hcorrected = Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0);
     64  if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
    6565  if (periode != NULL) { // also look for PAS values
    66     if (!Shielding.ParseMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
    67     if (!ShieldingPAS.ParseMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
     66    if (!Shielding.ParseFragmentMatrix(argv[1], dir, ShieldingSuffix, 1, 0)) return 1;
     67    if (!ShieldingPAS.ParseFragmentMatrix(argv[1], dir, ShieldingPASSuffix, 1, 0)) return 1;
    6868  }
    6969
  • src/parser.cpp

    rf3dc4c r8f019c  
    5555 */
    5656MatrixContainer::MatrixContainer() {
    57   Matrix = NULL;
    5857  Indices = NULL;
    59   Header = NULL;
     58  Header = (char *) Malloc(sizeof(char)*1023, "MatrixContainer::MatrixContainer: *Header");
     59  Matrix = (double ***) Malloc(sizeof(double **)*(1), "MatrixContainer::MatrixContainer: ***Matrix"); // one more each for the total molecule
     60  RowCounter = (int *) Malloc(sizeof(int)*(1), "MatrixContainer::MatrixContainer: *RowCounter");
     61  Matrix[0] = NULL;
     62  RowCounter[0] = -1;
    6063  MatrixCounter = 0;
    61   RowCounter = NULL;
    6264  ColumnCounter = 0;
    6365};
     
    8991  Free((void **)&Header, "MatrixContainer::~MatrixContainer: *Header");
    9092  Free((void **)&RowCounter, "MatrixContainer::~MatrixContainer: *RowCounter");
     93};
     94
     95
     96/** Parsing a number of matrices.
     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 * \param *name directory with files
     104 * \param skiplines number of inital lines to skip
     105 * \param skiplines number of inital columns to skip
     106 * \param MatrixNr index number in Matrix array to parse into
     107 * \return parsing successful
     108 */
     109bool MatrixContainer::ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr)
     110{
     111  ifstream input;
     112  stringstream line;
     113  string token;
     114  char filename[1023];
     115
     116  input.open(name, ios::in);
     117  //cout << "Opening " << name << " ... "  << input << endl;
     118  if (input == NULL) {
     119    cerr << endl << "Unable to open " << name << ", is the directory correct?" << endl;
     120    return false;
     121  }
     122 
     123  // skip some initial lines
     124  for (int m=skiplines+1;m--;)
     125    input.getline(Header, 1023);
     126 
     127  // scan header for number of columns
     128  line.str(Header);
     129  for(int k=skipcolumns;k--;)
     130    line >> Header;
     131  //cout << line.str() << endl;
     132  ColumnCounter=0;
     133  while ( getline(line,token, '\t') ) {
     134    if (token.length() > 0)
     135      ColumnCounter++;
     136  }
     137  //cout << line.str() << endl;
     138  //cout << "ColumnCounter: " << ColumnCounter << "." << endl;
     139  if (ColumnCounter == 0)
     140    cerr << "ColumnCounter: " << ColumnCounter << " from file " << name << ", this is probably an error!" << endl;
     141 
     142  // scan rest for number of rows/lines
     143  RowCounter[MatrixNr]=-1;    // counts one line too much
     144  while (!input.eof()) {
     145    input.getline(filename, 1023);
     146    //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
     147    RowCounter[MatrixNr]++; // then line was not last MeanForce
     148    if (strncmp(filename,"MeanForce", 9) == 0) {
     149      break;
     150    }
     151  }
     152  //cout << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
     153  if (RowCounter[MatrixNr] == 0)
     154    cerr << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
     155 
     156  // allocate matrix if it's not zero dimension in one direction
     157  if ((ColumnCounter > 0) && (RowCounter[MatrixNr] > -1)) {
     158    Matrix[MatrixNr] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixNr]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     159 
     160    // parse in each entry for this matrix
     161    input.clear();
     162    input.seekg(ios::beg);
     163    for (int m=skiplines+1;m--;)
     164      input.getline(Header, 1023);    // skip header
     165    line.str(Header);
     166    for(int k=skipcolumns;k--;)  // skip columns in header too
     167      line >> filename;
     168    strncpy(Header, line.str().c_str(), 1023); 
     169    for(int j=0;j<RowCounter[MatrixNr];j++) {
     170      Matrix[MatrixNr][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     171      input.getline(filename, 1023);
     172      stringstream lines(filename);
     173      //cout << "Matrix at level " << j << ":";// << filename << endl;
     174      for(int k=skipcolumns;k--;)
     175        lines >> filename;
     176      for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) {
     177        lines >> Matrix[MatrixNr][j][k];
     178        //cout << " " << setprecision(2) << Matrix[MatrixNr][j][k];;
     179      }
     180      //cout << endl;
     181      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[RowCounter[MatrixNr]][]");
     182      for(int j=ColumnCounter;j--;)
     183        Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
     184    }
     185  } else {
     186    cerr << "ERROR: Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl;
     187  }
     188  input.close();
     189  return true;
    91190};
    92191
     
    109208 * \return parsing successful
    110209 */
    111 bool MatrixContainer::ParseMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
     210bool MatrixContainer::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
    112211{
    113212  char filename[1023];
     
    117216  string token;
    118217 
    119   Header = (char *) Malloc(sizeof(char)*1023, "MatrixContainer::ParseMatrix: *EnergyHeader");
    120 
    121218  // count the number of matrices
    122219  MatrixCounter = -1; // we count one too much
     
    129226  while (!input.eof()) {
    130227    input.getline(filename, 1023);
     228    stringstream zeile(filename);
    131229    MatrixCounter++;
    132230  }
    133   input.close();
     231  input.close(); 
    134232  cout << "Determined " << MatrixCounter << " fragments." << endl;
    135233 
    136234  cout << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl;
    137   Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: ***Matrix"); // one more each for the total molecule
    138   RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: *RowCounter");
     235  Matrix = (double ***) ReAlloc(Matrix, sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
     236  RowCounter = (int *) ReAlloc(RowCounter, sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
    139237  for(int i=MatrixCounter+1;i--;) {
    140238    Matrix[i] = NULL;
    141239    RowCounter[i] = -1;
    142240  }
    143   for(int i=MatrixCounter+1;i--;) {
     241  for(int i=0; i < MatrixCounter;i++) {
    144242    // open matrix file
    145     stringstream line;
    146243    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    147244    file.str(" ");
    148     if (i != MatrixCounter) 
    149       file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix;
    150     else
    151       file << name << prefix << suffix;
    152     Free((void **)&FragmentNumber, "MatrixContainer::ParseMatrix: *FragmentNumber");
    153     input.open(file.str().c_str(), ios::in);
    154     //cout << "Opening " << file.str() << " ... "  << input << endl;
    155     if (input == NULL) {
    156       cerr << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     245    file << name << FRAGMENTPREFIX << FragmentNumber << prefix << suffix;
     246    if (!ParseMatrix(file.str().c_str(), skiplines, skipcolumns, i))
    157247      return false;
    158     }
    159    
    160     // skip some initial lines
    161     for (int m=skiplines+1;m--;)
    162       input.getline(Header, 1023);
    163    
    164     // scan header for number of columns
    165     line.str(Header);
    166     for(int k=skipcolumns;k--;)
    167       line >> Header;
    168     //cout << line.str() << endl;
    169     ColumnCounter=0;
    170     while ( getline(line,token, '\t') ) {
    171       if (token.length() > 0)
    172         ColumnCounter++;
    173     }
    174     //cout << line.str() << endl;
    175     //cout << "ColumnCounter: " << ColumnCounter << endl;
    176    
    177     // scan rest for number of rows/lines
    178     RowCounter[i]=-1;    // counts one line too much
    179     while (!input.eof()) {
    180       input.getline(filename, 1023);
    181       //cout << "Comparing: " << strncmp(filename,"MeanForce",9) << endl;
    182       RowCounter[i]++; // then line was not last MeanForce
    183       if (strncmp(filename,"MeanForce", 9) == 0) {
    184         break;
    185       }
    186     }
    187     //cout << "RowCounter[" << i << "]: " << RowCounter[i] << " from file " << file.str() << "." << endl;
    188    
    189     // allocate matrix if it's not zero dimension in one direction
    190     if ((ColumnCounter > 0) && (RowCounter[i] > -1)) {
    191       Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]");
    192    
    193       // parse in each entry for this matrix
    194       input.clear();
    195       input.seekg(ios::beg);
    196       for (int m=skiplines+1;m--;)
    197         input.getline(Header, 1023);    // skip header
    198       line.str(Header);
    199       for(int k=skipcolumns;k--;)  // skip columns in header too
    200         line >> filename;
    201       strncpy(Header, line.str().c_str(), 1023); 
    202       for(int j=0;j<RowCounter[i];j++) {
    203         Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]");
    204         input.getline(filename, 1023);
    205         stringstream lines(filename);
    206         //cout << "Matrix at level " << j << ":";// << filename << endl;
    207         for(int k=skipcolumns;k--;)
    208           lines >> filename;
    209         for(int k=0;(k<ColumnCounter) && (!lines.eof());k++) {
    210           lines >> Matrix[i][j][k];
    211           //cout << " " << setprecision(2) << Matrix[i][j][k];;
    212         }
    213         //cout << endl;
    214         Matrix[i][ RowCounter[i] ] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[RowCounter[i]][]");
    215         for(int j=ColumnCounter;j--;)
    216           Matrix[i][ RowCounter[i] ][j] = 0.;
    217       }
    218     } else {
    219       cerr << "ERROR: Matrix nr. " << i << " has column and row count of (" << ColumnCounter << "," << RowCounter[i] << "), could not allocate nor parse!" << endl;
    220     }
    221     input.close();
     248    Free((void **)&FragmentNumber, "MatrixContainer::ParseFragmentMatrix: *FragmentNumber");
    222249  }
    223250  return true;
     
    233260bool MatrixContainer::AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int CCounter)
    234261{
    235   Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseMatrix: *EnergyHeader");
     262  Header = (char *) Malloc(sizeof(char)*1024, "MatrixContainer::ParseFragmentMatrix: *EnergyHeader");
    236263  strncpy(Header, GivenHeader, 1023);
    237264
    238265  MatrixCounter = MCounter;
    239266  ColumnCounter = CCounter;
    240   Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: ***Matrix"); // one more each for the total molecule
    241   RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseMatrix: *RowCounter");
     267  Matrix = (double ***) Malloc(sizeof(double **)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
     268  RowCounter = (int *) Malloc(sizeof(int)*(MatrixCounter+1), "MatrixContainer::ParseFragmentMatrix: *RowCounter");
    242269  for(int i=MatrixCounter+1;i--;) {
    243270    RowCounter[i] = RCounter[i];
    244     Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseMatrix: **Matrix[]"); 
     271    Matrix[i] = (double **) Malloc(sizeof(double *)*(RowCounter[i]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]"); 
    245272    for(int j=RowCounter[i]+1;j--;) {
    246       Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseMatrix: *Matrix[][]");
     273      Matrix[i][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
    247274      for(int k=ColumnCounter;k--;)
    248275        Matrix[i][j][k] = 0.;
     
    481508};
    482509
     510/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
     511 * \param *name directory with files
     512 * \param *prefix prefix of each matrix file
     513 * \param *suffix suffix of each matrix file
     514 * \param skiplines number of inital lines to skip
     515 * \param skiplines number of inital columns to skip
     516 * \return parsing successful
     517 */
     518bool EnergyMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
     519{
     520  char filename[1024];
     521  bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
     522
     523  if (status) {
     524    // count maximum of columns
     525    RowCounter[MatrixCounter] = 0;
     526    for(int j=0; j < MatrixCounter;j++) // (energy matrix might be bigger than number of atoms in terms of rows)
     527      if (RowCounter[j] > RowCounter[MatrixCounter])
     528        RowCounter[MatrixCounter] = RowCounter[j];
     529    // allocate last plus one matrix
     530    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter << " columns." << endl;
     531    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     532    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     533      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     534   
     535    // try independently to parse global energysuffix file if present
     536    strncpy(filename, name, 1023);
     537    strncat(filename, prefix, 1023-strlen(filename));
     538    strncat(filename, suffix.c_str(), 1023-strlen(filename));
     539    ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
     540  }
     541  return status;
     542};
     543
    483544// ======================================= CLASS ForceMatrix =============================
    484545
     
    556617};
    557618
     619
     620/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
     621 * \param *name directory with files
     622 * \param *prefix prefix of each matrix file
     623 * \param *suffix suffix of each matrix file
     624 * \param skiplines number of inital lines to skip
     625 * \param skiplines number of inital columns to skip
     626 * \return parsing successful
     627 */
     628bool ForceMatrix::ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns)
     629{
     630  char filename[1023];
     631  ifstream input;
     632  stringstream file;
     633  int nr;
     634  bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
     635
     636  if (status) {
     637    // count number of atoms for last plus one matrix
     638    file << name << FRAGMENTPREFIX << KEYSETFILE;
     639    input.open(file.str().c_str(), ios::in);
     640    if (input == NULL) {
     641      cout << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     642      return false;
     643    }
     644    RowCounter[MatrixCounter] = 0;
     645    while (!input.eof()) {
     646      input.getline(filename, 1023);
     647      stringstream zeile(filename);
     648      while (!zeile.eof()) {
     649        zeile >> nr;
     650        //cout << "Current index: " << nr << "." << endl;
     651        if (nr > RowCounter[MatrixCounter])
     652          RowCounter[MatrixCounter] = nr;
     653      }
     654    }
     655    RowCounter[MatrixCounter]++;    // nr start at 0, count starts at 1
     656    input.close();
     657 
     658    // allocate last plus one matrix
     659    cout << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter << " columns." << endl;
     660    Matrix[MatrixCounter] = (double **) Malloc(sizeof(double *)*(RowCounter[MatrixCounter]+1), "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
     661    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     662      Matrix[MatrixCounter][j] = (double *) Malloc(sizeof(double)*ColumnCounter, "MatrixContainer::ParseFragmentMatrix: *Matrix[][]");
     663
     664    // try independently to parse global forcesuffix file if present
     665    strncpy(filename, name, 1023);
     666    strncat(filename, prefix, 1023-strlen(filename));
     667    strncat(filename, suffix.c_str(), 1023-strlen(filename));
     668    ParseMatrix(filename, skiplines, skipcolumns, MatrixCounter);
     669  }
     670 
     671
     672  return status;
     673};
    558674
    559675// ======================================= CLASS KeySetsContainer =============================
  • src/parser.hpp

    rf3dc4c r8f019c  
    5151  ~MatrixContainer();
    5252 
    53   bool ParseMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns);
     53  bool ParseMatrix(const char *name, int skiplines, int skipcolumns, int MatrixNr);
     54  virtual bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns);
    5455  bool AllocateMatrix(char *GivenHeader, int MCounter, int *RCounter, int CCounter);
    5556  bool ResetMatrix();
     
    7172    bool ParseIndices();
    7273    bool SumSubEnergy(class EnergyMatrix &Fragments, class EnergyMatrix *CorrectionFragments, class KeySetsContainer &KeySet, int Order, double sign);
     74    bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns);
    7375};
    7476
     
    7981    bool ParseIndices(char *name);
    8082    bool SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySet, int Order, double sign);
     83    bool ParseFragmentMatrix(char *name, char *prefix, string suffix, int skiplines, int skipcolumns);
    8184};
    8285
Note: See TracChangeset for help on using the changeset viewer.