Skip to content

Commit

Permalink
--weather=filename & --idd=filename implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Monika Sharma committed Oct 10, 2014
1 parent 006cbc9 commit 27e7399
Showing 1 changed file with 47 additions and 43 deletions.
90 changes: 47 additions & 43 deletions src/EnergyPlus/CommandLineInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,33 @@ namespace CommandLineInterface{
return mdret;
}

std::string EqualsToSpace(std::string text)
{
std::replace(text.begin(), text.end(), '=', ' ');
return text;
}

int
ProcessArgs(int argc, const char * argv[])
{

std::string weatherEquals;
std::string weatherLongOption;
std::ifstream input;
std::istream* instream;
std::ifstream inputW, inputIDD;
std::istream* instreamW;
std::istream* instreamIDD;

for ( int i = 1; i < argc; ++i ) {
std::string inputArg( argv[ i ] );
if(inputArg.substr(0,9) == "--weather"){
weatherLongOption = inputArg.substr(0,9);
inputWeatherFileName = returnFileExtension(inputArg);
if(inputArg.substr(0,10) == "--weather="){
std::string weatherLongOption = EqualsToSpace(inputArg.substr(0,10));
argv[i] = weatherLongOption.c_str();
weatherEquals = weatherLongOption + "=";
inputWeatherFileName = returnFileExtension(inputArg);
}
}

if(weatherLongOption.empty())
weatherLongOption = "--weather=";
if(inputArg.substr(0,6) == "--idd="){
std::string iddLongOption = EqualsToSpace(inputArg.substr(0,6));
argv[i] = iddLongOption.c_str();
inputIddFileName = returnFileExtension(inputArg);
}
}

ezOptionParser opt;

Expand All @@ -186,12 +192,16 @@ namespace CommandLineInterface{

opt.add("", 0, 0, 0, "Display version information", "-v", "--version");

opt.add("in.idf", 0, 1, 0, "Input data file path (default in.idf)", "");
// opt.add("in.idf", 0, 1, 0, "Input data file path (default in.idf)", "");

opt.add("in.epw", 0, 1, 0, "Weather file path (default in.epw)", "-w", "--weather");

opt.add("in.epw", 0, 1, 0, "Weather file path (default in.epw)", "-w", "--weather", "--weather=");
opt.add("", 0, 0, 0, "Weather file path", "--weather ");

opt.add("Energy+.idd", 0, 1, 0, "Input data dictionary path (default Energy+.idd in executable directory)", "-i", "--idd");

opt.add("", 0, 0, 0, "Input data dictionary path", "--idd ");

opt.add("", 0, 1, 0, "Prefix for output files (default same as input file name)", "-p", "--prefix");

opt.add("", 0, 0, 0, "Run ReadVarsESO to generate time-series CSV", "-r", "--readvars");
Expand Down Expand Up @@ -221,23 +231,21 @@ namespace CommandLineInterface{
exePathName = returnDirPathName(exePath);

if(inputWeatherFileName.empty())
inputWeatherFileName = "in.epw";
inputWeatherFileName = "in.epw";

instreamW = &inputW;
inputW.open( inputWeatherFileName.c_str() );

instream = &input;
input.open( inputWeatherFileName.c_str() );
if(inputIddFileName.empty())
inputIddFileName = "Energy+.idd";

opt.get("-i")->getString(inputIddFileName);
instreamIDD = &inputIDD;
inputIDD.open( inputIddFileName.c_str() );

opt.get("-d")->getString(dirPathName);

opt.get("-ep")->getString(inputIMFFileName);

/////////// For weather filename only (in case needed) ////////////////
//weatherFileNameWextn = returnFileName(inputWeatherFileName);
//weatherDirPathName = returnDirPathName(inputWeatherFileName);
//std::string weatherFileNameOnly = weatherFileNameWextn.substr(0,weatherFileNameWextn.size()-4);
//////////////////////////////////////////////////////////////////////

readVarsValue = false;
if (opt.isSet("-r")){
readVarsValue = true;
Expand All @@ -264,7 +272,7 @@ namespace CommandLineInterface{
char resolved_path[100];
realpath(arg.c_str(), resolved_path);
std::string idfPath = std::string(resolved_path);
DisplayString(idfPath +" is not a valid path. \n" );
DisplayString("ERROR: "+ idfPath +" is not a valid path. \n" );
exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -309,7 +317,6 @@ namespace CommandLineInterface{
}

if(dirPathName[dirPathName.size()-1]!=pathChar){
// force trailing / so we can handle everything in loop
dirPathName+=pathChar;
}

Expand Down Expand Up @@ -367,23 +374,19 @@ namespace CommandLineInterface{
std::vector<std::string> badOptions;
if(!opt.gotExpected(badOptions)) {
for(int i=0; i < badOptions.size(); ++i) {
if(badOptions[i] != "-w"){
DisplayString("\nERROR: Unexpected number of arguments for option " + badOptions[i] + "\n");
DisplayString(usage);
ShowFatalError("\nERROR: Unexpected number of arguments for option " + badOptions[i] + "\n");
exit(EXIT_FAILURE);
}
}
}

if(!opt.gotRequired(badOptions)) {
for(int i=0; i < badOptions.size(); ++i) {
if(badOptions[i] != "-w"){
DisplayString("\nERROR: Missing required option " + badOptions[i] + "\n");
DisplayString(usage);
ShowFatalError("\nERROR: Missing required option " + badOptions[i] + "\n");
exit(EXIT_FAILURE);
}
}
}

Expand All @@ -405,21 +408,22 @@ namespace CommandLineInterface{

/* std::string ExpandObjects = "ExpandObjects";
std::string runExpandObjects = "./"+ExpandObjects;
if(expandObjValue)
if(expandObjValue) {
system(runExpandObjects.c_str());
std::string expandIdfFile = "expanded.idf";
bool expandIdfFileExist = fileExist(expandIdfFile);
if(expandIdfFileExist) {
std::string expidfFileName = outputFilePrefix + ".expidf";
std::ifstream src(expandIdfFile.c_str());
std::ofstream dst(expidfFileName.c_str());
dst << src.rdbuf();
remove(idfFileNameOnly.c_str());
link(expidfFileName.c_str(), idfFileNameOnly.c_str());
}
else
std::cout<<"ExpandObjects file does not exist. \n";
std::string expandIdfFile = "expanded.idf";
bool expandIdfFileExist = fileExist(expandIdfFile);
if(expandIdfFileExist) {
std::string expidfFileName = outputFilePrefix + ".expidf";
std::ifstream src(expandIdfFile.c_str());
std::ofstream dst(expidfFileName.c_str());
dst << src.rdbuf();
remove(idfFileNameOnly.c_str());
link(expidfFileName.c_str(), idfFileNameOnly.c_str());
}
else
std::cout<<"ExpandObjects file does not exist. \n";
}
bool imfFileExist = fileExist(inputIMFFileName);
std::string defaultIMFFileName = "in.imf";
Expand Down

2 comments on commit 27e7399

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1277852-CommandLineInterface (monika0603) - x86_64-MacOS-10.9-clang: Tests Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1277852-CommandLineInterface (monika0603) - x86_64-MacOS-10.9-clang-Debug: Tests Failed

Build Badge Test Badge

Please sign in to comment.