diff --git a/ReleaseNotes2_3.md b/ReleaseNotes2_3.md index 67680a8..e7de309 100644 --- a/ReleaseNotes2_3.md +++ b/ReleaseNotes2_3.md @@ -53,3 +53,4 @@ This document describes the changes and updates that have been made in version 2 - `EN_PRESS_UNITS` can now be used with `EN_getoption` and `EN_setoption` to get or set the pressure unit used in EPANET. - Continuous barrier functions were added to constrain emitter flows to allowable values. - The `EN_openx` function has been added to enable the opening of input files with formatting errors through the API. This allows users to continue using toolkit functions even when such errors are present. +- The `EN_getnodesvalues` and `EN_getlinksvalues` were added to retrieve a property value for all nodes or links in the network. \ No newline at end of file diff --git a/include/epanet2.h b/include/epanet2.h index 5cc6a41..c9fe5f8 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -214,6 +214,8 @@ extern "C" { int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value); + int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *value); + int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value); int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, @@ -291,6 +293,8 @@ extern "C" { int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value); + int DLLEXPORT ENgetlinksvalues(int property, EN_API_FLOAT_TYPE *value); + int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value); int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length, diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 5a3c3af..01082e7 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -881,6 +881,20 @@ typedef struct Project *EN_Project; Values are returned in units that depend on the units used for flow rate (see @ref Units). */ + + int DLLEXPORT EN_getnodesvalues(EN_Project ph, int property, double *out_values); + + /** + @brief Retrieves an array of property values for all nodes. + @param ph an EPANET project handle. + @param property the property to retrieve (see @ref EN_NodeProperty). + @param[out] values an array of values for all nodes. + @return an error code. + + Values are returned in units that depend on the units used for flow rate + (see @ref Units). + */ + int DLLEXPORT EN_getnodevalue(EN_Project ph, int index, int property, double *out_value); /** @@ -1242,6 +1256,17 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_getlinkvalue(EN_Project ph, int index, int property, double *out_value); + /** + @brief Retrieves an array of property values for all links. + @param ph an EPANET project handle. + @param property the property to retrieve (see @ref EN_LinkProperty). + @param[out] values an array of values for all links. + @return an error code. + + Values are returned in units that depend on the units used for flow rate (see @ref Units). + */ + int DLLEXPORT EN_getlinksvalues(EN_Project ph, int property, double *out_values); + /** @brief Sets a property value for a link. @param ph an EPANET project handle. diff --git a/src/epanet.c b/src/epanet.c index 86b510b..45170f9 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -2358,6 +2358,26 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val return 0; } +int DLLEXPORT EN_getnodesvalues(EN_Project p, int property, double *values) +/*---------------------------------------------------------------- +** Input: property = node property code (see EN_NodeProperty) +** Output: values = array of node property values +** Returns: error code +** Purpose: retrieves an array of node property values +**---------------------------------------------------------------- +*/ +{ + int status = 0; + + for (int i = 1; i <= p->network.Nnodes; i++) + { + status = EN_getnodevalue(p, i, property, &values[i - 1]); + // if status is not 0, return the error code + if (status != 0) { return status; } + } + return 0; +} + int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double value) /*---------------------------------------------------------------- ** Input: index = node index @@ -3903,6 +3923,25 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val return 0; } +int DLLEXPORT EN_getlinksvalues(EN_Project p, int property, double *values) +/*---------------------------------------------------------------- +** Input: property = link property code (see EN_LinkProperty) +** Output: values = array of link property values +** Returns: error code +** Purpose: retrieves property values for all links +**---------------------------------------------------------------- +*/ +{ + int status = 0; + for(int i = 1; i <= p->network.Nlinks; i++) + { + status = EN_getlinkvalue(p, i, property, &values[i-1]); + // If an error occurs, return the error code + if(status != 0) { return status; } + } + return 0; +} + int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double value) /*---------------------------------------------------------------- ** Input: index = link index diff --git a/src/epanet2.c b/src/epanet2.c index 7d7cd50..63b2217 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -355,6 +355,11 @@ int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value) return errcode; } +int DLLEXPORT ENgetnodesvalues(int property, EN_API_FLOAT_TYPE *values) +{ + return EN_getnodesvalues(_defaultProject, property, values); +} + int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value) { return EN_setnodevalue(_defaultProject, index, property, value); @@ -523,6 +528,10 @@ int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value) *value = (EN_API_FLOAT_TYPE)v; return errcode; } +int DLLEXPORT ENgetlinksvalues(int property, EN_API_FLOAT_TYPE *values) +{ + return EN_getlinksvalues(_defaultProject, property, values); +} int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value) {