diff --git a/tests/test_hydrqual.cpp b/tests/test_hydrqual.cpp index d5295c5..60a2b50 100644 --- a/tests/test_hydrqual.cpp +++ b/tests/test_hydrqual.cpp @@ -18,7 +18,7 @@ //#endif -#define BOOST_TEST_MODULE hydqual +#define BOOST_TEST_MODULE hydrqual #include "test_shared.hpp" diff --git a/tests/test_node.cpp b/tests/test_node.cpp new file mode 100644 index 0000000..35c08b9 --- /dev/null +++ b/tests/test_node.cpp @@ -0,0 +1,78 @@ +// +// test_node.cpp +// +// Date Created: February 8, 2019 +// +// Author: Michael E. Tryby +// US EPA - ORD/NRMRL +// + + +#define BOOST_TEST_MODULE "node" + +#include "test_shared.hpp" + + +using namespace std; +using namespace boost; + + + +BOOST_AUTO_TEST_SUITE (test_node) + + +BOOST_FIXTURE_TEST_CASE(test_node_getvalue, FixtureOpenClose) +{ + const auto junc_props = { + EN_ELEVATION, + EN_BASEDEMAND, + EN_PATTERN, + EN_EMITTER, + EN_INITQUAL, + //demand + //head + //pressure + //quality + }; + const int num_props = 5; + + std::vector test (num_props); + double *value = test.data(); + + std::vector ref = {710.0, 150.0, 1.0, 0.0, 0.5}; + + + for (EN_NodeProperty p : junc_props) { + error = EN_getnodevalue(ph, 2, p, value++); + BOOST_REQUIRE(error == 0); + } + + BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); + + + const auto tank_props = { + EN_ELEVATION, + EN_INITQUAL, + EN_TANKLEVEL, + EN_INITVOLUME, + EN_MIXMODEL, + EN_MIXZONEVOL, + //demand + //head + //pressure + //quality + EN_TANKDIAM, + EN_MINVOLUME, + EN_MAXVOLUME, + EN_VOLCURVE, + EN_MINLEVEL, + EN_MAXLEVEL, + EN_MIXFRACTION, + EN_TANK_KBULK, + EN_TANKVOLUME + }; + +} + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_output.cpp b/tests/test_output.cpp index 6b7766f..e2da06b 100644 --- a/tests/test_output.cpp +++ b/tests/test_output.cpp @@ -18,11 +18,11 @@ #include #include -#include #define BOOST_TEST_MODULE "output" #include #include "epanet_output.h" +#include "epanet2_2.h" boost::test_tools::predicate_result check_cdd_float(std::vector& test, @@ -71,6 +71,11 @@ boost::test_tools::predicate_result check_string(std::string test, std::string r #define DATA_PATH_OUTPUT "./example1.out" +#define DATA_PATH_INP "./net1.inp" +#define DATA_PATH_RPT "./test.rpt" +#define DATA_PATH_OUT "./test.out" + + BOOST_AUTO_TEST_SUITE (test_output_auto) BOOST_AUTO_TEST_CASE(OpenCloseTest) { @@ -87,6 +92,48 @@ BOOST_AUTO_TEST_CASE(OpenCloseTest) { BOOST_CHECK(p_handle == NULL); } + +// Test access to output file with the project open +BOOST_AUTO_TEST_CASE(AccessTest){ + + std::string path_inp(DATA_PATH_INP); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); + + EN_Project ph = NULL; + ENR_Handle p_handle = NULL; + + EN_createproject(&ph); + + int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); + BOOST_REQUIRE(error == 0); + + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_solveQ(ph); + BOOST_REQUIRE(error == 0); + + error = EN_report(ph); + BOOST_REQUIRE(error == 0); + + + // Access to output file prior to project close + error = ENR_init(&p_handle); + BOOST_REQUIRE(error == 0); + error = ENR_open(p_handle, path_out.c_str()); + BOOST_REQUIRE(error == 0); + error = ENR_close(&p_handle); + BOOST_REQUIRE(error == 0); + + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + + EN_deleteproject(&ph); +} + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_shared.hpp b/tests/test_shared.hpp index 91176ca..024791b 100644 --- a/tests/test_shared.hpp +++ b/tests/test_shared.hpp @@ -55,7 +55,6 @@ boost::test_tools::predicate_result check_string(std::string test, std::string r } -// NOTE: Project Home needs to be updated to run unit test #define DATA_PATH_INP "./net1.inp" #define DATA_PATH_RPT "./test.rpt" #define DATA_PATH_OUT "./test.out" diff --git a/tools/epanet-output/CMakeLists.txt b/tools/epanet-output/CMakeLists.txt index 01002d7..0d85da4 100644 --- a/tools/epanet-output/CMakeLists.txt +++ b/tools/epanet-output/CMakeLists.txt @@ -4,12 +4,12 @@ # Created: March 9, 2018 # Author: Michael E. Tryby # US EPA ORD/NRMRL -# +# cmake_minimum_required (VERSION 3.0) -# Sets for output directory for executables and libraries. +# Sets for output directory for executables and libraries. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -25,16 +25,16 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(EPANET_OUT_SOURCES src/epanet_output.c src/errormanager.c) -# the binary output file API +# the binary output file API add_library(epanet-output SHARED ${EPANET_OUT_SOURCES}) target_include_directories(epanet-output PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) include(GenerateExportHeader) generate_export_header(epanet-output BASE_NAME epanet_output - EXPORT_MACRO_NAME DLLEXPORT + EXPORT_MACRO_NAME EXPORT_OUT_API EXPORT_FILE_NAME epanet_output_export.h STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC) -file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_output_export.h DESTINATION +file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_output_export.h DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/tools/epanet-output/include/epanet_output.h b/tools/epanet-output/include/epanet_output.h index 93a8425..9c06522 100644 --- a/tools/epanet-output/include/epanet_output.h +++ b/tools/epanet-output/include/epanet_output.h @@ -11,87 +11,16 @@ #define EPANET_OUTPUT_H_ /* Epanet Results binary file API */ + #define MAXFNAME 259 // Max characters in file name #define MAXID 31 // Max characters in ID name + // This is an opaque pointer to struct. Do not access variables. typedef void* ENR_Handle; -typedef enum { - ENR_node = 1, - ENR_link = 2 -} ENR_ElementType; - -typedef enum { - ENR_flowUnits = 1, - ENR_pressUnits = 2, - ENR_qualUnits = 3 -} ENR_Units; - -typedef enum { - ENR_CFS = 0, - ENR_GPM = 1, - ENR_MGD = 2, - ENR_IMGD = 3, - ENR_AFD = 4, - ENR_LPS = 5, - ENR_LPM = 6, - ENR_MLD = 7, - ENR_CMH = 8, - ENR_CMD = 9 -} ENR_FlowUnits; - -typedef enum { - ENR_PSI = 0, - ENR_MTR = 1, - ENR_KPA = 2 -} ENR_PressUnits; - -typedef enum { - ENR_NONE = 0, - ENR_MGL = 1, - ENR_UGL = 2, - ENR_HOURS = 3, - ENR_PRCNT = 4 -} ENR_QualUnits; - -typedef enum { - ENR_reportStart = 1, - ENR_reportStep = 2, - ENR_simDuration = 3, - ENR_numPeriods = 4 -}ENR_Time; - -typedef enum { - ENR_demand = 1, - ENR_head = 2, - ENR_pressure = 3, - ENR_quality = 4 -} ENR_NodeAttribute; - -typedef enum { - ENR_flow = 1, - ENR_velocity = 2, - ENR_headloss = 3, - ENR_avgQuality = 4, - ENR_status = 5, - ENR_setting = 6, - ENR_rxRate = 7, - ENR_frctnFctr = 8 -} ENR_LinkAttribute; - - -// #ifdef WINDOWS -// #ifdef __cplusplus -// #define DLLEXPORT __declspec(dllexport) __cdecl -// #else -// #define DLLEXPORT __declspec(dllexport) __stdcall -// #endif -// #else -// #define DLLEXPORT -// #endif - +#include "epanet_output_enums.h" #include "epanet_output_export.h" @@ -99,52 +28,52 @@ typedef enum { extern "C" { #endif -int DLLEXPORT ENR_init(ENR_Handle* p_handle_out); +int EXPORT_OUT_API ENR_init(ENR_Handle* p_handle_out); -int DLLEXPORT ENR_open(ENR_Handle p_handle_in, const char* path); +int EXPORT_OUT_API ENR_open(ENR_Handle p_handle_in, const char* path); -int DLLEXPORT ENR_getVersion(ENR_Handle p_handle_in, int* int_out); +int EXPORT_OUT_API ENR_getVersion(ENR_Handle p_handle_in, int* int_out); -int DLLEXPORT ENR_getNetSize(ENR_Handle p_handle_in, int** int_out, int* int_dim); +int EXPORT_OUT_API ENR_getNetSize(ENR_Handle p_handle_in, int** int_out, int* int_dim); -int DLLEXPORT ENR_getUnits(ENR_Handle p_handle_in, ENR_Units t_enum, int* int_out); +int EXPORT_OUT_API ENR_getUnits(ENR_Handle p_handle_in, ENR_Units t_enum, int* int_out); -int DLLEXPORT ENR_getTimes(ENR_Handle p_handle_in, ENR_Time t_enum, int* int_out); +int EXPORT_OUT_API ENR_getTimes(ENR_Handle p_handle_in, ENR_Time t_enum, int* int_out); -int DLLEXPORT ENR_getElementName(ENR_Handle p_handle_in, ENR_ElementType t_enum, +int EXPORT_OUT_API ENR_getElementName(ENR_Handle p_handle_in, ENR_ElementType t_enum, int elementIndex, char** string_out, int* slen); -int DLLEXPORT ENR_getEnergyUsage(ENR_Handle p_handle_in, int pumpIndex, +int EXPORT_OUT_API ENR_getEnergyUsage(ENR_Handle p_handle_in, int pumpIndex, int* int_out, float** float_out, int* int_dim); -int DLLEXPORT ENR_getNetReacts(ENR_Handle p_handle_in, float** float_out, int* int_dim); +int EXPORT_OUT_API ENR_getNetReacts(ENR_Handle p_handle_in, float** float_out, int* int_dim); -int DLLEXPORT ENR_getNodeSeries(ENR_Handle p_handle_in, int nodeIndex, ENR_NodeAttribute t_enum, +int EXPORT_OUT_API ENR_getNodeSeries(ENR_Handle p_handle_in, int nodeIndex, ENR_NodeAttribute t_enum, int startPeriod, int endPeriod, float** outValueSeries, int* dim); -int DLLEXPORT ENR_getLinkSeries(ENR_Handle p_handle_in, int linkIndex, ENR_LinkAttribute t_enum, +int EXPORT_OUT_API ENR_getLinkSeries(ENR_Handle p_handle_in, int linkIndex, ENR_LinkAttribute t_enum, int startPeriod, int endPeriod, float** outValueSeries, int* dim); -int DLLEXPORT ENR_getNodeAttribute(ENR_Handle p_handle_in, int periodIndex, +int EXPORT_OUT_API ENR_getNodeAttribute(ENR_Handle p_handle_in, int periodIndex, ENR_NodeAttribute t_enum, float** outValueArray, int* dim); -int DLLEXPORT ENR_getLinkAttribute(ENR_Handle p_handle_in, int periodIndex, +int EXPORT_OUT_API ENR_getLinkAttribute(ENR_Handle p_handle_in, int periodIndex, ENR_LinkAttribute t_enum, float** outValueArray, int* dim); -int DLLEXPORT ENR_getNodeResult(ENR_Handle p_handle_in, int periodIndex, int nodeIndex, +int EXPORT_OUT_API ENR_getNodeResult(ENR_Handle p_handle_in, int periodIndex, int nodeIndex, float** float_out, int* int_dim); -int DLLEXPORT ENR_getLinkResult(ENR_Handle p_handle_in, int periodIndex, int linkIndex, +int EXPORT_OUT_API ENR_getLinkResult(ENR_Handle p_handle_in, int periodIndex, int linkIndex, float** float_out, int* int_dim); -int DLLEXPORT ENR_close(ENR_Handle* p_handle_out); +int EXPORT_OUT_API ENR_close(ENR_Handle* p_handle_out); -void DLLEXPORT ENR_free(void** array); +void EXPORT_OUT_API ENR_free(void** array); -void DLLEXPORT ENR_clearError(ENR_Handle p_handle_in); +void EXPORT_OUT_API ENR_clearError(ENR_Handle p_handle_in); -int DLLEXPORT ENR_checkError(ENR_Handle p_handle_in, char** msg_buffer); +int EXPORT_OUT_API ENR_checkError(ENR_Handle p_handle_in, char** msg_buffer); #ifdef __cplusplus } diff --git a/tools/epanet-output/include/epanet_output_enums.h b/tools/epanet-output/include/epanet_output_enums.h new file mode 100644 index 0000000..0fa012f --- /dev/null +++ b/tools/epanet-output/include/epanet_output_enums.h @@ -0,0 +1,79 @@ +/* + * epanet_output_enums.h - EPANET Output API enums + * + * Created on: March 11, 2019 + * + * Author: Michael E. Tryby + * US EPA - ORD/NRMRL + */ + + +#ifndef EPANET_OUTPUT_ENUMS_H_ +#define EPANET_OUTPUT_ENUMS_H_ + + +typedef enum { + ENR_node = 1, + ENR_link = 2 +} ENR_ElementType; + +typedef enum { + ENR_flowUnits = 1, + ENR_pressUnits = 2, + ENR_qualUnits = 3 +} ENR_Units; + +typedef enum { + ENR_CFS = 0, + ENR_GPM = 1, + ENR_MGD = 2, + ENR_IMGD = 3, + ENR_AFD = 4, + ENR_LPS = 5, + ENR_LPM = 6, + ENR_MLD = 7, + ENR_CMH = 8, + ENR_CMD = 9 +} ENR_FlowUnits; + +typedef enum { + ENR_PSI = 0, + ENR_MTR = 1, + ENR_KPA = 2 +} ENR_PressUnits; + +typedef enum { + ENR_NONE = 0, + ENR_MGL = 1, + ENR_UGL = 2, + ENR_HOURS = 3, + ENR_PRCNT = 4 +} ENR_QualUnits; + +typedef enum { + ENR_reportStart = 1, + ENR_reportStep = 2, + ENR_simDuration = 3, + ENR_numPeriods = 4 +}ENR_Time; + +typedef enum { + ENR_demand = 1, + ENR_head = 2, + ENR_pressure = 3, + ENR_quality = 4 +} ENR_NodeAttribute; + +typedef enum { + ENR_flow = 1, + ENR_velocity = 2, + ENR_headloss = 3, + ENR_avgQuality = 4, + ENR_status = 5, + ENR_setting = 6, + ENR_rxRate = 7, + ENR_frctnFctr = 8 +} ENR_LinkAttribute; + + +#endif /* EPANET_OUTPUT_ENUMS_H_ */ diff --git a/tools/epanet-output/src/epanet_output.c b/tools/epanet-output/src/epanet_output.c index 741304f..eef6957 100644 --- a/tools/epanet-output/src/epanet_output.c +++ b/tools/epanet-output/src/epanet_output.c @@ -31,7 +31,7 @@ // data from the output file. As such they return arrays of data. The API // functions automatically allocate memory for the array to be returned. The // caller is responsible for deallocating memory. The function ENR_free() is -// provided to deallocate memory. +// provided for that purpose. // //----------------------------------------------------------------------------- @@ -96,7 +96,7 @@ int* newIntArray(int n); char* newCharArray(int n); -int DLLEXPORT ENR_init(ENR_Handle* dp_handle) +int EXPORT_OUT_API ENR_init(ENR_Handle* dp_handle) // Purpose: Initialized pointer for the opaque ENR_Handle. // // Returns: Error code 0 on success, -1 on failure @@ -122,7 +122,7 @@ int DLLEXPORT ENR_init(ENR_Handle* dp_handle) return errorcode; } -int DLLEXPORT ENR_close(ENR_Handle* p_handle) +int EXPORT_OUT_API ENR_close(ENR_Handle* p_handle) /*------------------------------------------------------------------------ ** Input: *p_handle = pointer to ENR_Handle struct ** @@ -157,7 +157,7 @@ int DLLEXPORT ENR_close(ENR_Handle* p_handle) return errorcode; } -int DLLEXPORT ENR_open(ENR_Handle p_handle, const char* path) +int EXPORT_OUT_API ENR_open(ENR_Handle p_handle, const char* path) /*------------------------------------------------------------------------ ** Input: path ** Output: p_handle = pointer to ENR_Handle struct @@ -221,7 +221,7 @@ int DLLEXPORT ENR_open(ENR_Handle p_handle, const char* path) return errorcode; } -int DLLEXPORT ENR_getVersion(ENR_Handle p_handle, int* version) +int EXPORT_OUT_API ENR_getVersion(ENR_Handle p_handle, int* version) /*------------------------------------------------------------------------ ** Input: p_handle = pointer to ENR_Handle struct ** Output: version Epanet version @@ -247,7 +247,7 @@ int DLLEXPORT ENR_getVersion(ENR_Handle p_handle, int* version) return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getNetSize(ENR_Handle p_handle, int** elementCount, int* length) +int EXPORT_OUT_API ENR_getNetSize(ENR_Handle p_handle, int** elementCount, int* length) /*------------------------------------------------------------------------ ** Input: p_handle = pointer to ENR_Handle struct ** Output: array of element counts (nodes, tanks, links, pumps, valves) @@ -278,7 +278,7 @@ int DLLEXPORT ENR_getNetSize(ENR_Handle p_handle, int** elementCount, int* lengt return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFlag) +int EXPORT_OUT_API ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFlag) /*------------------------------------------------------------------------ ** Input: p_handle = pointer to ENR_Handle struct ** code @@ -355,7 +355,7 @@ int DLLEXPORT ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFlag) return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getTimes(ENR_Handle p_handle, ENR_Time code, int* time) +int EXPORT_OUT_API ENR_getTimes(ENR_Handle p_handle, ENR_Time code, int* time) /*------------------------------------------------------------------------ ** Input: p_handle = pointer to ENR_Handle struct ** code = element code @@ -403,13 +403,13 @@ int DLLEXPORT ENR_getTimes(ENR_Handle p_handle, ENR_Time code, int* time) return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getChemData(ENR_Handle p_handle, char** name, int* length) +int EXPORT_OUT_API ENR_getChemData(ENR_Handle p_handle, char** name, int* length) { return 0; } -int DLLEXPORT ENR_getElementName(ENR_Handle p_handle, ENR_ElementType type, +int EXPORT_OUT_API ENR_getElementName(ENR_Handle p_handle, ENR_ElementType type, int elementIndex, char** name, int* length) /*------------------------------------------------------------------------ ** Input: p_handle = pointer to ENR_Handle struct @@ -469,7 +469,7 @@ int DLLEXPORT ENR_getElementName(ENR_Handle p_handle, ENR_ElementType type, return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex, +int EXPORT_OUT_API ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex, int* linkIndex, float** outValues, int* length) /* * Purpose: Returns pump energy usage statistics. @@ -514,7 +514,7 @@ int DLLEXPORT ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex, return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getNetReacts(ENR_Handle p_handle, float** outValues, int* length) +int EXPORT_OUT_API ENR_getNetReacts(ENR_Handle p_handle, float** outValues, int* length) /* * Purpose: Returns network wide average reaction rates and average * source mass inflow: @@ -549,7 +549,7 @@ int DLLEXPORT ENR_getNetReacts(ENR_Handle p_handle, float** outValues, int* leng return set_error(p_data->error_handle, errorcode); } -void DLLEXPORT ENR_free(void** array) +void EXPORT_OUT_API ENR_free(void** array) // // Purpose: Frees memory allocated by API calls // @@ -560,7 +560,7 @@ void DLLEXPORT ENR_free(void** array) } } -int DLLEXPORT ENR_getNodeSeries(ENR_Handle p_handle, int nodeIndex, ENR_NodeAttribute attr, +int EXPORT_OUT_API ENR_getNodeSeries(ENR_Handle p_handle, int nodeIndex, ENR_NodeAttribute attr, int startPeriod, int endPeriod, float** outValueSeries, int* dim) // // Purpose: Get time series results for particular attribute. Specify series @@ -595,7 +595,7 @@ int DLLEXPORT ENR_getNodeSeries(ENR_Handle p_handle, int nodeIndex, ENR_NodeAttr return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getLinkSeries(ENR_Handle p_handle, int linkIndex, ENR_LinkAttribute attr, +int EXPORT_OUT_API ENR_getLinkSeries(ENR_Handle p_handle, int linkIndex, ENR_LinkAttribute attr, int startPeriod, int endPeriod, float** outValueSeries, int* dim) // // Purpose: Get time series results for particular attribute. Specify series @@ -630,7 +630,7 @@ int DLLEXPORT ENR_getLinkSeries(ENR_Handle p_handle, int linkIndex, ENR_LinkAttr return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex, +int EXPORT_OUT_API ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex, ENR_NodeAttribute attr, float** outValueArray, int* length) // // Purpose: @@ -679,7 +679,7 @@ int DLLEXPORT ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex, return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex, +int EXPORT_OUT_API ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex, ENR_LinkAttribute attr, float** outValueArray, int* length) // // Purpose: @@ -729,7 +729,7 @@ int DLLEXPORT ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex, return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getNodeResult(ENR_Handle p_handle, int periodIndex, +int EXPORT_OUT_API ENR_getNodeResult(ENR_Handle p_handle, int periodIndex, int nodeIndex, float** outValueArray, int* length) // // Purpose: For a node at given time, get all attributes. @@ -759,7 +759,7 @@ int DLLEXPORT ENR_getNodeResult(ENR_Handle p_handle, int periodIndex, return set_error(p_data->error_handle, errorcode); } -int DLLEXPORT ENR_getLinkResult(ENR_Handle p_handle, int periodIndex, +int EXPORT_OUT_API ENR_getLinkResult(ENR_Handle p_handle, int periodIndex, int linkIndex, float** outValueArray, int* length) // // Purpose: For a link at given time, get all attributes @@ -786,7 +786,7 @@ int DLLEXPORT ENR_getLinkResult(ENR_Handle p_handle, int periodIndex, return set_error(p_data->error_handle, errorcode); } -void DLLEXPORT ENR_clearError(ENR_Handle p_handle) +void EXPORT_OUT_API ENR_clearError(ENR_Handle p_handle) { data_t* p_data; @@ -794,7 +794,7 @@ void DLLEXPORT ENR_clearError(ENR_Handle p_handle) clear_error(p_data->error_handle); } -int DLLEXPORT ENR_checkError(ENR_Handle p_handle, char** msg_buffer) +int EXPORT_OUT_API ENR_checkError(ENR_Handle p_handle, char** msg_buffer) { int errorcode = 0; char *temp = NULL; diff --git a/tools/epanet-output/src/epanet_output.i b/tools/epanet-output/src/epanet_output.i index d9eb3e1..8a239d6 100644 --- a/tools/epanet-output/src/epanet_output.i +++ b/tools/epanet-output/src/epanet_output.i @@ -1,12 +1,12 @@ /* * epanet_output.i - SWIG interface description file for EPANET Output API - * + * * Created: 9/20/2017 * * Author: Michael E. Tryby * US EPA - ORD/NRMRL * -*/ +*/ %module epanet_output %{ #include "errormanager.h" @@ -23,60 +23,9 @@ typedef void* ENR_Handle; -typedef enum { - ENR_node = 1, - ENR_link = 2 -} ENR_ElementType; -/* -typedef enum { - ENR_nodeCount = 1, - ENR_tankCount = 2, - ENR_linkCount = 3, - ENR_pumpCount = 4, - ENR_valveCount = 5 -} ENR_ElementCount; -*/ +%include "epanet_output_enums.h" -typedef enum { - ENR_flowUnits = 1, - ENR_pressUnits = 2 -} ENR_Units; - -typedef enum { - ENR_reportStart = 1, - ENR_reportStep = 2, - ENR_simDuration = 3, - ENR_numPeriods = 4 -}ENR_Time; - -typedef enum { - ENR_demand = 1, - ENR_head = 2, - ENR_pressure = 3, - ENR_quality = 4 -} ENR_NodeAttribute; - -typedef enum { - ENR_flow = 1, - ENR_velocity = 2, - ENR_headloss = 3, - ENR_avgQuality = 4, - ENR_status = 5, - ENR_setting = 6, - ENR_rxRate = 7, - ENR_frctnFctr = 8 -} ENR_LinkAttribute; - -#ifdef WINDOWS - #ifdef __cplusplus - #define DLLEXPORT __declspec(dllexport) __cdecl - #else - #define DLLEXPORT __declspec(dllexport) __stdcall - #endif -#else - #define DLLEXPORT -#endif /* TYPEMAPS FOR OPAQUE POINTER */ /* Used for functions that output a new opaque pointer */ @@ -92,7 +41,7 @@ and return a (possibly) different pointer */ { /* OUTPUT argout */ %append_output(SWIG_NewPointerObj(SWIG_as_voidptr(retval$argnum), $1_descriptor, 0)); -} +} /* No need for special IN typemap for opaque pointers, it works anyway */ @@ -118,7 +67,7 @@ and return a (possibly) different pointer */ if (*$1) { PyObject* o; o = PyUnicode_FromStringAndSize(*$1, *$2); - + $result = SWIG_Python_AppendOutput($result, o); free(*$1); } @@ -163,12 +112,12 @@ and return a (possibly) different pointer */ if (PyObject_HasAttrString($input,"value")) { PyObject* o; o = PyObject_GetAttrString($input, "value"); - ecode = SWIG_AsVal_int(o, &val); - } + ecode = SWIG_AsVal_int(o, &val); + } else { - SWIG_exception_fail(SWIG_ArgError(ecode), "in method '" "$symname" "', argument " "$argnum"" of type '" "$ltype""'"); - } - + SWIG_exception_fail(SWIG_ArgError(ecode), "in method '" "$symname" "', argument " "$argnum"" of type '" "$ltype""'"); + } + $1 = ($1_type)(val); } %apply EnumeratedType {ENR_ElementType, ENR_Units, ENR_Time, ENR_NodeAttribute, ENR_LinkAttribute} @@ -189,33 +138,33 @@ and return a (possibly) different pointer */ SWIG_fail; } } -/* INSERT EXCEPTION HANDLING FOR THESE FUNCTIONS */ -int DLLEXPORT ENR_open(ENR_Handle p_handle, const char* path); +/* INSERT EXCEPTION HANDLING FOR THESE FUNCTIONS */ +int ENR_open(ENR_Handle p_handle, const char* path); -int DLLEXPORT ENR_getVersion(ENR_Handle p_handle, int* int_out); -int DLLEXPORT ENR_getNetSize(ENR_Handle p_handle, int** int_out, int* int_dim); -int DLLEXPORT ENR_getUnits(ENR_Handle p_handle, ENR_Units t_enum, int* int_out); -int DLLEXPORT ENR_getTimes(ENR_Handle p_handle, ENR_Time t_enum, int* int_out); -int DLLEXPORT ENR_getElementName(ENR_Handle p_handle, ENR_ElementType t_enum, +int ENR_getVersion(ENR_Handle p_handle, int* int_out); +int ENR_getNetSize(ENR_Handle p_handle, int** int_out, int* int_dim); +int ENR_getUnits(ENR_Handle p_handle, ENR_Units t_enum, int* int_out); +int ENR_getTimes(ENR_Handle p_handle, ENR_Time t_enum, int* int_out); +int ENR_getElementName(ENR_Handle p_handle, ENR_ElementType t_enum, int elementIndex, char** string_out, int* slen); -int DLLEXPORT ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex, +int ENR_getEnergyUsage(ENR_Handle p_handle, int pumpIndex, int* int_out, float** float_out, int* int_dim); -int DLLEXPORT ENR_getNetReacts(ENR_Handle p_handle, float** float_out, int* int_dim); +int ENR_getNetReacts(ENR_Handle p_handle, float** float_out, int* int_dim); -int DLLEXPORT ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex, +int ENR_getNodeAttribute(ENR_Handle p_handle, int periodIndex, ENR_NodeAttribute t_enum, float** float_out, int* int_dim); -int DLLEXPORT ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex, +int ENR_getLinkAttribute(ENR_Handle p_handle, int periodIndex, ENR_LinkAttribute t_enum, float** float_out, int* int_dim); -%exception; +%exception; -/* NO EXCEPTION HANDLING FOR THESE FUNCTIONS */ -int DLLEXPORT ENR_init(ENR_Handle* p_handle_out); -int DLLEXPORT ENR_close(ENR_Handle* p_handle_out); -void DLLEXPORT ENR_free(void** array); +/* NO EXCEPTION HANDLING FOR THESE FUNCTIONS */ +int ENR_init(ENR_Handle* p_handle_out); +int ENR_close(ENR_Handle* p_handle_out); +void ENR_free(void** array); -void DLLEXPORT ENR_clearError(ENR_Handle p_handle); -int DLLEXPORT ENR_checkError(ENR_Handle p_handle, char** msg_buffer); +void ENR_clearError(ENR_Handle p_handle); +int ENR_checkError(ENR_Handle p_handle, char** msg_buffer); /* CODE ADDED DIRECTLY TO SWIGGED INTERFACE MODULE */ @@ -235,13 +184,13 @@ class Time(enum.Enum): REPORT_STEP = ENR_reportStep SIM_DURATION = ENR_simDuration NUM_PERIODS = ENR_numPeriods - + class NodeAttribute(enum.Enum): DEMAND = ENR_demand HEAD = ENR_head PRESSURE = ENR_pressure QUALITY = ENR_quality - + class LinkAttribute(enum.Enum): FLOW = ENR_flow VELOCITY = ENR_velocity