Changeset d2d7fc


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

Extracted reading of input char array into keyvalue into own function.

File:
1 edited

Legend:

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

    rab755a rd2d7fc  
    615615}
    616616
     617/** Parse the input configuration from char array into keyvalue container.
     618 *
     619 * \param parsedkv key value container to foll
     620 * \param values temporary options value structure
     621 * \param in_char_array char array with input file
     622 * \param use_simple_input whether the format in \a in_char_array is simple (1)
     623 *        or object-oriented (0)
     624 */
     625void parseIntoKeyValue(
     626    Ref<ParsedKeyVal> &parsedkv,
     627    struct OptionValues &values,
     628    char *in_char_array,
     629    int use_simple_input)
     630{
     631  if (use_simple_input) {
     632    MPQCIn mpqcin;
     633    char *simple_input_text = mpqcin.parse_string(in_char_array);
     634    if (values.simple_input) {
     635      ExEnv::out0() << "Generated object-oriented input file:" << endl
     636                   << simple_input_text
     637                   << endl;
     638      exit(0);
     639    }
     640    parsedkv = new ParsedKeyVal();
     641    parsedkv->parse_string(simple_input_text);
     642    delete[] simple_input_text;
     643  } else {
     644    parsedkv = new ParsedKeyVal();
     645    parsedkv->parse_string(in_char_array);
     646  }
     647}
     648
    617649/** Parse the input file into the key value container.
    618650 *
     
    622654 * \param input input file name
    623655 * \param generic_input filename of generic input
     656 * \param in_char_array char array with input file's contents on return
     657 * \param use_simple_input whether the file contents is in simple format (1)
     658 *        or object-oriented (0)
    624659 */
    625660void parseInputfile(
     
    628663    struct OptionValues &values,
    629664    const char *&input,
    630     const char *&generic_input
     665    const char *&generic_input,
     666    char *&in_char_array,
     667    int &use_simple_input
    631668    )
    632669{
    633670  // read the input file on only node 0
    634   char *in_char_array;
    635671  if (grp->me() == 0) {
    636672    ifstream is(input);
     
    657693    }
    658694
    659   int use_simple_input;
    660695  if (generic_input && grp->me() == 0) {
    661696    MPQCIn mpqcin;
     
    666701  }
    667702  grp->bcast(use_simple_input);
    668 
    669   if (use_simple_input) {
    670     MPQCIn mpqcin;
    671     char *simple_input_text = mpqcin.parse_string(in_char_array);
    672     if (values.simple_input) {
    673       ExEnv::out0() << "Generated object-oriented input file:" << endl
    674                    << simple_input_text
    675                    << endl;
    676       exit(0);
    677     }
    678     parsedkv = new ParsedKeyVal();
    679     parsedkv->parse_string(simple_input_text);
    680     delete[] simple_input_text;
    681     }
    682   else {
    683     parsedkv = new ParsedKeyVal();
    684     parsedkv->parse_string(in_char_array);
    685     }
    686   delete[] in_char_array;
    687703}
    688704
     
    11741190  // parse input into keyvalue container
    11751191  Ref<ParsedKeyVal> parsedkv;
    1176   parseInputfile(grp, parsedkv, values, input, generic_input);
     1192  char *in_char_array = 0;
     1193  int use_simple_input;
     1194  parseInputfile(grp, parsedkv, values, input, generic_input, in_char_array, use_simple_input);
     1195  parseIntoKeyValue(parsedkv, values, in_char_array, use_simple_input);
     1196  delete[] in_char_array;
    11771197
    11781198  // prefix parsed values wit "mpqc"
Note: See TracChangeset for help on using the changeset viewer.