Changes in src/config.cpp [42af9e:68f03d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/config.cpp
r42af9e r68f03d 14 14 #include "element.hpp" 15 15 #include "helpers.hpp" 16 #include "info.hpp"17 16 #include "lists.hpp" 18 17 #include "log.hpp" … … 94 93 return; 95 94 } else 96 buffer = new char *[NoLines];95 buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer"); 97 96 98 97 // scan each line and put into buffer … … 100 99 int i; 101 100 do { 102 buffer[lines] = new char[MAXSTRINGSIZE];101 buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]"); 103 102 file->getline(buffer[lines], MAXSTRINGSIZE-1); 104 103 i = strlen(buffer[lines]); … … 120 119 { 121 120 for(int i=0;i<NoLines;++i) 122 delete[](buffer[i]);123 delete[](buffer);124 delete[](LineMapping);121 Free(&buffer[i]); 122 Free(&buffer); 123 Free(&LineMapping); 125 124 } 126 125 … … 130 129 void ConfigFileBuffer::InitMapping() 131 130 { 132 LineMapping = new int[NoLines];131 LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping"); 133 132 for (int i=0;i<NoLines;i++) 134 133 LineMapping[i] = i; … … 180 179 MaxLevel(5), RiemannTensor(0), LevRFactor(0), RiemannLevel(0), Lev0Factor(2), RTActualUse(0), AddPsis(0), RCut(20.), StructOpt(0), IsAngstroem(1), RelativeCoord(0), 181 180 MaxTypes(0) { 182 mainname = new char[MAXSTRINGSIZE];183 defaultpath = new char[MAXSTRINGSIZE];184 pseudopotpath = new char[MAXSTRINGSIZE];185 databasepath = new char[MAXSTRINGSIZE];186 configpath = new char[MAXSTRINGSIZE];187 configname = new char[MAXSTRINGSIZE];181 mainname = Malloc<char>(MAXSTRINGSIZE,"config constructor: mainname"); 182 defaultpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: defaultpath"); 183 pseudopotpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: pseudopotpath"); 184 databasepath = Malloc<char>(MAXSTRINGSIZE,"config constructor: databasepath"); 185 configpath = Malloc<char>(MAXSTRINGSIZE,"config constructor: configpath"); 186 configname = Malloc<char>(MAXSTRINGSIZE,"config constructor: configname"); 188 187 strcpy(mainname,"pcp"); 189 188 strcpy(defaultpath,"not specified"); … … 200 199 config::~config() 201 200 { 202 delete[](mainname);203 delete[](defaultpath);204 delete[](pseudopotpath);205 delete[](databasepath);206 delete[](configpath);207 delete[](configname);208 delete[](ThermostatImplemented);201 Free(&mainname); 202 Free(&defaultpath); 203 Free(&pseudopotpath); 204 Free(&databasepath); 205 Free(&configpath); 206 Free(&configname); 207 Free(&ThermostatImplemented); 209 208 for (int j=0;j<MaxThermostats;j++) 210 delete[](ThermostatNames[j]);211 delete[](ThermostatNames);209 Free(&ThermostatNames[j]); 210 Free(&ThermostatNames); 212 211 213 212 if (BG != NULL) … … 219 218 void config::InitThermostats() 220 219 { 221 ThermostatImplemented = new int[MaxThermostats];222 ThermostatNames = new char *[MaxThermostats];220 ThermostatImplemented = Malloc<int>(MaxThermostats, "config constructor: *ThermostatImplemented"); 221 ThermostatNames = Malloc<char*>(MaxThermostats, "config constructor: *ThermostatNames"); 223 222 for (int j=0;j<MaxThermostats;j++) 224 ThermostatNames[j] = new char[12];223 ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]"); 225 224 226 225 strcpy(ThermostatNames[0],"None"); … … 243 242 void config::ParseThermostats(class ConfigFileBuffer * const fb) 244 243 { 245 char * const thermo = new char[12];244 char * const thermo = Malloc<char>(12, "IonsInitRead: thermo"); 246 245 const int verbose = 0; 247 246 … … 310 309 Thermostat = None; 311 310 } 312 delete[](thermo);311 Free(thermo); 313 312 }; 314 313 … … 1563 1562 for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) { 1564 1563 Walker = (*Runner)->start; 1565 int *elementNo = new int[MAX_ELEMENTS]; 1566 for (int i=0;i<MAX_ELEMENTS;i++) 1567 elementNo[i] = 0; 1564 int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo"); 1568 1565 AtomNo = 0; 1569 1566 while (Walker->next != (*Runner)->end) { … … 1588 1585 AtomNo++; 1589 1586 } 1590 delete[](elementNo);1587 Free(&elementNo); 1591 1588 MolNo++; 1592 1589 } … … 1607 1604 FILE *f = NULL; 1608 1605 1609 int *elementNo = new int[MAX_ELEMENTS]; 1610 for (int i=0;i<MAX_ELEMENTS;i++) 1611 elementNo[i] = 0; 1606 int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo"); 1612 1607 char name[MAXSTRINGSIZE]; 1613 1608 strncpy(name, filename, MAXSTRINGSIZE-1); … … 1616 1611 if (f == NULL) { 1617 1612 DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl); 1618 delete[](elementNo);1613 Free(&elementNo); 1619 1614 return false; 1620 1615 } … … 1645 1640 } 1646 1641 fclose(f); 1647 delete[](elementNo);1642 Free(&elementNo); 1648 1643 1649 1644 return true; … … 1713 1708 bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const 1714 1709 { 1715 Info FunctionInfo(__func__);1716 1710 atom *Walker = NULL; 1717 1711 ofstream *output = NULL; … … 1740 1734 1741 1735 // create global to local id map 1742 map<int, int> LocalNotoGlobalNoMap;1736 int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap"); 1743 1737 { 1744 unsignedint MolCounter = 0;1745 int AtomNo = 1;1738 int MolCounter = 0; 1739 int AtomNo = 0; 1746 1740 for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) { 1747 atom *Walker = (*MolWalker)->start; 1748 while (Walker->next != (*MolWalker)->end) { 1749 Walker = Walker->next; 1750 LocalNotoGlobalNoMap.insert( pair<int,int>(Walker->getId(), AtomNo++) ); 1751 } 1741 LocalNotoGlobalNoMap[MolCounter] = Calloc<int>(MolList->CountAllAtoms(), "config::SaveTREMOLO - *LocalNotoGlobalNoMap[]"); 1742 1743 (*MolWalker)->SetIndexedArrayForEachAtomTo( LocalNotoGlobalNoMap[MolCounter], &atom::nr, IncrementalAbsoluteValue, &AtomNo); 1744 1752 1745 MolCounter++; 1753 1746 } 1754 ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");1755 1747 } 1756 1748 … … 1763 1755 while (Walker->next != (*MolWalker)->end) { 1764 1756 Walker = Walker->next; 1765 *output << LocalNotoGlobalNoMap[ Walker->getId() ]<< "\t";1757 *output << AtomNo+1 << "\t"; 1766 1758 *output << Walker->getName() << "\t"; 1767 1759 *output << (*MolWalker)->name << "\t"; … … 1771 1763 *output << Walker->type->symbol << "\t"; 1772 1764 for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++) 1773 *output << LocalNotoGlobalNoMap[ (*runner)->GetOtherAtom(Walker)->getId() ]<< "\t";1765 *output << LocalNotoGlobalNoMap[MolCounter][ (*runner)->GetOtherAtom(Walker)->nr ]+1 << "\t"; 1774 1766 for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++) 1775 1767 *output << "-\t"; … … 1786 1778 delete(output); 1787 1779 delete(fname); 1780 for(size_t i=0;i<MolList->ListOfMolecules.size(); i++) 1781 Free(&LocalNotoGlobalNoMap[i]); 1782 Free(&LocalNotoGlobalNoMap); 1788 1783 1789 1784 return true; … … 1943 1938 char *dummy1 = NULL; 1944 1939 char *dummy = NULL; 1945 char free_dummy[MAXSTRINGSIZE]; // pointers in the line that is read in per step1940 char * const free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy"); // pointers in the line that is read in per step 1946 1941 dummy1 = free_dummy; 1947 1942 … … 1959 1954 if (file->eof()) { 1960 1955 if ((critical) && (found == 0)) { 1956 Free(free_dummy); 1961 1957 //Error(InitReading, name); 1962 1958 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); … … 1966 1962 file->clear(); 1967 1963 file->seekg(file_position, ios::beg); // rewind to start position 1964 Free(free_dummy); 1968 1965 return 0; 1969 1966 } … … 1996 1993 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword) 1997 1994 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name); 1995 //Free((void **)&free_dummy); 1998 1996 //Error(FileOpenParams, NULL); 1999 1997 } else { … … 2016 2014 if (file->eof()) { 2017 2015 if ((critical) && (found == 0)) { 2016 Free(free_dummy); 2018 2017 //Error(InitReading, name); 2019 2018 fprintf(stderr,"Error:InitReading, critical %s not found\n", name); … … 2023 2022 file->clear(); 2024 2023 file->seekg(file_position, ios::beg); // rewind to start position 2024 Free(free_dummy); 2025 2025 return 0; 2026 2026 } … … 2063 2063 if (critical) { 2064 2064 if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name); 2065 Free(free_dummy); 2065 2066 //return 0; 2066 2067 exit(255); … … 2070 2071 file->clear(); 2071 2072 file->seekg(file_position, ios::beg); // rewind to start position 2073 Free(free_dummy); 2072 2074 return 0; 2073 2075 } … … 2082 2084 file->seekg(file_position, ios::beg); // rewind to start position 2083 2085 } 2086 Free(free_dummy); 2084 2087 return 0; 2085 2088 } … … 2137 2140 if ((type >= row_int) && (verbose)) 2138 2141 fprintf(stderr,"\n"); 2142 Free(free_dummy); 2139 2143 if (!sequential) { 2140 2144 file->clear(); … … 2217 2221 dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword) 2218 2222 //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name); 2223 //Free(&free_dummy); 2219 2224 //Error(FileOpenParams, NULL); 2220 2225 } else {
Note:
See TracChangeset
for help on using the changeset viewer.