Changeset 5b15ab


Ignore:
Timestamp:
Apr 29, 2008, 6:30:38 AM (17 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:
2910e0
Parents:
555063
Message:

config::Load..() now get filename instead of pointer to file, bugfix for switch structure in command line parsin
g.

Load..() functions RetrieveConfigPath() - the path that is given for the config file on the command line - and p
ut it into config::configpath. This is necessary to allow later for a sensible storage path under fragmentation, as the old with defaultpath from the file was stupid, if the given path was wrong (whereas the config path always exists).
Switch structure in parsing the command line options needed to make better use of the already present flag in or
der to know when to just save and stop and when to continue to the interactive menu.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/builder.cpp

    r555063 r5b15ab  
    748748  char *ConfigFileName = NULL;
    749749  char *ElementsFileName = NULL;
    750   int flag = 1;
     750  int flag = 0;
    751751  int Z;
    752752  int j, axis, count, faktor;
     
    773773          case 'H':
    774774          case '?':
     775            flag=2;
    775776            cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
    776777            cout << "Usage: " << argv[0] << "[-{acepsthH?vfrp}] [further arguments] [config file]" << endl;
     
    785786            cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
    786787            cout << "\t-v/-V\t\tGives version information." << endl;
    787             return 0;
     788            cout << "Note: config files must not begin with '-' !" << endl;
    788789            break;
    789790          case 'v':
    790791          case 'V':
     792            flag=2;
    791793            cout << argv[0] << " " << VERSIONSTRING << endl;
    792794            cout << "Build your own molecule position set." << endl;
    793             return 0;
    794795            break;
    795796          case 'e':
     
    827828        }
    828829      } else {
     830        test.close();
    829831        ConfigFileName = argv[argc-1];
    830832        cout << Verbose(1) << "Specified config file found, parsing ...";
    831         switch (configuration.TestSyntax(&test, periode, mol)) {
     833        switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
    832834          case 1:
    833835            cout << "new syntax." << endl;
    834             configuration.Load(&test, periode, mol);
     836            configuration.Load(ConfigFileName, periode, mol);
    835837            config_present = present;
    836838            break;
    837839          case 0:
    838840            cout << "old syntax." << endl;
    839             configuration.LoadOld(&test, periode, mol);
     841            configuration.LoadOld(ConfigFileName, periode, mol);
    840842            config_present = present;
    841843            break;
     
    844846            config_present = empty;
    845847       }
    846         test.close();
    847848      }
    848849    } else
     
    856857          switch(argv[argptr-1][1]) {
    857858            case 'p':
     859              flag = 1;
    858860              cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
    859861              if (!mol->AddXYZFile(argv[argptr++]))
     
    871873            switch(argv[argptr-1][1]) {
    872874              case 't':
     875                flag = 1;
    873876                cout << Verbose(1) << "Translating all ions to new origin." << endl;
    874877                for (int i=0;i<3;i++)
     
    878881                break;
    879882              case 'a':
     883                flag = 1;
    880884                cout << Verbose(1) << "Adding new atom." << endl;
    881885                first = new atom;
     
    894898                break;
    895899              case 's':
     900                flag = 1;
    896901                j = -1;
    897902                cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
     
    914919                break;
    915920              case 'c':
     921                flag = 1;
    916922                j = -1;
    917923                cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
     
    930936                break;
    931937              case 'r':
     938                flag = 1;
    932939                cout << Verbose(1) << "Converting config file from supposed old to new syntax." << endl;
    933940                break;
    934941              case 'f':
    935942                int i,j;
    936                 flag = 0;
     943                flag = 1;
    937944                if (argc > argptr+3) {
    938945                  cout << Verbose(0) << "Creating connection matrix..." << endl;
     
    9981005          } else argptr++;
    9991006        } while (argptr < (argc-1));
    1000     if (flag)
     1007    if (flag == 1)  // 1 means save and exit
    10011008      SaveConfig(ConfigFileName, &configuration, periode, mol);
    1002     delete(mol);
    1003     delete(periode);
    1004     return (0);
     1009    if (flag > 1) { // 2 means just exit
     1010      delete(mol);
     1011      delete(periode);
     1012      return (0);
     1013    }
    10051014  }
    10061015
  • src/config.cpp

    r555063 r5b15ab  
    1616  defaultpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
    1717  pseudopotpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
     18  configpath = (char *) MallocString(sizeof(char)*255,"config constructor: mainname");
    1819  strcpy(mainname,"pcp");
    19   strcpy(defaultpath,"not specified                                                                                                                                                                                                                                               ");
    20   strcpy(pseudopotpath,"not specified                                                                                                                                                                                                                                               ");
     20  strcpy(defaultpath,"not specified");
     21  strcpy(pseudopotpath,"not specified");
    2122 
    2223  ProcPEGamma=8;
     
    8687  Free((void **)&defaultpath, "config::~config: *defaultpath");
    8788  Free((void **)&pseudopotpath, "config::~config: *pseudopotpath");
     89  Free((void **)&configpath, "config::~config: *configpath");
    8890};
    8991
     
    352354
    353355/** Tests whether a given configuration file adhears to old or new syntax.
    354  * \param *file input file stream being the opened config file
     356 * \param *filename filename of config file to be tested
    355357 * \param *periode pointer to a periodentafel class with all elements
    356358 * \param *mol pointer to molecule containing all atoms of the molecule
    357359 * \return 0 - old syntax, 1 - new syntax, -1 - unknown syntax
    358360 */
    359 int config::TestSyntax(ifstream *file, periodentafel *periode, molecule *mol)
     361int config::TestSyntax(char *filename, periodentafel *periode, molecule *mol)
    360362{
    361363  int test;
     364  ifstream file(filename);
     365 
    362366  // search file for keyword: ProcPEGamma (new syntax)
    363   if (ParseForParameter(1,file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional))
     367  if (ParseForParameter(1,&file,"ProcPEGamma", 0, 1, 1, int_type, &test, 1, optional)) {
     368    file.close();
    364369    return 1;
     370  }
    365371  // search file for keyword: ProcsGammaPsi (old syntax)
    366   if (ParseForParameter(1,file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional))
     372  if (ParseForParameter(1,&file,"ProcsGammaPsi", 0, 1, 1, int_type, &test, 1, optional)) {
     373    file.close();
    367374    return 0;
     375  }
     376  file.close();
    368377  return -1;
    369378}
     
    394403};
    395404
     405/** Retrieves the path in the given config file name.
     406 * \param *filename config file string
     407 */
     408void config::RetrieveConfigPath(char *filename)
     409{
     410  int last = -1;
     411  for(int i=0;i<255;i++) {
     412    if (filename[i] == '/')
     413      last = i;
     414    if (filename[i] == '\0')
     415      break;
     416  }
     417  if (last == -1) { // no path in front, set to local directory.
     418    strcpy(configpath, "./");
     419  } else {
     420    strncpy(configpath, filename, last+1);
     421    if (last < 254)
     422      configpath[last+1]='\0';
     423  }
     424  cout << "Found configpath: " << configpath << ", dir slash was found at " << last << "." << endl;
     425};
     426
     427
    396428/** Initializes config file structure by loading elements from a give file.
    397429 * \param *file input file stream being the opened config file
     
    399431 * \param *mol pointer to molecule containing all atoms of the molecule
    400432 */
    401 void config::Load(ifstream *file, periodentafel *periode, molecule *mol)
     433void config::Load(char *filename, periodentafel *periode, molecule *mol)
    402434{
     435  ifstream *file = new ifstream(filename);
     436  if (file == NULL) {
     437    cerr << "ERROR: config file " << filename << " missing!" << endl;
     438    return;
     439  }
     440  RetrieveConfigPath(filename);
    403441  // ParseParameters
    404442 
     
    615653    }
    616654  }
     655  file->close();
     656  delete(file);
    617657};
    618658
     
    622662 * \param *mol pointer to molecule containing all atoms of the molecule
    623663 */
    624 void config::LoadOld(ifstream *file, periodentafel *periode, molecule *mol)
     664void config::LoadOld(char *filename, periodentafel *periode, molecule *mol)
    625665{
     666  ifstream *file = new ifstream(filename);
     667  if (file == NULL) {
     668    cerr << "ERROR: config file " << filename << " missing!" << endl;
     669    return;
     670  }
     671  RetrieveConfigPath(filename);
    626672  // ParseParameters
    627673 
     
    810856    }
    811857  }   
     858  file->close();
     859  delete(file);
    812860};
    813861
  • src/molecules.hpp

    r555063 r5b15ab  
    612612    int ProcPEGamma;
    613613    int ProcPEPsi;
     614    char *configpath;
    614615   
    615616    private:
     
    674675  ~config();
    675676
    676   int TestSyntax(ifstream *file, periodentafel *periode, molecule *mol);
    677   void Load(ifstream *file, periodentafel *periode, molecule *mol);
    678   void LoadOld(ifstream *file, periodentafel *periode, molecule *mol);
     677  int TestSyntax(char *filename, periodentafel *periode, molecule *mol);
     678  void Load(char *filename, periodentafel *periode, molecule *mol);
     679  void LoadOld(char *filename, periodentafel *periode, molecule *mol);
     680  void RetrieveConfigPath(char *filename);
    679681  bool Save(ofstream *file, periodentafel *periode, molecule *mol) const;
    680682  void Edit(molecule *mol);
Note: See TracChangeset for help on using the changeset viewer.