Skip to content

Commit

Permalink
Only --weather=filename implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Monika Sharma committed Oct 9, 2014
1 parent d41108c commit 006cbc9
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 24 deletions.
147 changes: 128 additions & 19 deletions src/EnergyPlus/CommandLineInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
#include <unistd.h>
#include <exception>

// CLI Headers
#include <ezOptionParser.hpp>
//#include <io.cpccFileSystemMini.h>

// Project headers
#include <CommandLineInterface.hh>
Expand Down Expand Up @@ -87,9 +84,19 @@ namespace CommandLineInterface{
std::string idfFileNameOnly;
std::string exePathName;
std::string prefixOutName;
std::string inputIMFFileName;

bool readVarsValue;
bool prefixValue;
bool expandObjValue;
bool EPMacroValue;


bool fileExist(const std::string& filename)
{
std::ifstream infile(filename);
return infile.good();
}

std::string
returnFileName( std::string const& filename )
Expand All @@ -113,7 +120,7 @@ namespace CommandLineInterface{
std::string ext = "";

for(int i=0; i<filename.length(); i++){
if(filename[i] == '.'){
if(filename[i] == '.' || filename[i] == '=' || filename[i] == ' '){
for(int j = i+1; j<filename.length(); j++){
ext += filename[j];
}
Expand Down Expand Up @@ -149,7 +156,25 @@ namespace CommandLineInterface{
int
ProcessArgs(int argc, const char * argv[])
{
std::locale::global(std::locale(""));

std::string weatherEquals;
std::string weatherLongOption;
std::ifstream input;
std::istream* instream;

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);
argv[i] = weatherLongOption.c_str();
weatherEquals = weatherLongOption + "=";
}
}

if(weatherLongOption.empty())
weatherLongOption = "--weather=";

ezOptionParser opt;

opt.overview = VerString;
Expand All @@ -163,43 +188,51 @@ namespace CommandLineInterface{

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("Energy+.idd", 0, 1, 0, "Input data dictionary path (default Energy+.idd in executable directory)", "-i", "--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");

opt.add("", 0, 0, 0, "Run ExpandObjects", "-e", "--expandObj");

opt.add("", 0, 1, 0, "Run EPMacro", "-ep", "--epMacro");

opt.add("", 0, 1, 0, "Output directory (default current working directory)", "-d", "--dir");

// Parse arguments
opt.parse(argc, argv);

// print arguments parsed (useful for debugging)

/*std::string pretty;
opt.prettyPrint(pretty);
std::cout << pretty << std::endl;*/
//std::string pretty;
//opt.prettyPrint(pretty);
//std::cout << pretty << std::endl;

std::string usage, idfFileNameWextn, idfDirPathName;
std::string weatherFileNameWextn, weatherDirPathName;

opt.getUsage(usage);

//To check the path of EnergyPlus
char executable_path[100];
realpath(argv[0], executable_path);
std::string exePath = std::string(executable_path);
exePathName = returnDirPathName(exePath);
char executable_path[100];
realpath(argv[0], executable_path);
std::string exePath = std::string(executable_path);
exePathName = returnDirPathName(exePath);

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

opt.get("-w")->getString(inputWeatherFileName);
instream = &input;
input.open( inputWeatherFileName.c_str() );

opt.get("-i")->getString(inputIddFileName);

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

/////////// For weather filename only (incase needed) ////////////////
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);
Expand Down Expand Up @@ -259,6 +292,13 @@ namespace CommandLineInterface{
if(opt.isSet("-p"))
prefixValue = true;

expandObjValue = false;
if(opt.isSet("-e"))
expandObjValue = true;

EPMacroValue = false;
if(opt.isSet("-ep"))
EPMacroValue = true;

if (opt.isSet("-d") ){
struct stat sb = {0};
Expand Down Expand Up @@ -327,20 +367,24 @@ 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);
}
}
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);
}
}
exit(EXIT_FAILURE);
}

if(opt.firstArgs.size() > 1 || opt.unknownArgs.size() > 0){
Expand All @@ -358,6 +402,71 @@ namespace CommandLineInterface{
}
exit(EXIT_FAILURE);
}

/* std::string ExpandObjects = "ExpandObjects";
std::string runExpandObjects = "./"+ExpandObjects;
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";
bool imfFileExist = fileExist(inputIMFFileName);
std::string defaultIMFFileName = "in.imf";
if(imfFileExist)
link(inputIMFFileName.c_str(), defaultIMFFileName.c_str());
std::string outIDFFileName = "out.idf";
remove(outIDFFileName.c_str());
std::string outAuditFileName = "audit.out";
remove(outAuditFileName.c_str());
std::string epmdetFileName = outputFilePrefix+".epmdet";
remove(epmdetFileName.c_str());
std::string epmidfFileName = outputFilePrefix+".epmidf";
remove(epmidfFileName.c_str());
std::string EPMacroexe = "EPMacro";
std::string runEPMacro = "./"+EPMacroexe;
if(EPMacroValue){
system(runEPMacro.c_str());
std::cout<<"Running EPMacro...\n";
bool AuditFileExist = fileExist(outAuditFileName);
if(AuditFileExist){
std::string epmdetFileName = outputFilePrefix + ".epmdet";
std::ifstream src(outAuditFileName.c_str());
std::ofstream dst(epmdetFileName.c_str());
dst << src.rdbuf();
}
bool outFileExist = fileExist(outIDFFileName);
if(outFileExist){
std::string epmidfFileName = outputFilePrefix + ".epmidf";
std::ifstream src(outIDFFileName.c_str());
std::ofstream dst(epmidfFileName.c_str());
dst << src.rdbuf();
link(epmidfFileName.c_str(), idfFileNameOnly.c_str());
DisplayString("Input file: " + inputIMFFileName + "\n");
}
else{
ShowFatalError("EPMacro did not produce "+ outIDFFileName + "with "+ inputIMFFileName +"\n");
exit(EXIT_FAILURE);
}
}*/



return 0;
}
} //namespace options
Expand Down
3 changes: 3 additions & 0 deletions src/EnergyPlus/CommandLineInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ namespace CommandLineInterface {
extern std::string dirPathName;
extern std::string exePathName;
extern std::string prefixOutName;
extern std::string inputIMFFileName;

extern bool readVarsValue;
extern bool prefixValue;
extern bool expandObjValue;
extern bool EPMacroValue;

// Process command line arguments
int
Expand Down
9 changes: 4 additions & 5 deletions src/EnergyPlus/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <SimulationManager.hh>
#include <UtilityRoutines.hh>


int
main(int argc, const char * argv[])
{
Expand Down Expand Up @@ -432,13 +431,13 @@ main(int argc, const char * argv[])
nfile.close();

std::string ReadVars = "ReadVarsESO";
std::string Total = "./"+ReadVars+" "+RVIfile+" unlimited";
std::string Total1 = "./"+ReadVars+" "+MVIfile+" unlimited";
std::string ReadVarsRVI = "./"+ReadVars+" "+RVIfile+" unlimited";
std::string ReadVarsMVI = "./"+ReadVars+" "+MVIfile+" unlimited";


if(readVarsValue) {
system(Total.c_str());
system(Total1.c_str());
system(ReadVarsRVI.c_str());
system(ReadVarsMVI.c_str());
}

EndEnergyPlus();
Expand Down

4 comments on commit 006cbc9

@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

@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) - i386-Windows-7-VisualStudio-12: Build 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) - Win64-Windows-7-VisualStudio-12: Build Failed

Build Badge Test Badge

Please sign in to comment.