Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    r42af9e r68f03d  
    1414#include "element.hpp"
    1515#include "helpers.hpp"
    16 #include "info.hpp"
    1716#include "lists.hpp"
    1817#include "log.hpp"
     
    9493    return;
    9594  } else
    96     buffer = new char *[NoLines];
     95    buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
    9796
    9897  // scan each line and put into buffer
     
    10099  int i;
    101100  do {
    102     buffer[lines] = new char[MAXSTRINGSIZE];
     101    buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
    103102    file->getline(buffer[lines], MAXSTRINGSIZE-1);
    104103    i = strlen(buffer[lines]);
     
    120119{
    121120  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);
    125124}
    126125
     
    130129void ConfigFileBuffer::InitMapping()
    131130{
    132   LineMapping = new int[NoLines];
     131  LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
    133132  for (int i=0;i<NoLines;i++)
    134133    LineMapping[i] = i;
     
    180179    MaxLevel(5), RiemannTensor(0), LevRFactor(0), RiemannLevel(0), Lev0Factor(2), RTActualUse(0), AddPsis(0), RCut(20.), StructOpt(0), IsAngstroem(1), RelativeCoord(0),
    181180    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");
    188187  strcpy(mainname,"pcp");
    189188  strcpy(defaultpath,"not specified");
     
    200199config::~config()
    201200{
    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);
    209208  for (int j=0;j<MaxThermostats;j++)
    210     delete[](ThermostatNames[j]);
    211   delete[](ThermostatNames);
     209    Free(&ThermostatNames[j]);
     210  Free(&ThermostatNames);
    212211
    213212  if (BG != NULL)
     
    219218void config::InitThermostats()
    220219{
    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");
    223222  for (int j=0;j<MaxThermostats;j++)
    224     ThermostatNames[j] = new char[12];
     223    ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
    225224
    226225  strcpy(ThermostatNames[0],"None");
     
    243242void config::ParseThermostats(class ConfigFileBuffer * const fb)
    244243{
    245   char * const thermo = new char[12];
     244  char * const thermo = Malloc<char>(12, "IonsInitRead: thermo");
    246245  const int verbose = 0;
    247246
     
    310309    Thermostat = None;
    311310  }
    312   delete[](thermo);
     311  Free(thermo);
    313312};
    314313
     
    15631562  for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
    15641563    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");
    15681565    AtomNo = 0;
    15691566    while (Walker->next != (*Runner)->end) {
     
    15881585      AtomNo++;
    15891586    }
    1590     delete[](elementNo);
     1587    Free(&elementNo);
    15911588    MolNo++;
    15921589  }
     
    16071604  FILE *f = NULL;
    16081605
    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");
    16121607  char name[MAXSTRINGSIZE];
    16131608  strncpy(name, filename, MAXSTRINGSIZE-1);
     
    16161611  if (f == NULL) {
    16171612    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
    1618     delete[](elementNo);
     1613    Free(&elementNo);
    16191614    return false;
    16201615  }
     
    16451640  }
    16461641  fclose(f);
    1647   delete[](elementNo);
     1642  Free(&elementNo);
    16481643
    16491644  return true;
     
    17131708bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
    17141709{
    1715   Info FunctionInfo(__func__);
    17161710  atom *Walker = NULL;
    17171711  ofstream *output = NULL;
     
    17401734
    17411735  // create global to local id map
    1742   map<int, int> LocalNotoGlobalNoMap;
     1736  int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap");
    17431737  {
    1744     unsigned int MolCounter = 0;
    1745     int AtomNo = 1;
     1738    int MolCounter = 0;
     1739    int AtomNo = 0;
    17461740    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
    17521745      MolCounter++;
    17531746    }
    1754     ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
    17551747  }
    17561748
     
    17631755      while (Walker->next != (*MolWalker)->end) {
    17641756        Walker = Walker->next;
    1765         *output << LocalNotoGlobalNoMap[ Walker->getId() ] << "\t";
     1757        *output << AtomNo+1 << "\t";
    17661758        *output << Walker->getName() << "\t";
    17671759        *output << (*MolWalker)->name << "\t";
     
    17711763        *output << Walker->type->symbol << "\t";
    17721764        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";
    17741766        for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
    17751767          *output << "-\t";
     
    17861778  delete(output);
    17871779  delete(fname);
     1780  for(size_t i=0;i<MolList->ListOfMolecules.size(); i++)
     1781    Free(&LocalNotoGlobalNoMap[i]);
     1782  Free(&LocalNotoGlobalNoMap);
    17881783
    17891784  return true;
     
    19431938  char *dummy1 = NULL;
    19441939  char *dummy = NULL;
    1945   char free_dummy[MAXSTRINGSIZE];    // pointers in the line that is read in per step
     1940  char * const free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");    // pointers in the line that is read in per step
    19461941  dummy1 = free_dummy;
    19471942
     
    19591954      if (file->eof()) {
    19601955        if ((critical) && (found == 0)) {
     1956          Free(free_dummy);
    19611957          //Error(InitReading, name);
    19621958          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    19661962          file->clear();
    19671963          file->seekg(file_position, ios::beg);  // rewind to start position
     1964          Free(free_dummy);
    19681965          return 0;
    19691966        }
     
    19961993        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    19971994        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
     1995        //Free((void **)&free_dummy);
    19981996        //Error(FileOpenParams, NULL);
    19991997      } else {
     
    20162014              if (file->eof()) {
    20172015                if ((critical) && (found == 0)) {
     2016                  Free(free_dummy);
    20182017                  //Error(InitReading, name);
    20192018                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    20232022                  file->clear();
    20242023                  file->seekg(file_position, ios::beg);  // rewind to start position
     2024                  Free(free_dummy);
    20252025                  return 0;
    20262026                }
     
    20632063                  if (critical) {
    20642064                    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);
    20652066                    //return 0;
    20662067                    exit(255);
     
    20702071                    file->clear();
    20712072                    file->seekg(file_position, ios::beg);  // rewind to start position
     2073                    Free(free_dummy);
    20722074                    return 0;
    20732075                  }
     
    20822084                  file->seekg(file_position, ios::beg);  // rewind to start position
    20832085                }
     2086                Free(free_dummy);
    20842087                return 0;
    20852088              }
     
    21372140  if ((type >= row_int) && (verbose))
    21382141    fprintf(stderr,"\n");
     2142  Free(free_dummy);
    21392143  if (!sequential) {
    21402144    file->clear();
     
    22172221        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    22182222        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
     2223        //Free(&free_dummy);
    22192224        //Error(FileOpenParams, NULL);
    22202225      } else {
Note: See TracChangeset for help on using the changeset viewer.