Adds link vertex get/set functions to the API
This commit is contained in:
@@ -5,7 +5,7 @@ Attribute VB_Name = "Module1"
|
|||||||
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
|
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
|
||||||
'(EPANET2.DLL)
|
'(EPANET2.DLL)
|
||||||
|
|
||||||
'Last updated on 10/26/2019
|
'Last updated on 10/29/2019
|
||||||
|
|
||||||
' These are codes used by the DLL functions
|
' These are codes used by the DLL functions
|
||||||
Public Const EN_ELEVATION = 0 ' Node parameters
|
Public Const EN_ELEVATION = 0 ' Node parameters
|
||||||
@@ -336,6 +336,9 @@ Public Const EN_R_IS_ACTIVE = 3
|
|||||||
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal property As Long, value As Single) As Long
|
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal property As Long, value As Single) As Long
|
||||||
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal property As Long, ByVal value As Single) As Long
|
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal property As Long, ByVal value As Single) As Long
|
||||||
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Long, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Long
|
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Long, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Long
|
||||||
|
Declare Function ENgetvertexcount Lib "epanet2.dll" (ByVal index As Long, count As Long) As Long
|
||||||
|
Declare Function ENgetvertex Lib "epanet2.dll" (ByVal index As Long, ByVal vertex As Long, x As Double, y As Double) As Long
|
||||||
|
Declare Function ENsetvertices Lib "epanet2.dll" (ByVal index As Long, xCoords As Any, yCoords As Any, ByVal count As Long) As Long
|
||||||
|
|
||||||
'Pump Functions
|
'Pump Functions
|
||||||
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal linkIndex As Long, curveIndex As Long) As Long
|
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal linkIndex As Long, curveIndex As Long) As Long
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ EXPORTS
|
|||||||
ENgetlinknodes = _ENgetlinknodes@12
|
ENgetlinknodes = _ENgetlinknodes@12
|
||||||
ENsetlinknodes = _ENsetlinknodes@12
|
ENsetlinknodes = _ENsetlinknodes@12
|
||||||
ENgetlinktype = _ENgetlinktype@8
|
ENgetlinktype = _ENgetlinktype@8
|
||||||
ENgetlinkvalue = _ENgetlinkvalue@12
|
ENgetlinkvalue = _ENgetlinkvalue@12
|
||||||
ENgetnodeid = _ENgetnodeid@8
|
ENgetnodeid = _ENgetnodeid@8
|
||||||
ENgetnodeindex = _ENgetnodeindex@8
|
ENgetnodeindex = _ENgetnodeindex@8
|
||||||
ENgetnodetype = _ENgetnodetype@8
|
ENgetnodetype = _ENgetnodetype@8
|
||||||
@@ -69,6 +69,8 @@ EXPORTS
|
|||||||
ENgettimeparam = _ENgettimeparam@8
|
ENgettimeparam = _ENgettimeparam@8
|
||||||
ENgettitle = _ENgettitle@12
|
ENgettitle = _ENgettitle@12
|
||||||
ENgetversion = _ENgetversion@4
|
ENgetversion = _ENgetversion@4
|
||||||
|
ENgetvertex = _ENgetvertex@16
|
||||||
|
ENgetvertexcount = _ENgetvertexcount@8
|
||||||
ENinit = _ENinit@16
|
ENinit = _ENinit@16
|
||||||
ENinitH = _ENinitH@4
|
ENinitH = _ENinitH@4
|
||||||
ENinitQ = _ENinitQ@4
|
ENinitQ = _ENinitQ@4
|
||||||
@@ -121,6 +123,7 @@ EXPORTS
|
|||||||
ENsetthenaction = _ENsetthenaction@20
|
ENsetthenaction = _ENsetthenaction@20
|
||||||
ENsettimeparam = _ENsettimeparam@8
|
ENsettimeparam = _ENsettimeparam@8
|
||||||
ENsettitle = _ENsettitle@12
|
ENsettitle = _ENsettitle@12
|
||||||
|
ENsetvertices = _ENsetvertices@16
|
||||||
ENsolveH = _ENsolveH@0
|
ENsolveH = _ENsolveH@0
|
||||||
ENsolveQ = _ENsolveQ@0
|
ENsolveQ = _ENsolveQ@0
|
||||||
ENstepQ = _ENstepQ@4
|
ENstepQ = _ENstepQ@4
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -285,6 +285,12 @@ extern "C" {
|
|||||||
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
|
int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
|
||||||
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough,
|
EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough,
|
||||||
EN_API_FLOAT_TYPE mloss);
|
EN_API_FLOAT_TYPE mloss);
|
||||||
|
|
||||||
|
int DLLEXPORT ENgetvertexcount(int index, int *count);
|
||||||
|
|
||||||
|
int DLLEXPORT ENgetvertex(int index, int vertex, double *x, double *y);
|
||||||
|
|
||||||
|
int DLLEXPORT ENsetvertices(int index, double *x, double *y, int count);
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit epanet2;
|
|||||||
{ Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT }
|
{ Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT }
|
||||||
{ (EPANET2.DLL) }
|
{ (EPANET2.DLL) }
|
||||||
|
|
||||||
{Last updated on 10/26/19}
|
{Last updated on 10/29/19}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@@ -353,6 +353,10 @@ const
|
|||||||
function ENsetlinkvalue(Index: Integer; Code: Integer; Value: Single): Integer; stdcall; external EpanetLib;
|
function ENsetlinkvalue(Index: Integer; Code: Integer; Value: Single): Integer; stdcall; external EpanetLib;
|
||||||
function ENsetpipedata(Index: Integer; Length: Single; Diam: Single; Rough: Single; Mloss:Single): Integer; stdcall; external EpanetLib;
|
function ENsetpipedata(Index: Integer; Length: Single; Diam: Single; Rough: Single; Mloss:Single): Integer; stdcall; external EpanetLib;
|
||||||
|
|
||||||
|
function ENgetvertexcount(Index: Integer; var Count: Integer): Integer; stdcall; external EpanetLib;
|
||||||
|
function ENgetvertex(Index: Integer; Vertex: Integer; var X: Double; var Y: Double): Integer; stdcall; external EpanetLib;
|
||||||
|
function ENsetvertices(Index: Integer; X: array of Double; Y: array of Double; Count: Integer): Integer; stdcall; external EpanetLib;
|
||||||
|
|
||||||
{Pump Functions}
|
{Pump Functions}
|
||||||
function ENgetpumptype(LinkIndex: Integer; var PumpType: Integer): Integer; stdcall; external EpanetLib;
|
function ENgetpumptype(LinkIndex: Integer; var PumpType: Integer): Integer; stdcall; external EpanetLib;
|
||||||
function ENgetheadcurveindex(LinkIndex: Integer; var CurveIndex: Integer): Integer; stdcall; external EpanetLib;
|
function ENgetheadcurveindex(LinkIndex: Integer; var CurveIndex: Integer): Integer; stdcall; external EpanetLib;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
|
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
|
||||||
'(EPANET2.DLL) for use with VB.Net.
|
'(EPANET2.DLL) for use with VB.Net.
|
||||||
|
|
||||||
'Last updated on 10/26/2019
|
'Last updated on 10/29/2019
|
||||||
|
|
||||||
Imports System.Runtime.InteropServices
|
Imports System.Runtime.InteropServices
|
||||||
Imports System.Text
|
Imports System.Text
|
||||||
@@ -341,6 +341,9 @@ Public Const EN_R_IS_ACTIVE = 3
|
|||||||
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal property As Int32, value As Single) As Int32
|
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal property As Int32, value As Single) As Int32
|
||||||
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal property As Int32, ByVal value As Single) As Int32
|
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Int32, ByVal property As Int32, ByVal value As Single) As Int32
|
||||||
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Int32, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Int32
|
Declare Function ENsetpipedata Lib "epanet2.dll" (ByVal index As Int32, ByVal length As Single, ByVal diam As Single, ByVal rough As Single, ByVal mloss As Single) As Int32
|
||||||
|
Declare Function ENgetvertexcount Lib "epanet2.dll" (ByVal index As Int32, count As Int32) As Int32
|
||||||
|
Declare Function ENgetvertex Lib "epanet2.dll" (ByVal index As Int32, ByVal vertex As Int32, x As Double, y As Double) As Int32
|
||||||
|
Declare Function ENsetvertices Lib "epanet2.dll" (ByVal index As Int32, xCoords As Any, yCoords As Any, ByVal count As Int32) As Int32
|
||||||
|
|
||||||
'Pump Functions
|
'Pump Functions
|
||||||
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal linkIndex As Int32, curveIndex As Int32) As Int32
|
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal linkIndex As Int32, curveIndex As Int32) As Int32
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -1214,6 +1214,36 @@ typedef struct Project *EN_Project;
|
|||||||
int DLLEXPORT EN_setpipedata(EN_Project ph, int index, double length, double diam,
|
int DLLEXPORT EN_setpipedata(EN_Project ph, int index, double length, double diam,
|
||||||
double rough, double mloss);
|
double rough, double mloss);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Retrieves the number of internal vertex points assigned to a link.
|
||||||
|
@param ph an EPANET project handle.
|
||||||
|
@param index a link's index.
|
||||||
|
@param[out] count the number of vertex points that describe the link's shape.
|
||||||
|
@return an error code.
|
||||||
|
*/
|
||||||
|
int DLLEXPORT EN_getvertexcount(EN_Project ph, int index, int *count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Retrieves the coordinate's of a vertex point assigned to a link.
|
||||||
|
@param ph an EPANET project handle.
|
||||||
|
@param index a link's index.
|
||||||
|
@param vertex a vertex point index.
|
||||||
|
@param[out] x the vertex's X-coordinate value.
|
||||||
|
@param[out] y the vertex's Y-coordinate value.
|
||||||
|
@return an error code.
|
||||||
|
*/
|
||||||
|
int DLLEXPORT EN_getvertex(EN_Project ph, int index, int vertex, double *x, double *y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Assigns a set of internal vertex points to a link.
|
||||||
|
@param ph an EPANET project handle.
|
||||||
|
@param index a link's index.
|
||||||
|
@param x an array of X-coordinates for the vertex points.
|
||||||
|
@param y an array of Y-coordinates for the vertex points.
|
||||||
|
@param count the number of vertex points being assigned.
|
||||||
|
@return an error code.
|
||||||
|
*/
|
||||||
|
int DLLEXPORT EN_setvertices(EN_Project ph, int index, double *x, double *y, int count);
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
|
||||||
|
|||||||
114
src/epanet.c
114
src/epanet.c
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -3985,17 +3985,17 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu
|
|||||||
|
|
||||||
int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
|
int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
|
||||||
double diam, double rough, double mloss)
|
double diam, double rough, double mloss)
|
||||||
/*----------------------------------------------------------------
|
/*----------------------------------------------------------------
|
||||||
** Input: index = pipe link index
|
** Input: index = pipe link index
|
||||||
** length = pipe length
|
** length = pipe length
|
||||||
** diam = pipe diameter
|
** diam = pipe diameter
|
||||||
** rough = pipe roughness coefficient
|
** rough = pipe roughness coefficient
|
||||||
** mloss = minor loss coefficient
|
** mloss = minor loss coefficient
|
||||||
** Output: none
|
** Output: none
|
||||||
** Returns: error code
|
** Returns: error code
|
||||||
** Purpose: sets several properties for a pipe link
|
** Purpose: sets several properties for a pipe link
|
||||||
**----------------------------------------------------------------
|
**----------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Network *net = &p->network;
|
Network *net = &p->network;
|
||||||
|
|
||||||
@@ -4024,6 +4024,96 @@ int DLLEXPORT EN_setpipedata(EN_Project p, int index, double length,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT EN_getvertexcount(EN_Project p, int index, int *count)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: index = link index
|
||||||
|
** Output: count = number of link's vertex points
|
||||||
|
** Returns: error code
|
||||||
|
** Purpose: retrieves number of vertex points in a link
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Network *net = &p->network;
|
||||||
|
|
||||||
|
Slink *Link = net->Link;
|
||||||
|
Pvertices vertices;
|
||||||
|
|
||||||
|
// Check that link exists
|
||||||
|
*count = 0;
|
||||||
|
if (!p->Openflag) return 102;
|
||||||
|
if (index <= 0 || index > net->Nlinks) return 204;
|
||||||
|
|
||||||
|
// Set count to number of vertices
|
||||||
|
vertices = Link[index].Vertices;
|
||||||
|
if (vertices) *count = vertices->Npts;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT EN_getvertex(EN_Project p, int index, int vertex, double *x, double *y)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: index = link index
|
||||||
|
** vertex = index of a link vertex point
|
||||||
|
** Output: x = vertex point's X-coordinate
|
||||||
|
** y = vertex point's Y-coordinate
|
||||||
|
** Returns: error code
|
||||||
|
** Purpose: retrieves the coordinates of a vertex point in a link
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Network *net = &p->network;
|
||||||
|
|
||||||
|
Slink *Link = net->Link;
|
||||||
|
Pvertices vertices;
|
||||||
|
|
||||||
|
// Check that link exists
|
||||||
|
*x = MISSING;
|
||||||
|
*y = MISSING;
|
||||||
|
if (!p->Openflag) return 102;
|
||||||
|
if (index <= 0 || index > net->Nlinks) return 204;
|
||||||
|
|
||||||
|
// Check that vertex exists
|
||||||
|
vertices = Link[index].Vertices;
|
||||||
|
if (vertices == NULL) return 255;
|
||||||
|
if (vertex <= 0 || vertex > vertices->Npts) return 255;
|
||||||
|
*x = vertices->X[vertex - 1];
|
||||||
|
*y = vertices->Y[vertex - 1];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT EN_setvertices(EN_Project p, int index, double *x, double *y, int count)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: index = link index
|
||||||
|
** x = array of X-coordinates for vertex points
|
||||||
|
** y = array of Y-coordinates for vertex points
|
||||||
|
** count = number of vertex points
|
||||||
|
** Returns: error code
|
||||||
|
** Purpose: assigns a set of vertex points to a link
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Network *net = &p->network;
|
||||||
|
|
||||||
|
Slink *link;
|
||||||
|
int i;
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
// Check that link exists
|
||||||
|
if (!p->Openflag) return 102;
|
||||||
|
if (index <= 0 || index > net->Nlinks) return 204;
|
||||||
|
link = &net->Link[index];
|
||||||
|
|
||||||
|
// Delete existing set of vertices
|
||||||
|
freelinkvertices(link);
|
||||||
|
|
||||||
|
// Add each new vertex to the link
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
err = addlinkvertex(link, x[i], y[i]);
|
||||||
|
if (err) break;
|
||||||
|
}
|
||||||
|
if (err) freelinkvertices(link);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -512,6 +512,20 @@ int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
|
|||||||
return EN_setpipedata(_defaultProject, index, length, diam, rough, mloss);
|
return EN_setpipedata(_defaultProject, index, length, diam, rough, mloss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT ENgetvertexcount(int index, int *count)
|
||||||
|
{
|
||||||
|
return EN_getvertexcount(_defaultProject, index, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT ENgetvertex(int index, int vertex, double *x, double *y)
|
||||||
|
{
|
||||||
|
return EN_getvertex(_defaultProject, index, vertex, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLLEXPORT ENsetvertices(int index, double *x, double *y, int count)
|
||||||
|
{
|
||||||
|
return EN_setvertices(_defaultProject, index, x, y, count);
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************
|
/********************************************************************
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ DAT(251,"invalid parameter code")
|
|||||||
DAT(252,"invalid ID name")
|
DAT(252,"invalid ID name")
|
||||||
DAT(253,"nonexistent demand category")
|
DAT(253,"nonexistent demand category")
|
||||||
DAT(254,"node with no coordinates")
|
DAT(254,"node with no coordinates")
|
||||||
|
DAT(255,"invalid link vertex")
|
||||||
DAT(257,"nonexistent rule")
|
DAT(257,"nonexistent rule")
|
||||||
DAT(258,"nonexistent rule clause")
|
DAT(258,"nonexistent rule clause")
|
||||||
DAT(259,"attempt to delete a node that still has links connected to it")
|
DAT(259,"attempt to delete a node that still has links connected to it")
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 07/08/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifndef FUNCS_H
|
#ifndef FUNCS_H
|
||||||
@@ -41,6 +41,9 @@ Pdemand finddemand(Pdemand, int);
|
|||||||
int adddemand(Snode *, double, int, char *);
|
int adddemand(Snode *, double, int, char *);
|
||||||
void freedemands(Snode *);
|
void freedemands(Snode *);
|
||||||
|
|
||||||
|
int addlinkvertex(Slink *, double, double);
|
||||||
|
void freelinkvertices(Slink *);
|
||||||
|
|
||||||
void adjustpatterns(Network *, int);
|
void adjustpatterns(Network *, int);
|
||||||
void adjustcurves(Network *, int);
|
void adjustcurves(Network *, int);
|
||||||
int resizecurve(Scurve *, int);
|
int resizecurve(Scurve *, int);
|
||||||
@@ -101,6 +104,7 @@ int statusdata(Project *);
|
|||||||
int reportdata(Project *);
|
int reportdata(Project *);
|
||||||
int timedata(Project *);
|
int timedata(Project *);
|
||||||
int optiondata(Project *);
|
int optiondata(Project *);
|
||||||
|
int vertexdata(Project *);
|
||||||
|
|
||||||
// ------- RULES.C ------------------
|
// ------- RULES.C ------------------
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Description: saves network data to an EPANET formatted text file
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 05/15/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -76,7 +76,6 @@ void saveauxdata(Project *pr, FILE *f)
|
|||||||
// Write section heading to file
|
// Write section heading to file
|
||||||
switch (sect)
|
switch (sect)
|
||||||
{
|
{
|
||||||
case _VERTICES:
|
|
||||||
case _LABELS:
|
case _LABELS:
|
||||||
case _BACKDROP:
|
case _BACKDROP:
|
||||||
case _TAGS:
|
case _TAGS:
|
||||||
@@ -91,8 +90,6 @@ void saveauxdata(Project *pr, FILE *f)
|
|||||||
write = FALSE;
|
write = FALSE;
|
||||||
switch (sect)
|
switch (sect)
|
||||||
{
|
{
|
||||||
case _VERTICES:
|
|
||||||
if (findlink(&pr->network, tok) || *tok == ';') write = TRUE; break;
|
|
||||||
case _TAGS:
|
case _TAGS:
|
||||||
if (*tok == ';' ||
|
if (*tok == ';' ||
|
||||||
(match("NODE", tok) && findnode(&pr->network, strtok(NULL, SEPSTR))) ||
|
(match("NODE", tok) && findnode(&pr->network, strtok(NULL, SEPSTR))) ||
|
||||||
@@ -788,6 +785,20 @@ int saveinpfile(Project *pr, const char *fname)
|
|||||||
fprintf(f, "\n %-31s %14.6f %14.6f", node->ID, node->X, node->Y);
|
fprintf(f, "\n %-31s %14.6f %14.6f", node->ID, node->X, node->Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write [VERTICES] section
|
||||||
|
fprintf(f, "\n\n");
|
||||||
|
fprintf(f, s_VERTICES);
|
||||||
|
for (i = 1; i <= net->Nlinks; i++)
|
||||||
|
{
|
||||||
|
link = &net->Link[i];
|
||||||
|
if (link->Vertices != NULL)
|
||||||
|
{
|
||||||
|
for (j = 0; j < link->Vertices->Npts; j++)
|
||||||
|
fprintf(f, "\n %-31s %14.6f %14.6f",
|
||||||
|
link->ID, link->Vertices->X[j], link->Vertices->Y[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Save auxilary data to new input file
|
// Save auxilary data to new input file
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
saveauxdata(pr, f);
|
saveauxdata(pr, f);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Description: reads and interprets network data from an EPANET input file
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 05/15/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -330,11 +330,11 @@ int newline(Project *pr, int sect, char *line)
|
|||||||
case _TIMES: return (timedata(pr));
|
case _TIMES: return (timedata(pr));
|
||||||
case _OPTIONS: return (optiondata(pr));
|
case _OPTIONS: return (optiondata(pr));
|
||||||
case _COORDS: return (coordata(pr));
|
case _COORDS: return (coordata(pr));
|
||||||
|
case _VERTICES: return (vertexdata(pr));
|
||||||
|
|
||||||
// Data in these sections are not used for any computations
|
// Data in these sections are not used for any computations
|
||||||
case _LABELS:
|
case _LABELS:
|
||||||
case _TAGS:
|
case _TAGS:
|
||||||
case _VERTICES:
|
|
||||||
case _BACKDROP:
|
case _BACKDROP:
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/input3.c
33
src/input3.c
@@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -716,6 +716,37 @@ int coordata(Project *pr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vertexdata(Project *pr)
|
||||||
|
/*
|
||||||
|
**--------------------------------------------------------------
|
||||||
|
** Input: none
|
||||||
|
** Output: returns error code
|
||||||
|
** Purpose: processes link vertex data
|
||||||
|
** Format:
|
||||||
|
** [VERTICES]
|
||||||
|
** id x y
|
||||||
|
**--------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
Network *net = &pr->network;
|
||||||
|
Parser *parser = &pr->parser;
|
||||||
|
|
||||||
|
int j;
|
||||||
|
double x, y;
|
||||||
|
|
||||||
|
// Check for valid link ID
|
||||||
|
if (parser->Ntokens < 3) return 201;
|
||||||
|
if ((j = findlink(net, parser->Tok[0])) == 0) return setError(parser, 0, 204);
|
||||||
|
|
||||||
|
// Check for valid coordinate data
|
||||||
|
if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202);
|
||||||
|
if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202);
|
||||||
|
|
||||||
|
// Add to link's list of vertex points
|
||||||
|
return addlinkvertex(&net->Link[j], x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int demanddata(Project *pr)
|
int demanddata(Project *pr)
|
||||||
/*
|
/*
|
||||||
**--------------------------------------------------------------
|
**--------------------------------------------------------------
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,8 +18,6 @@
|
|||||||
//*** For the Windows SDK _tempnam function ***//
|
//*** For the Windows SDK _tempnam function ***//
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
//#else
|
|
||||||
//#include <unistd.h >
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@@ -363,6 +361,7 @@ int allocdata(Project *pr)
|
|||||||
}
|
}
|
||||||
for (n = 0; n <= pr->parser.MaxLinks; n++)
|
for (n = 0; n <= pr->parser.MaxLinks; n++)
|
||||||
{
|
{
|
||||||
|
pr->network.Link[n].Vertices = NULL;
|
||||||
pr->network.Link[n].Comment = NULL;
|
pr->network.Link[n].Comment = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,8 +408,9 @@ void freedata(Project *pr)
|
|||||||
// Free memory for link data
|
// Free memory for link data
|
||||||
if (pr->network.Link != NULL)
|
if (pr->network.Link != NULL)
|
||||||
{
|
{
|
||||||
for (j = 0; j <= pr->parser.MaxLinks; j++)
|
for (j = 1; j <= pr->parser.MaxLinks; j++)
|
||||||
{
|
{
|
||||||
|
freelinkvertices(&pr->network.Link[j]);
|
||||||
free(pr->network.Link[j].Comment);
|
free(pr->network.Link[j].Comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,6 +538,61 @@ void freedemands(Snode *node)
|
|||||||
node->D = NULL;
|
node->D = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int addlinkvertex(Slink *link, double x, double y)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: link = pointer to a network link
|
||||||
|
** x = x-coordinate of a new vertex
|
||||||
|
** y = y-coordiante of a new vertex
|
||||||
|
** Returns: an error code
|
||||||
|
** Purpose: adds to a link's collection of vertex points.
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
static int CHUNKSIZE = 5;
|
||||||
|
int n;
|
||||||
|
Pvertices vertices;
|
||||||
|
if (link->Vertices == NULL)
|
||||||
|
{
|
||||||
|
vertices = (struct Svertices *) malloc(sizeof(struct Svertices));
|
||||||
|
if (vertices == NULL) return 101;
|
||||||
|
vertices->Npts = 0;
|
||||||
|
vertices->Capacity = CHUNKSIZE;
|
||||||
|
vertices->X = (double *) calloc(vertices->Capacity, sizeof(double));
|
||||||
|
vertices->Y = (double *) calloc(vertices->Capacity, sizeof(double));
|
||||||
|
link->Vertices = vertices;
|
||||||
|
}
|
||||||
|
vertices = link->Vertices;
|
||||||
|
if (vertices->Npts >= vertices->Capacity)
|
||||||
|
{
|
||||||
|
vertices->Capacity += CHUNKSIZE;
|
||||||
|
vertices->X = realloc(vertices->X, vertices->Capacity * sizeof(double));
|
||||||
|
vertices->Y = realloc(vertices->Y, vertices->Capacity * sizeof(double));
|
||||||
|
}
|
||||||
|
if (vertices->X == NULL || vertices->Y == NULL) return 101;
|
||||||
|
n = vertices->Npts;
|
||||||
|
vertices->X[n] = x;
|
||||||
|
vertices->Y[n] = y;
|
||||||
|
vertices->Npts++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void freelinkvertices(Slink *link)
|
||||||
|
/*----------------------------------------------------------------
|
||||||
|
** Input: vertices = list of link vertex points
|
||||||
|
** Output: none
|
||||||
|
** Purpose: frees the memory used for a link's list of vertices.
|
||||||
|
**----------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
if (link->Vertices)
|
||||||
|
{
|
||||||
|
free(link->Vertices->X);
|
||||||
|
free(link->Vertices->Y);
|
||||||
|
free(link->Vertices);
|
||||||
|
link->Vertices = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int buildadjlists(Network *net)
|
int buildadjlists(Network *net)
|
||||||
/*
|
/*
|
||||||
**--------------------------------------------------------------
|
**--------------------------------------------------------------
|
||||||
|
|||||||
12
src/types.h
12
src/types.h
@@ -7,7 +7,7 @@
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 10/26/2019
|
Last Updated: 10/29/2019
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -366,6 +366,15 @@ struct Ssource // Water Quality Source Object
|
|||||||
};
|
};
|
||||||
typedef struct Ssource *Psource; // Pointer to source object
|
typedef struct Ssource *Psource; // Pointer to source object
|
||||||
|
|
||||||
|
struct Svertices // Coordinates of a link's vertices
|
||||||
|
{
|
||||||
|
double *X; // array of x-coordinates
|
||||||
|
double *Y; // array of y-coordinates
|
||||||
|
int Npts; // number of vertex points
|
||||||
|
int Capacity; // capacity of coordinate arrays
|
||||||
|
};
|
||||||
|
typedef struct Svertices *Pvertices; // Pointer to a link's vertices
|
||||||
|
|
||||||
typedef struct // Node Object
|
typedef struct // Node Object
|
||||||
{
|
{
|
||||||
char ID[MAXID+1]; // node ID
|
char ID[MAXID+1]; // node ID
|
||||||
@@ -397,6 +406,7 @@ typedef struct // Link Object
|
|||||||
double Rc; // reaction coeff.
|
double Rc; // reaction coeff.
|
||||||
LinkType Type; // link type
|
LinkType Type; // link type
|
||||||
StatusType Status; // initial status
|
StatusType Status; // initial status
|
||||||
|
Pvertices Vertices; // internal vertex coordinates
|
||||||
int Rpt; // reporting flag
|
int Rpt; // reporting flag
|
||||||
int ResultIndex; // saved result index
|
int ResultIndex; // saved result index
|
||||||
char *Comment; // link comment
|
char *Comment; // link comment
|
||||||
|
|||||||
Reference in New Issue
Block a user