-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix file not found output message #8324
Changes from 19 commits
c4f656d
80e4d8f
2ab0ac8
22126fc
578d433
8f6e5ea
8a3db61
75cd34d
e91271b
2f839eb
31a59c4
631eb86
11911ee
62d43df
f04d3a3
7d82651
b0ed48c
296a9b9
5438bb1
4a93d7e
f1bcbbd
fbdcded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1750,9 +1750,13 @@ namespace CurveManager { | |
std::size_t rowNum = indVarInstance.at("external_file_starting_row_number").get<std::size_t>() - 1; | ||
|
||
if (!state.dataCurveManager->btwxtManager.tableFiles.count(filePath)) { | ||
state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, TableFile{state, filePath}); | ||
TableFile tableFile; | ||
ErrorsFound |= tableFile.load(state, filePath); | ||
state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, tableFile); | ||
} | ||
|
||
if (ErrorsFound) continue; // Unable to load file so continue on to see if there are other errors before fataling | ||
|
||
axis = state.dataCurveManager->btwxtManager.tableFiles[filePath].getArray(state, {colNum, rowNum}); | ||
|
||
// remove NANs | ||
|
@@ -1940,10 +1944,15 @@ namespace CurveManager { | |
std::size_t colNum = fields.at("external_file_column_number").get<std::size_t>() - 1; | ||
std::size_t rowNum = fields.at("external_file_starting_row_number").get<std::size_t>() - 1; | ||
|
||
|
||
if (!state.dataCurveManager->btwxtManager.tableFiles.count(filePath)) { | ||
state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, TableFile{state, filePath}); | ||
TableFile tableFile; | ||
ErrorsFound |= tableFile.load(state, filePath); | ||
state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, tableFile); | ||
} | ||
|
||
if (ErrorsFound) continue; // Unable to load file so continue on to see if there are other errors before fataling | ||
|
||
lookupValues = state.dataCurveManager->btwxtManager.tableFiles[filePath].getArray(state, {colNum, rowNum}); | ||
|
||
// remove NANs | ||
|
@@ -2040,19 +2049,15 @@ namespace CurveManager { | |
tableFiles.clear(); | ||
} | ||
|
||
TableFile::TableFile(EnergyPlusData &state, std::string path) | ||
{ | ||
load(state, path); | ||
} | ||
|
||
void TableFile::load(EnergyPlusData &state, std::string path) | ||
bool TableFile::load(EnergyPlusData &state, std::string path) | ||
{ | ||
filePath = path; | ||
bool fileFound; | ||
std::string fullPath; | ||
DataSystemVariables::CheckForActualFileName(state, path, fileFound, fullPath); | ||
if (!fileFound) { | ||
ShowFatalError(state, "File \"" + filePath + "\" : File not found."); | ||
std::string contextString = "CurveManager::TableFile::load: "; | ||
DataSystemVariables::CheckForActualFileName(state, path, fileFound, fullPath, contextString); | ||
if(!fileFound){ | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was kind of thinking of it as an error code return where |
||
} | ||
std::ifstream file(fullPath); | ||
std::string line(""); | ||
|
@@ -2086,6 +2091,7 @@ namespace CurveManager { | |
++colNum; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
std::vector<double>& TableFile::getArray(EnergyPlusData &state, std::pair<std::size_t, std::size_t> colAndRow) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,9 @@ | |
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
|
||
//C++ Headers | ||
#include <utility> | ||
|
||
// ObjexxFCL Headers | ||
#include <ObjexxFCL/environment.hh> | ||
#include <ObjexxFCL/string.functions.hh> | ||
|
@@ -200,7 +203,8 @@ namespace DataSystemVariables { | |
void CheckForActualFileName(EnergyPlusData &state, | ||
std::string const &originalInputFileName, // name as input for object | ||
bool &FileFound, // Set to true if file found and is in CheckedFileName | ||
std::string &CheckedFileName // Blank if not found. | ||
std::string &CheckedFileName, // Blank if not found. | ||
const std::string contextString // | ||
) | ||
{ | ||
|
||
|
@@ -215,26 +219,11 @@ namespace DataSystemVariables { | |
// be accurate. This searches a few folders (CurrentWorkingFolder, Program folder) to see | ||
// if the file can be found. (It may have been input with full path so that is checked first.) | ||
|
||
// METHODOLOGY EMPLOYED: | ||
// na | ||
|
||
// REFERENCES: | ||
// na | ||
|
||
// USE STATEMENTS: | ||
// na | ||
|
||
// Locals | ||
// SUBROUTINE ARGUMENT DEFINITIONS: | ||
|
||
// SUBROUTINE PARAMETER DEFINITIONS: | ||
|
||
// INTERFACE BLOCK SPECIFICATIONS: | ||
// na | ||
|
||
// DERIVED TYPE DEFINITIONS: | ||
// na | ||
|
||
// SUBROUTINE LOCAL VARIABLE DECLARATIONS: | ||
std::string InputFileName; // save for changing out path characters | ||
std::string::size_type pos; | ||
|
@@ -251,81 +240,51 @@ namespace DataSystemVariables { | |
firstTime = false; | ||
} | ||
|
||
|
||
FileFound = false; | ||
CheckedFileName.clear(); | ||
InputFileName = originalInputFileName; | ||
makeNativePath(InputFileName); | ||
|
||
if (FileSystem::fileExists(InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (user input)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (user input)", getAbsolutePath(InputFileName)); | ||
} | ||
|
||
// Look relative to input file path | ||
if (FileSystem::fileExists(DataStringGlobals::inputDirPathName + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = DataStringGlobals::inputDirPathName + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (input file)", getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)); | ||
} | ||
|
||
// Look relative to input path | ||
if (FileSystem::fileExists(envinputpath1 + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envinputpath1 + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (epin)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (epin)", getAbsolutePath(envinputpath1 + InputFileName)); | ||
} | ||
|
||
// Look relative to input path | ||
if (FileSystem::fileExists(envinputpath2 + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envinputpath2 + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (input_path)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (input_path)", getAbsolutePath(envinputpath2 + InputFileName)); | ||
} | ||
|
||
// Look relative to program path | ||
if (FileSystem::fileExists(envprogrampath + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = envprogrampath + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (program_path)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (program_path)", getAbsolutePath(envprogrampath + InputFileName)); | ||
} | ||
|
||
if (!TestAllPaths) return; | ||
|
||
// Look relative to current working folder | ||
if (FileSystem::fileExists(CurrentWorkingFolder + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = CurrentWorkingFolder + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (CWF)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (CWF)", getAbsolutePath(CurrentWorkingFolder + InputFileName)); | ||
std::vector<std::pair<std::string, std::string>> pathsChecked; | ||
|
||
const std::vector<std::pair<std::string, std::string>> pathsToCheck = { | ||
{InputFileName, "Current Working Directory"}, | ||
{DataStringGlobals::inputDirPathName + InputFileName, "IDF Directory"}, | ||
{DataStringGlobals::exeDirectory + InputFileName, "EnergyPlus Executable Directory"}, | ||
{envinputpath1 + InputFileName, "\"epin\" Environment Variable"}, | ||
{envinputpath2 + InputFileName, "\"input_path\" Environment Variable"}, | ||
{envprogrampath + InputFileName, "\"program_path\" Environment Variable"}, | ||
{CurrentWorkingFolder + InputFileName, "INI File Directory"}, | ||
{ProgramPath + InputFileName, "\"program\", \"dir\" from INI File"} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is quite a small list, so it's not a big deal, but an array would've been acceptable here since I think this vector is staying fixed length. |
||
|
||
std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); | ||
|
||
for(std::size_t i = 0; i < numPathsToNotTest; i++) { | ||
if (FileSystem::fileExists(pathsToCheck[i].first)) { | ||
FileFound = true; | ||
CheckedFileName = pathsToCheck[i].first; | ||
print(state.files.audit, "{}={}\n", "found (" + pathsToCheck[i].second +")", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
std::pair <std::string,std::string> currentPath(getParentDirectoryPath(getAbsolutePath(pathsToCheck[i].first)), pathsToCheck[i].second); | ||
bool found = false; | ||
for(auto path: pathsChecked){ | ||
if (path.first == currentPath.first){ | ||
found = true; | ||
} | ||
} | ||
if (!found){ | ||
pathsChecked.push_back(currentPath); | ||
} | ||
print(state.files.audit, "{}={}\n", "not found (" + pathsToCheck[i].second +")\"", getAbsolutePath(pathsToCheck[i].first)); | ||
} | ||
} | ||
|
||
// Look relative to program path | ||
if (FileSystem::fileExists(ProgramPath + InputFileName)) { | ||
FileFound = true; | ||
CheckedFileName = ProgramPath + InputFileName; | ||
print(state.files.audit, "{}={}\n", "found (program path - ini)", getAbsolutePath(CheckedFileName)); | ||
return; | ||
} else { | ||
print(state.files.audit, "{}={}\n", "not found (program path - ini)", getAbsolutePath(ProgramPath + InputFileName)); | ||
if (!FileFound) { | ||
ShowSevereError(state, contextString+ "\"" + originalInputFileName + "\" not found. Paths searched:"); | ||
for(auto path: pathsChecked){ | ||
ShowContinueError(state, " " + path.second +": \"" + path.first +"\""); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1150,7 +1150,11 @@ namespace ExternalInterface { | |
cNumericFieldNames); | ||
// Get the FMU name | ||
FMU(Loop).Name = cAlphaArgs(1); | ||
CheckForActualFileName(state, cAlphaArgs(1), fileExist, tempFullFileName); | ||
|
||
std::string contextString = cCurrentModuleObject + ", " + cAlphaFieldNames(1) + ": "; | ||
|
||
CheckForActualFileName(state, cAlphaArgs(1), fileExist, tempFullFileName, contextString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense, just needing to add a new context string. |
||
|
||
if (fileExist) { | ||
pos = index(FMU(Loop).Name, pathChar, true); // look backwards | ||
if (pos != std::string::npos) { | ||
|
@@ -1165,8 +1169,6 @@ namespace ExternalInterface { | |
} | ||
fullFileName(Loop) = tempFullFileName; | ||
} else { | ||
ShowSevereError(state, "ExternalInterface/InitExternalInterfaceFMUImport:"); | ||
ShowContinueError(state, "file not located = \"" + cAlphaArgs(1) + "\"."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then no longer needing to report the error details. |
||
ErrorsFound = true; | ||
} | ||
// Get fmu time out | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking the initialization into a separate
bool load()
function makes sense.