diff --git a/include/epanet2.h b/include/epanet2.h index cdaba1e..d1d37f1 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -229,7 +229,9 @@ extern "C" { int DLLEXPORT ENgetlinktype(int, int *); int DLLEXPORT ENgetlinknodes(int, int *, int *); int DLLEXPORT ENgetlinkvalue(int, int, float *); - + + int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues); + int DLLEXPORT ENgetversion(int *); int DLLEXPORT ENsetcontrol(int, int, int, float, int, float); diff --git a/src/epanet.c b/src/epanet.c index ad10912..fd92f6f 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -1714,6 +1714,39 @@ int DLLEXPORT ENgetlinkvalue(int index, int code, float *value) } +int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues) // !sph +/*---------------------------------------------------------------- + ** Input: curveIndex = curve index + ** Output: *nValues = number of points on curve + ** *xValues = values for x + ** *yValues = values for y + ** Returns: error code + ** Purpose: retrieves end nodes of a specific link + **---------------------------------------------------------------- + */ +{ + int err = 0; + + Scurve curve = Curve[curveIndex]; + int nPoints = curve.Npts; + + float *pointX = calloc(nPoints, sizeof(float)); + float *pointY = calloc(nPoints, sizeof(float)); + + for (int iPoint = 0; iPoint < nPoints; iPoint++) { + double x = curve.X[iPoint] * Ucf[LENGTH]; + double y = curve.Y[iPoint] * Ucf[VOLUME]; + pointX[iPoint] = (float)x; + pointY[iPoint] = (float)y; + } + + *nValues = nPoints; + *xValues = pointX; + *yValues = pointY; + + return err; +} + /* ---------------------------------------------------------------- Functions for changing network data diff --git a/src/toolkit.h b/src/toolkit.h index 304076e..1c56c47 100755 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -221,6 +221,8 @@ extern "C" { int DLLEXPORT ENgetlinktype(int, int *); int DLLEXPORT ENgetlinknodes(int, int *, int *); int DLLEXPORT ENgetlinkvalue(int, int, float *); + + int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues); int DLLEXPORT ENgetversion(int *);