Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    r68f03d r42af9e  
    1414#include "element.hpp"
    1515#include "helpers.hpp"
     16#include "info.hpp"
    1617#include "lists.hpp"
    1718#include "log.hpp"
     
    9394    return;
    9495  } else
    95     buffer = Malloc<char*>(NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
     96    buffer = new char *[NoLines];
    9697
    9798  // scan each line and put into buffer
     
    99100  int i;
    100101  do {
    101     buffer[lines] = Malloc<char>(MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
     102    buffer[lines] = new char[MAXSTRINGSIZE];
    102103    file->getline(buffer[lines], MAXSTRINGSIZE-1);
    103104    i = strlen(buffer[lines]);
     
    119120{
    120121  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);
    124125}
    125126
     
    129130void ConfigFileBuffer::InitMapping()
    130131{
    131   LineMapping = Malloc<int>(NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
     132  LineMapping = new int[NoLines];
    132133  for (int i=0;i<NoLines;i++)
    133134    LineMapping[i] = i;
     
    179180    MaxLevel(5), RiemannTensor(0), LevRFactor(0), RiemannLevel(0), Lev0Factor(2), RTActualUse(0), AddPsis(0), RCut(20.), StructOpt(0), IsAngstroem(1), RelativeCoord(0),
    180181    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];
    187188  strcpy(mainname,"pcp");
    188189  strcpy(defaultpath,"not specified");
     
    199200config::~config()
    200201{
    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);
    208209  for (int j=0;j<MaxThermostats;j++)
    209     Free(&ThermostatNames[j]);
    210   Free(&ThermostatNames);
     210    delete[](ThermostatNames[j]);
     211  delete[](ThermostatNames);
    211212
    212213  if (BG != NULL)
     
    218219void config::InitThermostats()
    219220{
    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];
    222223  for (int j=0;j<MaxThermostats;j++)
    223     ThermostatNames[j] = Malloc<char>(12, "config constructor: ThermostatNames[]");
     224    ThermostatNames[j] = new char[12];
    224225
    225226  strcpy(ThermostatNames[0],"None");
     
    242243void config::ParseThermostats(class ConfigFileBuffer * const fb)
    243244{
    244   char * const thermo = Malloc<char>(12, "IonsInitRead: thermo");
     245  char * const thermo = new char[12];
    245246  const int verbose = 0;
    246247
     
    309310    Thermostat = None;
    310311  }
    311   Free(thermo);
     312  delete[](thermo);
    312313};
    313314
     
    15621563  for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
    15631564    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;
    15651568    AtomNo = 0;
    15661569    while (Walker->next != (*Runner)->end) {
     
    15851588      AtomNo++;
    15861589    }
    1587     Free(&elementNo);
     1590    delete[](elementNo);
    15881591    MolNo++;
    15891592  }
     
    16041607  FILE *f = NULL;
    16051608
    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;
    16071612  char name[MAXSTRINGSIZE];
    16081613  strncpy(name, filename, MAXSTRINGSIZE-1);
     
    16111616  if (f == NULL) {
    16121617    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
    1613     Free(&elementNo);
     1618    delete[](elementNo);
    16141619    return false;
    16151620  }
     
    16401645  }
    16411646  fclose(f);
    1642   Free(&elementNo);
     1647  delete[](elementNo);
    16431648
    16441649  return true;
     
    17081713bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
    17091714{
     1715  Info FunctionInfo(__func__);
    17101716  atom *Walker = NULL;
    17111717  ofstream *output = NULL;
     
    17341740
    17351741  // create global to local id map
    1736   int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap");
     1742  map<int, int> LocalNotoGlobalNoMap;
    17371743  {
    1738     int MolCounter = 0;
    1739     int AtomNo = 0;
     1744    unsigned int MolCounter = 0;
     1745    int AtomNo = 1;
    17401746    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      }
    17451752      MolCounter++;
    17461753    }
     1754    ASSERT(MolCounter == MolList->ListOfMolecules.size(), "SaveTREMOLO: LocalNotoGlobalNoMap[] has not been correctly initialized for each molecule");
    17471755  }
    17481756
     
    17551763      while (Walker->next != (*MolWalker)->end) {
    17561764        Walker = Walker->next;
    1757         *output << AtomNo+1 << "\t";
     1765        *output << LocalNotoGlobalNoMap[ Walker->getId() ] << "\t";
    17581766        *output << Walker->getName() << "\t";
    17591767        *output << (*MolWalker)->name << "\t";
     
    17631771        *output << Walker->type->symbol << "\t";
    17641772        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";
    17661774        for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
    17671775          *output << "-\t";
     
    17781786  delete(output);
    17791787  delete(fname);
    1780   for(size_t i=0;i<MolList->ListOfMolecules.size(); i++)
    1781     Free(&LocalNotoGlobalNoMap[i]);
    1782   Free(&LocalNotoGlobalNoMap);
    17831788
    17841789  return true;
     
    19381943  char *dummy1 = NULL;
    19391944  char *dummy = NULL;
    1940   char * const free_dummy = Malloc<char>(256, "config::ParseForParameter: *free_dummy");    // pointers in the line that is read in per step
     1945  char free_dummy[MAXSTRINGSIZE];    // pointers in the line that is read in per step
    19411946  dummy1 = free_dummy;
    19421947
     
    19541959      if (file->eof()) {
    19551960        if ((critical) && (found == 0)) {
    1956           Free(free_dummy);
    19571961          //Error(InitReading, name);
    19581962          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    19621966          file->clear();
    19631967          file->seekg(file_position, ios::beg);  // rewind to start position
    1964           Free(free_dummy);
    19651968          return 0;
    19661969        }
     
    19931996        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    19941997        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    1995         //Free((void **)&free_dummy);
    19961998        //Error(FileOpenParams, NULL);
    19971999      } else {
     
    20142016              if (file->eof()) {
    20152017                if ((critical) && (found == 0)) {
    2016                   Free(free_dummy);
    20172018                  //Error(InitReading, name);
    20182019                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     
    20222023                  file->clear();
    20232024                  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);
    20662065                    //return 0;
    20672066                    exit(255);
     
    20712070                    file->clear();
    20722071                    file->seekg(file_position, ios::beg);  // rewind to start position
    2073                     Free(free_dummy);
    20742072                    return 0;
    20752073                  }
     
    20842082                  file->seekg(file_position, ios::beg);  // rewind to start position
    20852083                }
    2086                 Free(free_dummy);
    20872084                return 0;
    20882085              }
     
    21402137  if ((type >= row_int) && (verbose))
    21412138    fprintf(stderr,"\n");
    2142   Free(free_dummy);
    21432139  if (!sequential) {
    21442140    file->clear();
     
    22212217        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
    22222218        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    2223         //Free(&free_dummy);
    22242219        //Error(FileOpenParams, NULL);
    22252220      } else {
Note: See TracChangeset for help on using the changeset viewer.