diff --git a/AMDiS/src/AdaptInfo.h b/AMDiS/src/AdaptInfo.h index ab86c4581391a5368efcc881c58e4e578e5b02da..0c10da50e8532946190d31b7c3963ccd4f517647 100644 --- a/AMDiS/src/AdaptInfo.h +++ b/AMDiS/src/AdaptInfo.h @@ -369,6 +369,12 @@ namespace AMDiS { return nTimesteps; } + /// Sets \ref nTimesteps. + inline void setNumberOfTimesteps(int num) + { + nTimesteps = num; + } + /// Increments \ref timestepNumber by 1; inline void incTimestepNumber() { diff --git a/AMDiS/src/Parameters.cc b/AMDiS/src/Parameters.cc index 92a1149e5e32329157bc5e06263e72c6883fcee1..6d30383675df895d7275f05980a82d7a80638e84 100644 --- a/AMDiS/src/Parameters.cc +++ b/AMDiS/src/Parameters.cc @@ -13,6 +13,7 @@ namespace AMDiS { const char Parameters::comment='%'; + const std::string Parameters::separators=",; "; Parameters* Parameters::singlett = NULL; const char* Parameters::param_call_fct = NULL; const char* Parameters::param_call_file = NULL; @@ -158,6 +159,68 @@ namespace AMDiS { (*vecVal)[ind] = atof(sstr.c_str()); } break; + case 'E': // list of double values, example parameter: {a,b,c,d,e} + case 'F': + case 'G': + { + std::vector<double> *vecVal = va_arg(arg, std::vector<double> *); + std::string sstr = std::string(word); + + std::string brackets1 = "[{(", brackets2 = "]})"; + int bracketIdx1 = sstr.find_first_of(brackets1); + int bracket = brackets1.find_first_of(sstr[bracketIdx1]); + int bracketIdx2 = sstr.find_first_of(brackets2[bracket]); + TEST_EXIT(bracket>=0 && bracketIdx1>=0 && bracketIdx2>=0 && bracketIdx1<bracketIdx2) + ("no enclosing brackets found in '%s' \n",key.data()); + sstr = sstr.substr(bracketIdx1+1, bracketIdx2-bracketIdx1); + + int found = sstr.find_first_of(separators); + std::string seperator; + seperator = sstr[found]; + + while (found != static_cast<int>(std::string::npos)) { + if (found > 0) { + vecVal->push_back(atof(sstr.substr(0, found).c_str())); + } + sstr = sstr.substr(found + 1); + found = sstr.find_first_of(seperator); + } + if (sstr.length() > 0) + vecVal->push_back(atof(sstr.c_str())); + if(vecVal->size()==0) + WARNING("no values in parameter vector!\n"); + } + break; + case 'D': // list of int values, example parameter: {a,b,c,d,e} + { + std::vector<int> *vecVal = va_arg(arg, std::vector<int> *); + std::string sstr = std::string(word); + + std::string brackets1 = "[{(", brackets2 = "]})"; + int bracketIdx1 = sstr.find_first_of(brackets1); + int bracket = brackets1.find_first_of(sstr[bracketIdx1]); + int bracketIdx2 = sstr.find_first_of(brackets2[bracket]); + TEST_EXIT(bracket>=0 && bracketIdx1>=0 && bracketIdx2>=0 && bracketIdx1<bracketIdx2) + ("no enclosing brackets found in '%s' \n",key.data()); + sstr = sstr.substr(bracketIdx1+1, bracketIdx2-bracketIdx1); + + int found = sstr.find_first_of(separators); + std::string seperator; + seperator = sstr[found]; + + while (found != static_cast<int>(std::string::npos)) { + if (found > 0) { + vecVal->push_back(atoi(sstr.substr(0, found).c_str())); + } + sstr = sstr.substr(found + 1); + found = sstr.find_first_of(seperator); + } + if (sstr.length() > 0) + vecVal->push_back(atoi(sstr.c_str())); + if(vecVal->size()==0) + WARNING("no values in parameter vector!\n"); + } + break; case '*': break; default: diff --git a/AMDiS/src/Parameters.h b/AMDiS/src/Parameters.h index e331285bf43498600a5657b5fc604c1d606d891a..575cfb641e026679c499dc7561e3ae97d041c2ed 100644 --- a/AMDiS/src/Parameters.h +++ b/AMDiS/src/Parameters.h @@ -122,7 +122,8 @@ namespace AMDiS { * The return value is the number of converted arguments. * * The control string must only contain the following characters used as - * conversion specification: \%s, \%c, \%d, \%e, \%f, \%g, \%U, \%S, or \%*. + * conversion specification: \%s, \%c, \%d, \%D, \%e, \%E, \%f, \%F, \%g, \%G, + * \%U, \%S, or \%*. * All other characters are ignored. In contrast to scanf(), a numerical * value for a field width is not allowed. For each element of the control * string the next word of the parameter string is converted as follows: @@ -143,11 +144,21 @@ namespace AMDiS { * the subject sequence of the atoi() function; the corresponding * argument should be a pointer to an int variable; * - * -\%e,%f,%g: matches an optionally signed floating point number, whose + * -\%D: matches a list of %d types; the corresponding argument should + * be a pointer to a std::vector<int> variable; the + * parameter should be enclosed in brackets, like {...}, [...] or (...) + * and the values separated by comma, semicolon or space; + * + * -\%e,\%f,\%g: matches an optionally signed floating point number, whose * format is the same as expected for the subject string of the atof() * function; the corresponding argument should be a pointer to a double * variable; * + * -\%E,\%F,\%G: matches a list of %e,%f or %g types; the corresponding argument + * should be a pointer to a std::vector<double> variable; the + * parameter should be enclosed in brackets, like {...}, [...] or (...) + * and the values separated by comma, semicolon or space; + * * -\%U: matches an unsigned decimal integer in the range [0,255], whose * format is the same as expected for the subject sequence of the * atoi() function; the corresponding argument should be a pointer to @@ -279,6 +290,7 @@ namespace AMDiS { }; static const char comment; + static const std::string separators; std::string buffer;