From c4f656d420e8fc87b97304d1fd5bc3baabb2dcac Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 16 Sep 2020 16:28:52 -0600 Subject: [PATCH 01/16] Create a vector to track locations tested for a file while searching and output as error messages if the file is not found. --- src/EnergyPlus/CurveManager.cc | 7 ++++++- src/EnergyPlus/DataSystemVariables.cc | 22 +++++++++++++++++++++- src/EnergyPlus/DataSystemVariables.hh | 3 ++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/EnergyPlus/CurveManager.cc b/src/EnergyPlus/CurveManager.cc index c1795a7b598..0eb917bdffb 100644 --- a/src/EnergyPlus/CurveManager.cc +++ b/src/EnergyPlus/CurveManager.cc @@ -2039,8 +2039,13 @@ namespace CurveManager { filePath = path; bool fileFound; std::string fullPath; - DataSystemVariables::CheckForActualFileName(ioFiles, path, fileFound, fullPath); + std::vector pathsChecked; + DataSystemVariables::CheckForActualFileName(ioFiles, path, fileFound, fullPath, &pathsChecked); if (!fileFound) { + for(std::size_t i=0; i *pathsChecked ) { @@ -267,6 +268,7 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (user input)", getAbsolutePath(CheckedFileName)); return; } else { + pathsChecked->push_back(getAbsolutePath(InputFileName)); print(ioFiles.audit, "{}={}\n", "not found (user input)", getAbsolutePath(InputFileName)); } @@ -277,6 +279,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (input file)", getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)); } @@ -287,6 +292,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (epin)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envinputpath1 + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(envinputpath1 + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (epin)", getAbsolutePath(envinputpath1 + InputFileName)); } @@ -297,6 +305,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (input_path)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envinputpath2 + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(envinputpath2 + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (input_path)", getAbsolutePath(envinputpath2 + InputFileName)); } @@ -307,6 +318,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (program_path)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envprogrampath + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(envprogrampath + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (program_path)", getAbsolutePath(envprogrampath + InputFileName)); } @@ -319,6 +333,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (CWF)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(CurrentWorkingFolder + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(CurrentWorkingFolder + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (CWF)", getAbsolutePath(CurrentWorkingFolder + InputFileName)); } @@ -329,6 +346,9 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (program path - ini)", getAbsolutePath(CheckedFileName)); return; } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(ProgramPath + InputFileName)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(ProgramPath + InputFileName)); + } print(ioFiles.audit, "{}={}\n", "not found (program path - ini)", getAbsolutePath(ProgramPath + InputFileName)); } } diff --git a/src/EnergyPlus/DataSystemVariables.hh b/src/EnergyPlus/DataSystemVariables.hh index 449737bb6b9..54961618e5d 100644 --- a/src/EnergyPlus/DataSystemVariables.hh +++ b/src/EnergyPlus/DataSystemVariables.hh @@ -172,7 +172,8 @@ namespace DataSystemVariables { void CheckForActualFileName(IOFiles &ioFiles, 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. + std::vector *pathsChecked = nullptr ); // Needed for unit tests, should not be normally called. From 22126fc3286ffc2c6c5585bdda8cca02238c991d Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Tue, 29 Sep 2020 20:07:23 -0600 Subject: [PATCH 02/16] Refactor the CheckForActualFileName function to loop through an array of locations to check for a file instead of checking them with multiple blocks of code. --- src/EnergyPlus/DataSystemVariables.cc | 110 ++++++-------------------- src/EnergyPlus/DataSystemVariables.hh | 1 + 2 files changed, 23 insertions(+), 88 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index eb882029c0d..c22843dac2f 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -256,100 +256,34 @@ namespace DataSystemVariables { firstTime = false; } - FileFound = false; CheckedFileName = blank; InputFileName = originalInputFileName; makeNativePath(InputFileName); - if (FileSystem::fileExists(InputFileName)) { - FileFound = true; - CheckedFileName = InputFileName; - print(ioFiles.audit, "{}={}\n", "found (user input)", getAbsolutePath(CheckedFileName)); - return; - } else { - pathsChecked->push_back(getAbsolutePath(InputFileName)); - print(ioFiles.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(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(DataStringGlobals::inputDirPathName + InputFileName)); - } - print(ioFiles.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(ioFiles.audit, "{}={}\n", "found (epin)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envinputpath1 + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(envinputpath1 + InputFileName)); - } - print(ioFiles.audit, "{}={}\n", "not found (epin)", getAbsolutePath(envinputpath1 + InputFileName)); - } - - // Look relative to input path - if (FileSystem::fileExists(envinputpath2 + InputFileName)) { - FileFound = true; - CheckedFileName = envinputpath2 + InputFileName; - print(ioFiles.audit, "{}={}\n", "found (input_path)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envinputpath2 + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(envinputpath2 + InputFileName)); - } - print(ioFiles.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(ioFiles.audit, "{}={}\n", "found (program_path)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(envprogrampath + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(envprogrampath + InputFileName)); - } - print(ioFiles.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(ioFiles.audit, "{}={}\n", "found (CWF)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(CurrentWorkingFolder + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(CurrentWorkingFolder + InputFileName)); - } - print(ioFiles.audit, "{}={}\n", "not found (CWF)", getAbsolutePath(CurrentWorkingFolder + InputFileName)); - } - - // Look relative to program path - if (FileSystem::fileExists(ProgramPath + InputFileName)) { - FileFound = true; - CheckedFileName = ProgramPath + InputFileName; - print(ioFiles.audit, "{}={}\n", "found (program path - ini)", getAbsolutePath(CheckedFileName)); - return; - } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(ProgramPath + InputFileName)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(ProgramPath + InputFileName)); + std::array pathsToCheck = { + InputFileName, + DataStringGlobals::inputDirPathName + InputFileName, + envinputpath1 + InputFileName, + envinputpath2 + InputFileName, + envprogrampath + InputFileName, + CurrentWorkingFolder + InputFileName, + ProgramPath + InputFileName + }; + + for(auto path : pathsToCheck) { + if (FileSystem::fileExists(path)) { + FileFound = true; + CheckedFileName = path; + print(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); + return; + } else { + if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(path)) == pathsChecked->end()){ + pathsChecked->push_back(getAbsolutePath(path)); + } + print(ioFiles.audit, "{}={}\n", "not found", getAbsolutePath(path)); } - print(ioFiles.audit, "{}={}\n", "not found (program path - ini)", getAbsolutePath(ProgramPath + InputFileName)); + if ( path ==(CurrentWorkingFolder + InputFileName) && !TestAllPaths ) return; } } diff --git a/src/EnergyPlus/DataSystemVariables.hh b/src/EnergyPlus/DataSystemVariables.hh index 54961618e5d..c7953cdd02b 100644 --- a/src/EnergyPlus/DataSystemVariables.hh +++ b/src/EnergyPlus/DataSystemVariables.hh @@ -53,6 +53,7 @@ // EnergyPlus Headers #include +#include namespace EnergyPlus { // Forward declarations From 578d43374faa805c052c7f85ff194f49c1948781 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Tue, 29 Sep 2020 20:08:05 -0600 Subject: [PATCH 03/16] Add a unit test for the CheckForActualFileName function which catches the file not found error outputs. --- tst/EnergyPlus/unit/CMakeLists.txt | 1 + .../unit/DataSystemVariables.unit.cc | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tst/EnergyPlus/unit/DataSystemVariables.unit.cc diff --git a/tst/EnergyPlus/unit/CMakeLists.txt b/tst/EnergyPlus/unit/CMakeLists.txt index c36fd1ef707..21297bf946b 100644 --- a/tst/EnergyPlus/unit/CMakeLists.txt +++ b/tst/EnergyPlus/unit/CMakeLists.txt @@ -72,6 +72,7 @@ set( test_src Datasets.unit.cc DataSizing.unit.cc DataSurfaces.unit.cc + DataSystemVariables.unit.cc DataZoneEquipment.unit.cc DaylightingManager.unit.cc DElightManager.unit.cc diff --git a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc new file mode 100644 index 00000000000..b80c1c29248 --- /dev/null +++ b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc @@ -0,0 +1,75 @@ +// EnergyPlus, Copyright (c) 1996-2020, The Board of Trustees of the University of Illinois, +// The Regents of the University of California, through Lawrence Berkeley National Laboratory +// (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge +// National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other +// contributors. All rights reserved. +// +// NOTICE: This Software was developed under funding from the U.S. Department of Energy and the +// U.S. Government consequently retains certain rights. As such, the U.S. Government has been +// granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, +// worldwide license in the Software to reproduce, distribute copies to the public, prepare +// derivative works, and perform publicly and display publicly, and to permit others to do so. +// +// Redistribution and use in source and binary forms, with or without modification, are permitted +// provided that the following conditions are met: +// +// (1) Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// (2) Redistributions in binary form must reproduce the above copyright notice, this list of +// conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory, +// the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific prior +// written permission. +// +// (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form +// without changes from the version obtained under this License, or (ii) Licensee makes a +// reference solely to the software portion of its product, Licensee must refer to the +// software as "EnergyPlus version X" software, where "X" is the version number Licensee +// obtained under this License and may not use a different name for the software. Except as +// specifically required in this Section (4), Licensee shall not use in a company name, a +// product name, in advertising, publicity, or other promotional activities any name, trade +// name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly +// similar designation, without the U.S. Department of Energy's prior written consent. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// EnergyPlus::SolarShading Unit Tests + +// Google Test Headers +#include + +// EnergyPlus Headers +#include +#include + +#include "Fixtures/EnergyPlusFixture.hh" + +using namespace EnergyPlus; + +TEST_F(EnergyPlusFixture, File_Not_Found_ERR_Output) +{ + IOFiles ioFiles = IOFiles(); + std::string filePath ="./NonExistentFile.txt"; + bool fileFound; + std::string fullPath; + std::vector pathsChecked; + DataSystemVariables::CheckForActualFileName(ioFiles, filePath, fileFound, fullPath, &pathsChecked); + ASSERT_EQ(pathsChecked.size(), 1); + ASSERT_FALSE(fileFound); + // "/Users/tony-scimone/Projects/EnergyPlus/builds/debug/Products/NonExistentFile.txt" + std::string expectedError = FileSystem::getAbsolutePath(DataStringGlobals::inputDirPathName + filePath); + std::string pathCheckedError = pathsChecked[0]; + ASSERT_EQ(expectedError, pathCheckedError); +} From 8a3db613cb442beb644e05c1919768b2fedb2933 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Tue, 29 Sep 2020 21:03:47 -0600 Subject: [PATCH 04/16] Add a flag to file checking function to output error messages if the flag is passed. --- src/EnergyPlus/CurveManager.cc | 9 +-------- src/EnergyPlus/DataSystemVariables.cc | 10 +++++++++- src/EnergyPlus/DataSystemVariables.hh | 3 ++- tst/EnergyPlus/unit/DataSystemVariables.unit.cc | 1 - 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/EnergyPlus/CurveManager.cc b/src/EnergyPlus/CurveManager.cc index 178225c043a..eac671c8404 100644 --- a/src/EnergyPlus/CurveManager.cc +++ b/src/EnergyPlus/CurveManager.cc @@ -2029,14 +2029,7 @@ namespace CurveManager { bool fileFound; std::string fullPath; std::vector pathsChecked; - DataSystemVariables::CheckForActualFileName(ioFiles, path, fileFound, fullPath, &pathsChecked); - if (!fileFound) { - for(std::size_t i=0; i *pathsChecked + std::vector *pathsChecked, + bool outputErrors ) { @@ -285,6 +286,13 @@ namespace DataSystemVariables { } if ( path ==(CurrentWorkingFolder + InputFileName) && !TestAllPaths ) return; } + if (outputErrors) { + for(std::size_t i=0; isize(); i++){ + ShowWarningMessage("Looking for File \"" + filePath + "\" : File not found in \"" + pathsChecked[i] +"\""); + } + ShowSevereError("File \"" + filePath + "\" : File not found."); + ShowFatalError("File \"" + filePath + "\" : File not found."); + } } void clear_state() diff --git a/src/EnergyPlus/DataSystemVariables.hh b/src/EnergyPlus/DataSystemVariables.hh index 69d37f3ec14..49d587edb45 100644 --- a/src/EnergyPlus/DataSystemVariables.hh +++ b/src/EnergyPlus/DataSystemVariables.hh @@ -174,7 +174,8 @@ namespace DataSystemVariables { 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::vector *pathsChecked = nullptr + std::vector *pathsChecked = nullptr, + bool outputErrors = false ); // Needed for unit tests, should not be normally called. diff --git a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc index b80c1c29248..58a66d7ba3f 100644 --- a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc +++ b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc @@ -68,7 +68,6 @@ TEST_F(EnergyPlusFixture, File_Not_Found_ERR_Output) DataSystemVariables::CheckForActualFileName(ioFiles, filePath, fileFound, fullPath, &pathsChecked); ASSERT_EQ(pathsChecked.size(), 1); ASSERT_FALSE(fileFound); - // "/Users/tony-scimone/Projects/EnergyPlus/builds/debug/Products/NonExistentFile.txt" std::string expectedError = FileSystem::getAbsolutePath(DataStringGlobals::inputDirPathName + filePath); std::string pathCheckedError = pathsChecked[0]; ASSERT_EQ(expectedError, pathCheckedError); From 75cd34d5dc11e1f8c2a66fa3195f8e97c3d338e7 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Tue, 29 Sep 2020 21:07:45 -0600 Subject: [PATCH 05/16] Fix output error where printing of file searching errors was always present. --- src/EnergyPlus/DataSystemVariables.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 2a090d6fc3c..726018798a1 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -286,7 +286,7 @@ namespace DataSystemVariables { } if ( path ==(CurrentWorkingFolder + InputFileName) && !TestAllPaths ) return; } - if (outputErrors) { + if (outputErrors && FileFound==false) { for(std::size_t i=0; isize(); i++){ ShowWarningMessage("Looking for File \"" + filePath + "\" : File not found in \"" + pathsChecked[i] +"\""); } From e91271b2ddcf551b3a4626df3ba08f12d8f59816 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Tue, 29 Sep 2020 21:26:18 -0600 Subject: [PATCH 06/16] Fix variable access issues in check for actual file. --- src/EnergyPlus/DataSystemVariables.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 726018798a1..a5a9cb15a46 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -288,10 +288,10 @@ namespace DataSystemVariables { } if (outputErrors && FileFound==false) { for(std::size_t i=0; isize(); i++){ - ShowWarningMessage("Looking for File \"" + filePath + "\" : File not found in \"" + pathsChecked[i] +"\""); + ShowWarningMessage("Looking for File \"" + originalInputFileName + "\" : File not found in \"" + (*pathsChecked)[i] +"\""); } - ShowSevereError("File \"" + filePath + "\" : File not found."); - ShowFatalError("File \"" + filePath + "\" : File not found."); + ShowSevereError("File \"" + originalInputFileName + "\" : File not found."); + ShowFatalError("File \"" + originalInputFileName + "\" : File not found."); } } From 2f839ebf1b6b5ac26d527e20a31b41cbcc96e2c5 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 30 Sep 2020 16:44:16 -0600 Subject: [PATCH 07/16] Refactor CheckForActualFileName, removing the parameter for passing an optional array to be filled with locations checked for, as well as the boolean value for outputting to the err file when a file is not found. This behavior of printing a list of locations checked when a file is not found to the err file is now always present. Additionally, a new string can optionally be passed to the function as a context string which will modify this printing output to give context about where this file missing output is coming from. Lastly, the table files object in curve manager has been modified to use this structure. --- src/EnergyPlus/CurveManager.cc | 24 ++++++++++++--------- src/EnergyPlus/CurveManager.hh | 3 +-- src/EnergyPlus/DataSystemVariables.cc | 31 ++++++++++++++------------- src/EnergyPlus/DataSystemVariables.hh | 5 ++--- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/EnergyPlus/CurveManager.cc b/src/EnergyPlus/CurveManager.cc index eac671c8404..a20e1882ccb 100644 --- a/src/EnergyPlus/CurveManager.cc +++ b/src/EnergyPlus/CurveManager.cc @@ -1729,7 +1729,9 @@ namespace CurveManager { std::size_t rowNum = indVarInstance.at("external_file_starting_row_number").get() - 1; if (!state.dataCurveManager->btwxtManager.tableFiles.count(filePath)) { - state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, TableFile{IOFiles::getSingleton(), filePath}); + TableFile tableFile; + ErrorsFound |= tableFile.load(IOFiles::getSingleton(), filePath); + state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, tableFile); } axis = state.dataCurveManager->btwxtManager.tableFiles[filePath].getArray({colNum, rowNum}); @@ -1918,8 +1920,11 @@ namespace CurveManager { std::size_t colNum = fields.at("external_file_column_number").get() - 1; std::size_t rowNum = fields.at("external_file_starting_row_number").get() - 1; + if (!state.dataCurveManager->btwxtManager.tableFiles.count(filePath)) { - state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, TableFile{IOFiles::getSingleton(), filePath}); + TableFile tableFile; + ErrorsFound |= tableFile.load(IOFiles::getSingleton(), filePath); + state.dataCurveManager->btwxtManager.tableFiles.emplace(filePath, tableFile); } lookupValues = state.dataCurveManager->btwxtManager.tableFiles[filePath].getArray({colNum, rowNum}); @@ -2018,18 +2023,16 @@ namespace CurveManager { tableFiles.clear(); } - TableFile::TableFile(IOFiles &ioFiles, std::string path) - { - load(ioFiles, path); - } - - void TableFile::load(IOFiles &ioFiles, std::string path) + bool TableFile::load(IOFiles &ioFiles, std::string path) { filePath = path; bool fileFound; std::string fullPath; - std::vector pathsChecked; - DataSystemVariables::CheckForActualFileName(ioFiles, path, fileFound, fullPath, &pathsChecked, true); + std::string contextString = "CurveManager::TableFile::load: "; + DataSystemVariables::CheckForActualFileName(ioFiles, path, fileFound, fullPath, contextString); + if(!fileFound){ + return true; + } std::ifstream file(fullPath); std::string line(""); numRows = 0; @@ -2062,6 +2065,7 @@ namespace CurveManager { ++colNum; } } + return false; } std::vector& TableFile::getArray(std::pair colAndRow) { diff --git a/src/EnergyPlus/CurveManager.hh b/src/EnergyPlus/CurveManager.hh index afd543a1131..23ca5de6a37 100644 --- a/src/EnergyPlus/CurveManager.hh +++ b/src/EnergyPlus/CurveManager.hh @@ -239,11 +239,10 @@ namespace CurveManager { { public: TableFile() = default; - TableFile(IOFiles &ioFiles, std::string path); std::string filePath; std::vector> contents; std::map, std::vector> arrays; - void load(IOFiles &ioFiles, std::string path); + bool load(IOFiles &ioFiles, std::string path); std::vector& getArray(std::pair colAndRow); private: diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index a5a9cb15a46..a02aaef441b 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -203,8 +203,7 @@ namespace DataSystemVariables { 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::vector *pathsChecked, - bool outputErrors + const std::string contextString // ) { @@ -262,7 +261,9 @@ namespace DataSystemVariables { InputFileName = originalInputFileName; makeNativePath(InputFileName); - std::array pathsToCheck = { + std::vector pathsChecked; + + const std::vector pathsToCheck = { InputFileName, DataStringGlobals::inputDirPathName + InputFileName, envinputpath1 + InputFileName, @@ -272,26 +273,26 @@ namespace DataSystemVariables { ProgramPath + InputFileName }; - for(auto path : pathsToCheck) { - if (FileSystem::fileExists(path)) { + std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); + + for(std::size_t i = 0; i < numPathsToNotTest; i++) { + if (FileSystem::fileExists(pathsToCheck[i])) { FileFound = true; - CheckedFileName = path; + CheckedFileName = pathsToCheck[i]; print(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); return; } else { - if (std::find(pathsChecked->begin(), pathsChecked->end(), getAbsolutePath(path)) == pathsChecked->end()){ - pathsChecked->push_back(getAbsolutePath(path)); + if (std::find(pathsChecked.begin(), pathsChecked.end(), getAbsolutePath(pathsToCheck[i])) == pathsChecked.end()){ + pathsChecked.push_back(getAbsolutePath(pathsToCheck[i])); } - print(ioFiles.audit, "{}={}\n", "not found", getAbsolutePath(path)); + print(ioFiles.audit, "{}={}\n", "not found", getAbsolutePath(pathsToCheck[i])); } - if ( path ==(CurrentWorkingFolder + InputFileName) && !TestAllPaths ) return; } - if (outputErrors && FileFound==false) { - for(std::size_t i=0; isize(); i++){ - ShowWarningMessage("Looking for File \"" + originalInputFileName + "\" : File not found in \"" + (*pathsChecked)[i] +"\""); + if (!FileFound) { + ShowSevereError(contextString+ "File \"" + originalInputFileName + "\" not found. Paths searched:"); + for(auto path: pathsChecked){ + ShowContinueError(" \"" + path +"\""); } - ShowSevereError("File \"" + originalInputFileName + "\" : File not found."); - ShowFatalError("File \"" + originalInputFileName + "\" : File not found."); } } diff --git a/src/EnergyPlus/DataSystemVariables.hh b/src/EnergyPlus/DataSystemVariables.hh index 49d587edb45..2a00b6e77b5 100644 --- a/src/EnergyPlus/DataSystemVariables.hh +++ b/src/EnergyPlus/DataSystemVariables.hh @@ -173,9 +173,8 @@ namespace DataSystemVariables { void CheckForActualFileName(IOFiles &ioFiles, 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::vector *pathsChecked = nullptr, - bool outputErrors = false + std::string &foundFileName, // Blank if not found. + const std::string contextString = std::string() ); // Needed for unit tests, should not be normally called. From 31a59c45459f57715709d37ce5a5efc3b8fa1f4f Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 30 Sep 2020 16:45:12 -0600 Subject: [PATCH 08/16] Clean up the other uses of CheckForActualFileName and add context strings to each, allowing for cleanup of error messages in these sections of code. --- src/EnergyPlus/ExternalInterface.cc | 6 +++--- src/EnergyPlus/HeatBalanceManager.cc | 7 ++----- src/EnergyPlus/ScheduleManager.cc | 17 ++++++----------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/EnergyPlus/ExternalInterface.cc b/src/EnergyPlus/ExternalInterface.cc index 6f01650d9a4..51d4fc89fa5 100644 --- a/src/EnergyPlus/ExternalInterface.cc +++ b/src/EnergyPlus/ExternalInterface.cc @@ -1156,7 +1156,9 @@ namespace ExternalInterface { cNumericFieldNames); // Get the FMU name FMU(Loop).Name = cAlphaArgs(1); - CheckForActualFileName(ioFiles, cAlphaArgs(1), fileExist, tempFullFileName); + std::string contextString = cCurrentModuleObject + ", " + cAlphaFieldNames(1) + ": "; + + CheckForActualFileName(ioFiles, cAlphaArgs(1), fileExist, tempFullFileName, contextString); if (fileExist) { pos = index(FMU(Loop).Name, pathChar, true); // look backwards if (pos != std::string::npos) { @@ -1171,8 +1173,6 @@ namespace ExternalInterface { } fullFileName(Loop) = tempFullFileName; } else { - ShowSevereError("ExternalInterface/InitExternalInterfaceFMUImport:"); - ShowContinueError("file not located = \"" + cAlphaArgs(1) + "\"."); ErrorsFound = true; } // Get fmu time out diff --git a/src/EnergyPlus/HeatBalanceManager.cc b/src/EnergyPlus/HeatBalanceManager.cc index bb9de2e761d..a23f6ddb9d2 100644 --- a/src/EnergyPlus/HeatBalanceManager.cc +++ b/src/EnergyPlus/HeatBalanceManager.cc @@ -6262,14 +6262,11 @@ namespace HeatBalanceManager { ConstructionFound = false; // ErrorsFound = .FALSE. EOFonFile = false; + std::string contextString = "HeatBalanceManager::SearchWindow5DataFile: "; - CheckForActualFileName(ioFiles, DesiredFileName, exists, ioFiles.TempFullFileName.fileName); + CheckForActualFileName(ioFiles, DesiredFileName, exists, ioFiles.TempFullFileName.fileName, contextString); // INQUIRE(FILE=TRIM(DesiredFileName), EXIST=exists) if (!exists) { - ShowSevereError("HeatBalanceManager: SearchWindow5DataFile: Could not locate Window5 Data File, expecting it as file name=" + - DesiredFileName); - ShowContinueError("Certain run environments require a full path to be included with the file name in the input field."); - ShowContinueError("Try again with putting full path and file name in the field."); ShowFatalError("Program terminates due to these conditions."); } diff --git a/src/EnergyPlus/ScheduleManager.cc b/src/EnergyPlus/ScheduleManager.cc index 46db4a2660f..68455f8325e 100644 --- a/src/EnergyPlus/ScheduleManager.cc +++ b/src/EnergyPlus/ScheduleManager.cc @@ -535,12 +535,10 @@ namespace ScheduleManager { inputProcessor->getObjectItem( CurrentModuleObject, 1, Alphas, NumAlphas, Numbers, NumNumbers, Status, lNumericBlanks, lAlphaBlanks, cAlphaFields, cNumericFields); std::string ShadingSunlitFracFileName = Alphas(1); - CheckForActualFileName(ioFiles, ShadingSunlitFracFileName, FileExists, ioFiles.TempFullFileName.fileName); + + std::string contextString = CurrentModuleObject + ", " + cAlphaFields(1) + ": "; + CheckForActualFileName(ioFiles, ShadingSunlitFracFileName, FileExists, ioFiles.TempFullFileName.fileName, contextString); if (!FileExists) { - ShowSevereError(RoutineName + ":\"" + ShadingSunlitFracFileName + - "\" not found when External Shading Calculation Method = ImportedShading."); - ShowContinueError("Certain run environments require a full path to be included with the file name in the input field."); - ShowContinueError("Try again with putting full path and file name in the field."); ShowFatalError("Program terminates due to previous condition."); } @@ -1750,16 +1748,13 @@ namespace ScheduleManager { // ENDDO // ENDIF - CheckForActualFileName(ioFiles, Alphas(3), FileExists, ioFiles.TempFullFileName.fileName); + std::string contextString = CurrentModuleObject + "=\"" + Alphas(1) + "\", " + cAlphaFields(3) + ": "; + + CheckForActualFileName(ioFiles, Alphas(3), FileExists, ioFiles.TempFullFileName.fileName, contextString); // INQUIRE(file=Alphas(3),EXIST=FileExists) // Setup file reading parameters if (!FileExists) { - DisplayString("Missing " + Alphas(3)); - ShowSevereError(RoutineName + CurrentModuleObject + "=\"" + Alphas(1) + "\", " + cAlphaFields(3) + "=\"" + Alphas(3) + - "\" not found."); - ShowContinueError("Certain run environments require a full path to be included with the file name in the input field."); - ShowContinueError("Try again with putting full path and file name in the field."); ErrorsFound = true; } else { auto SchdFile = ioFiles.TempFullFileName.try_open(); From 631eb86fef73e4df182fb69125510dbaa52040c9 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 30 Sep 2020 16:45:36 -0600 Subject: [PATCH 09/16] Remove a few unneeded comments from the code base. --- src/EnergyPlus/DataSystemVariables.cc | 15 --------------- tst/EnergyPlus/unit/DataSystemVariables.unit.cc | 2 -- 2 files changed, 17 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index a02aaef441b..036dc4c983a 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -218,15 +218,6 @@ 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: @@ -234,12 +225,6 @@ namespace DataSystemVariables { static std::string const blank; static ObjexxFCL::gio::Fmt fmtA("(A)"); - // 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; diff --git a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc index 58a66d7ba3f..c8c62128830 100644 --- a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc +++ b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc @@ -45,8 +45,6 @@ // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -// EnergyPlus::SolarShading Unit Tests - // Google Test Headers #include From 11911ee1b467190d750002434f9a81264a012aba Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 30 Sep 2020 16:46:29 -0600 Subject: [PATCH 10/16] Clean up some issues with the file not found unit test, making it workable for a cross platform situation and using the error stream matching function to detect the issue tested for is actually being printed in the err stream. --- tst/EnergyPlus/unit/DataSystemVariables.unit.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc index c8c62128830..2530165adad 100644 --- a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc +++ b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc @@ -59,14 +59,12 @@ using namespace EnergyPlus; TEST_F(EnergyPlusFixture, File_Not_Found_ERR_Output) { IOFiles ioFiles = IOFiles(); - std::string filePath ="./NonExistentFile.txt"; - bool fileFound; + std::string filePath = "./NonExistentFile.txt"; + FileSystem::makeNativePath(filePath); + std::string expectedError = FileSystem::getAbsolutePath(filePath); + bool fileFound = false; std::string fullPath; - std::vector pathsChecked; - DataSystemVariables::CheckForActualFileName(ioFiles, filePath, fileFound, fullPath, &pathsChecked); - ASSERT_EQ(pathsChecked.size(), 1); - ASSERT_FALSE(fileFound); - std::string expectedError = FileSystem::getAbsolutePath(DataStringGlobals::inputDirPathName + filePath); - std::string pathCheckedError = pathsChecked[0]; - ASSERT_EQ(expectedError, pathCheckedError); + DataSystemVariables::CheckForActualFileName(ioFiles, filePath, fileFound, fullPath); + EXPECT_FALSE(fileFound); + EXPECT_TRUE(match_err_stream(expectedError)); } From f04d3a383402130724887ca45f1e99b58e773724 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Wed, 30 Sep 2020 23:11:06 -0600 Subject: [PATCH 11/16] Add the variable being searched through to the output string. --- src/EnergyPlus/DataSystemVariables.cc | 38 +++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 036dc4c983a..0236d3aba00 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -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 + // ObjexxFCL Headers #include #include @@ -246,37 +249,38 @@ namespace DataSystemVariables { InputFileName = originalInputFileName; makeNativePath(InputFileName); - std::vector pathsChecked; + std::vector> pathsChecked; - const std::vector pathsToCheck = { - InputFileName, - DataStringGlobals::inputDirPathName + InputFileName, - envinputpath1 + InputFileName, - envinputpath2 + InputFileName, - envprogrampath + InputFileName, - CurrentWorkingFolder + InputFileName, - ProgramPath + InputFileName + const std::vector> pathsToCheck = { + {InputFileName, "InputFileName"}, + {DataStringGlobals::inputDirPathName + InputFileName, "inputDirPathName"}, + {envinputpath1 + InputFileName, "envinputpath1"}, + {envinputpath2 + InputFileName, "envinputpath2"}, + {envprogrampath + InputFileName, "envprogrampath"}, + {CurrentWorkingFolder + InputFileName, "CurrentWorkingFolder"}, + {ProgramPath + InputFileName, "ProgramPath"} }; std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); for(std::size_t i = 0; i < numPathsToNotTest; i++) { - if (FileSystem::fileExists(pathsToCheck[i])) { + if (FileSystem::fileExists(pathsToCheck[i].first)) { FileFound = true; - CheckedFileName = pathsToCheck[i]; - print(ioFiles.audit, "{}={}\n", "found (input file)", getAbsolutePath(CheckedFileName)); + CheckedFileName = pathsToCheck[i].first; + print(ioFiles.audit, "{}={}\n", "found (" + pathsToCheck[i].second +")", getAbsolutePath(CheckedFileName)); return; } else { - if (std::find(pathsChecked.begin(), pathsChecked.end(), getAbsolutePath(pathsToCheck[i])) == pathsChecked.end()){ - pathsChecked.push_back(getAbsolutePath(pathsToCheck[i])); + std::pair currentPath(getAbsolutePath(pathsToCheck[i].first), pathsToCheck[i].second); + if (std::find(pathsChecked.begin(), pathsChecked.end(), currentPath) == pathsChecked.end()){ + pathsChecked.push_back(currentPath); } - print(ioFiles.audit, "{}={}\n", "not found", getAbsolutePath(pathsToCheck[i])); + print(ioFiles.audit, "{}={}\n", "not found (" + pathsToCheck[i].second +")\"", getAbsolutePath(pathsToCheck[i].first)); } } if (!FileFound) { - ShowSevereError(contextString+ "File \"" + originalInputFileName + "\" not found. Paths searched:"); + ShowSevereError(contextString+ "\"" + originalInputFileName + "\" not found. Paths searched:"); for(auto path: pathsChecked){ - ShowContinueError(" \"" + path +"\""); + ShowContinueError(" (" + path.second +")\"" + path.first +"\""); } } } From 7d826517758858becb9c95c90be60ad01d817a15 Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Thu, 1 Oct 2020 15:32:15 -0600 Subject: [PATCH 12/16] Reformat the output messages to the .err file for file searching file not found errors, and fix the logic flow for file not found searches in CurveManager to not throw a fatal error immediately when a file is not found. This results in more output from the Curve Manager about additional files it could not find, and a more reasonable fatal error. --- src/EnergyPlus/CurveManager.cc | 4 ++++ src/EnergyPlus/DataSystemVariables.cc | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/EnergyPlus/CurveManager.cc b/src/EnergyPlus/CurveManager.cc index a20e1882ccb..c205c7c129f 100644 --- a/src/EnergyPlus/CurveManager.cc +++ b/src/EnergyPlus/CurveManager.cc @@ -1734,6 +1734,8 @@ namespace CurveManager { 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({colNum, rowNum}); // remove NANs @@ -1927,6 +1929,8 @@ namespace CurveManager { 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({colNum, rowNum}); // remove NANs diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 0236d3aba00..3ce2b9b414e 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -252,13 +252,14 @@ namespace DataSystemVariables { std::vector> pathsChecked; const std::vector> pathsToCheck = { - {InputFileName, "InputFileName"}, - {DataStringGlobals::inputDirPathName + InputFileName, "inputDirPathName"}, - {envinputpath1 + InputFileName, "envinputpath1"}, - {envinputpath2 + InputFileName, "envinputpath2"}, - {envprogrampath + InputFileName, "envprogrampath"}, - {CurrentWorkingFolder + InputFileName, "CurrentWorkingFolder"}, - {ProgramPath + InputFileName, "ProgramPath"} + {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"} }; std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); @@ -270,8 +271,14 @@ namespace DataSystemVariables { print(ioFiles.audit, "{}={}\n", "found (" + pathsToCheck[i].second +")", getAbsolutePath(CheckedFileName)); return; } else { - std::pair currentPath(getAbsolutePath(pathsToCheck[i].first), pathsToCheck[i].second); - if (std::find(pathsChecked.begin(), pathsChecked.end(), currentPath) == pathsChecked.end()){ + std::pair 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(ioFiles.audit, "{}={}\n", "not found (" + pathsToCheck[i].second +")\"", getAbsolutePath(pathsToCheck[i].first)); @@ -280,7 +287,7 @@ namespace DataSystemVariables { if (!FileFound) { ShowSevereError(contextString+ "\"" + originalInputFileName + "\" not found. Paths searched:"); for(auto path: pathsChecked){ - ShowContinueError(" (" + path.second +")\"" + path.first +"\""); + ShowContinueError(" " + path.second +": \"" + path.first +"\""); } } } From b0ed48c36f842955d22a3779103503b116bc518c Mon Sep 17 00:00:00 2001 From: Tony Scimone Date: Thu, 1 Oct 2020 15:42:30 -0600 Subject: [PATCH 13/16] Fix the expected error in the file not found unit test. --- tst/EnergyPlus/unit/DataSystemVariables.unit.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc index 2530165adad..a9c83a13bfd 100644 --- a/tst/EnergyPlus/unit/DataSystemVariables.unit.cc +++ b/tst/EnergyPlus/unit/DataSystemVariables.unit.cc @@ -61,7 +61,7 @@ TEST_F(EnergyPlusFixture, File_Not_Found_ERR_Output) IOFiles ioFiles = IOFiles(); std::string filePath = "./NonExistentFile.txt"; FileSystem::makeNativePath(filePath); - std::string expectedError = FileSystem::getAbsolutePath(filePath); + std::string expectedError = FileSystem::getParentDirectoryPath(FileSystem::getAbsolutePath(filePath)); bool fileFound = false; std::string fullPath; DataSystemVariables::CheckForActualFileName(ioFiles, filePath, fileFound, fullPath); From 4a93d7e429345e2140619b966ac099c6c61c3b1f Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 11 Nov 2020 13:34:35 -0700 Subject: [PATCH 14/16] Remove unused environment variable. --- src/EnergyPlus/DataSystemVariables.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index da4e0b0f2dd..4e3d664c2e6 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -182,7 +182,6 @@ namespace DataSystemVariables { bool lMinimalShadowing(false); // TRUE if MinimalShadowing is to override Solar Distribution flag std::string envinputpath1; std::string envinputpath2; - std::string envprogrampath; bool TestAllPaths(false); int iEnvSetThreads(0); bool lEnvSetThreadsInput(false); @@ -253,7 +252,6 @@ namespace DataSystemVariables { {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"} }; From f1bcbbdc4c23be0f77826a618495ed6ecd4710bf Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 11 Nov 2020 13:35:08 -0700 Subject: [PATCH 15/16] Convert to std::array. --- src/EnergyPlus/DataSystemVariables.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 4e3d664c2e6..04d618e4ad8 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -246,14 +246,14 @@ namespace DataSystemVariables { std::vector> pathsChecked; - const std::vector> pathsToCheck = { + const std::array, 7> 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"}, {CurrentWorkingFolder + InputFileName, "INI File Directory"}, - {ProgramPath + InputFileName, "\"program\", \"dir\" from INI File"} + {ProgramPath + InputFileName, "\"program\", \"dir\" from INI File"}} }; std::size_t numPathsToNotTest = (TestAllPaths) ? pathsToCheck.size()-2 : pathsToCheck.size(); From fbdcded3d0b247a5d31c3e17034091bc2d5c18ea Mon Sep 17 00:00:00 2001 From: Neal Kruis Date: Wed, 11 Nov 2020 13:35:44 -0700 Subject: [PATCH 16/16] Fix error message line break. --- src/EnergyPlus/DataSystemVariables.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/EnergyPlus/DataSystemVariables.cc b/src/EnergyPlus/DataSystemVariables.cc index 04d618e4ad8..dd6d8332cbe 100644 --- a/src/EnergyPlus/DataSystemVariables.cc +++ b/src/EnergyPlus/DataSystemVariables.cc @@ -279,9 +279,10 @@ namespace DataSystemVariables { } } if (!FileFound) { - ShowSevereError(state, contextString+ "\"" + originalInputFileName + "\" not found. Paths searched:"); + ShowSevereError(state, contextString+ "\"" + originalInputFileName + "\" not found."); + ShowContinueError(state, " Paths searched:"); for(auto path: pathsChecked){ - ShowContinueError(state, " " + path.second +": \"" + path.first +"\""); + ShowContinueError(state, " " + path.second +": \"" + path.first +"\""); } } }