Commit 6a6c7fb2 authored by frey_m's avatar frey_m
Browse files

Closes #232

parent 9cf9b5d2
......@@ -147,6 +147,24 @@ bool OpalSimulation::hasResultsAvailable() {
}
void OpalSimulation::createSymlink_m(const std::string& path) {
struct dirent **files;
int count = scandir(path.c_str(), &files, 0, alphasort);
for(int i=0; i<count; i++) {
if (files[i]->d_name == std::string(".") ||
files[i]->d_name == std::string("..")) continue;
std::string source = path + "/" + files[i]->d_name;
std::string target = simulationDirName_ + '/' + files[i]->d_name;
int err = symlink(source.c_str(), target.c_str());
if (err != 0) {
throw OptPilotException("OpalSimulation::createSymlink()",
"Cannot create symbolic link '" + source + "' to " +
target);
}
}
}
void OpalSimulation::setupSimulation() {
namespace fs = boost::filesystem;
......@@ -170,31 +188,18 @@ void OpalSimulation::setupSimulation() {
simulationName_ + ".in";
gs_->writeInputFile(infile);
// linking fieldmaps
// linking fieldmaps + distributions
if(getenv("FIELDMAPS") == NULL) {
throw OptPilotException("OpalSimulation::OpalSimulation",
"Environment variable FIELDMAPS not defined!");
}
std::string fieldmapPath = getenv("FIELDMAPS");
this->createSymlink_m(fieldmapPath);
struct dirent **files;
int count = scandir(fieldmapPath.c_str(), &files, 0, alphasort);
for(int i=0; i<count; i++) {
if (files[i]->d_name == std::string(".") ||
files[i]->d_name == std::string("..")) continue;
std::string source = fieldmapPath + "/" + files[i]->d_name;
std::string target = simulationDirName_ + '/' + files[i]->d_name;
int err = symlink(source.c_str(), target.c_str());
if (err != 0) {
// FIXME properly handle error
std::cout << "Cannot symlink fieldmap "
<< source.c_str() << " to "
<< target.c_str() << " error no " << err << std::endl;
std::cout << "fieldmapPath " << fieldmapPath << " i= " << i << std::endl;
std::cout << "target " << simulationDirName_ + '/' + files[i]->d_name << std::endl;
}
if ( getenv("DISTRIBUTIONS") != NULL ) {
std::string distPath = getenv("DISTRIBUTIONS");
this->createSymlink_m(distPath);
}
}
......@@ -504,4 +509,4 @@ void OpalSimulation::cleanUp() {
} catch(...) {
std::cout << "Can't remove directory '" << simulationDirName_ << "'" << std::endl;
}
}
\ No newline at end of file
}
......@@ -103,6 +103,10 @@ private:
/// check if we already have simulated the current set of design vars
bool hasResultsAvailable();
/// create symbolic links
void createSymlink_m(const std::string& path);
/// create directories, input files, fieldmaps...
void setupSimulation();
......@@ -117,4 +121,4 @@ private:
void restoreOut();
};
#endif
\ No newline at end of file
#endif
......@@ -73,6 +73,7 @@ namespace {
SIMTMPDIR,
TEMPLATEDIR,
FIELDMAPDIR,
DISTDIR,
SIZE
};
}
......@@ -132,7 +133,8 @@ OptimizeCmd::OptimizeCmd():
("TEMPLATEDIR", "Directory where templates are stored");
itsAttr[FIELDMAPDIR] = Attributes::makeString
("FIELDMAPDIR", "Directory where field maps are stored");
itsAttr[DISTDIR] = Attributes::makeString
("DISTDIR", "Directory where distributions are stored", "");
registerOwnership(AttributeHandler::COMMAND);
}
......@@ -314,6 +316,18 @@ void OptimizeCmd::execute() {
setenv("FIELDMAPS", dir.c_str(), 1);
}
if (Attributes::getString(itsAttr[DISTDIR]) != "") {
fs::path dir(Attributes::getString(itsAttr[DISTDIR]));
if (dir.is_relative()) {
fs::path path = fs::path(std::string(getenv("PWD")));
path /= dir;
dir = path;
}
setenv("DISTRIBUTIONS", dir.c_str(), 1);
}
*gmsg << endl;
for (size_t i = 0; i < arguments.size(); ++ i) {
argv.push_back(const_cast<char*>(arguments[i].c_str()));
......
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