diff --git a/build/WinSDK/epanet2.def b/build/WinSDK/epanet2.def index 1e34a59..1e2bd35 100644 --- a/build/WinSDK/epanet2.def +++ b/build/WinSDK/epanet2.def @@ -71,4 +71,7 @@ EXPORTS ENgetcurveindex = _ENgetcurveindex@8 ENgetcurveid = _ENgetcurveid@8 ENgetcurvelen = _ENgetcurvelen@8 - ENgetcurvevalue = _ENgetcurvevalue@16 \ No newline at end of file + ENgetcurvevalue = _ENgetcurvevalue@16 + ENsetcurvevalue = _ENsetcurvevalue@16 + ENsetcurve = _ENsetcurve@16 + ENaddcurve = _ENaddcurve@4 \ No newline at end of file diff --git a/include/epanet2.bas b/include/epanet2.bas index 2d804f8..86e8c38 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -223,4 +223,7 @@ Global Const EN_INITFLOW = 10 ' Re-initialize flow flag Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal ID As String, Index As Long) As Long Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal Index As Long, L As Long) As Long - Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Ptn As Long, X As Single, Y As Single) As Long \ No newline at end of file + Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Ptn As Long, X As Single, Y As Single) As Long + Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Ptn As Long, ByVal X As Single, ByVal Y As Single) As Long + Declare Function ENsetcurve Lib "epanet2.dll" (ByVal Index As Long, X As Any, Y As Any, ByVal N As Long) As Long + Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Long \ No newline at end of file diff --git a/include/epanet2.h b/include/epanet2.h index dab5ce2..03b1244 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -276,7 +276,10 @@ extern "C" { int DLLEXPORT ENgetcurveid(int index, char *id); int DLLEXPORT ENgetcurvelen(int index, int *len); int DLLEXPORT ENgetcurvevalue(int index, int pnt, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y); - + int DLLEXPORT ENsetcurvevalue(int index, int pnt, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE x); + int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y, int len); + int DLLEXPORT ENaddcurve(char *id); + #if defined(__cplusplus) } #endif diff --git a/include/epanet2.vb b/include/epanet2.vb index 5a219ad..ed0e116 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -221,5 +221,8 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32 Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Pnt As Int32, ByRef X As Single, ByRef Y As Single) As Int32 + Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Pnt As Int32, ByVal X As Single, ByVal Y As Single) As Int32 + Declare Function ENsetcurve Lib "epanet2.dll" (ByVal Index as Int32, ByRef X as Single, ByRef Y as Single, ByVal N as Int32) as Int32 + Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Int32 End Module diff --git a/src/epanet.c b/src/epanet.c index 5c682ab..c350434 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -2386,7 +2386,7 @@ int DLLEXPORT ENsetpattern(int index, EN_API_FLOAT_TYPE *f, int n) return(0); } - + int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value) /*---------------------------------------------------------------- ** Input: index = time pattern index @@ -2406,6 +2406,150 @@ int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value } +int DLLEXPORT ENaddcurve(char *id) +/*---------------------------------------------------------------- +** Input: id = ID name of the new curve +** Output: none +** Returns: error code +** Purpose: adds a new curve appended to the end of the +** existing curves. +**---------------------------------------------------------------- +*/ +{ + int i, j, n, err = 0; + Scurve *tmpCur; + +/* Check if a curve with same id already exists */ + + if ( !Openflag ) return(102); + if ( ENgetcurveindex(id, &i) == 0 ) return(215); + +/* Check that id name is not too long */ + + if (strlen(id) > MAXID) return(250); + +/* Allocate memory for a new array of curves */ + + n = Ncurves + 1; + tmpCur = (Scurve *) calloc(n+1, sizeof(Scurve)); + if ( tmpCur == NULL ) return(101); + +/* Copy contents of old curve array to new one */ + + for (i=0; i<=Ncurves; i++) + { + strcpy(tmpCur[i].ID, Curve[i].ID); + tmpCur[i].Npts = Curve[i].Npts; + tmpCur[i].X = (double *) calloc(Curve[i].Npts, sizeof(double)); + tmpCur[i].Y = (double *) calloc(Curve[i].Npts, sizeof(double)); + if (tmpCur[i].X == NULL) err = 1; + else if (tmpCur[i].Y == NULL) err = 1; + else for (j=0; j Ncurves) return(206); + if (n <= 0) return(202); + +/* Re-set number of points & reallocate memory for values */ + Curve[index].Npts = n; + Curve[index].X = (double *) realloc(Curve[index].X, n*sizeof(double)); + Curve[index].Y = (double *) realloc(Curve[index].Y, n*sizeof(double)); + if (Curve[index].X == NULL) return(101); + if (Curve[index].Y == NULL) return(101); + +/* Load values into curve */ + for (j=0; j Ncurves) return(206); + if (pnt <= 0 || pnt > Curve[index].Npts) return(251); + Curve[index].X[pnt-1] = x; + Curve[index].Y[pnt-1] = y; + return(0); +} + + int DLLEXPORT ENsettimeparam(int code, long value) /*---------------------------------------------------------------- ** Input: code = time parameter code (see EPANET2.H)