Merge pull request #230 from michaeltryby/copy-dev-swig

SWIG wrapper development
This commit is contained in:
Michael Tryby
2018-08-27 13:46:57 -04:00
committed by GitHub
21 changed files with 1606 additions and 836 deletions

View File

@@ -40,6 +40,7 @@
cmake_minimum_required (VERSION 2.8.8)
project(EPANET)
add_subdirectory(run)
add_subdirectory(tools/epanet-output)
IF (BUILD_TESTS)
@@ -51,6 +52,7 @@ 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)
# Sets the position independent code property for all targets
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -66,40 +68,25 @@ IF (MSVC)
ENDIF (MSVC)
#include_directories(include src)
# configure file groups
file(GLOB EPANET_SOURCES src/*.c)
#set(EPANET_API_HEADER include/epanet2.h)
set(EPANET_CLI_SOURCES run/main.c)
file(GLOB EPANET_LIB_ALL src/*)
file(GLOB EPANET_SOURCES src/*.c src/util/*.c)
file(GLOB EPANET_LIB_ALL src/* src/util/*)
source_group("Library" FILES ${EPANET_LIB_ALL})
source_group("CLI" REGULAR_EXPRESSION "run/.*")
# the shared library
add_library(epanet SHARED ${EPANET_SOURCES}) #${EPANET_API_HEADER})
target_include_directories(epanet PUBLIC ${PROJECT_SOURCE_DIR}/include)
# create export lib so we can link against dll using Visual Studio
#include(GenerateExportHeader)
#GENERATE_EXPORT_HEADER(epanet
# BASE_NAME epanet
# EXPORT_MACRO_NAME DLLEXPORT
# EXPORT_FILE_NAME epanet_export.h
# STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)
#
#file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_export.h
# DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_definitions(-D WITH_GENX)
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(epanet
BASE_NAME epanet
EXPORT_MACRO_NAME DLLEXPORT
EXPORT_FILE_NAME epanet_export.h
STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)
# the standalone executable
add_executable(runepanet ${EPANET_CLI_SOURCES})
if(NOT MSVC)
target_link_libraries(runepanet LINK_PUBLIC epanet m)
else(NOT MSVC)
target_link_libraries(runepanet LINK_PUBLIC epanet)
endif(NOT MSVC)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_export.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include)

View File

@@ -30,37 +30,40 @@
#define EN_API_FLOAT_TYPE float
#endif
// --- define WINDOWS
#undef WINDOWS
#ifdef _WIN32
#define WINDOWS
#endif
#ifdef __WIN32__
#define WINDOWS
#endif
#ifdef WITH_GENX
#include "epanet_export.h"
#else
// --- define WINDOWS
#undef WINDOWS
#ifdef _WIN32
#define WINDOWS
#endif
#ifdef __WIN32__
#define WINDOWS
#endif
// --- define DLLEXPORT
#ifndef DLLEXPORT
#ifdef WINDOWS
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif // __cplusplus
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(__APPLE__)
#ifdef __cplusplus
#define DLLEXPORT
// --- define DLLEXPORT
#ifndef DLLEXPORT
#ifdef WINDOWS
#ifdef __cplusplus
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif // __cplusplus
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(__APPLE__)
#ifdef __cplusplus
#define DLLEXPORT
#else
#define DLLEXPORT
#endif
#else
#define DLLEXPORT
#endif
#else
#define DLLEXPORT
#endif
#endif
//#include "epanet_export.h"
// --- Define the EPANET toolkit constants
@@ -276,7 +279,10 @@ extern "C" {
/**
@brief The EPANET Project wrapper object
*/
typedef struct EN_Project EN_Project;
typedef void *EN_ProjectHandle;
typedef struct EN_Pattern EN_Pattern;
typedef struct EN_Curve EN_Curve;
/**
@brief runs a complete EPANET simulation
@@ -291,7 +297,8 @@ extern "C" {
as it carries out its computations. If this feature is not
needed then the argument should be NULL.
*/
int DLLEXPORT ENepanet(char *inpFile, char *rptFile, char *binOutFile, void (*callback) (char *));
int DLLEXPORT ENepanet(const char *inpFile, const char *rptFile,
const char *binOutFile, void (*callback) (char *));
/**
@brief Initializes an EPANET session
@@ -1161,108 +1168,126 @@ extern "C" {
Threadsafe versions of all epanet functions
***************************************************/
int DLLEXPORT EN_createproject(EN_Project **p);
int DLLEXPORT EN_deleteproject(EN_Project *p);
int DLLEXPORT EN_createproject(EN_ProjectHandle *ph);
int DLLEXPORT EN_deleteproject(EN_ProjectHandle *ph);
int DLLEXPORT EN_epanet(char *inpFile, char *rptFile, char *binOutFile, void (*callback) (char *));
int DLLEXPORT EN_init(EN_Project *p, char *rptFile, char *binOutFile, EN_FlowUnits UnitsType, EN_FormType HeadlossFormula);
int DLLEXPORT EN_open(EN_Project *p, char *inpFile, char *rptFile, char *binOutFile);
int DLLEXPORT EN_saveinpfile(EN_Project *p, char *filename);
int DLLEXPORT EN_close(EN_Project *p);
int DLLEXPORT EN_solveH(EN_Project *p);
int DLLEXPORT EN_saveH(EN_Project *p);
int DLLEXPORT EN_openH(EN_Project *p);
int DLLEXPORT EN_initH(EN_Project *p, int EN_SaveOption);
int DLLEXPORT EN_runH(EN_Project *p, long *currentTime);
int DLLEXPORT EN_nextH(EN_Project *p, long *tStep);
int DLLEXPORT EN_closeH(EN_Project *p);
int DLLEXPORT EN_savehydfile(EN_Project *p, char *filename);
int DLLEXPORT EN_usehydfile(EN_Project *p, char *filename);
int DLLEXPORT EN_solveQ(EN_Project *p);
int DLLEXPORT EN_openQ(EN_Project *p);
int DLLEXPORT EN_initQ(EN_Project *p, int saveFlag);
int DLLEXPORT EN_runQ(EN_Project *p, long *currentTime);
int DLLEXPORT EN_nextQ(EN_Project *p, long *tStep);
int DLLEXPORT EN_stepQ(EN_Project *p, long *timeLeft);
int DLLEXPORT EN_closeQ(EN_Project *p);
int DLLEXPORT EN_writeline(EN_Project *p, char *line);
int DLLEXPORT EN_report(EN_Project *p);
int DLLEXPORT EN_resetreport(EN_Project *p);
int DLLEXPORT EN_setreport(EN_Project *p, char *reportFormat);
int DLLEXPORT EN_getcontrol(EN_Project *p, int controlIndex, int *controlType, int *linkIndex, EN_API_FLOAT_TYPE *setting, int *nodeIndex, EN_API_FLOAT_TYPE *level);
int DLLEXPORT EN_getcount(EN_Project *p, EN_CountType code, int *count);
int DLLEXPORT EN_getoption(EN_Project *p, EN_Option opt, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_gettimeparam(EN_Project *p, int code, long *value);
int DLLEXPORT EN_getflowunits(EN_Project *p, int *code);
int DLLEXPORT EN_setflowunits(EN_Project *p, int code);
int DLLEXPORT EN_getdemandmodel(EN_Project *p, int *type, EN_API_FLOAT_TYPE *pmin, EN_API_FLOAT_TYPE *preq,
EN_API_FLOAT_TYPE *pexp);
int DLLEXPORT EN_setdemandmodel(EN_Project *p, int type, EN_API_FLOAT_TYPE pmin, EN_API_FLOAT_TYPE preq,
EN_API_FLOAT_TYPE pexp);
int DLLEXPORT EN_getpatternindex(EN_Project *p, char *id, int *index);
int DLLEXPORT EN_getpatternid(EN_Project *p, int index, char *id);
int DLLEXPORT EN_getpatternlen(EN_Project *p, int index, int *len);
int DLLEXPORT EN_getpatternvalue(EN_Project *p, int index, int period, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getaveragepatternvalue(EN_Project *p, int index, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getqualtype(EN_Project *p, int *qualcode, int *tracenode);
void DLLEXPORT EN_clearError(EN_ProjectHandle ph);
int DLLEXPORT EN_checkError(EN_ProjectHandle ph, char** msg_buffer);
//int DLLEXPORT EN_epanet(EN_ProjectHandle ph, const char *f1, const char *f2,
// const char *f3, void(*pviewprog)(char *));
int DLLEXPORT EN_init(EN_ProjectHandle *ph, char *rptFile, char *binOutFile,
EN_FlowUnits UnitsType, EN_FormType HeadlossFormula);
int DLLEXPORT EN_open(EN_ProjectHandle ph, const char *inpFile,
const char *rptFile, const char *binOutFile);
int DLLEXPORT EN_saveinpfile(EN_ProjectHandle ph, char *filename);
int DLLEXPORT EN_close(EN_ProjectHandle ph);
int DLLEXPORT EN_solveH(EN_ProjectHandle ph);
int DLLEXPORT EN_saveH(EN_ProjectHandle ph);
int DLLEXPORT EN_openH(EN_ProjectHandle ph);
int DLLEXPORT EN_initH(EN_ProjectHandle ph, int EN_SaveOption);
int DLLEXPORT EN_runH(EN_ProjectHandle ph, long *currentTime);
int DLLEXPORT EN_nextH(EN_ProjectHandle ph, long *tStep);
int DLLEXPORT EN_closeH(EN_ProjectHandle ph);
int DLLEXPORT EN_savehydfile(EN_ProjectHandle ph, char *filename);
int DLLEXPORT EN_usehydfile(EN_ProjectHandle ph, char *filename);
int DLLEXPORT EN_solveQ(EN_ProjectHandle ph);
int DLLEXPORT EN_openQ(EN_ProjectHandle ph);
int DLLEXPORT EN_initQ(EN_ProjectHandle ph, int saveFlag);
int DLLEXPORT EN_runQ(EN_ProjectHandle ph, long *currentTime);
int DLLEXPORT EN_nextQ(EN_ProjectHandle ph, long *tStep);
int DLLEXPORT EN_stepQ(EN_ProjectHandle ph, long *timeLeft);
int DLLEXPORT EN_closeQ(EN_ProjectHandle ph);
int DLLEXPORT EN_writeline(EN_ProjectHandle ph, char *line);
int DLLEXPORT EN_report(EN_ProjectHandle ph);
int DLLEXPORT EN_resetreport(EN_ProjectHandle ph);
int DLLEXPORT EN_setreport(EN_ProjectHandle ph, char *reportFormat);
int DLLEXPORT EN_getcontrol(EN_ProjectHandle ph, int controlIndex, int *controlType, int *linkIndex, EN_API_FLOAT_TYPE *setting, int *nodeIndex, EN_API_FLOAT_TYPE *level);
int DLLEXPORT EN_getcount(EN_ProjectHandle ph, EN_CountType code, int *count);
int DLLEXPORT EN_getoption(EN_ProjectHandle ph, EN_Option opt, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_gettimeparam(EN_ProjectHandle ph, int code, long *value);
int DLLEXPORT EN_getflowunits(EN_ProjectHandle ph, int *code);
int DLLEXPORT EN_setflowunits(EN_ProjectHandle ph, int code);
int DLLEXPORT EN_getpatternindex(EN_ProjectHandle ph, char *id, int *index);
int DLLEXPORT EN_getpatternid(EN_ProjectHandle ph, int index, char *id);
int DLLEXPORT EN_getpatternlen(EN_ProjectHandle ph, int index, int *len);
int DLLEXPORT EN_getpatternvalue(EN_ProjectHandle ph, int index, int period, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getaveragepatternvalue(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getqualtype(EN_ProjectHandle ph, int *qualcode, int *tracenode);
int DLLEXPORT EN_geterror(int errcode, char *errmsg, int maxLen);
int DLLEXPORT EN_getstatistic(EN_Project *p, int code, EN_API_FLOAT_TYPE* value);
int DLLEXPORT EN_getnodeindex(EN_Project *p, char *id, int *index);
int DLLEXPORT EN_getnodeid(EN_Project *p, int index, char *id);
int DLLEXPORT EN_getnodetype(EN_Project *p, int index, int *code);
int DLLEXPORT EN_getnodevalue(EN_Project *p, int index, int code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getcoord(EN_Project *p, int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
int DLLEXPORT EN_setcoord(EN_Project *p, int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
int DLLEXPORT EN_getnumdemands(EN_Project *p, int nodeIndex, int *numDemands);
int DLLEXPORT EN_getbasedemand(EN_Project *p, int nodeIndex, int demandIndex, EN_API_FLOAT_TYPE *baseDemand);
int DLLEXPORT EN_getdemandpattern(EN_Project *p, int nodeIndex, int demandIndex, int *pattIndex);
int DLLEXPORT EN_getlinkindex(EN_Project *p, char *id, int *index);
int DLLEXPORT EN_getlinkid(EN_Project *p, int index, char *id);
int DLLEXPORT EN_getlinktype(EN_Project *p, int index, EN_LinkType *code);
int DLLEXPORT EN_setlinktype(EN_Project *p, char *id, EN_LinkType type);
int DLLEXPORT EN_getlinknodes(EN_Project *p, int index, int *node1, int *node2);
int DLLEXPORT EN_getlinkvalue(EN_Project *p, int index, EN_LinkProperty code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getcurve(EN_Project *p, int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues);
int DLLEXPORT EN_getheadcurveindex(EN_Project *p, int pumpIndex, int *curveIndex);
int DLLEXPORT EN_setheadcurveindex(EN_Project *p, int pumpIndex, int curveIndex);
int DLLEXPORT EN_getpumptype(EN_Project *p, int linkIndex, int *outType);
int DLLEXPORT EN_getcurvetype(EN_Project *p, int curveIndex, int *outType);
int DLLEXPORT EN_getstatistic(EN_ProjectHandle ph, int code, EN_API_FLOAT_TYPE* value);
int DLLEXPORT EN_getnodeindex(EN_ProjectHandle ph, char *id, int *index);
int DLLEXPORT EN_getnodeid(EN_ProjectHandle ph, int index, char *id);
int DLLEXPORT EN_getnodetype(EN_ProjectHandle ph, int index, int *code);
int DLLEXPORT EN_getnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getcoord(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
int DLLEXPORT EN_setcoord(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
int DLLEXPORT EN_getnumdemands(EN_ProjectHandle ph, int nodeIndex, int *numDemands);
int DLLEXPORT EN_getbasedemand(EN_ProjectHandle ph, int nodeIndex, int demandIndex, EN_API_FLOAT_TYPE *baseDemand);
int DLLEXPORT EN_getdemandpattern(EN_ProjectHandle ph, int nodeIndex, int demandIndex, int *pattIndex);
int DLLEXPORT EN_getlinkindex(EN_ProjectHandle ph, char *id, int *index);
int DLLEXPORT EN_getlinkid(EN_ProjectHandle ph, int index, char *id);
int DLLEXPORT EN_getlinktype(EN_ProjectHandle ph, int index, EN_LinkType *code);
int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, char *id, EN_LinkType type);
int DLLEXPORT EN_getlinknodes(EN_ProjectHandle ph, int index, int *node1, int *node2);
int DLLEXPORT EN_getlinkvalue(EN_ProjectHandle ph, int index, EN_LinkProperty code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getcurve(EN_ProjectHandle ph, int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues);
int DLLEXPORT EN_getheadcurveindex(EN_ProjectHandle ph, int pumpIndex, int *curveIndex);
int DLLEXPORT EN_setheadcurveindex(EN_ProjectHandle ph, int pumpIndex, int curveIndex);
int DLLEXPORT EN_getpumptype(EN_ProjectHandle ph, int linkIndex, int *outType);
int DLLEXPORT EN_getcurvetype(EN_ProjectHandle ph, int curveIndex, int *outType);
int DLLEXPORT EN_getversion(int *version);
int DLLEXPORT EN_setcontrol(EN_Project *p, int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
int DLLEXPORT EN_setnodevalue(EN_Project *p, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setlinkvalue(EN_Project *p, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_addpattern(EN_Project *p, char *id);
int DLLEXPORT EN_setpattern(EN_Project *p, int index, EN_API_FLOAT_TYPE *f, int len);
int DLLEXPORT EN_setpatternvalue(EN_Project *p, int index, int period, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_settimeparam(EN_Project *p, int code, long value);
int DLLEXPORT EN_setoption(EN_Project *p, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setstatusreport(EN_Project *p, int code);
int DLLEXPORT EN_setqualtype(EN_Project *p, int qualcode, char *chemname, char *chemunits, char *tracenode);
int DLLEXPORT EN_getqualinfo(EN_Project *p, int *qualcode, char *chemname, char *chemunits, int *tracenode);
int DLLEXPORT EN_setbasedemand(EN_Project *p, int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand);
int DLLEXPORT EN_getcurveindex(EN_Project *p, char *id, int *index);
int DLLEXPORT EN_getcurveid(EN_Project *p, int index, char *id);
int DLLEXPORT EN_getcurvelen(EN_Project *p, int index, int *len);
int DLLEXPORT EN_getcurvevalue(EN_Project *p, int curveIndex, int pointIndex, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
int DLLEXPORT EN_setcurvevalue(EN_Project *p, int curveIndex, int pointIndex, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
int DLLEXPORT EN_setcurve(EN_Project *p, int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y, int len);
int DLLEXPORT EN_addcurve(EN_Project *p, char *id);
int DLLEXPORT EN_getrule(EN_Project *p, int index, int *nPremises, int *nTrueActions, int *nFalseActions, EN_API_FLOAT_TYPE *priority);
int DLLEXPORT EN_setrulepriority(EN_Project *p, int index, EN_API_FLOAT_TYPE priority);
int DLLEXPORT EN_getpremise(EN_Project *p, int indexRule, int indexPremise, int *logop, int *object, int *indexObj, int *variable, int *relop, int *status, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_setpremise(EN_Project *p, int indexRule, int indexPremise, int logop, int object, int indexObj, int variable, int relop, int status, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_setpremiseindex(EN_Project *p, int indexRule, int indexPremise, int indexObj);
int DLLEXPORT EN_setpremisestatus(EN_Project *p, int indexRule, int indexPremise, int status);
int DLLEXPORT EN_setpremisevalue(EN_Project *p, int indexRule, int indexPremise, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_gettrueaction(EN_Project *p, int indexRule, int indexAction, int *indexLink, int *status, EN_API_FLOAT_TYPE *setting);
int DLLEXPORT EN_settrueaction(EN_Project *p, int indexRule, int indexAction, int indexLink, int status, EN_API_FLOAT_TYPE setting);
int DLLEXPORT EN_getfalseaction(EN_Project *p, int indexRule, int indexAction, int *indexLink, int *status, EN_API_FLOAT_TYPE *setting);
int DLLEXPORT EN_setfalseaction(EN_Project *p, int indexRule, int indexAction, int indexLink, int status, EN_API_FLOAT_TYPE setting);
int DLLEXPORT EN_getruleID(EN_Project *p, int indexRule, char* id);
int DLLEXPORT EN_addnode(EN_Project *p, char *id, EN_NodeType nodeType);
int DLLEXPORT EN_addlink(EN_Project *p, char *id, EN_LinkType linkType, char *fromNode, char *toNode);
int DLLEXPORT EN_deletenode(EN_Project *p, int nodeIndex);
int DLLEXPORT EN_deletelink(EN_Project *p, int linkIndex);
int DLLEXPORT EN_setcontrol(EN_ProjectHandle ph, int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setlinkvalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_addpattern(EN_ProjectHandle ph, char *id);
int DLLEXPORT EN_setpattern(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *f, int len);
int DLLEXPORT EN_setpatternvalue(EN_ProjectHandle ph, int index, int period, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_settimeparam(EN_ProjectHandle ph, int code, long value);
int DLLEXPORT EN_setoption(EN_ProjectHandle ph, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setstatusreport(EN_ProjectHandle ph, int code);
int DLLEXPORT EN_setqualtype(EN_ProjectHandle ph, int qualcode, char *chemname, char *chemunits, char *tracenode);
int DLLEXPORT EN_getdemandmodel(EN_ProjectHandle ph, int *type, EN_API_FLOAT_TYPE *pmin,
EN_API_FLOAT_TYPE *preq, EN_API_FLOAT_TYPE *pexp);
int DLLEXPORT EN_setdemandmodel(EN_ProjectHandle ph, int type, EN_API_FLOAT_TYPE pmin,
EN_API_FLOAT_TYPE preq, EN_API_FLOAT_TYPE pexp);
int DLLEXPORT EN_getqualinfo(EN_ProjectHandle ph, int *qualcode, char *chemname, char *chemunits, int *tracenode);
int DLLEXPORT EN_setbasedemand(EN_ProjectHandle ph, int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand);
int DLLEXPORT EN_getcurveindex(EN_ProjectHandle ph, char *id, int *index);
int DLLEXPORT EN_getcurveid(EN_ProjectHandle ph, int index, char *id);
int DLLEXPORT EN_getcurvelen(EN_ProjectHandle ph, int index, int *len);
int DLLEXPORT EN_getcurvevalue(EN_ProjectHandle ph, int curveIndex, int pointIndex, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
int DLLEXPORT EN_setcurvevalue(EN_ProjectHandle ph, int curveIndex, int pointIndex, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
int DLLEXPORT EN_setcurve(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y, int len);
int DLLEXPORT EN_addcurve(EN_ProjectHandle ph, char *id);
int DLLEXPORT EN_getrule(EN_ProjectHandle ph, int index, int *nPremises, int *nTrueActions, int *nFalseActions, EN_API_FLOAT_TYPE *priority);
int DLLEXPORT EN_setrulepriority(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE priority);
int DLLEXPORT EN_getpremise(EN_ProjectHandle ph, int indexRule, int indexPremise, int *logop, int *object, int *indexObj, int *variable, int *relop, int *status, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_setpremise(EN_ProjectHandle ph, int indexRule, int indexPremise, int logop, int object, int indexObj, int variable, int relop, int status, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_setpremiseindex(EN_ProjectHandle ph, int indexRule, int indexPremise, int indexObj);
int DLLEXPORT EN_setpremisestatus(EN_ProjectHandle ph, int indexRule, int indexPremise, int status);
int DLLEXPORT EN_setpremisevalue(EN_ProjectHandle ph, int indexRule, int indexPremise, EN_API_FLOAT_TYPE value);
int DLLEXPORT EN_gettrueaction(EN_ProjectHandle ph, int indexRule, int indexAction, int *indexLink, int *status, EN_API_FLOAT_TYPE *setting);
int DLLEXPORT EN_settrueaction(EN_ProjectHandle ph, int indexRule, int indexAction, int indexLink, int status, EN_API_FLOAT_TYPE setting);
int DLLEXPORT EN_getfalseaction(EN_ProjectHandle ph, int indexRule, int indexAction, int *indexLink, int *status, EN_API_FLOAT_TYPE *setting);
int DLLEXPORT EN_setfalseaction(EN_ProjectHandle ph, int indexRule, int indexAction, int indexLink, int status, EN_API_FLOAT_TYPE setting);
int DLLEXPORT EN_getruleID(EN_ProjectHandle ph, int indexRule, char* id);
int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType);
int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode);
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int nodeIndex);
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int linkIndex);
#if defined(__cplusplus)
}

28
run/CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
# EPANET COMMAND LINE EXECUTABLE
cmake_minimum_required (VERSION 3.0.2)
# 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)
# Sets the position independent code property for all targets.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Set up file groups for exe target
set(EPANET_CLI_SOURCES main.c)
include_directories(include)
source_group("CLI" FILES ${EPANET_CLI_SOURCES})
# Creates the EPANET command line executable
add_definitions(-D WITH_GENX)
add_executable(runepanet ${EPANET_CLI_SOURCES})
if(NOT WIN32)
target_link_libraries(runepanet LINK_PUBLIC epanet m)
else(NOT WIN32)
target_link_libraries(runepanet LINK_PUBLIC epanet)
endif(NOT WIN32)

File diff suppressed because it is too large Load Diff

View File

@@ -36,10 +36,11 @@ int allocdata(EN_Project *pr); /* Allocates memory
void freeTmplist(STmplist *); /* Frees items in linked list */
void freeFloatlist(SFloatlist *); /* Frees list of floats */
void freedata(EN_Project *pr); /* Frees allocated memory */
int openfiles(EN_Project *pr, char *,char *,char *); /* Opens input & report files */
int openfiles(EN_Project *pr, const char *,
const char *,const char *); /* Opens input & report files */
int openhydfile(EN_Project *pr); /* Opens hydraulics file */
int openoutfile(EN_Project *pr); /* Opens binary output file */
int strcomp(char *, char *); /* Compares two strings */
int strcomp(const char *, const char *); /* Compares two strings */
char* getTmpName(EN_Project *p, char* fname); /* Gets temporary file name */
double interp(int n, double x[], double y[],
double xx); /* Interpolates a data curve */
@@ -51,7 +52,7 @@ int findvalve(EN_Network *n, int); /* Find valve index from node
int findpump(EN_Network *n, int); /* Find pump index from node index */ // (AH)
char *geterrmsg(int errcode, char *msg); /* Gets text of error message */
void errmsg(EN_Project *p, int); /* Reports program error */
void writecon(char *); /* Writes text to console */
void writecon(const char *); /* Writes text to console */
void writewin(void (*vp)(char *), char *); /* Passes text to calling app */
/* ------- INPUT1.C --------------------*/
@@ -126,6 +127,8 @@ void freerules(EN_Project *pr); /* Frees rule base memory
int writeRuleinInp(EN_Project *pr, FILE *f, /* Writes rule to an INP file */
int RuleIdx);
int writeRuleinInp(EN_Project *pr, FILE *f, int RuleIdx);
/* ------------- REPORT.C --------------*/
int writereport(EN_Project *pr); /* Writes formatted report */
void writelogo(EN_Project *pr); /* Writes program logo */

View File

@@ -820,9 +820,10 @@ int match(const char *str, const char *substr)
break;
/* Check if substr matches remainder of str. */
for (i = i, j = 0; substr[j]; i++, j++)
for (j = 0; substr[j]; i++, j++)
if (!str[i] || UCHAR(str[i]) != UCHAR(substr[j]))
return (0);
return (1);
} /* end of match */

View File

@@ -112,7 +112,7 @@ int takeactions(EN_Project *pr);
void clearactlist(rules_t *rules);
void clearrules(EN_Project *pr);
void ruleerrmsg(EN_Project *pr, int);
int writeRuleinInp(EN_Project *pr, FILE *f, int RuleIdx);
//int writeRuleinInp(EN_Project *pr, FILE *f, int RuleIdx);
void initrules(rules_t *rules)
/*

View File

@@ -23,6 +23,8 @@ AUTHOR: L. Rossman
#include "epanet2.h"
#include "hash.h"
#include "mempool.h"
#include "util/errormanager.h"
/*********************************************************/
/* All floats have been re-declared as doubles (7/3/07). */
@@ -861,7 +863,7 @@ typedef struct {
/* project wrapper */
struct EN_Project {
typedef struct EN_Project {
EN_Network network; /// the network description struct
hydraulics_t hydraulics;
@@ -883,8 +885,10 @@ struct EN_Project {
Title[MAXTITLE][MAXMSG+1], /// Problem title
MapFname[MAXFNAME+1]; /// Map file name
error_handle_t* error_handle; //Simple error manager
void (* viewprog) (char *); /* Pointer to progress viewing function */
};
} EN_Project;
#endif

73
src/util/errormanager.c Normal file
View File

@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------------
//
// errormanager.c
//
// Purpose: Provides a simple interface for managing runtime error messages.
//
// Date: 08/25/2017
//
// Author: Michael E. Tryby
// US EPA - ORD/NRMRL
//-----------------------------------------------------------------------------
#include "errormanager.h"
error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int))
//
// Purpose: Constructs a new error handle.
//
{
error_handle_t* error_handle;
error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t));
if (error_handle != NULL)
error_handle->p_msg_lookup = p_error_message;
return error_handle;
}
void dst_errormanager(error_handle_t* error_handle)
//
// Purpose: Destroys the error handle.
//
{
free(error_handle);
}
int set_error(error_handle_t* error_handle, int errorcode)
//
// Purpose: Sets an error code in the handle.
//
{
// If the error code is 0 no action is taken and 0 is returned.
// This is a feature not a bug.
if (errorcode)
error_handle->error_status = errorcode;
return errorcode;
}
char* check_error(error_handle_t* error_handle)
//
// Purpose: Returns the error message or NULL.
//
// Note: Caller must free memory allocated by check_error
//
{
char* temp = NULL;
if (error_handle->error_status != 0) {
temp = (char*) calloc(ERR_MAXMSG, sizeof(char));
if (temp)
error_handle->p_msg_lookup(error_handle->error_status, temp, ERR_MAXMSG);
}
return temp;
}
void clear_error(error_handle_t* error_handle)
//
// Purpose: Clears the error from the handle.
//
{
error_handle->error_status = 0;
}

30
src/util/errormanager.h Normal file
View File

@@ -0,0 +1,30 @@
/*
* errormanager.h
*
* Created on: Aug 25, 2017
*
* Author: Michael E. Tryby
* US EPA - ORD/NRMRL
*/
#ifndef ERRORMANAGER_H_
#define ERRORMANAGER_H_
#include <stdlib.h>
#include <string.h>
#define ERR_MAXMSG 256
typedef struct error_s {
int error_status;
void (*p_msg_lookup)(int, char*, int);
} error_handle_t;
error_handle_t* new_errormanager(void (*p_error_message)(int, char*, int));
void dst_errormanager(error_handle_t* error_handle);
int set_error(error_handle_t* error_handle, int errorcode);
char* check_error(error_handle_t* error_handle);
void clear_error(error_handle_t* error_handle);
#endif /* ERRORMANAGER_H_ */

View File

@@ -11,6 +11,6 @@
// this single global variable is used only when the library is called in "legacy mode"
// with the 2.1-style API.
EXTERN EN_Project *_defaultModel;
EXTERN void *_defaultModel;
#endif

View File

@@ -37,8 +37,7 @@ foreach(testSrc ${TEST_SRCS})
#link to Boost libraries AND your targets and dependencies
target_link_libraries(${testName} ${Boost_LIBRARIES} epanet epanet-output)
#Finally add it to test execution -
#Finally add it to test execution
#Notice the WORKING_DIRECTORY and COMMAND
add_test(NAME ${testName}
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName}

BIN
tests/data/example1.out Normal file

Binary file not shown.

178
tests/data/net1.inp Normal file
View File

@@ -0,0 +1,178 @@
[TITLE]
EPANET Example Network 1
A simple example of modeling chlorine decay. Both bulk and
wall reactions are included.
[JUNCTIONS]
;ID Elev Demand Pattern
10 710 0 ;
11 710 150 ;
12 700 150 ;
13 695 100 ;
21 700 150 ;
22 695 200 ;
23 690 150 ;
31 700 100 ;
32 710 100 ;
[RESERVOIRS]
;ID Head Pattern
9 800 ;
[TANKS]
;ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
2 850 120 100 150 50.5 0 ;
[PIPES]
;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
10 10 11 10530 18 100 0 Open ;
11 11 12 5280 14 100 0 Open ;
12 12 13 5280 10 100 0 Open ;
21 21 22 5280 10 100 0 Open ;
22 22 23 5280 12 100 0 Open ;
31 31 32 5280 6 100 0 Open ;
110 2 12 200 18 100 0 Open ;
111 11 21 5280 10 100 0 Open ;
112 12 22 5280 12 100 0 Open ;
113 13 23 5280 8 100 0 Open ;
121 21 31 5280 8 100 0 Open ;
122 22 32 5280 6 100 0 Open ;
[PUMPS]
;ID Node1 Node2 Parameters
9 9 10 HEAD 1 ;
[VALVES]
;ID Node1 Node2 Diameter Type Setting MinorLoss
[TAGS]
[DEMANDS]
;Junction Demand Pattern Category
[STATUS]
;ID Status/Setting
[PATTERNS]
;ID Multipliers
;Demand Pattern
1 1.0 1.2 1.4 1.6 1.4 1.2
1 1.0 0.8 0.6 0.4 0.6 0.8
[CURVES]
;ID X-Value Y-Value
;PUMP: Pump Curve for Pump 9
1 1500 250
[CONTROLS]
LINK 9 OPEN IF NODE 2 BELOW 110
LINK 9 CLOSED IF NODE 2 ABOVE 140
[RULES]
[ENERGY]
Global Efficiency 75
Global Price 0.0
Demand Charge 0.0
[EMITTERS]
;Junction Coefficient
[QUALITY]
;Node InitQual
10 0.5
11 0.5
12 0.5
13 0.5
21 0.5
22 0.5
23 0.5
31 0.5
32 0.5
9 1.0
2 1.0
[SOURCES]
;Node Type Quality Pattern
[REACTIONS]
;Type Pipe/Tank Coefficient
[REACTIONS]
Order Bulk 1
Order Tank 1
Order Wall 1
Global Bulk -.5
Global Wall -1
Limiting Potential 0.0
Roughness Correlation 0.0
[MIXING]
;Tank Model
[TIMES]
Duration 24:00
Hydraulic Timestep 1:00
Quality Timestep 0:05
Pattern Timestep 2:00
Pattern Start 0:00
Report Timestep 1:00
Report Start 0:00
Start ClockTime 12 am
Statistic None
[REPORT]
Status Yes
Summary No
Page 0
[OPTIONS]
Units GPM
Headloss H-W
Specific Gravity 1.0
Viscosity 1.0
Trials 40
Accuracy 0.001
CHECKFREQ 2
MAXCHECK 10
DAMPLIMIT 0
Unbalanced Continue 10
Pattern 1
Demand Multiplier 1.0
Emitter Exponent 0.5
Quality Chlorine mg/L
Diffusivity 1.0
Tolerance 0.01
[COORDINATES]
;Node X-Coord Y-Coord
10 20.00 70.00
11 30.00 70.00
12 50.00 70.00
13 70.00 70.00
21 30.00 40.00
22 50.00 40.00
23 70.00 40.00
31 30.00 10.00
32 50.00 10.00
9 10.00 70.00
2 50.00 90.00
[VERTICES]
;Link X-Coord Y-Coord
[LABELS]
;X-Coord Y-Coord Label & Anchor Node
6.99 73.63 "Source"
13.48 68.13 "Pump"
43.85 91.21 "Tank"
[BACKDROP]
DIMENSIONS 7.00 6.00 73.00 94.00
UNITS None
FILE
OFFSET 0.00 0.00
[END]

View File

@@ -22,8 +22,7 @@
#include "epanet_output.h"
#define DATA_PATH "./net1.out"
#define DATA_PATH "./example1.out"
using namespace std;
@@ -117,7 +116,6 @@ struct Fixture{
float* array;
int array_dim;
};
BOOST_AUTO_TEST_SUITE(test_output_fixture)
@@ -144,6 +142,15 @@ BOOST_FIXTURE_TEST_CASE(test_getNetSize, Fixture)
ENR_free((void**)&i_array);
}
BOOST_FIXTURE_TEST_CASE(test_getUnits, Fixture) {
int flag;
error = ENR_getUnits(p_handle, ENR_qualUnits, &flag);
BOOST_REQUIRE(error == 0);
BOOST_CHECK_EQUAL(flag, ENR_MGL);
}
BOOST_FIXTURE_TEST_CASE(test_getElementName, Fixture) {
char* name = new char[MAXID];
int length, index = 1;
@@ -179,7 +186,6 @@ BOOST_FIXTURE_TEST_CASE(test_getNodeAttribute, Fixture) {
std::vector<float> ref_vec;
ref_vec.assign(ref_array, ref_array + ref_dim);
std::vector<float> test_vec;
test_vec.assign(array, array + array_dim);

207
tests/test_toolkit.cpp Normal file
View File

@@ -0,0 +1,207 @@
//
// test_epanet_toolkit.cpp
//
// Date Created: January 24, 2018
//
// Author: Michael E. Tryby
// US EPA - ORD/NRMRL
//
//#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#include <string>
#include "epanet2.h"
// 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"
using namespace std;
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE (test_alloc_free)
{
int error = 0;
EN_ProjectHandle ph = NULL;
error = EN_createproject(&ph);
BOOST_REQUIRE(error == 0);
BOOST_CHECK(ph != NULL);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
BOOST_CHECK(ph == NULL);
}
BOOST_AUTO_TEST_CASE (test_open_close)
{
EN_ProjectHandle ph = NULL;
EN_createproject(&ph);
std::string path_inp = std::string(DATA_PATH_INP);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_CASE(test_epanet)
{
std::string path_inp = std::string(DATA_PATH_INP);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
int error = ENepanet(path_inp.c_str(), path_rpt.c_str(), path_out.c_str(), NULL);
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_SUITE_END()
struct Fixture{
Fixture() {
path_inp = std::string(DATA_PATH_INP);
path_rpt = std::string(DATA_PATH_RPT);
path_out = std::string(DATA_PATH_OUT);
EN_createproject(&ph);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
}
~Fixture() {
error = EN_close(ph);
EN_deleteproject(&ph);
}
std::string path_inp;
std::string path_rpt;
std::string path_out;
int error;
EN_ProjectHandle ph;
};
BOOST_AUTO_TEST_SUITE(test_epanet_fixture)
BOOST_FIXTURE_TEST_CASE(test_epanet, Fixture)
{
error = EN_solveH(ph);
BOOST_REQUIRE(error == 0);
error = EN_solveQ(ph);
BOOST_REQUIRE(error == 0);
error = EN_report(ph);
BOOST_REQUIRE(error == 0);
}
BOOST_FIXTURE_TEST_CASE(test_hyd_step, Fixture)
{
int flag = 00;
long t, tstep;
error = EN_openH(ph);
BOOST_REQUIRE(error == 0);
error = EN_initH(ph, flag);
BOOST_REQUIRE(error == 0);
do {
error = EN_runH(ph, &t);
BOOST_REQUIRE(error == 0);
error = EN_nextH(ph, &tstep);
BOOST_REQUIRE(error == 0);
} while (tstep > 0);
error = EN_closeH(ph);
BOOST_REQUIRE(error == 0);
}
BOOST_FIXTURE_TEST_CASE(test_qual_step, Fixture)
{
int flag = 0;
long t, tstep;
error = EN_solveH(ph);
BOOST_REQUIRE(error == 0);
error = EN_openQ(ph);
BOOST_REQUIRE(error == 0);
error = EN_initQ(ph, flag);
BOOST_REQUIRE(error == 0);
do {
error = EN_runQ(ph, &t);
BOOST_REQUIRE(error == 0);
error = EN_nextQ(ph, &tstep);
BOOST_REQUIRE(error == 0);
} while (tstep > 0);
error = EN_closeQ(ph);
BOOST_REQUIRE(error == 0);
}
BOOST_FIXTURE_TEST_CASE(test_progressive_stepping, Fixture)
{
int flag = EN_NOSAVE;
long t, tstep_h, tstep_q;
error = EN_openH(ph);
BOOST_REQUIRE(error == 0);
error = EN_initH(ph, flag);
BOOST_REQUIRE(error == 0);
error = EN_openQ(ph);
BOOST_REQUIRE(error == 0);
error = EN_initQ(ph, flag);
BOOST_REQUIRE(error == 0);
do {
error = EN_runH(ph, &t);
BOOST_REQUIRE(error == 0);
error = EN_runQ(ph, &t);
BOOST_REQUIRE(error == 0);
error = EN_nextH(ph, &tstep_h);
BOOST_REQUIRE(error == 0);
error = EN_nextQ(ph, &tstep_q);
BOOST_REQUIRE(error == 0);
} while (tstep_h > 0);
error = EN_closeH(ph);
BOOST_REQUIRE(error == 0);
error = EN_closeQ(ph);
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -18,22 +18,42 @@
typedef void* ENR_Handle;
typedef enum {
ENR_node = 1,
ENR_link = 2
ENR_node = 1,
ENR_link = 2
} ENR_ElementType;
typedef enum {
ENR_getSeries = 1,
ENR_getAttribute = 2,
ENR_getResult = 3,
ENR_getReacts = 4,
ENR_getEnergy = 5
} ENR_ApiFunction;
ENR_flowUnits = 1,
ENR_pressUnits = 2,
ENR_qualUnits = 3
} ENR_Units;
typedef enum {
ENR_flowUnits = 1,
ENR_pressUnits = 2
} ENR_Units;
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,
@@ -43,21 +63,21 @@ typedef enum {
}ENR_Time;
typedef enum {
ENR_demand = 1,
ENR_head = 2,
ENR_pressure = 3,
ENR_quality = 4
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_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;

View File

@@ -57,7 +57,8 @@
#define MINNREC 14 // Minimum allowable number of records
#define PROLOGUE 884 // Preliminary fixed length section of header
#define MAXID_P1 32 // Max. # characters in ID name
#define MAXID_P1 32 // EPANET max characters in ID name PLUS 1
#define MAXMSG_P1 80 // EPANET max characters in message text PLUS 1
#define NELEMENTTYPES 5 // Number of element types
#define NENERGYRESULTS 6 // Number of energy results
@@ -303,6 +304,8 @@ int DLLEXPORT ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFlag)
*/
{
int errorcode = 0;
F_OFF offset;
char temp[MAXID_P1];
data_t* p_data;
*unitFlag = -1;
@@ -315,15 +318,37 @@ int DLLEXPORT ENR_getUnits(ENR_Handle p_handle, ENR_Units code, int* unitFlag)
switch (code)
{
case ENR_flowUnits:
fseek(p_data->file, 9*WORDSIZE, SEEK_SET);
_fseek(p_data->file, 9*WORDSIZE, SEEK_SET);
fread(unitFlag, WORDSIZE, 1, p_data->file);
break;
case ENR_pressUnits:
fseek(p_data->file, 10*WORDSIZE, SEEK_SET);
_fseek(p_data->file, 10*WORDSIZE, SEEK_SET);
fread(unitFlag, WORDSIZE, 1, p_data->file);
break;
case ENR_qualUnits:
offset = 7*WORDSIZE;
_fseek(p_data->file, offset, SEEK_SET);
fread(unitFlag, WORDSIZE, 1, p_data->file);
if (*unitFlag == 0) *unitFlag = ENR_NONE;
else if (*unitFlag == 1) {
offset = 15*WORDSIZE + 3*MAXMSG_P1 + 2*(MAXFNAME+1) + MAXID_P1;
_fseek(p_data->file, offset, SEEK_SET);
fread(temp, MAXID_P1, 1, p_data->file);
if (!strcmp(temp, "mg/L")) *unitFlag = ENR_MGL;
else *unitFlag = ENR_UGL;
}
else if (*unitFlag == 2) *unitFlag = ENR_HOURS;
else *unitFlag = ENR_PRCNT;
break;
default: errorcode = 421;
}
}
@@ -378,6 +403,12 @@ 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)
{
return 0;
}
int DLLEXPORT ENR_getElementName(ENR_Handle p_handle, ENR_ElementType type,
int elementIndex, char** name, int* length)
/*------------------------------------------------------------------------
@@ -815,7 +846,7 @@ void errorLookup(int errcode, char* dest_msg, int dest_len)
default: msg = ERRERR;
}
strncpy(dest_msg, msg, MAXMSG);
strncpy(dest_msg, msg, MSG_MAXLEN);
}
int validateFile(ENR_Handle p_handle)

View File

@@ -10,7 +10,7 @@
#ifndef MESSAGES_H_
#define MESSAGES_H_
/*------------------- Error Messages --------------------*/
#define MAXMSG 53
#define MSG_MAXLEN 53
#define WARN10 "Warning: model run issued warnings"

View File

@@ -1,102 +0,0 @@
#
# epanet_output_test.py
#
# Created: 11/8/2017
# Author: Michael E. Tryby
# US EPA - ORD/NRMRL
#
# Unit testing for EPANET Output API using pytest.
#
import pytest
import numpy as np
import epanet_output as oapi
from data import OUTPUT_FILE_EXAMPLE1
@pytest.fixture()
def enr_handle(request):
_handle = oapi.enr_init()
oapi.enr_open(_handle, OUTPUT_FILE_EXAMPLE1)
def enr_close():
oapi.enr_close()
request.addfinalizer(enr_close)
return _handle
def test_get_times(enr_handle):
num_periods = oapi.enr_get_times(enr_handle, oapi.Time.NUM_PERIODS)
assert num_periods == 25
# def test_get_size(file_path):
# handle = oapi.enr_init()
# oapi.enr_open(handle, file_path)
#
# size = oapi.enr_get_net_size(handle)
#
# print(size)
#
# handle = oapi.enr_close()
#
# def test_get_names(file_path):
# handle = oapi.enr_init()
# oapi.enr_open(handle, file_path)
#
# name = oapi.enr_get_element_name(handle, oapi.ElementType.NODE, 10)
#
# print(name)
#
# handle = oapi.enr_close()
#
# def test_get_energy(file_path):
# handle = oapi.enr_init()
# oapi.enr_open(handle, file_path)
#
# result = oapi.enr_get_energy_usage(handle, 1)
#
# print(result)
#
# handle = oapi.enr_close()
#
# def test_get_react(file_path):
# handle = oapi.enr_init()
# oapi.enr_open(handle, file_path)
#
# result = oapi.enr_get_net_reacts(handle)
#
# print(result)
#
# handle = oapi.enr_close()
#
def test_get_node_attribute(enr_handle):
ref_array = np.array([ 1., 0.44407997, 0.43766347, 0.42827705, 0.41342604,
0.42804748, 0.44152543, 0.40502965, 0.38635802, 1., 0.96745253])
array = oapi.enr_get_node_attribute(enr_handle, 1, oapi.NodeAttribute.QUALITY)
assert len(array) == 11
assert np.allclose(array, ref_array)
def test_get_link_attribute(enr_handle):
ref_array = np.array([ 1848.58117676, 1220.42736816, 130.11161804,
187.68930054, 119.88839722, 40.46448898, -748.58111572, 478.15377808,
191.73458862, 30.11160851, 140.4644928, 59.53551483, 1848.58117676])
array = oapi.enr_get_link_attribute(enr_handle, 1, oapi.LinkAttribute.FLOW)
assert len(array) == 13
assert np.allclose(array, ref_array)
# if __name__ == "__main__":
#
# file_path = "M:\\net mydocuments\\EPA Projects\\EPAnet Examples\\net1.out"
# test_get_times(file_path)
# test_get_size(file_path)
# test_get_names(file_path)
# test_get_energy(file_path)
# test_get_react(file_path)
# test_get_node_attribute(file_path)
# test_get_link_attribute(file_path)
#

View File

@@ -21,9 +21,9 @@ Find /i "x86" < checkOS.tmp > StringCheck.tmp
If %ERRORLEVEL% == 1 (
CALL "%SDK_PATH%bin\"SetEnv.cmd /x64 /release
rem : create EPANET2.DLL
cl -o epanet2.dll epanet.c hash.c hydraul.c hydcoeffs.c hydsolver.c hydstatus.c genmmd.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL
cl -o epanet2.dll epanet.c util\errormanager.c hash.c hydraul.c hydcoeffs.c hydsolver.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c genmmd.c /I ..\include /I ..\run /link /DLL
rem : create EPANET2.EXE
cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c hydcoeffs.c hydsolver.c hydstatus.c genmmd.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link
cl -o epanet2.exe epanet.c util\errormanager.c ..\run\main.c hash.c hydraul.c hydcoeffs.c hydsolver.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c genmmd.c /I ..\include /I ..\run /I ..\src /link
md "%Build_PATH%"\64bit
move /y "%SRC_PATH%"\*.dll "%Build_PATH%"\64bit
move /y "%SRC_PATH%"\*.exe "%Build_PATH%"\64bit
@@ -35,9 +35,9 @@ rem : 32 bit with DEF
CALL "%SDK_PATH%bin\"SetEnv.cmd /x86 /release
echo "32 bit with epanet2.def mapping"
rem : create EPANET2.DLL
cl -o epanet2.dll epanet.c hash.c hydraul.c hydcoeffs.c hydsolver.c hydstatus.c genmmd.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:..\win_build\WinSDK\epanet2.def /MAP
cl -o epanet2.dll epanet.c util\errormanager.c hash.c hydraul.c hydcoeffs.c hydsolver.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c genmmd.c /I ..\include /I ..\run /link /DLL /def:..\win_build\WinSDK\epanet2.def /MAP
rem : create EPANET2.EXE
cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c hydcoeffs.c hydstatus.c genmmd.c hydsolver.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link
cl -o epanet2.exe epanet.c util\errormanager.c ..\run\main.c hash.c hydraul.c hydcoeffs.c hydsolver.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c genmmd.c /I ..\include /I ..\run /I ..\src /link
md "%Build_PATH%"\32bit
move /y "%SRC_PATH%"\*.dll "%Build_PATH%"\32bit
move /y "%SRC_PATH%"\*.exe "%Build_PATH%"\32bit
@@ -51,4 +51,3 @@ del "%SRC_PATH%"\*.map
del "%SRC_PATH%"\*.tmp
cd "%Build_PATH%"