Ignore:
Timestamp:
May 15, 2010, 5:56:57 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
356180, 494bf6
Parents:
dbec4e
git-author:
Frederik Heber <heber@…> (05/14/10 20:14:27)
git-committer:
Frederik Heber <heber@…> (05/15/10 17:56:57)
Message:

Added all commands defined in ParseCommandLineOptions() as Actions.

  • Actions are not yet used, except verbose, version and help.
  • Files are present and included in Makefile.am
  • not unit tests written so far
  • no action has been tested so far (except for MapOfActions)
  • structure introduced to to transition from ParseCommandLineOptions to actions.
  • program name and config file are fixed arguments.

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/builder.cpp

    rdbec4e r2e06c4  
    7777#include "Actions/ActionRegistry.hpp"
    7878#include "Actions/ActionHistory.hpp"
     79#include "Actions/MapOfActions.hpp"
    7980#include "Actions/MethodAction.hpp"
    8081#include "Actions/MoleculeAction/ChangeNameAction.hpp"
     
    14801481
    14811482/** Parses the command line options.
     1483 * Note that this function is from now on transitional. All commands that are not passed
     1484 * here are handled by CommandLineParser and the actions of CommandLineUIFactory.
    14821485 * \param argc argument count
    14831486 * \param **argv arguments array
     
    14871490 * \param *ConfigFileName pointer to config file name in **argv
    14881491 * \param *PathToDatabases pointer to db's path in **argv
     1492 * \param &ArgcList list of arguments that we do not parse here
    14891493 * \return exit code (0 - successful, all else - something's wrong)
    14901494 */
    1491 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
    1492                                    config& configuration, char *&ConfigFileName)
     1495static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,
     1496                                   config& configuration, char *&ConfigFileName, list<int> &ArgcList)
    14931497{
    14941498  Vector x,y,z,n;  // coordinates for absolute point in cell volume
     
    15081512  molecule *mol = NULL;
    15091513  string BondGraphFileName("\n");
    1510   int verbosity = 0;
    15111514  strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
    15121515
     
    15221525          case 'H':
    15231526          case '?':
    1524             DoLog(0) && (Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl);
    1525             DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl);
    1526             DoLog(0) && (Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl);
    1527             DoLog(0) && (Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl);
    1528             DoLog(0) && (Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl);
    1529             DoLog(0) && (Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
    1530             DoLog(0) && (Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
    1531             DoLog(0) && (Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl);
    1532             DoLog(0) && (Log() << Verbose(0) << "\t-C <type> [params] <output> <bin output> <BinWidth> <BinStart> <BinEnd>\tPair Correlation analysis." << endl);
    1533             DoLog(0) && (Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl);
    1534             DoLog(0) && (Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl);
    1535             DoLog(0) && (Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl);
    1536             DoLog(0) && (Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl);
    1537             DoLog(0) && (Log() << Verbose(0) << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl);
    1538             DoLog(0) && (Log() << Verbose(0) << "\t-F <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
    1539             DoLog(0) && (Log() << Verbose(0) << "\t-FF <MaxDistance> <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
    1540             DoLog(0) && (Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl);
    1541             DoLog(0) && (Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl);
    1542             DoLog(0) && (Log() << Verbose(0) << "\t-I\t Dissect current system of molecules into a set of disconnected (subgraphs of) molecules." << endl);
    1543             DoLog(0) && (Log() << Verbose(0) << "\t-j\t<path> Store all bonds to file." << endl);
    1544             DoLog(0) && (Log() << Verbose(0) << "\t-J\t<path> Store adjacency per atom to file." << endl);
    1545             DoLog(0) && (Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl);
    1546             DoLog(0) && (Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl);
    1547             DoLog(0) && (Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl);
    1548             DoLog(0) && (Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl);
    1549             DoLog(0) && (Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl);
    1550             DoLog(0) && (Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl);
    1551             DoLog(0) && (Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl);
    1552             DoLog(0) && (Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl);
    1553             DoLog(0) && (Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl);
    1554             DoLog(0) && (Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl);
    1555             DoLog(0) && (Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl);
    1556             DoLog(0) && (Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl);
    1557             DoLog(0) && (Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl);
    1558             DoLog(0) && (Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl);
    1559             DoLog(0) && (Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl);
    1560             DoLog(0) && (Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl);
    1561             DoLog(0) && (Log() << Verbose(0) << "\t-v\t\tsets verbosity (more is more)." << endl);
    1562             DoLog(0) && (Log() << Verbose(0) << "\t-V\t\tGives version information." << endl);
    1563             DoLog(0) && (Log() << Verbose(0) << "\t-X\t\tset default name of a molecule." << endl);
    1564             DoLog(0) && (Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl);
    1565             return (1);
     1527            ArgcList.push_back(argptr-1);
     1528            return(1);
    15661529            break;
    15671530          case 'v':
    1568             while (argv[argptr-1][verbosity+1] == 'v') {
    1569               verbosity++;
    1570             }
    1571             setVerbosity(verbosity);
    1572             DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
     1531            ArgcList.push_back(argptr-1);
     1532            return(1);
    15731533            break;
    15741534          case 'V':
    1575             DoLog(0) && (Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl);
    1576             DoLog(0) && (Log() << Verbose(0) << "Build your own molecule position set." << endl);
    1577             return (1);
     1535            ArgcList.push_back(argptr-1);
     1536            ArgcList.push_back(argptr);
     1537            argptr++;
    15781538            break;
    15791539          case 'B':
     
    25152475
    25162476void cleanUp(){
    2517   UIFactory::purgeInstance();
    25182477  World::purgeInstance();
    25192478  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    25242483  logger::purgeInstance();
    25252484  errorLogger::purgeInstance();
     2485  UIFactory::purgeInstance();
     2486  MapOfActions::purgeInstance();
    25262487  CommandLineParser::purgeInstance();
    25272488  ActionRegistry::purgeInstance();
     
    25362497    ofstream output;
    25372498    string line;
     2499    char **Arguments = NULL;
     2500    int ArgcSize = 0;
     2501    bool ArgumentsCopied = false;
    25382502
    25392503    cout << ESPACKVersion << endl;
     
    25432507    ActionHistory::init();
    25442508
     2509    // Parse command line options and if present create respective UI
    25452510    {
    2546       // Parse command line options and if present create respective UI
    2547       CommandLineParser::getInstance().generic.add_options()
    2548           ("help,h", "produce help message")
    2549           ("version,v", "show version")
    2550           ("parse-xyz,p", po::value< vector<string> >(), "parse xyz file into World")
    2551           ;
    2552       CommandLineParser::getInstance().Run(argc,argv);
    2553       if (!CommandLineParser::getInstance().isEmpty())
     2511      list<int> ArgcList;
     2512      ArgcList.push_back(0); // push back program!
     2513      ArgcList.push_back(1); // push back config file name
     2514      char ConfigFileName[MAXSTRINGSIZE];
     2515      // handle arguments by ParseCommandLineOptions()
     2516      ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), (char *&)ConfigFileName, ArgcList);
     2517      // copy all remaining arguments to a new argv
     2518      Arguments = Malloc<char *>(ArgcList.size(), "main - **Arguments");
     2519      cout << "The following arguments are handled by CommandLineParser: ";
     2520      for (list<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) {
     2521        Arguments[ArgcSize] = Malloc<char>(strlen(argv[*ArgcRunner])+2, "main - *Arguments[]");
     2522        strcpy(Arguments[ArgcSize], argv[*ArgcRunner]);
     2523        cout << " " << argv[*ArgcRunner];
     2524        ArgcSize++;
     2525      }
     2526      cout << endl;
     2527      ArgumentsCopied = true;
     2528      // handle remaining arguments by CommandLineParser
     2529      MapOfActions::getInstance().AddOptionsToParser();
     2530      CommandLineParser::getInstance().Run(ArgcSize,Arguments);
     2531      if (!CommandLineParser::getInstance().isEmpty()) {
     2532        DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
    25542533        UIFactory::makeUserInterface(UIFactory::CommandLine);
    2555       else
     2534      } else {
     2535        DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
    25562536        UIFactory::makeUserInterface(UIFactory::Text);
     2537      }
    25572538    }
    25582539
     
    25692550        Log() << Verbose(0) << "Saving of elements.db failed." << endl;
    25702551
     2552  // free the new argv
     2553  if (ArgumentsCopied) {
     2554    for (int i=0; i<ArgcSize;i++)
     2555      Free(&Arguments[i]);
     2556    Free(&Arguments);
     2557  }
     2558
    25712559  cleanUp();
    2572 
    25732560  Memory::getState();
    25742561  return (0);
Note: See TracChangeset for help on using the changeset viewer.