Commit 9eb8ad95 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Small code refactoring.

parent a10991dc
...@@ -507,73 +507,16 @@ namespace AMDiS { ...@@ -507,73 +507,16 @@ namespace AMDiS {
singlett->read(fn); singlett->read(fn);
} else { } else {
singlett->inputFile.open(fn.data(), std::ios::in); singlett->inputFile.open(fn.data(), std::ios::in);
if (!(singlett->inputFile.rdstate())) { if (!(singlett->inputFile.rdstate())) {
ERROR("can not read from file %s\n", fn.data()); ERROR("can not read from file %s\n", fn.data());
return; return;
} }
singlett->inputFile.close(); singlett->inputFile.close();
time(&act_time); ERROR("no cpp available; reading file %s without help of cpp\n", fn.c_str());
if (sys_test("test -w", "/tmp")) { /* you may write to /tmp */ init(p, fn);
file = fn.substr(fn.find_last_of("/\\"));
tmp_file << "/tmp/"<<file<< ".cpp"; return;
if (sys_test("test -f", tmp_file.str())) { /* file exists :-( */
tmp_file.freeze(false);
tmp_file<< "."<< static_cast<int>( act_time);
if (sys_test("test -f", tmp_file.str())) /* file exists :-( */
*(tmp_file.str()) = '\0';
}
}
if (*(tmp_file.str()) == '\0')
if (sys_test("test -f", tmp_file.str()+5))
*(tmp_file.str()) = '\0';
if (*(tmp_file.str())!='\0' && (outFile.open(tmp_file.str()))) {
outFile.close();
} else {
ERROR("could not open temporary file for CPP\n");
ERROR("can not write to /tmp and files %s.cpp and\n", fn);
ERROR_EXIT("%s.cpp.%d either exist or are not writable\n",
fn, act_time);
}
tmp_file.freeze(false);
cpp_flags<< "-DDIM="<<DIM<<" -DDIM_OF_WORLD="<<Global::getGeo(WORLD);
if (flags)
cpp_flags << flags;
call_cpp << CPP <<" "<<cpp_flags<<" "<<fn<< " > "<<tmp_file;
/****************************************************************************/
/* invoke cpp: */
/****************************************************************************/
val = system(call_cpp.str());
if (val) {
MSG("val = %d\n", val);
ERROR("error during cpp call; reading file %s without help of cpp\n", fn);
WAIT;
init(p, fn);
return;
}
/**********************************************************************/
/* read parameters from temp file */
/**********************************************************************/
cpp_read = true;
singlett->read(tmp_file);
cpp_read = false;
/**********************************************************************/
/* remove temp file */
/**********************************************************************/
sprintf(call_cpp.str(), "/bin/rm %s", tmp_file.str());
val = system(call_cpp.str());
call_cpp.freeze(false);
tmp_file.freeze(false);
} }
val = 10; // default for level of information val = 10; // default for level of information
...@@ -591,7 +534,7 @@ namespace AMDiS { ...@@ -591,7 +534,7 @@ namespace AMDiS {
if (!singlett->msgInfo) if (!singlett->msgInfo)
singlett->paramInfo = 0; singlett->paramInfo = 0;
if (p && singlett->msgInfo) if (p && singlett->msgInfo)
printParameters(); printParameters();
Global::init(); Global::init();
...@@ -644,8 +587,6 @@ namespace AMDiS { ...@@ -644,8 +587,6 @@ namespace AMDiS {
{ {
FUNCNAME("Parameters::addGlobalParameter()"); FUNCNAME("Parameters::addGlobalParameter()");
int val;
initIntern(); initIntern();
if (key.size() == 0 || par.size() == 0) if (key.size() == 0 || par.size() == 0)
...@@ -653,7 +594,7 @@ namespace AMDiS { ...@@ -653,7 +594,7 @@ namespace AMDiS {
singlett->addParam(key, par, std::string(file), line, fname); singlett->addParam(key, par, std::string(file), line, fname);
val = 10; // defualt for level of information int val = 10; // defualt for level of information
getGlobalParameter(0, "level of information", "%d", &val); getGlobalParameter(0, "level of information", "%d", &val);
singlett->msgInfo = val; singlett->msgInfo = val;
...@@ -683,13 +624,12 @@ namespace AMDiS { ...@@ -683,13 +624,12 @@ namespace AMDiS {
return NULL; return NULL;
int wb2 = s->find_first_of(" "); int wb2 = s->find_first_of(" ");
if (wb2 == static_cast<int>(std::string::npos)) { if (wb2 == static_cast<int>(std::string::npos))
wb2 = s->length(); wb2 = s->length();
}
s->copy(Val, wb2 - wb1, wb1);
s->copy(Val, wb2-wb1, wb1);
Val[wb2-wb1] = '\0'; Val[wb2 - wb1] = '\0';
return Val; return Val;
} }
...@@ -702,7 +642,7 @@ namespace AMDiS { ...@@ -702,7 +642,7 @@ namespace AMDiS {
initIntern(); initIntern();
fp.open(file.data(), std::ios::out); fp.open(file.data(), std::ios::out);
if (0 != fp.rdstate()) if (0 != fp.rdstate())
return; return;
for (it = singlett->allParam.begin(); it !=singlett->allParam.end(); it++) { for (it = singlett->allParam.begin(); it !=singlett->allParam.end(); it++) {
......
Supports Markdown
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