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