Changeset ec4b04 for src/bin/mpqc


Ignore:
Timestamp:
Jul 10, 2012, 1:15:51 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
52aacc
Parents:
e9a571
git-author:
Frederik Heber <heber@…> (07/08/12 19:12:09)
git-committer:
Frederik Heber <heber@…> (07/10/12 13:15:51)
Message:

Placed all option parsing at beginning.

  • GetLongOpts is now only used at the very beginning. Parsed values are stored in temporary structure for later access.
  • this is to make the whole function contained inside the try_main() routine to be accessible with the command-line, e.g. by a call from another function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/bin/mpqc/mpqc.cc

    re9a571 rec4b04  
    305305}
    306306
     307/** Temporary structure for storing information from command-line
     308 *
     309 * This structure has been introduced to gather the various calls to GetLongOpts
     310 * at one (initial) place and to abstract it from the source of command-lines.
     311 * This temporary object can be set by other means, too. I.e. we become
     312 * independent of usage in command-line programs.
     313 */
     314struct OptionValues {
     315  const char *keyvalue; // option "k"
     316  const char *debug; // option ""
     317  int limit; // option "l"
     318  const char *check; // option "c"
     319  const char *simple_input; // option "i"
     320
     321#ifdef HAVE_CHEMISTRY_CCA
     322  string cca_load;  // option "cca-path"
     323  string cc_path; // option "cca-load"
     324#endif
     325};
     326
     327/** Parse remainder options not treated by ComputeOptions() into temporary storage.
     328 *
     329 * \param options option structure to obtain values from
     330 * \param values remaining option values which are processed later and now
     331 *        stored in a temporary structure
     332 */
     333void parseRemainderOptions(
     334    GetLongOpt &options,
     335    struct OptionValues &values)
     336{
     337  values.keyvalue = options.retrieve("k");
     338  values.debug = options.retrieve("d");
     339  values.limit = atoi(options.retrieve("l"));
     340  values.check = options.retrieve("c");
     341  values.simple_input = options.retrieve("i");
     342
     343#ifdef HAVE_CHEMISTRY_CCA
     344  values.cca_load = options.retrieve("cca-load");
     345  values.cca_path = options.retrieve("cca-path");
     346#endif
     347}
     348
    307349/** Sets object and generic input file names.
    308350 *
    309351 * \param object_input filename of object-oriented input
    310352 * \param generic_input filename of generic input
    311  * \param options option structure
     353 * \param options (command-line)option structure
    312354 * \param argc argument count
    313355 * \param argv argument array
     
    573615 * \param grp message group
    574616 * \param parsedkev keyvalue container on return
    575  * \param options options structure
     617 * \param values (command-line) options structure
    576618 * \param input input file name
    577619 * \param generic_input filename of generic input
     
    580622    Ref<MessageGrp> &grp,
    581623    Ref<ParsedKeyVal> &parsedkv,
    582     GetLongOpt &options,
     624    struct OptionValues &values,
    583625    const char *&input,
    584626    const char *&generic_input
     
    624666    MPQCIn mpqcin;
    625667    char *simple_input_text = mpqcin.parse_string(in_char_array);
    626     if (options.retrieve("i")) {
     668    if (values.simple_input) {
    627669      ExEnv::out0() << "Generated object-oriented input file:" << endl
    628670                   << simple_input_text
     
    700742 *
    701743 * \param keyval keyvalue container
    702  * \param options parsed command line options
     744 * \param values parsed (command-line) options
    703745 */
    704746void prepareCCA(
    705747    Ref<KeyVal> &keyval,
    706     GetLongOpt &options
     748    struct OptionValues &values
    707749    )
    708750{
     
    712754  bool do_cca = keyval->booleanvalue("do_cca",falsevalue);
    713755
    714   string cca_path(options.retrieve("cca-path"));
    715   string cca_load(options.retrieve("cca-load"));
     756  string cca_path(values.cca_path);
     757  string cca_load(values.cca_load);
    716758  if(cca_path.size()==0)
    717759    cca_path = keyval->stringvalue("cca_path",emptystring);
     
    752794    Ref<MessageGrp> &grp,
    753795    Ref<Debugger> &debugger,
    754     GetLongOpt &options,
     796    struct OptionValues &values,
    755797    char **argv)
    756798{
     
    760802    debugger->set_exec(argv[0]);
    761803    debugger->set_prefix(grp->me());
    762     if (options.retrieve("d"))
     804    if (values.debug)
    763805      debugger->debug("Starting debugger because -d given on command line.");
    764806  }
     
    867909/** Checks whether limit on command-line exceeds the basis functions.
    868910 *
    869  * \param options parsed command-line options
    870911 * \param mole molecular energy object
     912 * \param values temporarily storage for (command-line) options
    871913 * \return 0 - not exceeded, 1 - exceeded
    872914 */
    873915int checkBasisSetLimit(
    874     GetLongOpt &options,
    875     Ref<MolecularEnergy> &mole
     916    Ref<MolecularEnergy> &mole,
     917    struct OptionValues &values
    876918    )
    877919{
    878   int check = (options.retrieve("c") != 0);
    879   int limit = atoi(options.retrieve("l"));
     920  int check = (values.check != (const char *)0);
     921  int limit = values.limit;
    880922  if (limit) {
    881923    Ref<Wavefunction> wfn; wfn << mole;
     
    11301172  ostream *outstream = 0;
    11311173  ComputeOptions(options, output, outstream);
     1174  OptionValues values;
     1175  parseRemainderOptions(options, values);
    11321176
    11331177  // get the message group.  first try the commandline and environment
     
    11451189  // parse input into keyvalue container
    11461190  Ref<ParsedKeyVal> parsedkv;
    1147   parseInputfile(grp, parsedkv, options, input, generic_input);
    1148   if (options.retrieve("k")) parsedkv->verbose(1);
     1191  parseInputfile(grp, parsedkv, values, input, generic_input);
     1192  if (values.keyvalue) parsedkv->verbose(1);
    11491193  Ref<KeyVal> keyval = new PrefixKeyVal(parsedkv.pointer(),"mpqc");
    11501194
     
    11831227
    11841228  // prepare CCA if available
    1185   prepareCCA(keyval, options);
     1229  prepareCCA(keyval, values);
    11861230
    11871231  // now set up the debugger
    11881232  Ref<Debugger> debugger;
    1189   setupDebugger(keyval, grp, debugger, options, argv);
     1233  setupDebugger(keyval, grp, debugger, values, argv);
    11901234
    11911235  // now check to see what matrix kit to use
     
    12501294
    12511295  // check basis set limit
    1252   const int check = checkBasisSetLimit(options, mole);
     1296  const int check = checkBasisSetLimit(mole, values);
    12531297  if (check) {
    12541298    ExEnv::out0() << endl << indent
Note: See TracChangeset for help on using the changeset viewer.