From b640a8685c1958e9efbbec4270e8e99c54132f8e Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Sat, 26 Oct 2019 11:25:09 -0400 Subject: [PATCH] Adds EN_getresultindex function to the API See issue #546 . Also fixes a small bug in project.c. --- include/epanet2.bas | 3 ++- include/epanet2.def | 3 ++- include/epanet2.h | 3 ++- include/epanet2.pas | 5 +++-- include/epanet2.vb | 3 ++- include/epanet2_2.h | 4 +++- src/epanet.c | 31 ++++++++++++++++++++++++++++++- src/epanet2.c | 8 +++++++- src/hydraul.c | 6 ++++-- src/input3.c | 7 ++++++- src/project.c | 7 +++---- src/types.h | 4 +++- 12 files changed, 67 insertions(+), 17 deletions(-) diff --git a/include/epanet2.bas b/include/epanet2.bas index 37f2804..9d7aa51 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -5,7 +5,7 @@ Attribute VB_Name = "Module1" 'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT '(EPANET2.DLL) -'Last updated on 07/18/2019 +'Last updated on 10/26/2019 ' These are codes used by the DLL functions Public Const EN_ELEVATION = 0 ' Node parameters @@ -282,6 +282,7 @@ Public Const EN_R_IS_ACTIVE = 3 Declare Function ENgetcount Lib "epanet2.dll" (ByVal object As Long, count As Long) As Long Declare Function ENgeterror Lib "epanet2.dll" (ByVal errcode As Long, ByVal errmsg As String, ByVal maxLen As Long) As Long Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal type_ As Long, ByRef value As Single) As Long + Declare Function ENgetresultindex Lib "epanet2.dll" (ByVal type_ As Long, ByVal index As Long, ByRef value As Long) As Long 'Analysis Options Functions Declare Function ENgetoption Lib "epanet2.dll" (ByVal option_ As Long, value As Single) As Long diff --git a/include/epanet2.def b/include/epanet2.def index b813d20..fd528a9 100644 --- a/include/epanet2.def +++ b/include/epanet2.def @@ -60,7 +60,8 @@ EXPORTS ENgetpremise = _ENgetpremise@36 ENgetpumptype = _ENgetpumptype@8 ENgetqualinfo = _ENgetqualinfo@16 - ENgetqualtype = _ENgetqualtype@8 + ENgetqualtype = _ENgetqualtype@8 + ENgetresultindex = _ENgetresultindex@12 ENgetrule = _ENgetrule@20 ENgetruleID = _ENgetruleID@8 ENgetstatistic = _ENgetstatistic@8 diff --git a/include/epanet2.h b/include/epanet2.h index d759c8d..807f9a9 100644 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 03/17/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -157,6 +157,7 @@ extern "C" { int DLLEXPORT ENgetstatistic(int type, EN_API_FLOAT_TYPE* value); + int DLLEXPORT ENgetresultindex(int type, int index, int *value); /******************************************************************** diff --git a/include/epanet2.pas b/include/epanet2.pas index 830a29c..491258f 100644 --- a/include/epanet2.pas +++ b/include/epanet2.pas @@ -3,7 +3,7 @@ unit epanet2; { Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT } { (EPANET2.DLL) } -{Last updated on 7/18/19} +{Last updated on 10/26/19} interface @@ -297,7 +297,8 @@ const function ENsetstatusreport(Code: Integer): Integer; stdcall; external EpanetLib; function ENgetversion(var Version: Integer): Integer; stdcall; external EpanetLib; function ENgeterror(Errcode: Integer; Errmsg: PAnsiChar; MaxLen: Integer): Integer; stdcall; external EpanetLib; - function ENgetstatistic(StatType: Integer; var Value: Single): Integer; stdcall; external EpanetLib; + function ENgetstatistic(StatType: Integer; var Value: Single): Integer; stdcall; external EpanetLib; + function ENgetresultindex(Code: Integer; Index: Integer; var Value: Integer): Integer; stdcall; external EpanetLib; {Analysis Options Functions} function ENgetoption(Code: Integer; var Value: Single): Integer; stdcall; external EpanetLib; diff --git a/include/epanet2.vb b/include/epanet2.vb index 92622e3..47f9709 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -4,7 +4,7 @@ 'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT '(EPANET2.DLL) for use with VB.Net. -'Last updated on 07/18/2019 +'Last updated on 10/26/2019 Imports System.Runtime.InteropServices Imports System.Text @@ -287,6 +287,7 @@ Public Const EN_R_IS_ACTIVE = 3 Declare Function ENgetcount Lib "epanet2.dll" (ByVal object As Int32, count As Int32) As Int32 Declare Function ENgeterror Lib "epanet2.dll" (ByVal errcode As Int32, ByVal errmsg As String, ByVal maxLen As Int32) As Int32 Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal type_ As Int32, ByRef value As Single) As Int32 + Declare Function ENgetresultindex Lib "epanet2.dll" (ByVal type_ As Int32, ByVal index As Int32, ByRef value As Int32) As Int32 'Analysis Options Functions Declare Function ENgetoption Lib "epanet2.dll" (ByVal option As Int32, value As Single) As Int32 diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 9ed1b5c..d8eb33c 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -11,7 +11,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 07/20/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -638,6 +638,8 @@ typedef struct Project *EN_Project; */ int DLLEXPORT EN_getstatistic(EN_Project ph, int type, double* value); + int DLLEXPORT EN_getresultindex(EN_Project ph, int type, int index, int *value); + /******************************************************************** Analysis Options Functions diff --git a/src/epanet.c b/src/epanet.c index 1029b3b..d476e0d 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 07/18/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -1066,6 +1066,33 @@ int DLLEXPORT EN_getstatistic(EN_Project p, int type, double *value) return 0; } +int DLLEXPORT EN_getresultindex(EN_Project p, int type, int index, int *value) +/*---------------------------------------------------------------- +** Input: type = type of object (either EN_NODE or EN_LINK) +** index = the object's index +** Output: value = the order in which the object's results were saved +** Returns: error code +** Purpose: retrieves the order in which a node's or link's results +** were saved to an output file. +**---------------------------------------------------------------- +*/ +{ + *value = 0; + if (!p->Openflag) return 102; + if (type == EN_NODE) + { + if (index <= 0 || index > p->network.Nnodes) return 203; + *value = p->network.Node[index].ResultIndex; + } + else if (type == EN_LINK) + { + if (index <= 0 || index > p->network.Nlinks) return 204; + *value = p->network.Link[index].ResultIndex; + } + else return 251; + return 0; +} + /******************************************************************** Analysis Options Functions @@ -1827,6 +1854,7 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType, int *index) node->C0 = 0; node->Ke = 0; node->Rpt = 0; + node->ResultIndex = 0; node->X = MISSING; node->Y = MISSING; node->Comment = NULL; @@ -3210,6 +3238,7 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, int linkType, link->R = 0; link->Rc = 0; link->Rpt = 0; + link->ResultIndex = 0; link->Comment = NULL; hashtable_insert(net->LinkHashTable, link->ID, n); diff --git a/src/epanet2.c b/src/epanet2.c index b6c5b7c..ac2e210 100644 --- a/src/epanet2.c +++ b/src/epanet2.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 05/15/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -227,6 +227,12 @@ int DLLEXPORT ENgetstatistic(int type, EN_API_FLOAT_TYPE *value) return errcode; } +int DLLEXPORT ENgetresultindex(int type, int index, int *value) +{ + return EN_getresultindex(_defaultProject, type, index, value); +} + + /******************************************************************** Analysis Options Functions diff --git a/src/hydraul.c b/src/hydraul.c index d3cd761..59bf7d6 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 05/15/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -115,8 +115,9 @@ void inithyd(Project *pr, int initflag) // Initialize emitter flows memset(hyd->EmitterFlow,0,(net->Nnodes+1)*sizeof(double)); - for (i = 1; i <= net->Njuncs; i++) + for (i = 1; i <= net->Nnodes; i++) { + net->Node[i].ResultIndex = i; if (net->Node[i].Ke > 0.0) hyd->EmitterFlow[i] = 1.0; } @@ -124,6 +125,7 @@ void inithyd(Project *pr, int initflag) for (i = 1; i <= net->Nlinks; i++) { link = &net->Link[i]; + link->ResultIndex = i; // Initialize status and setting hyd->LinkStatus[i] = link->Status; diff --git a/src/input3.c b/src/input3.c index 48635b7..c43866f 100644 --- a/src/input3.c +++ b/src/input3.c @@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 06/19/2019 +Last Updated: 10/26/2019 ****************************************************************************** */ @@ -109,6 +109,7 @@ int juncdata(Project *pr) node->S = NULL; node->Ke = 0.0; node->Rpt = 0; + node->ResultIndex = 0; node->Type = JUNCTION; node->Comment = xstrcpy(&node->Comment, parser->Comment, MAXMSG); @@ -222,6 +223,7 @@ int tankdata(Project *pr) node->X = MISSING; node->Y = MISSING; node->Rpt = 0; + node->ResultIndex = 0; node->El = el; node->C0 = 0.0; node->S = NULL; @@ -335,6 +337,7 @@ int pipedata(Project *pr) link->Type = type; link->Status = status; link->Rpt = 0; + link->ResultIndex = 0; link->Comment = xstrcpy(&link->Comment, parser->Comment, MAXMSG); return 0; } @@ -400,6 +403,7 @@ int pumpdata(Project *pr) link->Type = PUMP; link->Status = OPEN; link->Rpt = 0; + link->ResultIndex = 0; link->Comment = xstrcpy(&link->Comment, parser->Comment, MAXMSG); pump->Link = net->Nlinks; pump->Ptype = NOCURVE; // NOCURVE is a placeholder @@ -556,6 +560,7 @@ int valvedata(Project *pr) link->Type = type; link->Status = status; link->Rpt = 0; + link->ResultIndex = 0; link->Comment = xstrcpy(&link->Comment, parser->Comment, MAXMSG); net->Valve[net->Nvalves].Link = net->Nlinks; return 0; diff --git a/src/project.c b/src/project.c index 76a863f..bfe901c 100644 --- a/src/project.c +++ b/src/project.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 05/24/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -174,10 +174,9 @@ int openoutfile(Project *pr) // Close output file if already opened closeoutfile(pr); - // If output file name was supplied, then attempt to - // open it. Otherwise open a temporary output file. + // Try to open binary output file pr->outfile.OutFile = fopen(pr->outfile.OutFname, "w+b"); - if (pr->outfile.OutFile == NULL) errcode = 304; + if (pr->outfile.OutFile == NULL) return 304; // Save basic network data & energy usage results ERRCODE(savenetdata(pr)); diff --git a/src/types.h b/src/types.h index 4a51d82..326e615 100755 --- a/src/types.h +++ b/src/types.h @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 07/08/2019 + Last Updated: 10/26/2019 ****************************************************************************** */ @@ -377,6 +377,7 @@ typedef struct // Node Object double C0; // initial quality double Ke; // emitter coeff. int Rpt; // reporting flag + int ResultIndex; // saved result index NodeType Type; // node type char *Comment; // node comment } Snode; @@ -397,6 +398,7 @@ typedef struct // Link Object LinkType Type; // link type StatusType Status; // initial status int Rpt; // reporting flag + int ResultIndex; // saved result index char *Comment; // link comment } Slink;