Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config.cpp

    rce5ac3 r042f82  
    11/** \file config.cpp
    2  * 
     2 *
    33 * Function implementations for the class config.
    4  * 
     4 *
    55 */
    66
    77#include "molecules.hpp"
     8
     9/******************************** Functions for class ConfigFileBuffer **********************/
     10
     11/** Structure containing compare function for Ion_Type sorting.
     12 */
     13struct IonTypeCompare {
     14  bool operator()(const char* s1, const char *s2) const {
     15    char number1[8];
     16    char number2[8];
     17    char *dummy1, *dummy2;
     18    //cout << s1 << "  " << s2 << endl;
     19    dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     20    dummy2 = strchr(dummy1, '_');
     21    strncpy(number1, dummy1, dummy2-dummy1); // copy the number
     22    number1[dummy2-dummy1]='\0';
     23    dummy1 = strchr(s2, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     24    dummy2 = strchr(dummy1, '_');
     25    strncpy(number2, dummy1, dummy2-dummy1); // copy the number
     26    number2[dummy2-dummy1]='\0';
     27    if (atoi(number1) != atoi(number2))
     28      return (atoi(number1) < atoi(number2));
     29    else {
     30      dummy1 = strchr(s1, '_')+sizeof(char);
     31      dummy1 = strchr(dummy1, '_')+sizeof(char);
     32      dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
     33      strncpy(number1, dummy1, dummy2-dummy1); // copy the number
     34      number1[dummy2-dummy1]='\0';
     35      dummy1 = strchr(s2, '_')+sizeof(char);
     36      dummy1 = strchr(dummy1, '_')+sizeof(char);
     37      dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
     38      strncpy(number2, dummy1, dummy2-dummy1); // copy the number
     39      number2[dummy2-dummy1]='\0';
     40      return (atoi(number1) < atoi(number2));
     41    }
     42  }
     43};
     44
     45/** Constructor for ConfigFileBuffer class.
     46 */
     47ConfigFileBuffer::ConfigFileBuffer()
     48{
     49  NoLines = 0;
     50  CurrentLine = 0;
     51  buffer = NULL;
     52  LineMapping = NULL;
     53}
     54
     55/** Constructor for ConfigFileBuffer class with filename to be parsed.
     56 * \param *filename file name
     57 */
     58ConfigFileBuffer::ConfigFileBuffer(char *filename)
     59{
     60  NoLines = 0;
     61  CurrentLine = 0;
     62  buffer = NULL;
     63  LineMapping = NULL;
     64  ifstream *file = NULL;
     65  char line[MAXSTRINGSIZE];
     66
     67  // prescan number of lines
     68  file= new ifstream(filename);
     69  if (file == NULL) {
     70    cerr << "ERROR: config file " << filename << " missing!" << endl;
     71    return;
     72  }
     73  NoLines = 0; // we're overcounting by one
     74  long file_position = file->tellg(); // mark current position
     75  do {
     76    file->getline(line, 256);
     77    NoLines++;
     78  } while (!file->eof());
     79  file->clear();
     80  file->seekg(file_position, ios::beg);
     81  cout << Verbose(1) << NoLines-1 << " lines were recognized." << endl;
     82
     83  // allocate buffer's 1st dimension
     84  if (buffer != NULL) {
     85    cerr << "ERROR: FileBuffer->buffer is not NULL!" << endl;
     86    return;
     87  } else
     88    buffer = (char **) Malloc(sizeof(char *)*NoLines, "ConfigFileBuffer::ConfigFileBuffer: **buffer");
     89
     90  // scan each line and put into buffer
     91  int lines=0;
     92  int i;
     93  do {
     94    buffer[lines] = (char *) Malloc(sizeof(char)*MAXSTRINGSIZE, "ConfigFileBuffer::ConfigFileBuffer: *buffer[]");
     95    file->getline(buffer[lines], MAXSTRINGSIZE-1);
     96    i = strlen(buffer[lines]);
     97    buffer[lines][i] = '\n';
     98    buffer[lines][i+1] = '\0';
     99    lines++;
     100  } while((!file->eof()) && (lines < NoLines));
     101  cout << Verbose(1) << lines-1 << " lines were read into the buffer." << endl;
     102
     103  // close and exit
     104  file->close();
     105  file->clear();
     106  delete(file);
     107}
     108
     109/** Destructor for ConfigFileBuffer class.
     110 */
     111ConfigFileBuffer::~ConfigFileBuffer()
     112{
     113  for(int i=0;i<NoLines;++i)
     114    Free((void **)&buffer[i], "ConfigFileBuffer::~ConfigFileBuffer: *buffer[]");
     115  Free((void **)&buffer, "ConfigFileBuffer::~ConfigFileBuffer: **buffer");
     116  Free((void **)&LineMapping, "ConfigFileBuffer::~ConfigFileBuffer: *LineMapping");
     117}
     118
     119
     120/** Create trivial mapping.
     121 */
     122void ConfigFileBuffer::InitMapping()
     123{
     124  LineMapping = (int *) Malloc(sizeof(int)*NoLines, "ConfigFileBuffer::InitMapping: *LineMapping");
     125  for (int i=0;i<NoLines;i++)
     126    LineMapping[i] = i;
     127}
     128
     129/** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
     130 * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
     131 * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
     132 * points to first Ion_Type entry.
     133 * \param *FileBuffer pointer to buffer structure
     134 * \param NoAtoms of subsequent lines to look at
     135 */
     136void ConfigFileBuffer::MapIonTypesInBuffer(int NoAtoms)
     137{
     138  map<const char *, int, IonTypeCompare> LineList;
     139  if (LineMapping == NULL) {
     140    cerr << "map pointer is NULL: " << LineMapping << endl;
     141    return;
     142  }
     143
     144  // put all into hashed map
     145  for (int i=0; i<NoAtoms; ++i) {
     146    LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
     147  }
     148
     149  // fill map
     150  int nr=0;
     151  for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) {
     152    if (CurrentLine+nr < NoLines)
     153      LineMapping[CurrentLine+(nr++)] = runner->second;
     154    else
     155      cerr << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl;
     156  }
     157}
    8158
    9159/************************************* Functions for class config ***************************/
     
    14164{
    15165  mainname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    16   defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    17   pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    18   configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    19   configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: mainname");
    20   ThermostatImplemented = (int *) Malloc((MaxThermostats)*(sizeof(int)), "IonsInitRead: *ThermostatImplemented");
    21   ThermostatNames = (char **) Malloc((MaxThermostats)*(sizeof(char *)), "IonsInitRead: *ThermostatNames");
    22   for (int j=0;j<MaxThermostats;j++)
    23     ThermostatNames[j] = (char *) MallocString(12*(sizeof(char)), "IonsInitRead: ThermostatNames[]");
    24   Thermostat = 4;
    25   alpha = 0.;
    26   ScaleTempStep = 25;
    27   TempFrequency = 2.5;
     166  defaultpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: defaultpath");
     167  pseudopotpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: pseudopotpath");
     168  databasepath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: databasepath");
     169  configpath = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configpath");
     170  configname = (char *) MallocString(sizeof(char)*MAXSTRINGSIZE,"config constructor: configname");
    28171  strcpy(mainname,"pcp");
    29172  strcpy(defaultpath,"not specified");
     
    31174  configpath[0]='\0';
    32175  configname[0]='\0';
    33   basis="3-21G";
    34  
    35 
    36   strcpy(ThermostatNames[0],"None");
    37   ThermostatImplemented[0] = 1;
    38   strcpy(ThermostatNames[1],"Woodcock");
    39   ThermostatImplemented[1] = 1;
    40   strcpy(ThermostatNames[2],"Gaussian");
    41   ThermostatImplemented[2] = 1;
    42   strcpy(ThermostatNames[3],"Langevin");
    43   ThermostatImplemented[3] = 1;
    44   strcpy(ThermostatNames[4],"Berendsen");
    45   ThermostatImplemented[4] = 1;
    46   strcpy(ThermostatNames[5],"NoseHoover");
    47   ThermostatImplemented[5] = 1;
     176  basis = "3-21G";
    48177
    49178  FastParsing = false;
     
    58187  DoFullCurrent=0;
    59188  DoWannier=0;
    60   DoConstrainedMD=0;
    61189  CommonWannier=0;
    62190  SawtoothStart=0.01;
     
    65193  UseAddGramSch=1;
    66194  Seed=1;
     195
    67196  MaxOuterStep=0;
    68   Deltat=0.01;
     197  Deltat=1;
    69198  OutVisStep=10;
    70199  OutSrcStep=5;
     
    73202  MaxPsiStep=0;
    74203  EpsWannier=1e-7;
    75  
     204
    76205  MaxMinStep=100;
    77206  RelEpsTotalEnergy=1e-7;
     
    84213  InitMaxMinStopStep=1;
    85214  InitMaxMinGapStopStep=0;
    86  
     215
    87216  //BoxLength[NDIM*NDIM];
    88  
     217
    89218  ECut=128.;
    90219  MaxLevel=5;
     
    99228  PsiMaxNoDown=0;
    100229  AddPsis=0;
    101  
     230
    102231  RCut=20.;
    103232  StructOpt=0;
     
    115244  Free((void **)&defaultpath, "config::~config: *defaultpath");
    116245  Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
     246  Free((void **)&databasepath, "config::~config: *databasepath");
    117247  Free((void **)&configpath, "config::~config: *configpath");
    118248  Free((void **)&configname, "config::~config: *configname");
    119249};
    120250
    121 /** Readin of Thermostat related values from parameter file.
    122  * \param *source parameter file
    123  */
    124 void config::InitThermostats(ifstream *source)
    125 {
    126   char *thermo = MallocString(12, "IonsInitRead: thermo");
    127   int verbose = 0;
    128 
    129   // read desired Thermostat from file along with needed additional parameters
    130   if (ParseForParameter(verbose,source,"Thermostat", 0, 1, 1, string_type, thermo, 1, optional)) {
    131     if (strcmp(thermo, ThermostatNames[0]) == 0) { // None
    132       if (ThermostatImplemented[0] == 1) {
    133         Thermostat = None;
    134       } else {
    135         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    136         Thermostat = None;
    137       }
    138     } else if (strcmp(thermo, ThermostatNames[1]) == 0) { // Woodcock
    139       if (ThermostatImplemented[1] == 1) {
    140         Thermostat = Woodcock;
    141         ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
    142       } else {
    143         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    144         Thermostat = None;
    145       }
    146     } else if (strcmp(thermo, ThermostatNames[2]) == 0) { // Gaussian
    147       if (ThermostatImplemented[2] == 1) {
    148         Thermostat = Gaussian;
    149         ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
    150       } else {
    151         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    152         Thermostat = None;
    153       }
    154     } else if (strcmp(thermo, ThermostatNames[3]) == 0) { // Langevin
    155       if (ThermostatImplemented[3] == 1) {
    156         Thermostat = Langevin;
    157         ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
    158         if (ParseForParameter(verbose,source,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
    159           cout << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl;
    160         } else {
    161           alpha = 1.;
    162         }
    163       } else {
    164         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    165         Thermostat = None;
    166       }
    167     } else if (strcmp(thermo, ThermostatNames[4]) == 0) { // Berendsen
    168       if (ThermostatImplemented[4] == 1) {
    169         Thermostat = Berendsen;
    170         ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
    171       } else {
    172         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    173         Thermostat = None;
    174       }
    175     } else if (strcmp(thermo, ThermostatNames[5]) == 0) { // Nose-Hoover
    176       if (ThermostatImplemented[5] == 1) {
    177         Thermostat = NoseHoover;
    178         ParseForParameter(verbose,source,"Thermostat", 0, 2, 1, double_type, &HooverMass, 1, critical); // read Hoovermass
    179         alpha = 0.;
    180       } else {
    181         cout << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
    182         Thermostat = None;
    183       }
    184     } else {
    185       cout << Verbose(1) << " Warning: thermostat name was not understood!" << endl;
    186       Thermostat = None;
    187     }
    188   } else {
    189     if ((MaxOuterStep > 0) && (TargetTemp != 0))
    190       cout << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl;
    191     Thermostat = None;
    192   }
    193   Free((void **)&thermo, "InitThermostats: thermo");
    194 };
    195 
    196 
    197251/** Displays menu for editing each entry of the config file.
    198252 * Nothing fancy here, just lots of cout << Verbose(0)s for the menu and a switch/case
    199253 * for each entry of the config file structure.
    200254 */
    201 void config::Edit(molecule *mol)
     255void config::Edit()
    202256{
    203257  char choice;
    204  
     258
    205259  do {
    206260    cout << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
     
    235289    cout << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
    236290    cout << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
    237     cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
     291//    cout << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
    238292    cout << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
    239293    cout << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
     
    255309    cout << Verbose(0) << "INPUT: ";
    256310    cin >> choice;
    257    
     311
    258312    switch (choice) {
    259313        case 'A': // mainname
     
    380434          cin >> config::InitMaxMinStopStep;
    381435          break;
    382        
    383         case 'j': // BoxLength
    384           cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
    385           for (int i=0;i<6;i++) {
    386             cout << Verbose(0) << "Cell size" << i << ": ";
    387             cin >> mol->cell_size[i];
    388           }
    389           break;
    390        
     436
     437//        case 'j': // BoxLength
     438//          cout << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
     439//          for (int i=0;i<6;i++) {
     440//            cout << Verbose(0) << "Cell size" << i << ": ";
     441//            cin >> mol->cell_size[i];
     442//          }
     443//          break;
     444
    391445        case 'k': // ECut
    392446          cout << Verbose(0) << "Old: " << config::ECut << "\t new: ";
     
    462516 * \param *periode pointer to a periodentafel class with all elements
    463517 * \param *mol pointer to molecule containing all atoms of the molecule
    464  * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax 
     518 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
    465519 */
    466520int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
     
    468522  int test;
    469523  ifstream file(filename);
    470  
     524
    471525  // search file for keyword: ProcPEGamma (new syntax)
    472526  if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
     
    539593 * \param *file input file stream being the opened config file
    540594 * \param *periode pointer to a periodentafel class with all elements
    541  * \param *mol pointer to molecule containing all atoms of the molecule 
     595 * \param *mol pointer to molecule containing all atoms of the molecule
    542596 */
    543597void config::Load(char *filename, periodentafel *periode, molecule *mol)
    544598{
    545   ifstream *file = new ifstream(filename);
    546   if (file == NULL) {
    547     cerr << "ERROR: config file " << filename << " missing!" << endl;
    548     return;
    549   }
    550599  RetrieveConfigPathAndName(filename);
    551   // ParseParameters
    552  
     600
     601  // ParseParameterFile
     602  struct ConfigFileBuffer *FileBuffer = new ConfigFileBuffer(filename);
     603  FileBuffer->InitMapping();
     604
    553605  /* Oeffne Hauptparameterdatei */
    554606  int di;
     
    562614  int verbose = 0;
    563615  double value[3];
    564  
    565   InitThermostats(file);
    566  
     616
    567617  /* Namen einlesen */
    568618
    569   ParseForParameter(verbose,file, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
    570   ParseForParameter(verbose,file, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
    571   ParseForParameter(verbose,file, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
    572   ParseForParameter(verbose,file,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
    573   ParseForParameter(verbose,file,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
    574 
    575   if (!ParseForParameter(verbose,file,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
     619  ParseForParameter(verbose,FileBuffer, "mainname", 0, 1, 1, string_type, (config::mainname), 1, critical);
     620  ParseForParameter(verbose,FileBuffer, "defaultpath", 0, 1, 1, string_type, (config::defaultpath), 1, critical);
     621  ParseForParameter(verbose,FileBuffer, "pseudopotpath", 0, 1, 1, string_type, (config::pseudopotpath), 1, critical);
     622  ParseForParameter(verbose,FileBuffer,"ProcPEGamma", 0, 1, 1, int_type, &(config::ProcPEGamma), 1, critical);
     623  ParseForParameter(verbose,FileBuffer,"ProcPEPsi", 0, 1, 1, int_type, &(config::ProcPEPsi), 1, critical);
     624
     625  if (!ParseForParameter(verbose,FileBuffer,"Seed", 0, 1, 1, int_type, &(config::Seed), 1, optional))
    576626    config::Seed = 1;
    577627
    578   if(!ParseForParameter(verbose,file,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
     628  if(!ParseForParameter(verbose,FileBuffer,"DoOutOrbitals", 0, 1, 1, int_type, &(config::DoOutOrbitals), 1, optional)) {
    579629    config::DoOutOrbitals = 0;
    580630  } else {
     
    582632    if (config::DoOutOrbitals > 1) config::DoOutOrbitals = 1;
    583633  }
    584   ParseForParameter(verbose,file,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
     634  ParseForParameter(verbose,FileBuffer,"DoOutVis", 0, 1, 1, int_type, &(config::DoOutVis), 1, critical);
    585635  if (config::DoOutVis < 0) config::DoOutVis = 0;
    586636  if (config::DoOutVis > 1) config::DoOutVis = 1;
    587   if (!ParseForParameter(verbose,file,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
     637  if (!ParseForParameter(verbose,FileBuffer,"VectorPlane", 0, 1, 1, int_type, &(config::VectorPlane), 1, optional))
    588638    config::VectorPlane = -1;
    589   if (!ParseForParameter(verbose,file,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
     639  if (!ParseForParameter(verbose,FileBuffer,"VectorCut", 0, 1, 1, double_type, &(config::VectorCut), 1, optional))
    590640    config::VectorCut = 0.;
    591   ParseForParameter(verbose,file,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
     641  ParseForParameter(verbose,FileBuffer,"DoOutMes", 0, 1, 1, int_type, &(config::DoOutMes), 1, critical);
    592642  if (config::DoOutMes < 0) config::DoOutMes = 0;
    593643  if (config::DoOutMes > 1) config::DoOutMes = 1;
    594   if (!ParseForParameter(verbose,file,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
     644  if (!ParseForParameter(verbose,FileBuffer,"DoOutCurr", 0, 1, 1, int_type, &(config::DoOutCurrent), 1, optional))
    595645    config::DoOutCurrent = 0;
    596646  if (config::DoOutCurrent < 0) config::DoOutCurrent = 0;
    597   if (config::DoOutCurrent > 1) config::DoOutCurrent = 1; 
    598   ParseForParameter(verbose,file,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
     647  if (config::DoOutCurrent > 1) config::DoOutCurrent = 1;
     648  ParseForParameter(verbose,FileBuffer,"AddGramSch", 0, 1, 1, int_type, &(config::UseAddGramSch), 1, critical);
    599649  if (config::UseAddGramSch < 0) config::UseAddGramSch = 0;
    600650  if (config::UseAddGramSch > 2) config::UseAddGramSch = 2;
    601   if(!ParseForParameter(verbose,file,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
     651  if(!ParseForParameter(verbose,FileBuffer,"DoWannier", 0, 1, 1, int_type, &(config::DoWannier), 1, optional)) {
    602652    config::DoWannier = 0;
    603653  } else {
     
    605655    if (config::DoWannier > 1) config::DoWannier = 1;
    606656  }
    607   if(!ParseForParameter(verbose,file,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
     657  if(!ParseForParameter(verbose,FileBuffer,"CommonWannier", 0, 1, 1, int_type, &(config::CommonWannier), 1, optional)) {
    608658    config::CommonWannier = 0;
    609659  } else {
     
    611661    if (config::CommonWannier > 4) config::CommonWannier = 4;
    612662  }
    613   if(!ParseForParameter(verbose,file,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
     663  if(!ParseForParameter(verbose,FileBuffer,"SawtoothStart", 0, 1, 1, double_type, &(config::SawtoothStart), 1, optional)) {
    614664    config::SawtoothStart = 0.01;
    615665  } else {
     
    617667    if (config::SawtoothStart > 1.) config::SawtoothStart = 1.;
    618668  }
    619  
    620   if (ParseForParameter(verbose,file,"DoConstrainedMD", 0, 1, 1, int_type, &(config::DoConstrainedMD), 1, optional))
    621     if (config::DoConstrainedMD < 0)
    622       config::DoConstrainedMD = 0;
    623   ParseForParameter(verbose,file,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
    624   if (!ParseForParameter(verbose,file,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
     669
     670  ParseForParameter(verbose,FileBuffer,"MaxOuterStep", 0, 1, 1, int_type, &(config::MaxOuterStep), 1, critical);
     671  if (!ParseForParameter(verbose,FileBuffer,"Deltat", 0, 1, 1, double_type, &(config::Deltat), 1, optional))
    625672    config::Deltat = 1;
    626   ParseForParameter(verbose,file,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
    627   ParseForParameter(verbose,file,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
    628   ParseForParameter(verbose,file,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
    629   //ParseForParameter(verbose,file,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
    630   if (!ParseForParameter(verbose,file,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
     673  ParseForParameter(verbose,FileBuffer,"OutVisStep", 0, 1, 1, int_type, &(config::OutVisStep), 1, optional);
     674  ParseForParameter(verbose,FileBuffer,"OutSrcStep", 0, 1, 1, int_type, &(config::OutSrcStep), 1, optional);
     675  ParseForParameter(verbose,FileBuffer,"TargetTemp", 0, 1, 1, double_type, &(config::TargetTemp), 1, optional);
     676  //ParseForParameter(verbose,FileBuffer,"Thermostat", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
     677  if (!ParseForParameter(verbose,FileBuffer,"EpsWannier", 0, 1, 1, double_type, &(config::EpsWannier), 1, optional))
    631678    config::EpsWannier = 1e-8;
    632  
     679
    633680  // stop conditions
    634681  //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
    635   ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
     682  ParseForParameter(verbose,FileBuffer,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
    636683  if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
    637  
    638   ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
    639   ParseForParameter(verbose,file,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
    640   ParseForParameter(verbose,file,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
    641   ParseForParameter(verbose,file,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
    642   ParseForParameter(verbose,file,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
     684
     685  ParseForParameter(verbose,FileBuffer,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
     686  ParseForParameter(verbose,FileBuffer,"RelEpsTotalE", 0, 1, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
     687  ParseForParameter(verbose,FileBuffer,"RelEpsKineticE", 0, 1, 1, double_type, &(config::RelEpsKineticEnergy), 1, critical);
     688  ParseForParameter(verbose,FileBuffer,"MaxMinStopStep", 0, 1, 1, int_type, &(config::MaxMinStopStep), 1, critical);
     689  ParseForParameter(verbose,FileBuffer,"MaxMinGapStopStep", 0, 1, 1, int_type, &(config::MaxMinGapStopStep), 1, critical);
    643690  if (config::MaxMinStep <= 0) config::MaxMinStep = config::MaxPsiStep;
    644691  if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
    645692  if (config::MaxMinGapStopStep < 1) config::MaxMinGapStopStep = 1;
    646  
    647   ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
    648   ParseForParameter(verbose,file,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
    649   ParseForParameter(verbose,file,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
    650   ParseForParameter(verbose,file,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
    651   ParseForParameter(verbose,file,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
     693
     694  ParseForParameter(verbose,FileBuffer,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
     695  ParseForParameter(verbose,FileBuffer,"InitRelEpsTotalE", 0, 1, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
     696  ParseForParameter(verbose,FileBuffer,"InitRelEpsKineticE", 0, 1, 1, double_type, &(config::InitRelEpsKineticEnergy), 1, critical);
     697  ParseForParameter(verbose,FileBuffer,"InitMaxMinStopStep", 0, 1, 1, int_type, &(config::InitMaxMinStopStep), 1, critical);
     698  ParseForParameter(verbose,FileBuffer,"InitMaxMinGapStopStep", 0, 1, 1, int_type, &(config::InitMaxMinGapStopStep), 1, critical);
    652699  if (config::MaxInitMinStep <= 0) config::MaxInitMinStep = config::MaxPsiStep;
    653700  if (config::InitMaxMinStopStep < 1) config::InitMaxMinStopStep = 1;
    654701  if (config::InitMaxMinGapStopStep < 1) config::InitMaxMinGapStopStep = 1;
    655  
     702
    656703  // Unit cell and magnetic field
    657   ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
     704  ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
    658705  mol->cell_size[0] = BoxLength[0];
    659706  mol->cell_size[1] = BoxLength[3];
     
    662709  mol->cell_size[4] = BoxLength[7];
    663710  mol->cell_size[5] = BoxLength[8];
    664   if (1) fprintf(stderr,"\n");
    665 
    666   ParseForParameter(verbose,file,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
    667   ParseForParameter(verbose,file,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
    668   if (!ParseForParameter(verbose,file,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
     711  //if (1) fprintf(stderr,"\n");
     712
     713  ParseForParameter(verbose,FileBuffer,"DoPerturbation", 0, 1, 1, int_type, &(config::DoPerturbation), 1, optional);
     714  ParseForParameter(verbose,FileBuffer,"DoOutNICS", 0, 1, 1, int_type, &(config::DoOutNICS), 1, optional);
     715  if (!ParseForParameter(verbose,FileBuffer,"DoFullCurrent", 0, 1, 1, int_type, &(config::DoFullCurrent), 1, optional))
    669716    config::DoFullCurrent = 0;
    670717  if (config::DoFullCurrent < 0) config::DoFullCurrent = 0;
    671   if (config::DoFullCurrent > 2) config::DoFullCurrent = 2; 
     718  if (config::DoFullCurrent > 2) config::DoFullCurrent = 2;
    672719  if (config::DoOutNICS < 0) config::DoOutNICS = 0;
    673   if (config::DoOutNICS > 2) config::DoOutNICS = 2; 
     720  if (config::DoOutNICS > 2) config::DoOutNICS = 2;
    674721  if (config::DoPerturbation == 0) {
    675722    config::DoFullCurrent = 0;
     
    677724  }
    678725
    679   ParseForParameter(verbose,file,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
    680   ParseForParameter(verbose,file,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
    681   ParseForParameter(verbose,file,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
     726  ParseForParameter(verbose,FileBuffer,"ECut", 0, 1, 1, double_type, &(config::ECut), 1, critical);
     727  ParseForParameter(verbose,FileBuffer,"MaxLevel", 0, 1, 1, int_type, &(config::MaxLevel), 1, critical);
     728  ParseForParameter(verbose,FileBuffer,"Level0Factor", 0, 1, 1, int_type, &(config::Lev0Factor), 1, critical);
    682729  if (config::Lev0Factor < 2) {
    683730    config::Lev0Factor = 2;
    684731  }
    685   ParseForParameter(verbose,file,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
     732  ParseForParameter(verbose,FileBuffer,"RiemannTensor", 0, 1, 1, int_type, &di, 1, critical);
    686733  if (di >= 0 && di < 2) {
    687734    config::RiemannTensor = di;
    688735  } else {
    689736    fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
    690     exit(1); 
     737    exit(1);
    691738  }
    692739  switch (config::RiemannTensor) {
     
    702749        config::MaxLevel = 3;
    703750      }
    704       ParseForParameter(verbose,file,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
     751      ParseForParameter(verbose,FileBuffer,"RiemannLevel", 0, 1, 1, int_type, &(config::RiemannLevel), 1, critical);
    705752      if (config::RiemannLevel < 2) {
    706753        config::RiemannLevel = 2;
    707       } 
     754      }
    708755      if (config::RiemannLevel > config::MaxLevel-1) {
    709756        config::RiemannLevel = config::MaxLevel-1;
    710757      }
    711       ParseForParameter(verbose,file,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
     758      ParseForParameter(verbose,FileBuffer,"LevRFactor", 0, 1, 1, int_type, &(config::LevRFactor), 1, critical);
    712759      if (config::LevRFactor < 2) {
    713760        config::LevRFactor = 2;
    714       } 
     761      }
    715762      config::Lev0Factor = 2;
    716763      config::RTActualUse = 2;
    717764      break;
    718765  }
    719   ParseForParameter(verbose,file,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
     766  ParseForParameter(verbose,FileBuffer,"PsiType", 0, 1, 1, int_type, &di, 1, critical);
    720767  if (di >= 0 && di < 2) {
    721768    config::PsiType = di;
    722769  } else {
    723770    fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
    724     exit(1); 
     771    exit(1);
    725772  }
    726773  switch (config::PsiType) {
    727774  case 0: // SpinDouble
    728     ParseForParameter(verbose,file,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
    729     ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
     775    ParseForParameter(verbose,FileBuffer,"MaxPsiDouble", 0, 1, 1, int_type, &(config::MaxPsiDouble), 1, critical);
     776    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
    730777    break;
    731778  case 1: // SpinUpDown
    732779    if (config::ProcPEGamma % 2) config::ProcPEGamma*=2;
    733     ParseForParameter(verbose,file,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
    734     ParseForParameter(verbose,file,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
    735     ParseForParameter(verbose,file,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
     780    ParseForParameter(verbose,FileBuffer,"PsiMaxNoUp", 0, 1, 1, int_type, &(config::PsiMaxNoUp), 1, critical);
     781    ParseForParameter(verbose,FileBuffer,"PsiMaxNoDown", 0, 1, 1, int_type, &(config::PsiMaxNoDown), 1, critical);
     782    ParseForParameter(verbose,FileBuffer,"AddPsis", 0, 1, 1, int_type, &(config::AddPsis), 1, optional);
    736783    break;
    737784  }
    738  
     785
    739786  // IonsInitRead
    740  
    741   ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
    742   ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
    743   ParseForParameter(verbose,file,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
    744   if (!ParseForParameter(verbose,file,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
     787
     788  ParseForParameter(verbose,FileBuffer,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
     789  ParseForParameter(verbose,FileBuffer,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
     790  ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(config::MaxTypes), 1, critical);
     791  if (!ParseForParameter(verbose,FileBuffer,"RelativeCoord", 0, 1, 1, int_type, &(config::RelativeCoord) , 1, optional))
    745792    config::RelativeCoord = 0;
    746   if (!ParseForParameter(verbose,file,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
     793  if (!ParseForParameter(verbose,FileBuffer,"StructOpt", 0, 1, 1, int_type, &(config::StructOpt), 1, optional))
    747794    config::StructOpt = 0;
    748795  if (MaxTypes == 0) {
     
    751798    // prescan number of ions per type
    752799    cout << Verbose(0) << "Prescanning ions per type: " << endl;
     800    int NoAtoms = 0;
    753801    for (int i=0; i < config::MaxTypes; i++) {
    754802      sprintf(name,"Ion_Type%i",i+1);
    755       ParseForParameter(verbose,file, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
    756       ParseForParameter(verbose,file, name, 0, 2, 1, int_type, &Z, 1, critical);
     803      ParseForParameter(verbose,FileBuffer, (const char*)name, 0, 1, 1, int_type, &No[i], 1, critical);
     804      ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
    757805      elementhash[i] = periode->FindElement(Z);
    758       cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
     806      cout << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
     807      NoAtoms += No[i];
    759808    }
    760809    int repetition = 0; // which repeated keyword shall be read
    761  
     810
     811    // sort the lines via the LineMapping
     812    sprintf(name,"Ion_Type%i",config::MaxTypes);
     813    if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
     814      cerr << "There are no atoms in the config file!" << endl;
     815      return;
     816    }
     817    FileBuffer->CurrentLine++;
     818    //cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine]];
     819    FileBuffer->MapIonTypesInBuffer(NoAtoms);
     820    //for (int i=0; i<(NoAtoms < 100 ? NoAtoms : 100 < 100 ? NoAtoms : 100);++i) {
     821    //  cout << FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine+i]];
     822    //}
     823
    762824    map<int, atom *> AtomList[config::MaxTypes];
     825    map<int, atom *> LinearList;
    763826    if (!FastParsing) {
    764827      // parse in trajectories
     
    774837              neues = new atom();
    775838              AtomList[i][j] = neues;
     839              LinearList[FileBuffer->CurrentLine] = neues;
    776840              neues->type = elementhash[i]; // find element type
    777               mol->AddAtom(neues);
    778841            } else
    779842              neues = AtomList[i][j];
    780             status = (status && 
    781                     ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
    782                     ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
    783                     ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
    784                     ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
     843            status = (status &&
     844                    ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], 1, (repetition == 0) ? critical : optional) &&
     845                    ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], 1, (repetition == 0) ? critical : optional) &&
     846                    ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], 1, (repetition == 0) ? critical : optional) &&
     847                    ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, 1, (repetition == 0) ? critical : optional));
    785848            if (!status) break;
    786    
     849
    787850            // check size of vectors
    788851            if (mol->Trajectories[neues].R.size() <= (unsigned int)(repetition)) {
     
    792855              mol->Trajectories[neues].F.resize(repetition+10);
    793856            }
    794          
     857
    795858            // put into trajectories list
    796859            for (int d=0;d<NDIM;d++)
    797860              mol->Trajectories[neues].R.at(repetition).x[d] = neues->x.x[d];
    798            
     861
    799862            // parse velocities if present
    800             if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
     863            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], 1,optional))
    801864              neues->v.x[0] = 0.;
    802             if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
     865            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], 1,optional))
    803866              neues->v.x[1] = 0.;
    804             if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
     867            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], 1,optional))
    805868              neues->v.x[2] = 0.;
    806869            for (int d=0;d<NDIM;d++)
    807870              mol->Trajectories[neues].U.at(repetition).x[d] = neues->v.x[d];
    808      
     871
    809872            // parse forces if present
    810             if(!ParseForParameter(verbose,file, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
     873            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 8, 1, double_type, &value[0], 1,optional))
    811874              value[0] = 0.;
    812             if(!ParseForParameter(verbose,file, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
     875            if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 9, 1, double_type, &value[1], 1,optional))
    813876              value[1] = 0.;
    814             if(!ParseForParameter(verbose,file, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
     877            if(!ParseForParameter(verbose,FileBuffer, keyword, 1, 10, 1, double_type, &value[2], 1,optional))
    815878              value[2] = 0.;
    816879            for (int d=0;d<NDIM;d++)
    817880              mol->Trajectories[neues].F.at(repetition).x[d] = value[d];
    818  
    819   //            cout << "Parsed position of step " << (repetition) << ": ("; 
     881
     882  //            cout << "Parsed position of step " << (repetition) << ": (";
    820883  //            for (int d=0;d<NDIM;d++)
    821884  //              cout << mol->Trajectories[neues].R.at(repetition).x[d] << " ";          // next step
     
    831894        repetition++;
    832895      }
     896      // put atoms into the molecule in their original order
     897      for(map<int, atom*>::iterator runner = LinearList.begin(); runner != LinearList.end(); ++runner) {
     898        mol->AddAtom(runner->second);
     899      }
    833900      repetition--;
    834901      cout << "Found " << repetition << " trajectory steps." << endl;
     
    837904      // find the maximum number of MD steps so that we may parse last one (Ion_Type1_1 must always be present, because is the first atom)
    838905      repetition = 0;
    839       while ( ParseForParameter(verbose,file, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
    840               ParseForParameter(verbose,file, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
    841               ParseForParameter(verbose,file, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
     906      while ( ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 1, 1, double_type, &value[0], repetition, (repetition == 0) ? critical : optional) &&
     907              ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 2, 1, double_type, &value[1], repetition, (repetition == 0) ? critical : optional) &&
     908              ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
    842909        repetition++;
    843910      cout << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
     
    849916          atom *neues = new atom();
    850917          // then parse for each atom the coordinates as often as present
    851           ParseForParameter(verbose,file, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
    852           ParseForParameter(verbose,file, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
    853           ParseForParameter(verbose,file, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
    854           ParseForParameter(verbose,file, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
    855           if(!ParseForParameter(verbose,file, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
     918          ParseForParameter(verbose,FileBuffer, keyword, 0, 1, 1, double_type, &neues->x.x[0], repetition,critical);
     919          ParseForParameter(verbose,FileBuffer, keyword, 0, 2, 1, double_type, &neues->x.x[1], repetition,critical);
     920          ParseForParameter(verbose,FileBuffer, keyword, 0, 3, 1, double_type, &neues->x.x[2], repetition,critical);
     921          ParseForParameter(verbose,FileBuffer, keyword, 0, 4, 1, int_type, &neues->FixedIon, repetition,critical);
     922          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 5, 1, double_type, &neues->v.x[0], repetition,optional))
    856923            neues->v.x[0] = 0.;
    857           if(!ParseForParameter(verbose,file, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
     924          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 6, 1, double_type, &neues->v.x[1], repetition,optional))
    858925            neues->v.x[1] = 0.;
    859           if(!ParseForParameter(verbose,file, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
     926          if(!ParseForParameter(verbose,FileBuffer, keyword, 0, 7, 1, double_type, &neues->v.x[2], repetition,optional))
    860927            neues->v.x[2] = 0.;
    861928          // here we don't care if forces are present (last in trajectories is always equal to current position)
     
    866933    }
    867934  }
    868   file->close();
    869   delete(file);
     935  delete(FileBuffer);
    870936};
    871937
     
    873939 * \param *file input file stream being the opened config file with old pcp syntax
    874940 * \param *periode pointer to a periodentafel class with all elements
    875  * \param *mol pointer to molecule containing all atoms of the molecule 
     941 * \param *mol pointer to molecule containing all atoms of the molecule
    876942 */
    877943void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
     
    884950  RetrieveConfigPathAndName(filename);
    885951  // ParseParameters
    886  
     952
    887953  /* Oeffne Hauptparameterdatei */
    888954  int l, i, di;
     
    894960  int Z, No, AtomNo, found;
    895961  int verbose = 0;
    896  
     962
    897963  /* Namen einlesen */
    898964
     
    926992  ParseForParameter(verbose,file,"ScaleTempStep", 0, 1, 1, int_type, &(config::ScaleTempStep), 1, optional);
    927993  config::EpsWannier = 1e-8;
    928  
     994
    929995  // stop conditions
    930996  //if (config::MaxOuterStep <= 0) config::MaxOuterStep = 1;
    931997  ParseForParameter(verbose,file,"MaxPsiStep", 0, 1, 1, int_type, &(config::MaxPsiStep), 1, critical);
    932998  if (config::MaxPsiStep <= 0) config::MaxPsiStep = 3;
    933  
     999
    9341000  ParseForParameter(verbose,file,"MaxMinStep", 0, 1, 1, int_type, &(config::MaxMinStep), 1, critical);
    9351001  ParseForParameter(verbose,file,"MaxMinStep", 0, 2, 1, double_type, &(config::RelEpsTotalEnergy), 1, critical);
     
    9391005  if (config::MaxMinStopStep < 1) config::MaxMinStopStep = 1;
    9401006  config::MaxMinGapStopStep = 1;
    941  
     1007
    9421008  ParseForParameter(verbose,file,"MaxInitMinStep", 0, 1, 1, int_type, &(config::MaxInitMinStep), 1, critical);
    9431009  ParseForParameter(verbose,file,"MaxInitMinStep", 0, 2, 1, double_type, &(config::InitRelEpsTotalEnergy), 1, critical);
     
    9701036  } else {
    9711037    fprintf(stderr, "0 <= RiemanTensor < 2: 0 UseNotRT, 1 UseRT");
    972     exit(1); 
     1038    exit(1);
    9731039  }
    9741040  switch (config::RiemannTensor) {
     
    9871053      if (config::RiemannLevel < 2) {
    9881054        config::RiemannLevel = 2;
    989       } 
     1055      }
    9901056      if (config::RiemannLevel > config::MaxLevel-1) {
    9911057        config::RiemannLevel = config::MaxLevel-1;
     
    9941060      if (config::LevRFactor < 2) {
    9951061        config::LevRFactor = 2;
    996       } 
     1062      }
    9971063      config::Lev0Factor = 2;
    9981064      config::RTActualUse = 2;
     
    10041070  } else {
    10051071    fprintf(stderr, "0 <= PsiType < 2: 0 UseSpinDouble, 1 UseSpinUpDown");
    1006     exit(1); 
     1072    exit(1);
    10071073  }
    10081074  switch (config::PsiType) {
     
    10181084    break;
    10191085  }
    1020  
     1086
    10211087  // IonsInitRead
    1022  
     1088
    10231089  ParseForParameter(verbose,file,"RCut", 0, 1, 1, double_type, &(config::RCut), 1, critical);
    10241090  ParseForParameter(verbose,file,"IsAngstroem", 0, 1, 1, int_type, &(config::IsAngstroem), 1, critical);
     
    10271093
    10281094  // Routine from builder.cpp
    1029  
    1030  
    1031   for (i=MAX_ELEMENTS;i--;) 
     1095
     1096
     1097  for (i=MAX_ELEMENTS;i--;)
    10321098    elementhash[i] = NULL;
    10331099  cout << Verbose(0) << "Parsing Ions ..." << endl;
     
    10401106    }
    10411107    if (found > 0) {
    1042       if (zeile.find("Ions_Data") == 0) 
     1108      if (zeile.find("Ions_Data") == 0)
    10431109        getline(*file,zeile,'\n'); // read next line and parse this one
    10441110      istringstream input(zeile);
     
    10691135      No++;
    10701136    }
    1071   }   
     1137  }
    10721138  file->close();
    10731139  delete(file);
     
    10771143 * \param *filename name of file
    10781144 * \param *periode pointer to a periodentafel class with all elements
    1079  * \param *mol pointer to molecule containing all atoms of the molecule 
     1145 * \param *mol pointer to molecule containing all atoms of the molecule
    10801146 */
    10811147bool config::Save(const char *filename, periodentafel *periode, molecule *mol) const
     
    11021168    *output << "DoPerturbation\t" << config::DoPerturbation << "\t# Do perturbation calculate and determine susceptibility and shielding" << endl;
    11031169    *output << "DoFullCurrent\t" << config::DoFullCurrent << "\t# Do full perturbation" << endl;
    1104     *output << "DoConstrainedMD\t" << config::DoConstrainedMD << "\t# Do perform a constrained (>0, relating to current MD step) instead of unconstrained (0) MD" << endl;
    1105     *output << "Thermostat\t" << ThermostatNames[Thermostat] << "\t";
    1106     switch(Thermostat) {
    1107       default:
    1108       case None:
    1109         break;
    1110       case Woodcock:
    1111         *output << ScaleTempStep;
    1112         break;
    1113       case Gaussian:
    1114         *output << ScaleTempStep;
    1115         break;
    1116       case Langevin:
    1117         *output << TempFrequency << "\t" << alpha;
    1118         break;
    1119       case Berendsen:
    1120         *output << TempFrequency;
    1121         break;
    1122       case NoseHoover:
    1123         *output << HooverMass;
    1124         break;
    1125     };
    1126     *output << "\t# Which Thermostat and its parameters to use in MD case." << endl;
    11271170    *output << "CommonWannier\t" << config::CommonWannier << "\t# Put virtual centers at indivual orbits, all common, merged by variance, to grid point, to cell center" << endl;
    11281171    *output << "SawtoothStart\t" << config::SawtoothStart << "\t# Absolute value for smooth transition at cell border " << endl;
     
    12071250 * Note that this format cannot be parsed again.
    12081251 * \param *filename name of file (without ".in" suffix!)
    1209  * \param *mol pointer to molecule containing all atoms of the molecule 
     1252 * \param *mol pointer to molecule containing all atoms of the molecule
    12101253 */
    12111254bool config::SaveMPQC(const char *filename, molecule *mol) const
     
    12181261  ofstream *output = NULL;
    12191262  stringstream *fname = NULL;
    1220  
     1263
    12211264  // first without hessian
    12221265  fname = new stringstream;
     
    12271270  *output << "\tsavestate = no" << endl;
    12281271  *output << "\tdo_gradient = yes" << endl;
    1229   *output << "\tmole<CLHF>: (" << endl;
     1272  *output << "\tmole<MBPT2>: (" << endl;
    12301273  *output << "\t\tmaxiter = 200" << endl;
    12311274  *output << "\t\tbasis = $:basis" << endl;
    12321275  *output << "\t\tmolecule = $:molecule" << endl;
     1276  *output << "\t\treference<CLHF>: (" << endl;
     1277  *output << "\t\t\tbasis = $:basis" << endl;
     1278  *output << "\t\t\tmolecule = $:molecule" << endl;
     1279  *output << "\t\t)" << endl;
    12331280  *output << "\t)" << endl;
    12341281  *output << ")" << endl;
     
    12581305  *output << ")" << endl;
    12591306  *output << "basis<GaussianBasisSet>: (" << endl;
    1260   *output << "\tname = \"" << basis << "\"" << endl;
     1307  *output << "\tname = \""<< basis << "\"" << endl;
    12611308  *output << "\tmolecule = $:molecule" << endl;
    12621309  *output << ")" << endl;
     
    13131360  delete(output);
    13141361  delete(fname);
    1315  
     1362
    13161363  return true;
    13171364};
     
    13231370 * \warning value is modified (both in contents and position)!
    13241371 * \param verbose 1 - print found value to stderr, 0 - don't
    1325  * \param file file to be parsed
     1372 * \param *file file to be parsed
    13261373 * \param name Name of value in file (at least 3 chars!)
    1327  * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning 
     1374 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
    13281375 *        (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
    13291376 *         best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
     
    13451392  dummy1 = free_dummy = (char *) Malloc(256 * sizeof(char), "config::ParseForParameter: *free_dummy");
    13461393
    1347   //fprintf(stderr,"Parsing for %s\n",name); 
     1394  //fprintf(stderr,"Parsing for %s\n",name);
    13481395  if (repetition == 0)
    13491396    //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
     
    13661413          file->clear();
    13671414          file->seekg(file_position, ios::beg);  // rewind to start position
    1368           Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");         
     1415          Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
    13691416          return 0;
    13701417        }
     
    13721419      line++;
    13731420    } while (dummy != NULL && dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
    1374    
     1421
    13751422    // C++ getline removes newline at end, thus re-add
    13761423    if ((dummy1 != NULL) && (strchr(dummy1,'\n') == NULL)) {
     
    13981445        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
    13991446        //Free((void **)&free_dummy);
    1400         //Error(FileOpenParams, NULL);     
     1447        //Error(FileOpenParams, NULL);
    14011448      } else {
    14021449        //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
     
    14071454    if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
    14081455      found++; // found the parameter!
    1409       //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);   
    1410      
     1456      //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
     1457
    14111458      if (found == repetition) {
    14121459        for (i=0;i<xth;i++) { // i = rows
     
    14471494            dummy1[j+1] = '\0';
    14481495          }
    1449  
     1496
    14501497          int start = (type >= grid) ? 0 : yth-1 ;
    14511498          for (j=start;j<yth;j++) { // j = columns
     
    14701517                    //return 0;
    14711518                    exit(255);
    1472                     //Error(FileOpenParams, NULL);     
     1519                    //Error(FileOpenParams, NULL);
    14731520                  } else {
    14741521                    //if (!sequential)
     
    14851532                // found comment, skipping rest of line
    14861533                //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
    1487                 if (!sequential) { // here we need it! 
     1534                if (!sequential) { // here we need it!
    14881535                  file->seekg(file_position, ios::beg);  // rewind to start position
    14891536                }
     
    15001547                    //value += sizeof(int);
    15011548                  break;
    1502                 case(row_double): 
     1549                case(row_double):
    15031550                case(grid):
    15041551                case(lower_trigrid):
     
    15411588      }
    15421589    }
    1543   } 
     1590  }
    15441591  if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
    15451592  Free((void **)&free_dummy, "config::ParseForParameter: *free_dummy");
     
    15491596  }
    15501597  //fprintf(stderr, "End of Parsing\n\n");
    1551  
     1598
    15521599  return (found); // true if found, false if not
    15531600}
     1601
     1602
     1603/** Reads parameter from a parsed file.
     1604 * The file is either parsed for a certain keyword or if null is given for
     1605 * the value in row yth and column xth. If the keyword was necessity#critical,
     1606 * then an error is thrown and the programme aborted.
     1607 * \warning value is modified (both in contents and position)!
     1608 * \param verbose 1 - print found value to stderr, 0 - don't
     1609 * \param *FileBuffer pointer to buffer structure
     1610 * \param name Name of value in file (at least 3 chars!)
     1611 * \param sequential 1 - do not reset file pointer to begin of file, 0 - set to beginning
     1612 *        (if file is sequentially parsed this can be way faster! However, beware of multiple values per line, as whole line is read -
     1613 *         best approach: 0 0 0 1 (not resetted only on last value of line) - and of yth, which is now
     1614 *         counted from this unresetted position!)
     1615 * \param xth Which among a number of parameters it is (in grid case it's row number as grid is read as a whole!)
     1616 * \param yth In grid case specifying column number, otherwise the yth \a name matching line
     1617 * \param type Type of the Parameter to be read
     1618 * \param value address of the value to be read (must have been allocated)
     1619 * \param repetition determines, if the keyword appears multiply in the config file, which repetition shall be parsed, i.e. 1 if not multiply
     1620 * \param critical necessity of this keyword being specified (optional, critical)
     1621 * \return 1 - found, 0 - not found
     1622 * \note Routine is taken from the pcp project and hack-a-slack adapted to C++
     1623 */
     1624int config::ParseForParameter(int verbose, struct ConfigFileBuffer *FileBuffer, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical) {
     1625  int i,j;  // loop variables
     1626  int length = 0, maxlength = -1;
     1627  int OldCurrentLine = FileBuffer->CurrentLine;
     1628  char *dummy1, *dummy;    // pointers in the line that is read in per step
     1629
     1630  //fprintf(stderr,"Parsing for %s\n",name);
     1631  if (repetition == 0)
     1632    //Error(SomeError, "ParseForParameter(): argument repetition must not be 0!");
     1633    return 0;
     1634
     1635  int line = 0; // marks line where parameter was found
     1636  int found = (type >= grid) ? 0 : (-yth + 1);  // marks if yth parameter name was found
     1637  while((found != repetition)) {
     1638    dummy1 = dummy = NULL;
     1639    do {
     1640      dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[FileBuffer->CurrentLine++] ];
     1641      if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
     1642        if ((critical) && (found == 0)) {
     1643          //Error(InitReading, name);
     1644          fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     1645          exit(255);
     1646        } else {
     1647          FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
     1648          return 0;
     1649        }
     1650      }
     1651      if (dummy1 == NULL) {
     1652        if (verbose) fprintf(stderr,"Error reading line %i\n",line);
     1653      } else {
     1654        //fprintf(stderr,"Now parsing the line %i: %s\n", line, dummy1);
     1655      }
     1656      line++;
     1657    } while (dummy1 != NULL && ((dummy1[0] == '#') || (dummy1[0] == '\0'))); // skip commentary and empty lines
     1658
     1659    // Seek for possible end of keyword on line if given ...
     1660    if (name != NULL) {
     1661      dummy = strchr(dummy1,'\t');  // set dummy on first tab or space which ever's nearer
     1662      if (dummy == NULL) {
     1663        dummy = strchr(dummy1, ' ');  // if not found seek for space
     1664        while ((dummy != NULL) && ((*dummy == '\t') || (*dummy == ' ')))    // skip some more tabs and spaces if necessary
     1665          dummy++;
     1666      }
     1667      if (dummy == NULL) {
     1668        dummy = strchr(dummy1, '\n'); // set on line end then (whole line = keyword)
     1669        //fprintf(stderr,"Error: Cannot find tabs or spaces on line %i in search for %s\n", line, name);
     1670        //Free((void **)&free_dummy);
     1671        //Error(FileOpenParams, NULL);
     1672      } else {
     1673        //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)dummy1);
     1674      }
     1675    } else dummy = dummy1;
     1676    // ... and check if it is the keyword!
     1677    //fprintf(stderr,"name %p, dummy %i/%c, dummy1 %i/%c, strlen(name) %i\n", &name, dummy, *dummy, dummy1, *dummy1, strlen(name));
     1678    if ((name == NULL) || (((dummy-dummy1 >= 3) && (strncmp(dummy1, name, strlen(name)) == 0)) && ((unsigned int)(dummy-dummy1) == strlen(name)))) {
     1679      found++; // found the parameter!
     1680      //fprintf(stderr,"found %s at line %i between %i and %i\n", name, line, dummy1, dummy);
     1681
     1682      if (found == repetition) {
     1683        for (i=0;i<xth;i++) { // i = rows
     1684          if (type >= grid) {
     1685            // grid structure means that grid starts on the next line, not right after keyword
     1686            dummy1 = dummy = NULL;
     1687            do {
     1688              dummy1 = FileBuffer->buffer[ FileBuffer->LineMapping[ FileBuffer->CurrentLine++] ];
     1689              if (FileBuffer->CurrentLine >= FileBuffer->NoLines) {
     1690                if ((critical) && (found == 0)) {
     1691                  //Error(InitReading, name);
     1692                  fprintf(stderr,"Error:InitReading, critical %s not found\n", name);
     1693                  exit(255);
     1694                } else {
     1695                  FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
     1696                  return 0;
     1697                }
     1698              }
     1699              if (dummy1 == NULL) {
     1700                if (verbose) fprintf(stderr,"Error reading line %i\n", line);
     1701              } else {
     1702                //fprintf(stderr,"Reading next line %i: %s\n", line, dummy1);
     1703              }
     1704              line++;
     1705            } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
     1706            dummy = dummy1;
     1707          } else { // simple int, strings or doubles start in the same line
     1708            while ((*dummy == '\t') || (*dummy == ' '))  // skip interjacent tabs and spaces
     1709              dummy++;
     1710          }
     1711
     1712          for (j=((type >= grid) ? 0 : yth-1);j<yth;j++) { // j = columns
     1713            // check for lower triangular area and upper triangular area
     1714            if ( ((i > j) && (type == upper_trigrid)) || ((j > i) && (type == lower_trigrid))) {
     1715              *((double *)value) = 0.0;
     1716              fprintf(stderr,"%f\t",*((double *)value));
     1717              value = (void *)((long)value + sizeof(double));
     1718              //value += sizeof(double);
     1719            } else {
     1720              // otherwise we must skip all interjacent tabs and spaces and find next value
     1721              dummy1 = dummy;
     1722              dummy = strchr(dummy1, '\t'); // seek for tab or space
     1723              if (dummy == NULL)
     1724                dummy = strchr(dummy1, ' ');  // if not found seek for space
     1725              if (dummy == NULL) { // if still zero returned ...
     1726                dummy = strchr(dummy1, '\n'); // ... at line end then
     1727                if ((j < yth-1) && (type < 4)) {  // check if xth value or not yet
     1728                  if (critical) {
     1729                    if (verbose) fprintf(stderr,"Error: EoL at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
     1730                    //return 0;
     1731                    exit(255);
     1732                    //Error(FileOpenParams, NULL);
     1733                  } else {
     1734                    if (!sequential) { // here we need it!
     1735                      FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
     1736                    }
     1737                    return 0;
     1738                  }
     1739                }
     1740              } else {
     1741                //fprintf(stderr,"found tab at %i\n",(char *)dummy-(char *)free_dummy);
     1742              }
     1743              if (*dummy1 == '#') {
     1744                // found comment, skipping rest of line
     1745                //if (verbose) fprintf(stderr,"Error: '#' at %i and still missing %i value(s) for parameter %s\n", line, yth-j, name);
     1746                if (!sequential) { // here we need it!
     1747                  FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
     1748                }
     1749                return 0;
     1750              }
     1751              //fprintf(stderr,"value from %i to %i\n",(char *)dummy1-(char *)free_dummy,(char *)dummy-(char *)free_dummy);
     1752              switch(type) {
     1753                case (row_int):
     1754                  *((int *)value) = atoi(dummy1);
     1755                  if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
     1756                  if (verbose) fprintf(stderr,"%i\t",*((int *)value));
     1757                    value = (void *)((long)value + sizeof(int));
     1758                    //value += sizeof(int);
     1759                  break;
     1760                case(row_double):
     1761                case(grid):
     1762                case(lower_trigrid):
     1763                case(upper_trigrid):
     1764                  *((double *)value) = atof(dummy1);
     1765                  if ((verbose) && (i==0) && (j==0)) fprintf(stderr,"%s = ", name);
     1766                  if (verbose) fprintf(stderr,"%lg\t",*((double *)value));
     1767                  value = (void *)((long)value + sizeof(double));
     1768                  //value += sizeof(double);
     1769                  break;
     1770                case(double_type):
     1771                  *((double *)value) = atof(dummy1);
     1772                  if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %lg\n", name, *((double *) value));
     1773                  //value += sizeof(double);
     1774                  break;
     1775                case(int_type):
     1776                  *((int *)value) = atoi(dummy1);
     1777                  if ((verbose) && (i == xth-1)) fprintf(stderr,"%s = %i\n", name, *((int *) value));
     1778                  //value += sizeof(int);
     1779                  break;
     1780                default:
     1781                case(string_type):
     1782                  if (value != NULL) {
     1783                    //if (maxlength == -1) maxlength = strlen((char *)value); // get maximum size of string array
     1784                    maxlength = MAXSTRINGSIZE;
     1785                    length = maxlength > (dummy-dummy1) ? (dummy-dummy1) : maxlength; // cap at maximum
     1786                    strncpy((char *)value, dummy1, length); // copy as much
     1787                    ((char *)value)[length] = '\0'; // and set end marker
     1788                    if ((verbose) && (i == xth-1)) fprintf(stderr,"%s is '%s' (%i chars)\n",name,((char *) value), length);
     1789                    //value += sizeof(char);
     1790                  } else {
     1791                  }
     1792                break;
     1793              }
     1794            }
     1795            while (*dummy == '\t')
     1796              dummy++;
     1797          }
     1798        }
     1799      }
     1800    }
     1801  }
     1802  if ((type >= row_int) && (verbose)) fprintf(stderr,"\n");
     1803  if (!sequential) {
     1804    FileBuffer->CurrentLine = OldCurrentLine; // rewind to start position
     1805  }
     1806  //fprintf(stderr, "End of Parsing\n\n");
     1807
     1808  return (found); // true if found, false if not
     1809}
Note: See TracChangeset for help on using the changeset viewer.