Skip to content
Snippets Groups Projects
Commit 14ae585a authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

read vector-parameters from init-files by %E,%F,%G or %D

parent 8c586a2d
No related branches found
No related tags found
No related merge requests found
...@@ -369,6 +369,12 @@ namespace AMDiS { ...@@ -369,6 +369,12 @@ namespace AMDiS {
return nTimesteps; return nTimesteps;
} }
/// Sets \ref nTimesteps.
inline void setNumberOfTimesteps(int num)
{
nTimesteps = num;
}
/// Increments \ref timestepNumber by 1; /// Increments \ref timestepNumber by 1;
inline void incTimestepNumber() inline void incTimestepNumber()
{ {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
namespace AMDiS { namespace AMDiS {
const char Parameters::comment='%'; const char Parameters::comment='%';
const std::string Parameters::separators=",; ";
Parameters* Parameters::singlett = NULL; Parameters* Parameters::singlett = NULL;
const char* Parameters::param_call_fct = NULL; const char* Parameters::param_call_fct = NULL;
const char* Parameters::param_call_file = NULL; const char* Parameters::param_call_file = NULL;
...@@ -158,6 +159,68 @@ namespace AMDiS { ...@@ -158,6 +159,68 @@ namespace AMDiS {
(*vecVal)[ind] = atof(sstr.c_str()); (*vecVal)[ind] = atof(sstr.c_str());
} }
break; 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 '*': case '*':
break; break;
default: default:
......
...@@ -122,7 +122,8 @@ namespace AMDiS { ...@@ -122,7 +122,8 @@ namespace AMDiS {
* The return value is the number of converted arguments. * The return value is the number of converted arguments.
* *
* The control string must only contain the following characters used as * 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 * 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 * 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: * string the next word of the parameter string is converted as follows:
...@@ -143,11 +144,21 @@ namespace AMDiS { ...@@ -143,11 +144,21 @@ namespace AMDiS {
* the subject sequence of the atoi() function; the corresponding * the subject sequence of the atoi() function; the corresponding
* argument should be a pointer to an int variable; * 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&lt;int&gt; 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() * format is the same as expected for the subject string of the atof()
* function; the corresponding argument should be a pointer to a double * function; the corresponding argument should be a pointer to a double
* variable; * variable;
* *
* -\%E,\%F,\%G: matches a list of %e,%f or %g types; the corresponding argument
* should be a pointer to a std::vector&lt;double&gt; 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 * -\%U: matches an unsigned decimal integer in the range [0,255], whose
* format is the same as expected for the subject sequence of the * format is the same as expected for the subject sequence of the
* atoi() function; the corresponding argument should be a pointer to * atoi() function; the corresponding argument should be a pointer to
...@@ -279,6 +290,7 @@ namespace AMDiS { ...@@ -279,6 +290,7 @@ namespace AMDiS {
}; };
static const char comment; static const char comment;
static const std::string separators;
std::string buffer; std::string buffer;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment