Adds EN_getresultindex function to the API

See issue #546 . Also fixes a small bug in project.c.
This commit is contained in:
Lew Rossman
2019-10-26 11:25:09 -04:00
parent 344700a136
commit b640a8685c
12 changed files with 67 additions and 17 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));

View File

@@ -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;