Changeset 88104f


Ignore:
Timestamp:
Jun 12, 2010, 11:12:20 AM (15 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
a3fded
Parents:
980dd6
Message:

Placed class ConfigFileBuffer into its own module.

  • this is a first step in clearing up config.[ch]pp and implementing PcpParser.
Location:
src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r980dd6 r88104f  
    9090  Parser/TremoloParser.cpp \
    9191  Parser/XyzParser.cpp
     92
    9293PARSERHEADER = \
    9394  Parser/ChangeTracker.hpp \
     
    114115  Descriptors/MoleculeDescriptor.cpp \
    115116  Descriptors/MoleculeIdDescriptor.cpp \
    116   Descriptors/MoleculeNameDescriptor.cpp \ 
    117   Descriptors/MoleculePtrDescriptor.cpp 
     117  Descriptors/MoleculeNameDescriptor.cpp \
     118  Descriptors/MoleculePtrDescriptor.cpp
    118119                                   
    119120
     
    151152  CommandLineParser.cpp \
    152153  config.cpp \
     154  ConfigFileBuffer.cpp \
    153155  element.cpp \
    154156  elements_db.cpp \
     
    196198  CommandLineParser.hpp \
    197199  config.hpp \
     200  ConfigFileBuffer.hpp \
    198201  defs.hpp \
    199202  element.hpp \
  • src/config.cpp

    r980dd6 r88104f  
    88#include <cstring>
    99
    10 #include "World.hpp"
    1110#include "atom.hpp"
    1211#include "bond.hpp"
     
    2221#include "periodentafel.hpp"
    2322#include "World.hpp"
    24 
    25 /******************************** Functions for class ConfigFileBuffer **********************/
    26 
    27 /** Structure containing compare function for Ion_Type sorting.
    28  */
    29 struct IonTypeCompare {
    30   bool operator()(const char* s1, const char *s2) const {
    31     char number1[8];
    32     char number2[8];
    33     const char *dummy1, *dummy2;
    34     //Log() << Verbose(0) << s1 << "  " << s2 << endl;
    35     dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    36     dummy2 = strchr(dummy1, '_');
    37     strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    38     number1[dummy2-dummy1]='\0';
    39     dummy1 = strchr(s2, '_')+sizeof(char)*5;  // go just after "Ion_Type"
    40     dummy2 = strchr(dummy1, '_');
    41     strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    42     number2[dummy2-dummy1]='\0';
    43     if (atoi(number1) != atoi(number2))
    44       return (atoi(number1) < atoi(number2));
    45     else {
    46       dummy1 = strchr(s1, '_')+sizeof(char);
    47       dummy1 = strchr(dummy1, '_')+sizeof(char);
    48       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    49       strncpy(number1, dummy1, dummy2-dummy1); // copy the number
    50       number1[dummy2-dummy1]='\0';
    51       dummy1 = strchr(s2, '_')+sizeof(char);
    52       dummy1 = strchr(dummy1, '_')+sizeof(char);
    53       dummy2 = strchr(dummy1, ' ') < strchr(dummy1, '\t') ? strchr(dummy1, ' ') : strchr(dummy1, '\t');
    54       strncpy(number2, dummy1, dummy2-dummy1); // copy the number
    55       number2[dummy2-dummy1]='\0';
    56       return (atoi(number1) < atoi(number2));
    57     }
    58   }
    59 };
    60 
    61 /** Constructor for ConfigFileBuffer class.
    62  */
    63 ConfigFileBuffer::ConfigFileBuffer() : buffer(NULL), LineMapping(NULL), CurrentLine(0), NoLines(0)
    64 {
    65 };
    66 
    67 /** Constructor for ConfigFileBuffer class with filename to be parsed.
    68  * \param *filename file name
    69  */
    70 ConfigFileBuffer::ConfigFileBuffer(const char * const filename) : buffer(NULL), LineMapping(NULL), CurrentLine(0), NoLines(0)
    71 {
    72   ifstream *file = NULL;
    73   char line[MAXSTRINGSIZE];
    74 
    75   // prescan number of lines
    76   file= new ifstream(filename);
    77   if (file == NULL) {
    78     DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
    79     return;
    80   }
    81   NoLines = 0; // we're overcounting by one
    82   long file_position = file->tellg(); // mark current position
    83   do {
    84     file->getline(line, 256);
    85     NoLines++;
    86   } while (!file->eof());
    87   file->clear();
    88   file->seekg(file_position, ios::beg);
    89   DoLog(1) && (Log() << Verbose(1) << NoLines-1 << " lines were recognized." << endl);
    90 
    91   // allocate buffer's 1st dimension
    92   if (buffer != NULL) {
    93     DoeLog(1) && (eLog()<< Verbose(1) << "FileBuffer->buffer is not NULL!" << endl);
    94     return;
    95   } else
    96     buffer = new char *[NoLines];
    97 
    98   // scan each line and put into buffer
    99   int lines=0;
    100   int i;
    101   do {
    102     buffer[lines] = new char[MAXSTRINGSIZE];
    103     file->getline(buffer[lines], MAXSTRINGSIZE-1);
    104     i = strlen(buffer[lines]);
    105     buffer[lines][i] = '\n';
    106     buffer[lines][i+1] = '\0';
    107     lines++;
    108   } while((!file->eof()) && (lines < NoLines));
    109   DoLog(1) && (Log() << Verbose(1) << lines-1 << " lines were read into the buffer." << endl);
    110 
    111   // close and exit
    112   file->close();
    113   file->clear();
    114   delete(file);
    115 }
    116 
    117 /** Destructor for ConfigFileBuffer class.
    118  */
    119 ConfigFileBuffer::~ConfigFileBuffer()
    120 {
    121   for(int i=0;i<NoLines;++i)
    122     delete[](buffer[i]);
    123   delete[](buffer);
    124   delete[](LineMapping);
    125 }
    126 
    127 
    128 /** Create trivial mapping.
    129  */
    130 void ConfigFileBuffer::InitMapping()
    131 {
    132   LineMapping = new int[NoLines];
    133   for (int i=0;i<NoLines;i++)
    134     LineMapping[i] = i;
    135 }
    136 
    137 /** Creates a mapping for the \a *FileBuffer's lines containing the Ion_Type keyword such that they are sorted.
    138  * \a *map on return contains a list of NoAtom entries such that going through the list, yields indices to the
    139  * lines in \a *FileBuffer in a sorted manner of the Ion_Type?_? keywords. We assume that ConfigFileBuffer::CurrentLine
    140  * points to first Ion_Type entry.
    141  * \param *FileBuffer pointer to buffer structure
    142  * \param NoAtoms of subsequent lines to look at
    143  */
    144 void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
    145 {
    146   map<const char *, int, IonTypeCompare> IonTypeLineMap;
    147   if (LineMapping == NULL) {
    148     DoeLog(0) && (eLog()<< Verbose(0) << "map pointer is NULL: " << LineMapping << endl);
    149     performCriticalExit();
    150     return;
    151   }
    152 
    153   // put all into hashed map
    154   for (int i=0; i<NoAtoms; ++i) {
    155     IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
    156   }
    157 
    158   // fill map
    159   int nr=0;
    160   for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
    161     if (CurrentLine+nr < NoLines)
    162       LineMapping[CurrentLine+(nr++)] = runner->second;
    163     else {
    164       DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl);
    165       performCriticalExit();
    166     }
    167   }
    168 }
    16923
    17024/************************************* Functions for class config ***************************/
  • src/config.hpp

    r980dd6 r88104f  
    2121
    2222#include "bondgraph.hpp"
     23#include "ConfigFileBuffer.hpp"
    2324
    2425/****************************************** forward declarations *****************************/
     
    2930
    3031/********************************************** declarations *******************************/
    31 
    32 class ConfigFileBuffer {
    33   public:
    34     char **buffer;
    35     int *LineMapping;
    36     int CurrentLine;
    37     int NoLines;
    38 
    39     ConfigFileBuffer();
    40     ConfigFileBuffer(const char * const filename);
    41     ~ConfigFileBuffer();
    42 
    43     void InitMapping();
    44     void MapIonTypesInBuffer(const int NoAtoms);
    45 };
    4632
    4733/** The config file.
Note: See TracChangeset for help on using the changeset viewer.