Changeset 9758f7
- Timestamp:
- Oct 18, 2011, 8:07:37 AM (13 years ago)
- 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)
- Location:
- src/Fragmentation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/EnergyMatrix.cpp
ra9b86d r9758f7 35 35 { 36 36 DoLog(0) && (Log() << Verbose(0) << "Parsing energy indices." << endl); 37 Indices = new int*[MatrixCounter + 1];37 Indices.resize(MatrixCounter + 1); 38 38 for(int i=MatrixCounter+1;i--;) { 39 Indices[i] = new int[RowCounter[i]];39 Indices[i].resize(RowCounter[i]); 40 40 for(int j=RowCounter[i];j--;) 41 41 Indices[i][j] = j; … … 93 93 } 94 94 // 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); 97 97 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]); 99 100 100 101 // try independently to parse global energysuffix file if present -
src/Fragmentation/ForceMatrix.cpp
ra9b86d r9758f7 44 44 45 45 DoLog(0) && (Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl); 46 Indices = new int*[MatrixCounter + 1];46 Indices.resize(MatrixCounter + 1); 47 47 line << name << FRAGMENTPREFIX << FORCESFILE; 48 48 input.open(line.str().c_str(), ios::in); … … 57 57 line.str(filename); 58 58 // parse the values 59 Indices[i] = new int[RowCounter[i]];59 Indices[i].resize(RowCounter[i]); 60 60 FragmentNumber = FixedDigitNumber(MatrixCounter, i); 61 61 //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:"; … … 67 67 //Log() << Verbose(0) << endl; 68 68 } 69 Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];69 Indices[MatrixCounter].resize(RowCounter[MatrixCounter]); 70 70 for(int j=RowCounter[MatrixCounter];j--;) { 71 71 Indices[MatrixCounter][j] = j; … … 152 152 153 153 // 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); 156 156 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]); 158 159 159 160 // try independently to parse global forcesuffix file if present -
src/Fragmentation/HessianMatrix.cpp
ra9b86d r9758f7 44 44 45 45 DoLog(0) && (Log() << Verbose(0) << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl); 46 Indices = new int*[MatrixCounter + 1];46 Indices.resize(MatrixCounter + 1); 47 47 line << name << FRAGMENTPREFIX << FORCESFILE; 48 48 input.open(line.str().c_str(), ios::in); … … 57 57 line.str(filename); 58 58 // parse the values 59 Indices[i] = new int[RowCounter[i]];59 Indices[i].resize(RowCounter[i]); 60 60 FragmentNumber = FixedDigitNumber(MatrixCounter, i); 61 61 //Log() << Verbose(0) << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:"; … … 67 67 //Log() << Verbose(0) << endl; 68 68 } 69 Indices[MatrixCounter] = new int[RowCounter[MatrixCounter]];69 Indices[MatrixCounter].resize(RowCounter[MatrixCounter]); 70 70 for(int j=RowCounter[MatrixCounter];j--;) { 71 71 Indices[MatrixCounter][j] = j; … … 243 243 // allocate last plus one matrix 244 244 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); 246 247 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]); 248 250 249 251 // try independently to parse global forcesuffix file if present -
src/Fragmentation/KeySetsContainer.cpp
ra9b86d r9758f7 21 21 22 22 #include <fstream> 23 #include <sstream> 23 24 24 25 #include "CodePatterns/Log.hpp" … … 32 33 */ 33 34 KeySetsContainer::KeySetsContainer() : 34 KeySets(NULL),35 AtomCounter(NULL),36 35 FragmentCounter(0), 37 36 Order(0), 38 FragmentsPerOrder(0), 39 OrderSet(NULL) 37 FragmentsPerOrder(0) 40 38 {}; 41 39 … … 43 41 */ 44 42 KeySetsContainer::~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); 53 51 }; 54 52 … … 59 57 * \return parsing succesful 60 58 */ 61 bool KeySetsContainer::ParseKeySets(const char *name, const int *ACounter, const int FCounter) {59 bool KeySetsContainer::ParseKeySets(const std::string name, const IntVector ACounter, const int FCounter) { 62 60 ifstream input; 63 61 char *FragmentNumber = NULL; … … 67 65 FragmentCounter = FCounter; 68 66 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); 72 68 file << name << FRAGMENTPREFIX << KEYSETFILE; 73 69 input.open(file.str().c_str(), ios::in); … … 77 73 } 78 74 79 AtomCounter = new int[FragmentCounter];75 AtomCounter.resize(FragmentCounter); 80 76 for(int i=0;(i<FragmentCounter) && (!input.eof());i++) { 81 77 stringstream line; 82 78 AtomCounter[i] = ACounter[i]; 83 79 // parse the values 84 KeySets[i] = new int[AtomCounter[i]];80 KeySets[i].resize(AtomCounter[i]); 85 81 for(int j=AtomCounter[i];j--;) 86 82 KeySets[i][j] = -1; … … 121 117 122 118 // 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; 126 122 for(int i=FragmentCounter;i--;) { 127 123 Counter=0; … … 135 131 136 132 // scan through all to gather indices to each order set 137 OrderSet = new int*[Order];133 OrderSet.resize(Order); 138 134 for(int i=Order;i--;) 139 OrderSet[i] = new int[FragmentsPerOrder[i]];135 OrderSet[i].resize(FragmentsPerOrder[i]); 140 136 for(int i=Order;i--;) 141 137 FragmentsPerOrder[i] = 0; -
src/Fragmentation/KeySetsContainer.hpp
ra9b86d r9758f7 20 20 class KeySetsContainer { 21 21 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; 24 26 int FragmentCounter; 25 27 int Order; 26 int *FragmentsPerOrder;27 int **OrderSet;28 IntVector FragmentsPerOrder; 29 ArrayOfIntVectors OrderSet; 28 30 29 31 KeySetsContainer(); 30 32 ~KeySetsContainer(); 31 33 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); 33 35 bool ParseManyBodyTerms(); 34 36 bool Contains(const int GreaterSet, const int SmallerSet); -
src/Fragmentation/MatrixContainer.cpp
ra9b86d r9758f7 35 35 /** Constructor of MatrixContainer class. 36 36 */ 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; 37 MatrixContainer::MatrixContainer() 38 { 39 Header.resize(1); 40 RowCounter.resize(1); 41 ColumnCounter.resize(1); 42 ColumnCounter[0] = -1; 47 43 MatrixCounter = 0; 48 ColumnCounter[0] = -1;49 44 }; 50 45 51 46 /** Destructor of MatrixContainer class. 52 47 */ 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 }; 48 MatrixContainer::~MatrixContainer() 49 {} 86 50 87 51 /** Either copies index matrix from another MatrixContainer or initialises with trivial mapping if NULL. … … 90 54 * \return true - copy/initialisation sucessful, false - dimension false for copying 91 55 */ 92 bool MatrixContainer::InitialiseIndices(class MatrixContainer * Matrix)56 bool MatrixContainer::InitialiseIndices(class MatrixContainer *_container) 93 57 { 94 58 DoLog(0) && (Log() << Verbose(0) << "Initialising indices"); 95 if ( Matrix== NULL) {59 if (_container == NULL) { 96 60 DoLog(0) && (Log() << Verbose(0) << " with trivial mapping." << endl); 97 Indices = new int*[MatrixCounter + 1];61 Indices.resize(MatrixCounter + 1); 98 62 for(int i=MatrixCounter+1;i--;) { 99 Indices[i] = new int[RowCounter[i]];63 Indices[i].resize(RowCounter[i]); 100 64 for(int j=RowCounter[i];j--;) 101 65 Indices[i][j] = j; … … 103 67 } else { 104 68 DoLog(0) && (Log() << Verbose(0) << " from other MatrixContainer." << endl); 105 if (MatrixCounter != Matrix->MatrixCounter)69 if (MatrixCounter != _container->MatrixCounter) 106 70 return false; 107 Indices = new int*[MatrixCounter + 1];71 Indices.resize(MatrixCounter + 1); 108 72 for(int i=MatrixCounter+1;i--;) { 109 if (RowCounter[i] != Matrix->RowCounter[i])73 if (RowCounter[i] != _container->RowCounter[i]) 110 74 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]; 114 78 //Log() << Verbose(0) << Indices[i][j] << "\t"; 115 79 } … … 133 97 * \return parsing successful 134 98 */ 135 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, int MatrixNr)99 bool MatrixContainer::ParseMatrix(std::istream &input, int skiplines, int skipcolumns, size_t MatrixNr) 136 100 { 137 101 stringstream line; … … 146 110 147 111 // 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]; 151 116 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); 156 119 for(int k=skipcolumns;k--;) 157 120 line >> Header[MatrixNr]; 158 121 Log() << Verbose(0) << line.str() << endl; 122 123 // scan header for number of columns 124 if (ColumnCounter.size() <= MatrixNr) 125 ColumnCounter.resize(MatrixNr); 159 126 ColumnCounter[MatrixNr]=0; 160 127 while ( getline(line,token, '\t') ) { … … 170 137 171 138 // scan rest for number of rows/lines 139 if (RowCounter.size() <= MatrixNr) 140 RowCounter.resize(MatrixNr); 172 141 RowCounter[MatrixNr]=-1; // counts one line too much 173 142 while (!input.eof()) { … … 186 155 187 156 // 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++) 210 166 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.;226 167 } 227 168 } 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 230 195 return true; 231 196 }; … … 249 214 * \return parsing successful 250 215 */ 251 bool MatrixContainer::ParseFragmentMatrix(const char *name, const char *prefix,string suffix, int skiplines, int skipcolumns)216 bool MatrixContainer::ParseFragmentMatrix(const std::string name, const std::string prefix, std::string suffix, int skiplines, int skipcolumns) 252 217 { 253 218 char filename[1023]; … … 274 239 275 240 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); 290 249 for(int i=0; i < MatrixCounter;i++) { 291 250 // open matrix file … … 312 271 * \return Allocation successful 313 272 */ 314 bool MatrixContainer::AllocateMatrix( char **GivenHeader, int MCounter, int *RCounter, int *CCounter)273 bool MatrixContainer::AllocateMatrix(StringVector GivenHeader, int MCounter, IntVector RCounter, IntVector CCounter) 315 274 { 316 275 MatrixCounter = MCounter; 317 Header = new char*[MatrixCounter + 1];318 Matrix = new double**[MatrixCounter + 1]; // one more each for the total molecule319 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); 321 280 for(int i=MatrixCounter+1;i--;) { 322 Header[i] = new char[1024]; 323 strncpy(Header[i], GivenHeader[i], 1023); 281 Header[i] = GivenHeader[i]; 324 282 RowCounter[i] = RCounter[i]; 325 283 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 332 290 } 333 291 return true; … … 396 354 * \return true if successful 397 355 */ 398 bool MatrixContainer::SetLastMatrix( double **values, int skipcolumns)356 bool MatrixContainer::SetLastMatrix(const MatrixArray &values, int skipcolumns) 399 357 { 400 358 for(int j=RowCounter[MatrixCounter]+1;j--;) … … 466 424 * \return file was written 467 425 */ 468 bool MatrixContainer::WriteTotalFragments(const char *name, const char *prefix)426 bool MatrixContainer::WriteTotalFragments(const std::string name, const std::string prefix) 469 427 { 470 428 ofstream output; … … 500 458 * \return file was written 501 459 */ 502 bool MatrixContainer::WriteLastMatrix(const char *name, const char *prefix, const char *suffix)460 bool MatrixContainer::WriteLastMatrix(const std::string name, const std::string prefix, const std::string suffix) 503 461 { 504 462 ofstream output; -
src/Fragmentation/MatrixContainer.hpp
ra9b86d r9758f7 14 14 #endif 15 15 16 #include "boost/serialization/array.hpp" 17 18 #include "boost/multi_array.hpp" 16 #include <vector> 19 17 20 18 /** Contains a sequence of matrices parsed from file. … … 23 21 class MatrixContainer { 24 22 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; 28 32 int MatrixCounter; 29 int *RowCounter;30 int *ColumnCounter;33 IntVector RowCounter; 34 IntVector ColumnCounter; 31 35 32 36 MatrixContainer(); … … 34 38 35 39 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); 39 43 bool ResetMatrix(); 40 44 double FindMinValue(); 41 45 double FindMaxValue(); 42 46 bool SetLastMatrix(double value, int skipcolumns); 43 bool SetLastMatrix( double **values, int skipcolumns);47 bool SetLastMatrix(const MatrixArray &values, int skipcolumns); 44 48 //bool ParseIndices(); 45 49 //bool SumSubValues(); 46 50 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); 49 53 }; 50 54
Note:
See TracChangeset
for help on using the changeset viewer.