diff --git a/Examples/ParameterEstimation/CMakeLists.txt b/Examples/ParameterEstimation/CMakeLists.txt index 1a223998a..c8cc4dceb 100644 --- a/Examples/ParameterEstimation/CMakeLists.txt +++ b/Examples/ParameterEstimation/CMakeLists.txt @@ -60,6 +60,8 @@ # - Cameron Rutherford #]] +add_compile_definitions("PARAMETER_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + add_executable(paramest ParameterEstimation.cpp) target_link_libraries(paramest GRIDKIT::bus diff --git a/Examples/ParameterEstimation/ParameterEstimation.cpp b/Examples/ParameterEstimation/ParameterEstimation.cpp index 5e69e600d..9264add05 100644 --- a/Examples/ParameterEstimation/ParameterEstimation.cpp +++ b/Examples/ParameterEstimation/ParameterEstimation.cpp @@ -72,7 +72,10 @@ #include #include #include +#include +#define STRING(x) #x +#define XSTRING(x) STRING(x) int main(int argc, char** argv) { @@ -98,7 +101,8 @@ int main(int argc, char** argv) // Create numerical integrator and configure it for the generator model Ida* idas = new Ida(model); - const std::string input_data = (argc == 2) ? argv[1] : "lookup_table.dat"; + const std::string input_data = (argc == 2) ? argv[1] : std::string(XSTRING(PARAMETER_DIR)) + "/lookup_table.dat"; + double t_init = -1.0; double t_final = -1.0; diff --git a/Utilities/FileIO.hpp b/Utilities/FileIO.hpp index 825123c97..12d3bf768 100644 --- a/Utilities/FileIO.hpp +++ b/Utilities/FileIO.hpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -251,6 +252,18 @@ void readMatPowerBaseMVA(SystemModelData& mp, std::string& line) namespace GridKit { + +/** + * @brief Reads a file in for tabulated data + * + * @todo needs to return int for file error codes + * + * @tparam ScalarT + * @param table + * @param filename + * @param ti + * @param tf + */ template void setLookupTable(std::vector>& table, std::string filename, @@ -258,6 +271,12 @@ void setLookupTable(std::vector>& table, ScalarT& tf) { std::ifstream idata(filename); + if (!idata.is_open()) { + ///@todo swap with returing error codes instead of crashing. + std::cerr << "Error. Given file name \"" << filename<< "\" does not exsist." << std::endl; + abort(); + } + std::string line; int oldwordcount = -1; while (std::getline(idata, line)) { @@ -281,6 +300,12 @@ void setLookupTable(std::vector>& table, } size_t N = table.size(); + if (N < 2) { + ///@todo swap with returing error codes instead of crashing. + std::cerr << "Error. Only " << N << " data points found in file " << filename << std::endl; + abort(); + } + ti = table[0][0]; tf = table[N - 1][0]; }