Changeset 9758f7


Ignore:
Timestamp:
Oct 18, 2011, 8:07:37 AM (13 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:
1b145f
Parents:
a9b86d
git-author:
Frederik Heber <heber@…> (09/16/11 16:24:18)
git-committer:
Frederik Heber <heber@…> (10/18/11 08:07:37)
Message:

Removed C arrays in KeySetsContainer and MatrixContainer.

  • replaced by std::vector<>s.
  • transition is so far very minimal, external (range) counters are still present.
  • extracted allocation of memory into own block in MatrixContainer::parseMatrix().
Location:
src/Fragmentation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/EnergyMatrix.cpp

    ra9b86d r9758f7  
    3535{
    3636  DoLog(0) && (Log() << Verbose(0) << "Parsing energy indices." << endl);
    37   Indices = new int*[MatrixCounter + 1];
     37  Indices.resize(MatrixCounter + 1);
    3838  for(int i=MatrixCounter+1;i--;) {
    39     Indices[i] = new int[RowCounter[i]];
     39    Indices[i].resize(RowCounter[i]);
    4040    for(int j=RowCounter[i];j--;)
    4141      Indices[i][j] = j;
     
    9393    }
    9494    // allocate last plus one matrix
    95     DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    96     Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
     95    if (Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
     96      Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
    9797    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    98       Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
     98      if (Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
     99        Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
    99100
    100101    // try independently to parse global energysuffix file if present
  • src/Fragmentation/ForceMatrix.cpp

    ra9b86d r9758f7  
    4444
    4545  DoLog(0) && (Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl);
    46   Indices = new int*[MatrixCounter + 1];
     46  Indices.resize(MatrixCounter + 1);
    4747  line << name << FRAGMENTPREFIX << FORCESFILE;
    4848  input.open(line.str().c_str(), ios::in);
     
    5757    line.str(filename);
    5858    // parse the values
    59     Indices[i] = new int[RowCounter[i]];
     59    Indices[i].resize(RowCounter[i]);
    6060    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    6161    //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
     
    6767    //Log() << Verbose(0) << endl;
    6868  }
    69   Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];
     69  Indices[MatrixCounter].resize(RowCounter[MatrixCounter]);
    7070  for(int j=RowCounter[MatrixCounter];j--;) {
    7171    Indices[MatrixCounter][j] = j;
     
    152152
    153153    // allocate last plus one matrix
    154     DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    155     Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
     154    if (Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
     155      Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
    156156    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    157       Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
     157      if (Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
     158        Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
    158159
    159160    // try independently to parse global forcesuffix file if present
  • src/Fragmentation/HessianMatrix.cpp

    ra9b86d r9758f7  
    4444
    4545  DoLog(0) && (Log() << Verbose(0) << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl);
    46   Indices = new int*[MatrixCounter + 1];
     46  Indices.resize(MatrixCounter + 1);
    4747  line << name << FRAGMENTPREFIX << FORCESFILE;
    4848  input.open(line.str().c_str(), ios::in);
     
    5757    line.str(filename);
    5858    // parse the values
    59     Indices[i] = new int[RowCounter[i]];
     59    Indices[i].resize(RowCounter[i]);
    6060    FragmentNumber = FixedDigitNumber(MatrixCounter, i);
    6161    //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
     
    6767    //Log() << Verbose(0) << endl;
    6868  }
    69   Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];
     69  Indices[MatrixCounter].resize(RowCounter[MatrixCounter]);
    7070  for(int j=RowCounter[MatrixCounter];j--;) {
    7171    Indices[MatrixCounter][j] = j;
     
    243243    // allocate last plus one matrix
    244244    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    245     Matrix[MatrixCounter] = new double*[RowCounter[MatrixCounter] + 1];
     245    if (Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
     246      Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
    246247    for(int j=0;j<=RowCounter[MatrixCounter];j++)
    247       Matrix[MatrixCounter][j] = new double[ColumnCounter[MatrixCounter]];
     248      if (Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
     249        Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
    248250
    249251    // try independently to parse global forcesuffix file if present
  • src/Fragmentation/KeySetsContainer.cpp

    ra9b86d r9758f7  
    2121
    2222#include <fstream>
     23#include <sstream>
    2324
    2425#include "CodePatterns/Log.hpp"
     
    3233 */
    3334KeySetsContainer::KeySetsContainer() :
    34   KeySets(NULL),
    35   AtomCounter(NULL),
    3635  FragmentCounter(0),
    3736  Order(0),
    38   FragmentsPerOrder(0),
    39   OrderSet(NULL)
     37  FragmentsPerOrder(0)
    4038{};
    4139
     
    4341 */
    4442KeySetsContainer::~KeySetsContainer() {
    45   for(int i=FragmentCounter;i--;)
    46     delete[](KeySets[i]);
    47   for(int i=Order;i--;)
    48     delete[](OrderSet[i]);
    49   delete[](KeySets);
    50   delete[](OrderSet);
    51   delete[](AtomCounter);
    52   delete[](FragmentsPerOrder);
     43//  for(int i=FragmentCounter;i--;)
     44//    delete[](KeySets[i]);
     45//  for(int i=Order;i--;)
     46//    delete[](OrderSet[i]);
     47//  delete[](KeySets);
     48//  delete[](OrderSet);
     49//  delete[](AtomCounter);
     50//  delete[](FragmentsPerOrder);
    5351};
    5452
     
    5957 * \return parsing succesful
    6058 */
    61 bool KeySetsContainer::ParseKeySets(const char *name, const int *ACounter, const int FCounter) {
     59bool KeySetsContainer::ParseKeySets(const std::string name, const IntVector ACounter, const int FCounter) {
    6260  ifstream input;
    6361  char *FragmentNumber = NULL;
     
    6765  FragmentCounter = FCounter;
    6866  DoLog(0) && (Log() << Verbose(0) << "Parsing key sets." << endl);
    69   KeySets = new int*[FragmentCounter];
    70   for(int i=FragmentCounter;i--;)
    71     KeySets[i] = NULL;
     67  KeySets.resize(FragmentCounter);
    7268  file << name << FRAGMENTPREFIX << KEYSETFILE;
    7369  input.open(file.str().c_str(), ios::in);
     
    7773  }
    7874
    79   AtomCounter = new int[FragmentCounter];
     75  AtomCounter.resize(FragmentCounter);
    8076  for(int i=0;(i<FragmentCounter) && (!input.eof());i++) {
    8177    stringstream line;
    8278    AtomCounter[i] = ACounter[i];
    8379    // parse the values
    84     KeySets[i] = new int[AtomCounter[i]];
     80    KeySets[i].resize(AtomCounter[i]);
    8581    for(int j=AtomCounter[i];j--;)
    8682      KeySets[i][j] = -1;
     
    121117
    122118  // scan through all to determine fragments per order
    123   FragmentsPerOrder = new int[Order];
    124   for(int i=Order;i--;)
    125     FragmentsPerOrder[i] = 0;
     119  FragmentsPerOrder.resize(Order);
     120//  for(int i=Order;i--;)
     121//    FragmentsPerOrder[i] = 0;
    126122  for(int i=FragmentCounter;i--;) {
    127123    Counter=0;
     
    135131
    136132  // scan through all to gather indices to each order set
    137   OrderSet = new int*[Order];
     133  OrderSet.resize(Order);
    138134  for(int i=Order;i--;)
    139     OrderSet[i] = new int[FragmentsPerOrder[i]];
     135    OrderSet[i].resize(FragmentsPerOrder[i]);
    140136  for(int i=Order;i--;)
    141137    FragmentsPerOrder[i] = 0;
  • src/Fragmentation/KeySetsContainer.hpp

    ra9b86d r9758f7  
    2020class KeySetsContainer {
    2121  public:
    22     int **KeySets;
    23     int *AtomCounter;
     22    typedef std::vector<int> IntVector;
     23    typedef std::vector<IntVector> ArrayOfIntVectors;
     24    ArrayOfIntVectors KeySets;
     25    IntVector AtomCounter;
    2426    int FragmentCounter;
    2527    int Order;
    26     int *FragmentsPerOrder;
    27     int **OrderSet;
     28    IntVector FragmentsPerOrder;
     29    ArrayOfIntVectors OrderSet;
    2830
    2931  KeySetsContainer();
    3032  ~KeySetsContainer();
    3133
    32   bool ParseKeySets(const char *name, const int *ACounter, const int FCounter);
     34  bool ParseKeySets(const std::string name, const std::vector<int> ACounter, const int FCounter);
    3335  bool ParseManyBodyTerms();
    3436  bool Contains(const int GreaterSet, const int SmallerSet);
  • src/Fragmentation/MatrixContainer.cpp

    ra9b86d r9758f7  
    3535/** Constructor of MatrixContainer class.
    3636 */
    37 MatrixContainer::MatrixContainer() :
    38   Indices(NULL)
    39 {
    40   Header = new char*[1];
    41   Matrix = new double**[1]; // one more each for the total molecule
    42   RowCounter = new int[1];
    43   ColumnCounter = new int[1];
    44   Header[0] = NULL;
    45   Matrix[0] = NULL;
    46   RowCounter[0] = -1;
     37MatrixContainer::MatrixContainer()
     38{
     39  Header.resize(1);
     40  RowCounter.resize(1);
     41  ColumnCounter.resize(1);
     42  ColumnCounter[0] = -1;
    4743  MatrixCounter = 0;
    48   ColumnCounter[0] = -1;
    4944};
    5045
    5146/** Destructor of MatrixContainer class.
    5247 */
    53 MatrixContainer::~MatrixContainer() {
    54   if (Matrix != NULL) {
    55     // free Matrix[MatrixCounter]
    56     if ((ColumnCounter != NULL) && (RowCounter != NULL) && (Matrix[MatrixCounter] != NULL))
    57       for(int j=RowCounter[MatrixCounter]+1;j--;)
    58         delete[](Matrix[MatrixCounter][j]);
    59     //if (MatrixCounter != 0)
    60     delete[](Matrix[MatrixCounter]);
    61     // free all matrices but ultimate one
    62     for(int i=MatrixCounter;i--;) {
    63       if ((ColumnCounter != NULL) && (RowCounter != NULL)) {
    64           for(int j=RowCounter[i]+1;j--;)
    65             delete[](Matrix[i][j]);
    66           delete[](Matrix[i]);
    67       }
    68     }
    69     delete[](Matrix);
    70   }
    71   // free indices
    72   if (Indices != NULL)
    73     for(int i=MatrixCounter+1;i--;) {
    74       delete[](Indices[i]);
    75     }
    76   delete[](Indices);
    77 
    78   // free header and counters
    79   if (Header != NULL)
    80     for(int i=MatrixCounter+1;i--;)
    81       delete[](Header[i]);
    82   delete[](Header);
    83   delete[](RowCounter);
    84   delete[](ColumnCounter);
    85 };
     48MatrixContainer::~MatrixContainer()
     49{}
    8650
    8751/** Either copies index matrix from another MatrixContainer or initialises with trivial mapping if NULL.
     
    9054 * \return true - copy/initialisation sucessful, false - dimension false for copying
    9155 */
    92 bool MatrixContainer::InitialiseIndices(class MatrixContainer *Matrix)
     56bool MatrixContainer::InitialiseIndices(class MatrixContainer *_container)
    9357{
    9458  DoLog(0) && (Log() << Verbose(0) << "Initialising indices");
    95   if (Matrix == NULL) {
     59  if (_container == NULL) {
    9660    DoLog(0) && (Log() << Verbose(0) << " with trivial mapping." << endl);
    97     Indices = new int*[MatrixCounter + 1];
     61    Indices.resize(MatrixCounter + 1);
    9862    for(int i=MatrixCounter+1;i--;) {
    99       Indices[i] = new int[RowCounter[i]];
     63      Indices[i].resize(RowCounter[i]);
    10064      for(int j=RowCounter[i];j--;)
    10165        Indices[i][j] = j;
     
    10367  } else {
    10468    DoLog(0) && (Log() << Verbose(0) << " from other MatrixContainer." << endl);
    105     if (MatrixCounter != Matrix->MatrixCounter)
     69    if (MatrixCounter != _container->MatrixCounter)
    10670      return false;
    107     Indices = new int*[MatrixCounter + 1];
     71    Indices.resize(MatrixCounter + 1);
    10872    for(int i=MatrixCounter+1;i--;) {
    109       if (RowCounter[i] != Matrix->RowCounter[i])
     73      if (RowCounter[i] != _container->RowCounter[i])
    11074        return false;
    111       Indices[i] = new int[Matrix->RowCounter[i]];
    112       for(int j=Matrix->RowCounter[i];j--;) {
    113         Indices[i][j] = Matrix->Indices[i][j];
     75      Indices[i].resize(_container->RowCounter[i]);
     76      for(int j=_container->RowCounter[i];j--;) {
     77        Indices[i][j] = _container->Indices[i][j];
    11478        //Log() << Verbose(0) << Indices[i][j] << "\t";
    11579      }
     
    13397 * \return parsing successful
    13498 */
    135 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr)
     99bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, size_t MatrixNr)
    136100{
    137101  stringstream line;
     
    146110
    147111  // parse header
    148   if (Header[MatrixNr] != NULL)
    149     delete[] Header[MatrixNr];
    150   Header[MatrixNr] = new char[1024];
     112  if (Header.size() <= MatrixNr)
     113    Header.resize(MatrixNr);
     114  Header[MatrixNr] = std::string("");
     115  char dummy[1024];
    151116  for (int m=skiplines+1;m--;)
    152     input.getline(Header[MatrixNr], 1023);
    153 
    154   // scan header for number of columns
    155   line.str(Header[MatrixNr]);
     117    input.getline(dummy, 1023);
     118  line.str(dummy);
    156119  for(int k=skipcolumns;k--;)
    157120    line >> Header[MatrixNr];
    158121  Log() << Verbose(0) << line.str() << endl;
     122
     123  // scan header for number of columns
     124  if (ColumnCounter.size() <= MatrixNr)
     125    ColumnCounter.resize(MatrixNr);
    159126  ColumnCounter[MatrixNr]=0;
    160127  while ( getline(line,token, '\t') ) {
     
    170137
    171138  // scan rest for number of rows/lines
     139  if (RowCounter.size() <= MatrixNr)
     140    RowCounter.resize(MatrixNr);
    172141  RowCounter[MatrixNr]=-1;    // counts one line too much
    173142  while (!input.eof()) {
     
    186155
    187156  // allocate matrix if it's not zero dimension in one direction
    188   if ((ColumnCounter[MatrixNr] > 0) && (RowCounter[MatrixNr] > -1)) {
    189     if (Matrix[MatrixNr] != NULL)
    190       delete[] Matrix[MatrixNr];
    191     Matrix[MatrixNr] = new double*[RowCounter[MatrixNr] + 1];
    192     for(int j=0;j<RowCounter[MatrixNr]+1;j++)
    193       Matrix[MatrixNr][j] = 0;
    194 
    195     // parse in each entry for this matrix
    196     input.clear();
    197     input.seekg(ios::beg);
    198     for (int m=skiplines+1;m--;)
    199       input.getline(Header[MatrixNr], 1023);    // skip header
    200     line.str(Header[MatrixNr]);
    201     Log() << Verbose(0) << "Header: " << line.str() << endl;
    202     for(int k=skipcolumns;k--;)  // skip columns in header too
    203       line >> filename;
    204     strncpy(Header[MatrixNr], line.str().c_str(), 1023);
    205     for(int j=0;j<RowCounter[MatrixNr];j++) {
    206       if (Matrix[MatrixNr][j] != NULL)
    207         delete[] Matrix[MatrixNr][j];
    208       Matrix[MatrixNr][j] = new double[ColumnCounter[MatrixNr]];
    209       for(int k=0;k<ColumnCounter[MatrixNr];k++)
     157  if (Matrix.size() <= MatrixNr)
     158    Matrix.resize(MatrixNr+1);
     159  if ((Matrix[MatrixNr].size() <= (size_t)RowCounter[MatrixNr] + 1) && (RowCounter[MatrixNr] > -1)) {
     160    Matrix[MatrixNr].resize(RowCounter[MatrixNr] + 2);
     161    for(int j=0;j<=RowCounter[MatrixNr];j++) {
     162      if ((Matrix[MatrixNr][j].size() <= (size_t)ColumnCounter[MatrixNr]) && (ColumnCounter[MatrixNr] > -1))
     163        Matrix[MatrixNr][j].resize(ColumnCounter[MatrixNr]+1);
     164      // clear
     165      for(int k=0;k<=ColumnCounter[MatrixNr];k++)
    210166        Matrix[MatrixNr][j][k] = 0;
    211 
    212       input.getline(filename, 1023);
    213       stringstream lines(filename);
    214       Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
    215       for(int k=skipcolumns;k--;)
    216         lines >> filename;
    217       for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
    218         lines >> Matrix[MatrixNr][j][k];
    219         Log() << Verbose(1) << " " << std::setprecision(2) << Matrix[MatrixNr][j][k] << endl;
    220       }
    221       if (Matrix[MatrixNr][ RowCounter[MatrixNr] ] != NULL)
    222         delete[] Matrix[MatrixNr][ RowCounter[MatrixNr] ];
    223       Matrix[MatrixNr][ RowCounter[MatrixNr] ] = new double[ColumnCounter[MatrixNr]];
    224       for(int j=ColumnCounter[MatrixNr];j--;)
    225         Matrix[MatrixNr][ RowCounter[MatrixNr] ][j] = 0.;
    226167    }
    227168  } else {
    228     DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl);
    229   }
     169    ELOG(1, "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!");
     170    return false;
     171  }
     172
     173  // parse in each entry for this matrix
     174  input.clear();
     175  input.seekg(ios::beg);
     176  for (int m=skiplines+1;m--;)
     177    input.getline(dummy, 1023);    // skip header
     178  line.str(dummy);
     179  Log() << Verbose(0) << "Header: " << line.str() << endl;
     180  for(int k=skipcolumns;k--;)  // skip columns in header too
     181    line >> filename;
     182  Header[MatrixNr] = line.str();
     183  for(int j=0;j<RowCounter[MatrixNr];j++) {
     184    input.getline(filename, 1023);
     185    stringstream lines(filename);
     186    Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
     187    for(int k=skipcolumns;k--;)
     188      lines >> filename;
     189    for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
     190      lines >> Matrix[MatrixNr][j][k];
     191      Log() << Verbose(1) << " " << std::setprecision(2) << Matrix[MatrixNr][j][k] << endl;
     192    }
     193  }
     194
    230195  return true;
    231196};
     
    249214 * \return parsing successful
    250215 */
    251 bool MatrixContainer::ParseFragmentMatrix(const char *name, const char *prefix, string suffix, int skiplines, int skipcolumns)
     216bool MatrixContainer::ParseFragmentMatrix(const std::string name, const std::string prefix, std::string suffix, int skiplines, int skipcolumns)
    252217{
    253218  char filename[1023];
     
    274239
    275240  DoLog(0) && (Log() << Verbose(0) << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl);
    276   delete[](Header);
    277   delete[](Matrix);
    278   delete[](RowCounter);
    279   delete[](ColumnCounter);
    280   Header = new char*[MatrixCounter + 1]; // one more each for the total molecule
    281   Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule
    282   RowCounter = new int[MatrixCounter + 1];
    283   ColumnCounter = new int[MatrixCounter + 1];
    284   for(int i=MatrixCounter+1;i--;) {
    285     Matrix[i] = NULL;
    286     Header[i] = NULL;
    287     RowCounter[i] = -1;
    288     ColumnCounter[i] = -1;
    289   }
     241  Header.clear();
     242  Matrix.clear();
     243  RowCounter.clear();
     244  ColumnCounter.clear();
     245  Header.resize(MatrixCounter + 1); // one more each for the total molecule
     246  Matrix.resize(MatrixCounter + 1); // one more each for the total molecule
     247  RowCounter.resize(MatrixCounter + 1);
     248  ColumnCounter.resize(MatrixCounter + 1);
    290249  for(int i=0; i < MatrixCounter;i++) {
    291250    // open matrix file
     
    312271 * \return Allocation successful
    313272 */
    314 bool MatrixContainer::AllocateMatrix(char **GivenHeader, int MCounter, int *RCounter, int *CCounter)
     273bool MatrixContainer::AllocateMatrix(StringVector GivenHeader, int MCounter, IntVector RCounter, IntVector CCounter)
    315274{
    316275  MatrixCounter = MCounter;
    317   Header = new char*[MatrixCounter + 1];
    318   Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule
    319   RowCounter = new int[MatrixCounter + 1];
    320   ColumnCounter = new int[MatrixCounter + 1];
     276  Header.resize(MatrixCounter + 1);
     277  Matrix.resize(MatrixCounter + 1); // one more each for the total molecule
     278  RowCounter.resize(MatrixCounter + 1);
     279  ColumnCounter.resize(MatrixCounter + 1);
    321280  for(int i=MatrixCounter+1;i--;) {
    322     Header[i] = new char[1024];
    323     strncpy(Header[i], GivenHeader[i], 1023);
     281    Header[i] = GivenHeader[i];
    324282    RowCounter[i] = RCounter[i];
    325283    ColumnCounter[i] = CCounter[i];
    326     Matrix[i] = new double*[RowCounter[i] + 1];
    327     for(int j=RowCounter[i]+1;j--;) {
    328       Matrix[i][j] = new double[ColumnCounter[i]];
    329       for(int k=ColumnCounter[i];k--;)
    330         Matrix[i][j][k] = 0.;
    331     }
     284    if (Matrix[i].size() <= RowCounter[i] + 2)
     285      Matrix[i].resize(RowCounter[i] + 1);
     286    for(int j=0;j<=RowCounter[i];j++)
     287      if (Matrix[i][j].size() <= ColumnCounter[i]+1)
     288        Matrix[i][j].resize(ColumnCounter[i]);
     289    // allocation with 0 is guaranted by STL
    332290  }
    333291  return true;
     
    396354 * \return true if successful
    397355 */
    398 bool MatrixContainer::SetLastMatrix(double **values, int skipcolumns)
     356bool MatrixContainer::SetLastMatrix(const MatrixArray &values, int skipcolumns)
    399357{
    400358  for(int j=RowCounter[MatrixCounter]+1;j--;)
     
    466424 * \return file was written
    467425 */
    468 bool MatrixContainer::WriteTotalFragments(const char *name, const char *prefix)
     426bool MatrixContainer::WriteTotalFragments(const std::string name, const std::string prefix)
    469427{
    470428  ofstream output;
     
    500458 * \return file was written
    501459 */
    502 bool MatrixContainer::WriteLastMatrix(const char *name, const char *prefix, const char *suffix)
     460bool MatrixContainer::WriteLastMatrix(const std::string name, const std::string prefix, const std::string suffix)
    503461{
    504462  ofstream output;
  • src/Fragmentation/MatrixContainer.hpp

    ra9b86d r9758f7  
    1414#endif
    1515
    16 #include "boost/serialization/array.hpp"
    17 
    18 #include "boost/multi_array.hpp"
     16#include <vector>
    1917
    2018/** Contains a sequence of matrices parsed from file.
     
    2321class MatrixContainer {
    2422  public:
    25     double ***Matrix;
    26     int **Indices;
    27     char **Header;
     23    typedef std::vector<std::vector<double> > MatrixArray;
     24    typedef std::vector<MatrixArray> ArrayOfMatrices;
     25    typedef std::vector<std::string> StringVector;
     26    typedef std::vector<int> IntVector;
     27    typedef std::vector<IntVector> VectorOfIntVectors;
     28
     29    ArrayOfMatrices Matrix;
     30    VectorOfIntVectors Indices;
     31    StringVector Header;
    2832    int MatrixCounter;
    29     int *RowCounter;
    30     int *ColumnCounter;
     33    IntVector RowCounter;
     34    IntVector ColumnCounter;
    3135
    3236  MatrixContainer();
     
    3438
    3539  bool InitialiseIndices(class MatrixContainer *Matrix = NULL);
    36   bool ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr);
    37   virtual bool ParseFragmentMatrix(const char *name, const char *prefix, std::string suffix, int skiplines, int skipcolumns);
    38   bool AllocateMatrix(char **GivenHeader, int MCounter, int *RCounter, int *CCounter);
     40  bool ParseMatrix(std::istream &input, int skiplines, int skipcolumns, size_t MatrixNr);
     41  virtual bool ParseFragmentMatrix(const std::string name, const std::string prefix, std::string suffix, int skiplines, int skipcolumns);
     42  bool AllocateMatrix(StringVector GivenHeader, int MCounter, IntVector RCounter, IntVector CCounter);
    3943  bool ResetMatrix();
    4044  double FindMinValue();
    4145  double FindMaxValue();
    4246  bool SetLastMatrix(double value, int skipcolumns);
    43   bool SetLastMatrix(double **values, int skipcolumns);
     47  bool SetLastMatrix(const MatrixArray &values, int skipcolumns);
    4448  //bool ParseIndices();
    4549  //bool SumSubValues();
    4650  bool SumSubManyBodyTerms(class MatrixContainer &Matrix, class KeySetsContainer &KeySets, int Order);
    47   bool WriteTotalFragments(const char *name, const char *prefix);
    48   bool WriteLastMatrix(const char *name, const char *prefix, const char *suffix);
     51  bool WriteTotalFragments(const std::string name, const std::string prefix);
     52  bool WriteLastMatrix(const std::string name, const std::string prefix, const std::string suffix);
    4953};
    5054
Note: See TracChangeset for help on using the changeset viewer.