Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit 705566b3 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Initfile-parser extended

parent 694a35a3
......@@ -41,7 +41,10 @@ namespace AMDiS {
Zoltan_Initialize(argc, argv, &zoltanVersion);
#endif
#endif
Parameters::clearData();
Parameters::readArgv(argc, argv);
if (initFileName == "") {
TEST_EXIT(argc >= 2)("No init file!\n");
Parameters::init(string(argv[1]));
......
......@@ -92,20 +92,26 @@ namespace AMDiS {
template<typename T>
class DOFIndexed : public DOFIndexedBase
{
public:
typedef T value_type;
typedef DegreeOfFreedom size_type;
typedef value_type& reference;
typedef value_type const& const_reference;
public:
virtual ~DOFIndexed() {}
/// Returns iterator to the begin of container
virtual typename std::vector<T>::iterator begin() = 0;
virtual typename std::vector<value_type>::iterator begin() = 0;
/// Returns iterator to the end of container
virtual typename std::vector<T>::iterator end() = 0;
virtual typename std::vector<value_type>::iterator end() = 0;
/// Returns container element at index i
virtual T& operator[](DegreeOfFreedom i) = 0;
virtual reference operator[](size_type i) = 0;
/// Returns container element at index i
virtual const T& operator[](DegreeOfFreedom i) const = 0;
virtual const_reference operator[](size_type i) const = 0;
};
void mv(MatrixTranspose transpose,
......
......@@ -57,6 +57,7 @@
#endif
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>
#include "boost/tuple/tuple.hpp"
#include "AMDiS_fwd.h"
......@@ -123,6 +124,20 @@ namespace AMDiS {
}
};
/// check for file existence
inline bool file_exists(const std::string filename)
{
return access(filename.c_str(), F_OK) == 0;
};
/// trim std::string
inline std::string trim(const std::string& oldStr)
{
std::string swap(oldStr);
boost::algorithm::trim(swap);
return swap;
};
// ===== some simple template functions ======================================
template<typename T> inline T abs(T a)
......
......@@ -39,7 +39,6 @@ namespace AMDiS {
void Initfile::init(std::string in)
{
initIntern();
singlett->clear();
fn_include_list.clear();
singlett->read(in);
singlett->getInternalParameters();
......@@ -84,8 +83,8 @@ namespace AMDiS {
Parser parser(sw);
// add parameter to map after variable replacement
std::string paramName = variableReplacement(InitfileInternal::trim(parser.name));
std::string paramValue = variableReplacement(InitfileInternal::trim(parser.value));
std::string paramName = variableReplacement(trim(parser.name));
std::string paramValue = variableReplacement(trim(parser.value));
paramValue = variableEvaluation(paramValue);
operator[](paramName) = paramValue;
......@@ -164,7 +163,7 @@ namespace AMDiS {
std::string replaceName = inputSwap.substr(posVar , posVarEnd - posVar + (posVarBegin - posVar));
inputSwap.replace(inputSwap.find(replaceName), replaceName.length(), varParam);
posVar = inputSwap.find_first_of('$',posVarEnd);
posVar = inputSwap.find_first_of('$',posVarBegin);
}
return inputSwap;
......@@ -174,16 +173,11 @@ namespace AMDiS {
{
std::string whitespaces = " \t\r\f";
std::string inputSwap = input;
size_t posVar = inputSwap.find_first_of('$');
size_t posVar = inputSwap.find("$(");
while (posVar != string::npos) {
size_t posVarBegin, posVarEnd;
if(inputSwap[posVar+1] == '(') { // $(expr)
posVarEnd = inputSwap.find_first_of(')',posVar + 2);
posVarBegin = posVar + 1;
} else {
posVar = inputSwap.find_first_of('$',posVar+1);
continue;
}
posVarEnd = inputSwap.find_first_of(')',posVar + 2);
posVarBegin = posVar + 1;
std::string varName = inputSwap.substr(posVarBegin + 1 , posVarEnd - posVarBegin - 1);
double value = 0.0;
......@@ -193,7 +187,7 @@ namespace AMDiS {
std::string replaceName = inputSwap.substr(posVar , posVarEnd - posVar + (posVarBegin - posVar));
inputSwap.replace(inputSwap.find(replaceName), replaceName.length(), varName);
posVar = inputSwap.find_first_of('$');
posVar = inputSwap.find("$(",posVarBegin);
}
return inputSwap;
......@@ -201,11 +195,36 @@ namespace AMDiS {
void Initfile::readArgv(int argc, char **argv)
{
initIntern();
for (int i = 0; i < argc; i++) {
if (strcmp("-rs", argv[i]) == 0) {
std::string input(argv[i + 1]);
add("argv->rs", input, 0);
}
else if (strcmp("-parameters", argv[i]) == 0) {
std::string input(argv[i + 1]);
int found = input.find_first_of(';');
std::vector<std::string> parameters;
while (found != static_cast<int>(std::string::npos)) {
if (found > 2) {
parameters.push_back(input.substr(0, found).c_str());
}
input = input.substr(found + 1);
found = input.find_first_of(';');
}
if (input.length() > 2)
parameters.push_back(input.c_str());
for (size_t i = 0; i < parameters.size(); i++) {
int found = input.find_first_of(':');
if (found != static_cast<int>(std::string::npos)) {
std::string value = input.substr(found+1);
set(input.substr(0, found), value, 0);
}
}
}
}
}
......
......@@ -24,7 +24,6 @@
#include <typeinfo>
#include "FixVec.h"
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
......@@ -132,16 +131,7 @@ namespace AMDiS {
">\nParser message: '" + m + "'")
{}
};
/// trim std::string
inline std::string trim(const std::string& oldStr)
{
std::string swap(oldStr);
boost::algorithm::trim(swap);
return swap;
}
/// return the delimiter or throw an exception if there is no known
/// delimiter in value
......
......@@ -199,7 +199,7 @@ namespace AMDiS {
{
WorldVector<DOFVector<double>*> valuesWV;
for (int i =0 ; i < valuesWV.getSize(); i++)
valuesWV[i] = new DOFVector<double>(values->getFeSpace(), "valuesWV_i");
valuesWV[i] = new DOFVector<double>(values->getFeSpace(), "values["+boost::lexical_cast<std::string>(i)+"]");
transform(values, &valuesWV);
writeFile(valuesWV, filename, writeParallel);
for (int i = 0; i < valuesWV.getSize(); i++)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment