Merging upstream dev

This commit is contained in:
Michael Tryby
2018-11-05 10:12:24 -05:00
18 changed files with 1264 additions and 755 deletions

View File

@@ -1,4 +1,3 @@
Release Notes for EPANET 2.2 (Draft) Release Notes for EPANET 2.2 (Draft)
============================ ============================
@@ -29,7 +28,7 @@ int runEpanet(char *finp, char *frpt)
if (!err) err = EN_solveH(ph); if (!err) err = EN_solveH(ph);
if (!err) err = EN_report(ph); if (!err) err = EN_report(ph);
EN_close(ph); EN_close(ph);
EN_deleteproject(ph); EN_deleteproject(&ph);
return err; return err;
} }
``` ```
@@ -129,35 +128,35 @@ Both network files are available [here](https://doi.org/10.23719/1375314).
## New API functions ## New API functions
|Function|Description| |Function|Description|
|--|--| |--|--|
|`ENaddlink`| | |`ENgetcurvetype`|Get the type of a curve|
|`ENaddnode`| | |`ENgetdemandmodel`|Retrieves the type of demand model in use and its parameters|
|`ENgetcurvetype`| | |`ENsetdemandmodel`|Sets the type of demand model to use and its parameters|
|`ENgetdemandmodel`|| |`ENsetflowunits`|Sets the flow units|
|`ENsetdemandmodel`|| |`ENaddcontrol`|Specify parameters to add a new simple control|
|`ENsetflowunits`|| |`ENsetdemandpattern`|Sets the index of the demand pattern assigned to a node for a category index|
|`ENaddcontrol`|| |`ENgetrule`|Gets the number of premises, true actions, and false actions and the priority of an existing rule-based control|
|`ENsetdemandpattern`|| |`ENsetrulepriority`|Sets the priority of the existing rule-based control|
|`ENgetrule`|| |`ENgetpremise`|Gets the components of a premise/condition in an existing rule-based control|
|`ENsetrulepriority`|| |`ENsetpremise`|Sets the components of a premise/condition in an existing rule-based control|
|`ENgetpremise`|| |`ENsetpremiseindex`|Sets the index of an object in a premise of an existing rule-based control|
|`ENsetpremise`|| |`ENsetpremisestatus`|Sets the status in a premise of an existing rule-based control|
|`ENsetpremiseindex`|| |`ENsetpremisevalue`|Sets the value in a premise of an existing rule-based control|
|`ENsetpremisestatus`|| |`ENgettrueaction`|Gets the components of a true-action in an existing rule-based control|
|`ENsetpremisevalue`|| |`ENsettrueaction`|Sets the components of a true-action in an existing rule-based control|
|`ENgettrueaction`|| |`ENgetfalseaction`|Gets the components of a false-action in an existing rule-based control|
|`ENsettrueaction`|| |`ENsetfalseaction`|Sets the components of a false-action in an existing rule-based control|
|`ENgetfalseaction`|| |`ENgetruleID`|Returns the ID of a rule|
|`ENsetfalseaction`|| |`ENinit`|Initializes an EPANET session|
|`ENgetruleID`|| |`ENsetheadcurveindex`|Sets the curve id for a specified pump index|
|`ENinit`|| |`ENsetlinktype`|Set the link type code for a specified link|
|`ENsetheadcurveindex`|| |`ENaddnode`|Adds a new node|
|`ENsetlinktype`|| |`ENaddlink`|Adds a new link|
|`ENaddnode`|| |`ENdeletelink`|Deletes a link|
|`ENaddlink`|| |`ENdeletenode`|Deletes a node|
|`ENdeletelink`|| | `ENsetnodeid` |Change the ID name for a node|
|`ENdeletenode`|| | `ENsetlinkid` |Change the ID name for a link|
|`ENgetdemandname`|| |`ENgetdemandname`|Sets the node's demand name for a category|
|`ENsetdemandname`|| |`ENsetdemandname`|Sets the node's demand name for a category|
## API Extensions (additional definitions) ## API Extensions (additional definitions)
### Link value types: ### Link value types:
@@ -174,10 +173,14 @@ Both network files are available [here](https://doi.org/10.23719/1375314).
- `EN_HW` - `EN_HW`
- `EN_DW` - `EN_DW`
- `EN_CM` - `EN_CM`
### Misc. options: ### Option types:
- `EN_HEADERROR` - `EN_HEADERROR`
- `EN_FLOWCHANGE` - `EN_FLOWCHANGE`
- `EN_DEMANDDEFPAT` - `EN_DEMANDDEFPAT`
- `EN_HEADLOSSFORM`
### Time statistic types:
- `EN_MAXHEADERROR`
- `EN_MAXFLOWCHANGE`
- `EN_MASSBALANCE` - `EN_MASSBALANCE`
### Curve types: ### Curve types:
- `EN_V_CURVE` - `EN_V_CURVE`
@@ -185,6 +188,9 @@ Both network files are available [here](https://doi.org/10.23719/1375314).
- `EN_E_CURVE` - `EN_E_CURVE`
- `EN_H_CURVE` - `EN_H_CURVE`
- `EN_G_CURVE` - `EN_G_CURVE`
### Demand model types:
- `EN_DDA`
- `EN_PDA`
## Authors contributing to this release: ## Authors contributing to this release:
- List item - List item

View File

@@ -175,11 +175,15 @@ Public Const EN_G_CURVE = 4 ' General\default curve
'These are the external functions that comprise the DLL 'These are the external functions that comprise the DLL
'System Functions
Declare Function ENgetversion Lib "epanet2.dll" (value As Long) As Long
Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As Any) As Long Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As Any) As Long
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Long, ByVal HeadlossFormula As Long) As Long
Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Long Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Long
Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Long Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Long
Declare Function ENclose Lib "epanet2.dll" () As Long Declare Function ENclose Lib "epanet2.dll" () As Long
'Hydraulic Analysis Functions
Declare Function ENsolveH Lib "epanet2.dll" () As Long Declare Function ENsolveH Lib "epanet2.dll" () As Long
Declare Function ENsaveH Lib "epanet2.dll" () As Long Declare Function ENsaveH Lib "epanet2.dll" () As Long
Declare Function ENopenH Lib "epanet2.dll" () As Long Declare Function ENopenH Lib "epanet2.dll" () As Long
@@ -190,6 +194,7 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Long Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Long
Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Long Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Long
'Water Quality Analysis Functions
Declare Function ENsolveQ Lib "epanet2.dll" () As Long Declare Function ENsolveQ Lib "epanet2.dll" () As Long
Declare Function ENopenQ Lib "epanet2.dll" () As Long Declare Function ENopenQ Lib "epanet2.dll" () As Long
Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Long) As Long Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Long) As Long
@@ -198,80 +203,97 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENstepQ Lib "epanet2.dll" (Tleft As Long) As Long Declare Function ENstepQ Lib "epanet2.dll" (Tleft As Long) As Long
Declare Function ENcloseQ Lib "epanet2.dll" () As Long Declare Function ENcloseQ Lib "epanet2.dll" () As Long
'Reporting Functions
Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Long Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Long
Declare Function ENreport Lib "epanet2.dll" () As Long Declare Function ENreport Lib "epanet2.dll" () As Long
Declare Function ENresetreport Lib "epanet2.dll" () As Long Declare Function ENresetreport Lib "epanet2.dll" () As Long
Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Long Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Long
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, Ctype As Long, Lindex As Long, setting As Single, Nindex As Long, Level As Single) As Long
Declare Function ENgetcount Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long Declare Function ENgetcount Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) As Long
'Analysis Options Functions
Declare Function ENgetoption Lib "epanet2.dll" (ByVal code As Long, value As Single) As Long Declare Function ENgetoption Lib "epanet2.dll" (ByVal code As Long, value As Single) As Long
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long Declare Function ENsetoption Lib "epanet2.dll" (ByVal code As Long, ByVal value As Single) As Long
Declare Function ENgetflowunits Lib "epanet2.dll" (code As Long) As Long Declare Function ENgetflowunits Lib "epanet2.dll" (code As Long) As Long
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal code As Long, ByVal value As Long) As Long
Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long
Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, TraceNode As Long) As Long
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long
'Basic Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long) As Long
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal index As Long, X As Single, Y As Single) As Long
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Long, ByVal X As Single, ByVal Y As Single) As Long
'Nodal Demand Functions
Declare Function ENgetdemandmodel Lib "epanet2.dll" (mtype As Long, pmin As Single, preq As Single, pexp As Single) As Long
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Long, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Long
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal index As Long, numDemands As Long) As Long
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, value As Single) As Long
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, ByVal BaseDemand As Single) As Long
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, ByVal PatIndex As Long) As Long
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
'Basic Link Functions
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Long, ByVal fromNode As String, ByVal toNode As String) As Long
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENsetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENsetlinktype Lib "epanet2.dll" (index As Long, ByVal code As Long) As Long
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal index As Long, Node1 As Long, Node2 As Long) As Long
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Long, ByVal node1 As Long, ByVal node2 As Long) As Long
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, curveIndex As Long) As Long
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, ByVal curveIndex As Long) As Long
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal index As Long, PumpType As Long) As Long
'Time Pattern Functions
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal index As Long, L As Long) As Long Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal index As Long, L As Long) As Long
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, value As Single) As Long Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, value As Single) As Long
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Long, value As Single) As Long
Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) As Long
Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal code As Long, value As Single) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal index As Long, X As Single, Y As Single) As Long
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Long, ByVal X As Single, ByVal Y As Single) As Long
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal index As Long, numDemands As Long) As Long
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, value As Single) As Long
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal index As Long, Node1 As Long, Node2 As Long) As Long
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal curveIndex As Long, ByVal CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, curveIndex As Long) As Long
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal index As Long, PumpType As Long) As Long
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Long, CurveType As Long) As Long
Declare Function ENgetversion Lib "epanet2.dll" (value As Long) As Long
Declare Function ENgetdemandmodel Lib "epanet2.dll" (mtype As Long, pmin As Single, preq As Single, pexp As Single) As Long
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Long, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Long
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENaddcontrol Lib "epanet2.dll" (Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Long, F As Any, ByVal N As Long) As Long
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, ByVal value As Single) As Long Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, ByVal value As Single) As Long
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal code As Long, ByVal value As Long) As Long Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Long, value As Single) As Long
Declare Function ENsetoption Lib "epanet2.dll" (ByVal code As Long, ByVal value As Single) As Long Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Long, F As Any, ByVal N As Long) As Long
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long
Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, TraceNode As Long) As Long
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal BaseDemand As Single) As Long
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal PatIndex As Long) As Long
'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long 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 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 ENgetcurvelen Lib "epanet2.dll" (ByVal index As Long, L As Long) As Long
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Long, CurveType 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 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 ENsetcurvevalue Lib "epanet2.dll" (ByVal index As Long, ByVal Ptn As Long, ByVal X As Single, ByVal Y As Single) As Long
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal curveIndex As Long, ByVal CurveID As String, nValues As Long, xValues As Any, yValues As Any) 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 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
'Simple Control Functions
Declare Function ENaddcontrol Lib "epanet2.dll" (Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal Cindex as Long) As Long
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, Ctype As Long, Lindex As Long, setting As Single, Nindex As Long, Level As Single) As Long
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
'Rue-Based Control Functions
Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Long, nPremises As Long, nTrueActions As Long, nFalseActions As Long, priority As Single) As Long Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Long, nPremises As Long, nTrueActions As Long, nFalseActions As Long, priority As Single) As Long
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Long, ByVal id As String) As Long
Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Long, ByVal priority As Single) As Long Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Long, ByVal priority As Single) As Long
Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, logop As Long, object As Long, indexObj As Long, variable As Long, relop As Long, status As Long, value As Single) As Long Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, logop As Long, object As Long, indexObj As Long, variable As Long, relop As Long, status As Long, value As Single) As Long
Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, ByVal logop As Long, ByVal object As Long, ByVal indexObj As Long, ByVal variable As Long, ByVal relop As Long, ByVal status As Long, ByVal value As Single) As Long Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, ByVal logop As Long, ByVal object As Long, ByVal indexObj As Long, ByVal variable As Long, ByVal relop As Long, ByVal status As Long, ByVal value As Single) As Long
@@ -282,12 +304,3 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long
Declare Function ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, indexLink As Long, status As Long, setting As Single) As Long Declare Function ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, indexLink As Long, status As Long, setting As Single) As Long
Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Long, ByVal id As String) As Long
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Long, ByVal HeadlossFormula As Long) As Long
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, ByVal curveIndex As Long) As Long
Declare Function ENsetlinktype Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long) As Long
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long) As Long
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Long, ByVal fromNode As String, ByVal toNode As String) As Long
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long

View File

@@ -67,6 +67,9 @@
// --- Define the EPANET toolkit constants // --- Define the EPANET toolkit constants
#define EN_MAXID 31 /**< Max. # characters in ID name */
#define EN_MAXMSG 255 /**< Max. # characters in message text */
/// Node property codes /// Node property codes
typedef enum { typedef enum {
EN_ELEVATION = 0, /**< Node Elevation */ EN_ELEVATION = 0, /**< Node Elevation */
@@ -740,12 +743,12 @@ extern "C" {
/** /**
@brief Set the link type code for a specified link @brief Set the link type code for a specified link
@param id The id of a link @param[in,out] index The index of a link before [in] and after [out] the type change.
@param type The type code of the link. @param code The new type code of the link.
@return Error code @return Error code
@see EN_LinkType @see EN_LinkType
*/ */
int DLLEXPORT ENsetlinktype(char *id, EN_LinkType type); int DLLEXPORT ENsetlinktype(int *index, EN_LinkType code);
/** /**
@brief Get the indexes of a link's start- and end-nodes. @brief Get the indexes of a link's start- and end-nodes.
@@ -831,6 +834,13 @@ extern "C" {
*/ */
int DLLEXPORT ENaddcontrol(int *cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level); int DLLEXPORT ENaddcontrol(int *cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
/**
@brief Delete an existing simple control
@param cindex The index of the control. First control is index 1.
@return Error code.
*/
int DLLEXPORT ENdeletecontrol(int cindex);
/** /**
@brief Specify parameters to define a simple control @brief Specify parameters to define a simple control
@param cindex The index of the control to edit. First control is index 1. @param cindex The index of the control to edit. First control is index 1.
@@ -843,6 +853,14 @@ extern "C" {
*/ */
int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level); int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
/**
@brief Change the ID name for a node.
@param index The index of a node. First node is index 1.
@param newid A string containing the node's new ID name.
@return Error code.
*/
int DLLEXPORT ENsetnodeid(int index, char *newid);
/** /**
@brief Set a property value for a node. @brief Set a property value for a node.
@param index The index of a node. First node is index 1. @param index The index of a node. First node is index 1.
@@ -853,6 +871,24 @@ extern "C" {
*/ */
int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v); int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v);
/**
@brief Change the ID name for a link.
@param index The index of a link. First link is index 1.
@param newid A string containing the link's new ID name.
@return Error code.
*/
int DLLEXPORT ENsetlinkid(int index, char *newid);
/**
@brief Set the indexes of a link's start- and end-nodes.
@param index The index of a link (first link is index 1)
@param node1 The index of the link's start node (first node is index 1).
@param node2 The index of the link's end node (first node is index 1).
@return Error code
@see ENsetnodeid, ENsetlinkid
*/
int DLLEXPORT ENsetlinknodes(int index, int node1, int node2);
/** /**
@brief Set a property value for a link. @brief Set a property value for a link.
@param index The index of a link. First link is index 1. @param index The index of a link. First link is index 1.
@@ -1046,7 +1082,6 @@ extern "C" {
*/ */
int DLLEXPORT ENaddcurve(char *id); int DLLEXPORT ENaddcurve(char *id);
/** /**
@brief Gets the number of premises, true actions, and false actions and the priority of an existing rule-based control. @brief Gets the number of premises, true actions, and false actions and the priority of an existing rule-based control.
@param index The index of a rule-based control. @param index The index of a rule-based control.
@@ -1284,7 +1319,6 @@ extern "C" {
int DLLEXPORT EN_getlinkindex(EN_ProjectHandle ph, char *id, int *index); int DLLEXPORT EN_getlinkindex(EN_ProjectHandle ph, char *id, int *index);
int DLLEXPORT EN_getlinkid(EN_ProjectHandle ph, int index, char *id); int DLLEXPORT EN_getlinkid(EN_ProjectHandle ph, int index, char *id);
int DLLEXPORT EN_getlinktype(EN_ProjectHandle ph, int index, EN_LinkType *code); int DLLEXPORT EN_getlinktype(EN_ProjectHandle ph, int index, EN_LinkType *code);
int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, char *id, EN_LinkType type);
int DLLEXPORT EN_getlinknodes(EN_ProjectHandle ph, int index, int *node1, int *node2); int DLLEXPORT EN_getlinknodes(EN_ProjectHandle ph, int index, int *node1, int *node2);
int DLLEXPORT EN_getlinkvalue(EN_ProjectHandle ph, int index, EN_LinkProperty code, EN_API_FLOAT_TYPE *value); int DLLEXPORT EN_getlinkvalue(EN_ProjectHandle ph, int index, EN_LinkProperty code, EN_API_FLOAT_TYPE *value);
int DLLEXPORT EN_getcurve(EN_ProjectHandle ph, int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues); int DLLEXPORT EN_getcurve(EN_ProjectHandle ph, int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues);
@@ -1297,7 +1331,11 @@ extern "C" {
int DLLEXPORT EN_addcontrol(EN_ProjectHandle ph, int *cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level); int DLLEXPORT EN_addcontrol(EN_ProjectHandle ph, int *cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
int DLLEXPORT EN_setcontrol(EN_ProjectHandle ph, int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level); int DLLEXPORT EN_setcontrol(EN_ProjectHandle ph, int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
int DLLEXPORT EN_setnodeid(EN_ProjectHandle ph, int index, char *newid);
int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v); int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_setlinkid(EN_ProjectHandle ph, int index, char *newid);
int DLLEXPORT EN_setlinknodes(EN_ProjectHandle ph, int index, int node1, int node2);
int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, int *index, EN_LinkType code);
int DLLEXPORT EN_setlinkvalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v); int DLLEXPORT EN_setlinkvalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v);
int DLLEXPORT EN_addpattern(EN_ProjectHandle ph, char *id); int DLLEXPORT EN_addpattern(EN_ProjectHandle ph, char *id);
int DLLEXPORT EN_setpattern(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *f, int len); int DLLEXPORT EN_setpattern(EN_ProjectHandle ph, int index, EN_API_FLOAT_TYPE *f, int len);
@@ -1340,6 +1378,7 @@ extern "C" {
int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode); int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode);
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int nodeIndex); int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int nodeIndex);
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int linkIndex); int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int linkIndex);
int DLLEXPORT EN_deletecontrol(EN_ProjectHandle ph, int controlIndex);
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@@ -39,6 +39,7 @@ Public Const EN_MIXFRACTION = 22
Public Const EN_TANK_KBULK = 23 Public Const EN_TANK_KBULK = 23
Public Const EN_TANKVOLUME = 24 'ES Public Const EN_TANKVOLUME = 24 'ES
Public Const EN_MAXVOLUME = 25
Public Const EN_DIAMETER = 0 ' Link parameters Public Const EN_DIAMETER = 0 ' Link parameters
Public Const EN_LENGTH = 1 Public Const EN_LENGTH = 1
@@ -60,6 +61,9 @@ Public Const EN_EFFICIENCY = 16
Public Const EN_HEADCURVE = 17 Public Const EN_HEADCURVE = 17
Public Const EN_EFFICIENCYCURVE = 18 Public Const EN_EFFICIENCYCURVE = 18
Public Const EN_PRICEPATTERN = 19 Public Const EN_PRICEPATTERN = 19
Public Const EN_STATE = 20
Public Const EN_CONST_POWER = 21
Public Const EN_SPEED = 22
Public Const EN_DURATION = 0 ' Time parameters Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1 Public Const EN_HYDSTEP = 1
@@ -115,6 +119,10 @@ Public Const EN_MASS = 1
Public Const EN_SETPOINT = 2 Public Const EN_SETPOINT = 2
Public Const EN_FLOWPACED = 3 Public Const EN_FLOWPACED = 3
Public Const EN_HW = 0 ' Head loss formula
Public Const EN_DW = 1
Public Const EN_CM = 2
Public Const EN_CFS = 0 ' Flow units types Public Const EN_CFS = 0 ' Flow units types
Public Const EN_GPM = 1 Public Const EN_GPM = 1
Public Const EN_MGD = 2 Public Const EN_MGD = 2
@@ -126,6 +134,9 @@ Public Const EN_MLD = 7
Public Const EN_CMH = 8 Public Const EN_CMH = 8
Public Const EN_CMD = 9 Public Const EN_CMD = 9
Public Const EN_DDA = 0 ' Demand driven analysis
Public Const EN_PDA = 1 ' Pressure driven analysis
Public Const EN_TRIALS = 0 ' Misc. options Public Const EN_TRIALS = 0 ' Misc. options
Public Const EN_ACCURACY = 1 Public Const EN_ACCURACY = 1
Public Const EN_TOLERANCE = 2 Public Const EN_TOLERANCE = 2
@@ -159,13 +170,23 @@ Public Const EN_CONST_HP = 0 ' constant horsepower
Public Const EN_POWER_FUNC = 1 ' power function Public Const EN_POWER_FUNC = 1 ' power function
Public Const EN_CUSTOM = 2 ' user-defined custom curve Public Const EN_CUSTOM = 2 ' user-defined custom curve
Public Const EN_V_CURVE = 0 ' volume curve
Public Const EN_P_CURVE = 1 ' pump curve
Public Const EN_E_CURVE = 2 ' efficiency curve
Public Const EN_H_CURVE = 3 ' head loss curve
Public Const EN_G_CURVE = 4 ' General\default curve
'These are the external functions that comprise the DLL 'These are the external functions that comprise the DLL
'System Functions
Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32
Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As String) As Int32 Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As String) As Int32
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Int32, ByVal HeadlossFormula As Int32) As Int32
Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Int32 Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Int32
Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Int32 Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Int32
Declare Function ENclose Lib "epanet2.dll" () As Int32 Declare Function ENclose Lib "epanet2.dll" () As Int32
'Hydraulic Analysis Functions
Declare Function ENsolveH Lib "epanet2.dll" () As Int32 Declare Function ENsolveH Lib "epanet2.dll" () As Int32
Declare Function ENsaveH Lib "epanet2.dll" () As Int32 Declare Function ENsaveH Lib "epanet2.dll" () As Int32
Declare Function ENopenH Lib "epanet2.dll" () As Int32 Declare Function ENopenH Lib "epanet2.dll" () As Int32
@@ -176,6 +197,7 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve
Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Int32 Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Int32
Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Int32 Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Int32
'Water Quality Analysis Functions
Declare Function ENsolveQ Lib "epanet2.dll" () As Int32 Declare Function ENsolveQ Lib "epanet2.dll" () As Int32
Declare Function ENopenQ Lib "epanet2.dll" () As Int32 Declare Function ENopenQ Lib "epanet2.dll" () As Int32
Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Int32) As Int32 Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Int32) As Int32
@@ -184,71 +206,98 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve
Declare Function ENstepQ Lib "epanet2.dll" (ByRef Tleft As Int32) As Int32 Declare Function ENstepQ Lib "epanet2.dll" (ByRef Tleft As Int32) As Int32
Declare Function ENcloseQ Lib "epanet2.dll" () As Int32 Declare Function ENcloseQ Lib "epanet2.dll" () As Int32
'Reporting Functions
Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Int32 Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Int32
Declare Function ENreport Lib "epanet2.dll" () As Int32 Declare Function ENreport Lib "epanet2.dll" () As Int32
Declare Function ENresetreport Lib "epanet2.dll" () As Int32 Declare Function ENresetreport Lib "epanet2.dll" () As Int32
Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Int32 Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Int32
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Int32) As Int32
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByRef CtlType As Int32, ByRef Lindex As Int32, ByRef Setting As Single, ByRef Nindex As Int32, ByRef Level As Single) As Int32
Declare Function ENgetcount Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 Declare Function ENgetcount Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32
Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32 Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Int32, ByVal ErrMsg As StringBuilder, ByVal N As Int32) As Int32
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal code As Int32, ByRef value As Single) As Int32
Declare Function ENgetflowunits Lib "epanet2.dll" (ByRef Code As Int32) As Int32
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByRef Value As Single) As Int32
Declare Function ENgetqualtype Lib "epanet2.dll" (ByRef QualCode As Int32, ByRef TraceNode As Int32) As Int32
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Int32, ByVal ErrMsg As StringBuilder, ByVal N As Int32)
'Analysis Options Functions
Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENgetflowunits Lib "epanet2.dll" (ByRef Code As Int32) As Int32
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Int32) As Int32
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Int32) As Int32
Declare Function ENgetqualtype Lib "epanet2.dll" (ByRef QualCode As Int32, ByRef TraceNode As Int32) As Int32
Declare Function ENgetqualinfo Lib "epanet2.dll" (ByRef QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByRef TraceNode As Int32) As Int32
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Int32
'Basic Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Int32) As Int32
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Int32, ByVal newid As String) As Int32
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32 Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32 Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByRef X As Single, ByRef Y As Single) As Int32 Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByRef X As Single, ByRef Y As Single) As Int32
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByVal X As Single, ByVal Y As Single) As Int32 Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByVal X As Single, ByVal Y As Single) As Int32
'Nodal Demand Functions
Declare Function ENgetdemandmodel Lib "epanet2.dll" (ByRef mtype As Int32, ByRef pmin As Single, ByRef preq As Single, ByRef pexp As Single) As Int32
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Int32, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Int32
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Int32, ByRef numDemands As Int32) As Int32 'ES Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Int32, ByRef numDemands As Int32) As Int32 'ES
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef BaseDemand As Single) As Int32 'ES Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef BaseDemand As Single) As Int32 'ES
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByVal BaseDemand As Single) As Int32 'ES Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByVal BaseDemand As Single) As Int32 'ES
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef PatIndex As Int32) As Int32 'ES Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef PatIndex As Int32) As Int32 'ES
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByVal PatIndex As Int32) As Int32 'ES Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal index As Int32, ByVal DemandIndex As Int32, ByVal PatIndex As Int32) As Int32
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Int32, ByVal DemandIndex As Int32, ByVal demandName As String) As Int32
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal DemandIndex As Int32, ByVal demandName As String) As Int32
'Basic Link Functions
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Int32, ByVal fromNode As String, ByVal toNode As String) As Int32
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENsetlinkid Lib "epanet2.dll" (ByVal index As Int32, ByVal newid As String) As Int32
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32 Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENsetlinktype Lib "epanet2.dll" (ByRef index As Int32, ByVal code As Int32) As Int32
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Int32, ByRef Node1 As Int32, ByRef Node2 As Int32) As Int32 Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Int32, ByRef Node1 As Int32, ByRef Node2 As Int32) As Int32
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Int32, ByVal node1 As Int32, ByVal node2 As Int32) As Int32
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32 Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Int32, ByRef nValues As Int32, ByRef xValues As Single, ByRef yValues As Single) As Int32 'ES 'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal Index As Int32, ByVal CurveIndex As int32) As Int32 'ES Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal Index As Int32, ByVal CurveIndex As int32) As Int32 'ES
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Int32, ByVal curveIndex As Int32) As Int32
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Int32, ByRef PumpType As Int32) As Int32 'ES Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Int32, ByRef PumpType As Int32) As Int32 'ES
Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32 'Time Pattern Functions
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal CtlType As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByVal Value As Single) As Int32
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Int32) As Int32
Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Int32) As Int32
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Int32
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal ID As String) As Int32 Declare Function ENaddpattern Lib "epanet2.dll" (ByVal ID As String) As Int32
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByRef Value As Single) As Int32
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByVal Value As Single) As Int32
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByRef value As Single) As Int32
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32
'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Int32
Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 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 ENgetcurvelen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Int32, ByRef CurveType 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 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 ENsetcurvevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Pnt As Int32, ByVal X As Single, ByVal Y As Single) As Int32
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Int32, ByRef nValues As Int32, ByRef xValues As Single, ByRef yValues As Single) As Int32 'ES
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 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
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Long 'Simple Control Functions
Declare Function ENaddcontrol Lib "epanet2.dll" (ByRef Cindex As Int32, ByVal Ctype As Int32, ByVal Lindex As Int32, ByVal setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal Cindex as Int32) As Int32
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByRef CtlType As Int32, ByRef Lindex As Int32, ByRef Setting As Single, ByRef Nindex As Int32, ByRef Level As Single) As Int32
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal CtlType As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
'Rule-Based Control Functions
Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Int32, ByRef nPremises As Int32, ByRef nTrueActions As Int32, ByRef nFalseActions As Int32, ByRef priority As Single) As Int32 Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Int32, ByRef nPremises As Int32, ByRef nTrueActions As Int32, ByRef nFalseActions As Int32, ByRef priority As Single) As Int32
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal id As StringBuilder) As Int32
Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Int32, ByVal priority As Single) As Int32 Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Int32, ByVal priority As Single) As Int32
Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByRef logop As Int32, ByRef object As Int32, ByRef indexObj As Int32, ByRef variable As Int32, ByRef relop As Int32, ByRef status As Int32, ByRef value As Single) As Int32 Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByRef logop As Int32, ByRef object As Int32, ByRef indexObj As Int32, ByRef variable As Int32, ByRef relop As Int32, ByRef status As Int32, ByRef value As Single) As Int32
Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal logop As Int32, ByVal object As Int32, ByVal indexObj As Int32, ByVal variable As Int32, ByVal relop As Int32, ByVal status As Int32, ByVal value As Single) As Int32 Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal logop As Int32, ByVal object As Int32, ByVal indexObj As Int32, ByVal variable As Int32, ByVal relop As Int32, ByVal status As Int32, ByVal value As Single) As Int32
@@ -257,10 +306,7 @@ Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Long
Declare Function ENsetpremisevalue Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal value As Single) As Int32 Declare Function ENsetpremisevalue Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal value As Single) As Int32
Declare Function ENgettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32 Declare Function ENgettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32
Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32 Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32
Decalre FUnction ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32 Declare Function ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32
Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32 Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal id As StringBuilder) As Int32
End Module End Module

View File

@@ -89,9 +89,9 @@ This module calls the following functions that reside in other modules:
writelogo() writelogo()
writereport() writereport()
HASH.C HASH.C
ENHashTablecreate() hashtable_create()
ENHashTableFind() hashtable_find()
ENHashTableFree() hashtable_free()
The macro ERRCODE(x) is defined in TYPES.H. It says if the current The macro ERRCODE(x) is defined in TYPES.H. It says if the current
value of the error code variable (errcode) is not fatal (< 100) then value of the error code variable (errcode) is not fatal (< 100) then
@@ -138,49 +138,13 @@ void *_defaultModel;
// Local functions // Local functions
void errorLookup(int errcode, char *errmsg, int len); void errorLookup(int errcode, char *errmsg, int len);
/**************************************************************** /****************************************************************
LEGACY (v <= 2.1) API: uses global project variable LEGACY (v <= 2.1) API: uses global project variable
*****************************************************************/ *****************************************************************/
int runconcurrent(EN_ProjectHandle ph, const char *inputfile, const char *reportfile,
const char *outputfile, void(*pviewprog)(char *))
{
long t, tstep_h, tstep_q;
int errcode = 0;
EN_Project *p = NULL;
ERRCODE(EN_open(ph, inputfile, reportfile, outputfile));
p = (EN_Project*)(ph);
p->viewprog = pviewprog;
ERRCODE(EN_openH(ph));
ERRCODE(EN_initH(ph, EN_SAVE));
ERRCODE(EN_openQ(ph));
ERRCODE(EN_initQ(ph, EN_SAVE));
do {
ERRCODE(EN_runH(ph, &t));
ERRCODE(EN_runQ(ph, &t));
ERRCODE(EN_nextH(ph, &tstep_h));
ERRCODE(EN_nextQ(ph, &tstep_q));
} while (tstep_h > 0);
ERRCODE(EN_closeH(ph));
ERRCODE(EN_closeQ(ph));
ERRCODE(EN_report(ph));
ERRCODE(EN_close(ph));
return errcode;
}
/*------------------------------------------------------------------------ /*------------------------------------------------------------------------
** Input: f1 = pointer to name of input file ** Input: f1 = pointer to name of input file
** f2 = pointer to name of report file ** f2 = pointer to name of report file
@@ -201,14 +165,17 @@ int runconcurrent(EN_ProjectHandle ph, const char *inputfile, const char *report
int DLLEXPORT ENepanet(const char *f1, const char *f2, const char *f3, void (*pviewprog)(char *)) int DLLEXPORT ENepanet(const char *f1, const char *f2, const char *f3, void (*pviewprog)(char *))
{ {
int errcode = 0; int errcode = 0;
int warncode = 0;
EN_Project *p = NULL; EN_Project *p = NULL;
ERRCODE(EN_createproject(&_defaultModel)); ERRCODE(EN_createproject(&_defaultModel));
ERRCODE(EN_runproject(_defaultModel, f1, f2, f3, pviewprog)); ERRCODE(EN_runproject(_defaultModel, f1, f2, f3, pviewprog));
if (errcode < 100) warncode = errcode;
ERRCODE(EN_deleteproject(&_defaultModel)); ERRCODE(EN_deleteproject(&_defaultModel));
if (warncode) errcode = MAX(errcode, warncode);
return (errcode); return (errcode);
} }
@@ -437,10 +404,31 @@ int DLLEXPORT ENaddcontrol(int *cindex, int ctype, int lindex,
level); level);
} }
int DLLEXPORT ENdeletecontrol(int cindex) {
return EN_deletecontrol(_defaultModel, cindex);
}
int DLLEXPORT ENsetnodeid(int index, char *newid) {
return EN_setnodeid(_defaultModel, index, newid);
}
int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) { int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) {
return EN_setnodevalue(_defaultModel, index, code, v); return EN_setnodevalue(_defaultModel, index, code, v);
} }
int DLLEXPORT ENsetlinkid(int index, char *newid) {
return EN_setlinkid(_defaultModel, index, newid);
}
int DLLEXPORT ENsetlinknodes(int index, int node1, int node2) {
return EN_setlinknodes(_defaultModel, index, node1, node2);
}
int DLLEXPORT ENsetlinktype(int *index, EN_LinkType type) {
return EN_setlinktype(_defaultModel, index, type);
}
int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v) { int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v) {
return EN_setlinkvalue(_defaultModel, index, code, v); return EN_setlinkvalue(_defaultModel, index, code, v);
} }
@@ -593,10 +581,6 @@ int DLLEXPORT ENgetruleID(int indexRule, char* id){
return EN_getruleID(_defaultModel, indexRule, id); return EN_getruleID(_defaultModel, indexRule, id);
} }
int DLLEXPORT ENsetlinktype(char *id, EN_LinkType toType) {
return EN_setlinktype(_defaultModel, id, toType);
}
int DLLEXPORT ENaddnode(char *id, EN_NodeType nodeType) { int DLLEXPORT ENaddnode(char *id, EN_NodeType nodeType) {
return EN_addnode(_defaultModel, id, nodeType); return EN_addnode(_defaultModel, id, nodeType);
} }
@@ -675,6 +659,7 @@ int DLLEXPORT EN_runproject(EN_ProjectHandle ph, const char *f1, const char *f2,
EN_close(ph); EN_close(ph);
if (p->Warnflag) errcode = MAX(errcode, p->Warnflag);
return errcode; return errcode;
} }
@@ -784,7 +769,6 @@ int DLLEXPORT EN_open(EN_ProjectHandle ph, const char *f1, const char *f2, const
writelogo(p); writelogo(p);
/* Find network size & allocate memory for data */ /* Find network size & allocate memory for data */
writecon(FMT02);
writewin(p->viewprog, FMT100); writewin(p->viewprog, FMT100);
ERRCODE(netsize(p)); ERRCODE(netsize(p));
ERRCODE(allocdata(p)); ERRCODE(allocdata(p));
@@ -842,14 +826,12 @@ int DLLEXPORT EN_close(EN_ProjectHandle ph)
out_file_t *out; out_file_t *out;
EN_Project *p = (EN_Project*)ph; EN_Project *p = (EN_Project*)ph;
if (p->Openflag) { if (p->Openflag) {
writetime(p, FMT105); writetime(p, FMT105);
} }
freedata(p); freedata(p);
out = &p->out_files; out = &p->out_files;
if (out->TmpOutFile != out->OutFile) { if (out->TmpOutFile != out->OutFile) {
if (out->TmpOutFile != NULL) { if (out->TmpOutFile != NULL) {
fclose(out->TmpOutFile); fclose(out->TmpOutFile);
@@ -914,19 +896,14 @@ int DLLEXPORT EN_solveH(EN_ProjectHandle ph)
if (!errcode) { if (!errcode) {
/* Initialize hydraulics */ /* Initialize hydraulics */
errcode = EN_initH(ph, EN_SAVE); errcode = EN_initH(ph, EN_SAVE);
writecon(FMT14);
/* Analyze each hydraulic period */ /* Analyze each hydraulic period */
if (!errcode) if (!errcode)
do { do {
/* Display progress message */ /* Display progress message */
/*** Updated 6/24/02 ***/
sprintf(p->Msg, "%-10s", sprintf(p->Msg, "%-10s",
clocktime(p->report.Atime, p->time_options.Htime)); clocktime(p->report.Atime, p->time_options.Htime));
writecon(p->Msg);
sprintf(p->Msg, FMT101, p->report.Atime); sprintf(p->Msg, FMT101, p->report.Atime);
writewin(p->viewprog, p->Msg); writewin(p->viewprog, p->Msg);
@@ -934,16 +911,10 @@ int DLLEXPORT EN_solveH(EN_ProjectHandle ph)
tstep = 0; tstep = 0;
ERRCODE(EN_runH(ph, &t)); ERRCODE(EN_runH(ph, &t));
ERRCODE(EN_nextH(ph, &tstep)); ERRCODE(EN_nextH(ph, &tstep));
/*** Updated 6/24/02 ***/
writecon("\b\b\b\b\b\b\b\b\b\b");
} while (tstep > 0); } while (tstep > 0);
} }
/* Close hydraulics solver */ /* Close hydraulics solver */
/*** Updated 6/24/02 ***/
writecon("\b\b\b\b\b\b\b\b ");
EN_closeH(ph); EN_closeH(ph);
errcode = MAX(errcode, p->Warnflag); errcode = MAX(errcode, p->Warnflag);
@@ -1184,24 +1155,15 @@ int DLLEXPORT EN_solveQ(EN_ProjectHandle ph) {
if (!errcode) { if (!errcode) {
/* Initialize WQ */ /* Initialize WQ */
errcode = EN_initQ(ph, EN_SAVE); errcode = EN_initQ(ph, EN_SAVE);
if (p->quality.Qualflag) if (!p->quality.Qualflag) writewin(p->viewprog, FMT106);
writecon(FMT15);
else {
writecon(FMT16);
writewin(p->viewprog, FMT103);
}
/* Analyze each hydraulic period */ /* Analyze each hydraulic period */
if (!errcode) if (!errcode)
do { do {
/* Display progress message */ /* Display progress message */
/*** Updated 6/24/02 ***/
sprintf(p->Msg, "%-10s", sprintf(p->Msg, "%-10s",
clocktime(p->report.Atime, p->time_options.Htime)); clocktime(p->report.Atime, p->time_options.Htime));
writecon(p->Msg);
if (p->quality.Qualflag) { if (p->quality.Qualflag) {
sprintf(p->Msg, FMT102, p->report.Atime); sprintf(p->Msg, FMT102, p->report.Atime);
writewin(p->viewprog, p->Msg); writewin(p->viewprog, p->Msg);
@@ -1211,17 +1173,10 @@ int DLLEXPORT EN_solveQ(EN_ProjectHandle ph) {
tstep = 0; tstep = 0;
ERRCODE(EN_runQ(ph, &t)); ERRCODE(EN_runQ(ph, &t));
ERRCODE(EN_nextQ(ph, &tstep)); ERRCODE(EN_nextQ(ph, &tstep));
/*** Updated 6/24/02 ***/
writecon("\b\b\b\b\b\b\b\b\b\b");
} while (tstep > 0); } while (tstep > 0);
} }
/* Close WQ solver */ /* Close WQ solver */
/*** Updated 6/24/02 ***/
writecon("\b\b\b\b\b\b\b\b ");
EN_closeQ(ph); EN_closeQ(ph);
return set_error(p->error_handle, errcode); return set_error(p->error_handle, errcode);
} }
@@ -1349,6 +1304,7 @@ int DLLEXPORT EN_report(EN_ProjectHandle ph) {
/* Check if results saved to binary output file */ /* Check if results saved to binary output file */
if (!p->save_options.SaveQflag) if (!p->save_options.SaveQflag)
return set_error(p->error_handle, 106); return set_error(p->error_handle, 106);
writewin(p->viewprog, FMT103);
errcode = writereport(p); errcode = writereport(p);
if (errcode) if (errcode)
errmsg(p, errcode); errmsg(p, errcode);
@@ -1377,9 +1333,10 @@ int DLLEXPORT EN_setreport(EN_ProjectHandle ph, char *s) {
if (!p->Openflag) if (!p->Openflag)
return set_error(p->error_handle, 102); return set_error(p->error_handle, 102);
if (strlen(s) > MAXLINE) if (strlen(s) >= MAXLINE)
return set_error(p->error_handle, 250); return set_error(p->error_handle, 250);
strcpy(s1, s); strcpy(s1, s);
strcat(s1, "\n");
if (setreport(p, s1) > 0) if (setreport(p, s1) > 0)
return set_error(p->error_handle, 250); return set_error(p->error_handle, 250);
else else
@@ -2891,6 +2848,34 @@ int DLLEXPORT EN_setcontrol(EN_ProjectHandle ph, int cindex, int ctype, int lind
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
int DLLEXPORT EN_setnodeid(EN_ProjectHandle ph, int index, char *newid)
{
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
size_t n;
// Check for valid arguments
if (index <= 0 || index > net->Nnodes)
{
return set_error(p->error_handle, 203);
}
n = strlen(newid);
if (n < 1 || n > MAXID) return set_error(p->error_handle, 209);
if (strcspn(newid, " ;") < n) return set_error(p->error_handle, 209);
// Check if another node with same name exists
if (hashtable_find(net->NodeHashTable, newid) > 0)
{
return set_error(p->error_handle, 215);
}
// Replace the existing node ID with the new value
hashtable_delete(net->NodeHashTable, net->Node[index].ID);
strncpy(net->Node[index].ID, newid, MAXID);
hashtable_insert(net->NodeHashTable, net->Node[index].ID, index);
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v) int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_FLOAT_TYPE v)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: index = node index ** Input: index = node index
@@ -3157,6 +3142,68 @@ int DLLEXPORT EN_setnodevalue(EN_ProjectHandle ph, int index, int code, EN_API_F
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
int DLLEXPORT EN_setlinkid(EN_ProjectHandle ph, int index, char *newid)
{
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
size_t n;
// Check for valid arguments
if (index <= 0 || index > net->Nlinks)
{
return set_error(p->error_handle, 204);
}
n = strlen(newid);
if (n < 1 || n > MAXID) return set_error(p->error_handle, 211);
if (strcspn(newid, " ;") < n) return set_error(p->error_handle, 211);
// Check if another link with same name exists
if (hashtable_find(net->LinkHashTable, newid) > 0)
{
return set_error(p->error_handle, 215);
}
// Replace the existing link ID with the new value
hashtable_delete(net->LinkHashTable, net->Link[index].ID);
strncpy(net->Link[index].ID, newid, MAXID);
hashtable_insert(net->LinkHashTable, net->Link[index].ID, index);
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_setlinknodes(EN_ProjectHandle ph, int index, int node1, int node2)
{
int type;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
// Check that end and start nodes are not the same
if (node1 == node2) return set_error(p->error_handle, 222);
// Check that nodes exist
if (node1 < 0 || node1 > net->Nnodes) return set_error(p->error_handle, 203);
if (node2 < 0 || node2 > net->Nnodes) return set_error(p->error_handle, 203);
// Check for illegal valve connection
type = net->Link[index].Type;
if (type == EN_PRV || type == EN_PSV || type == EN_FCV)
{
// Can't be connected to a fixed grade node
if (node1 > net->Njuncs ||
node2 > net->Njuncs) return set_error(p->error_handle, 219);
// Can't be connected to another pressure/flow control valve
if (!valvecheck(p, type, node1, node2))
{
return set_error(p->error_handle, 220);
}
}
// Assign new end nodes to link
net->Link[index].N1 = node1;
net->Link[index].N2 = node2;
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_setlinkvalue(EN_ProjectHandle ph, int index, int code, int DLLEXPORT EN_setlinkvalue(EN_ProjectHandle ph, int index, int code,
EN_API_FLOAT_TYPE v) EN_API_FLOAT_TYPE v)
@@ -3772,6 +3819,7 @@ int DLLEXPORT EN_setoption(EN_ProjectHandle ph, int code, EN_API_FLOAT_TYPE v)
for (demand = node->D; demand != NULL; demand = demand->next) { for (demand = node->D; demand != NULL; demand = demand->next) {
if (demand->Pat == tmpPat) { if (demand->Pat == tmpPat) {
demand->Pat = (int)value; demand->Pat = (int)value;
strcpy(demand->Name, "");
} }
} }
} }
@@ -3910,7 +3958,7 @@ int DLLEXPORT EN_setheadcurveindex(EN_ProjectHandle ph, int index, int curveinde
pump->Ptype = NOCURVE; pump->Ptype = NOCURVE;
pump->Hcurve = curveindex; pump->Hcurve = curveindex;
// update pump parameters // update pump parameters
getpumpparams(p); updatepumpparams(p, pIdx);
// convert units // convert units
if (pump->Ptype == POWER_FUNC) { if (pump->Ptype == POWER_FUNC) {
pump->H0 /= Ucf[HEAD]; pump->H0 /= Ucf[HEAD];
@@ -4000,20 +4048,16 @@ int openfiles(EN_Project *p, const char *f1, const char *f2, const char *f3)
/* Check that file names are not identical */ /* Check that file names are not identical */
if (strcomp(f1, f2) || strcomp(f1, f3) || if (strcomp(f1, f2) || strcomp(f1, f3) ||
(strcomp(f2, f3) && (strlen(f2) > 0 || strlen(f3) > 0))) { (strcomp(f2, f3) && (strlen(f2) > 0 || strlen(f3) > 0))) {
writecon(FMT04);
return 301; return 301;
} }
/* Attempt to open input and report files */ /* Attempt to open input and report files */
if ((par->InFile = fopen(f1, "rt")) == NULL) { if ((par->InFile = fopen(f1, "rt")) == NULL) {
writecon(FMT05);
writecon(f1);
return 302; return 302;
} }
if (strlen(f2) == 0) if (strlen(f2) == 0)
rep->RptFile = stdout; rep->RptFile = stdout;
else if ((rep->RptFile = fopen(f2, "wt")) == NULL) { else if ((rep->RptFile = fopen(f2, "wt")) == NULL) {
writecon(FMT06);
return 303; return 303;
} }
@@ -4144,7 +4188,6 @@ int openoutfile(EN_Project *p)
if (out->Outflag == SAVE) if (out->Outflag == SAVE)
{ {
if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL) { if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL) {
writecon(FMT07);
errcode = 304; errcode = 304;
} }
} }
@@ -4154,7 +4197,6 @@ int openoutfile(EN_Project *p)
getTmpName(p, out->OutFname); getTmpName(p, out->OutFname);
if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL) if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL)
{ {
writecon(FMT08);
errcode = 304; errcode = 304;
} }
} }
@@ -4260,8 +4302,8 @@ int allocdata(EN_Project *p)
parser_data_t *par; parser_data_t *par;
/* Allocate node & link ID hash tables */ /* Allocate node & link ID hash tables */
p->network.NodeHashTable = ENHashTableCreate(); p->network.NodeHashTable = hashtable_create();
p->network.LinkHashTable = ENHashTableCreate(); p->network.LinkHashTable = hashtable_create();
ERRCODE(MEMCHECK(p->network.NodeHashTable)); ERRCODE(MEMCHECK(p->network.NodeHashTable));
ERRCODE(MEMCHECK(p->network.LinkHashTable)); ERRCODE(MEMCHECK(p->network.LinkHashTable));
@@ -4466,10 +4508,9 @@ void freedata(EN_Project *p)
freerules(p); freerules(p);
/* Free hash table memory */ /* Free hash table memory */
if (net->NodeHashTable != NULL) if (net->NodeHashTable != NULL) hashtable_free(net->NodeHashTable);
ENHashTableFree(net->NodeHashTable);
if (net->LinkHashTable != NULL) if (net->LinkHashTable != NULL) hashtable_free(net->LinkHashTable);
ENHashTableFree(net->LinkHashTable);
} }
/* /*
@@ -4572,7 +4613,7 @@ int findnode(EN_Network *n, char *id)
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
return (ENHashTableFind(n->NodeHashTable, id)); return (hashtable_find(n->NodeHashTable, id));
} }
int findlink(EN_Network *n, char *id) int findlink(EN_Network *n, char *id)
@@ -4584,7 +4625,7 @@ int findlink(EN_Network *n, char *id)
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
return (ENHashTableFind(n->LinkHashTable, id)); return (hashtable_find(n->LinkHashTable, id));
} }
int findtank(EN_Network *n, int index) int findtank(EN_Network *n, int index)
@@ -4652,6 +4693,7 @@ char *geterrmsg(int errcode, char *msg)
{ {
switch (errcode) { /* Warnings */ switch (errcode) { /* Warnings */
#define DAT(code,enumer,string) case code: strcpy(msg, string); break; #define DAT(code,enumer,string) case code: strcpy(msg, string); break;
//#define DAT(code,enumer,string) case code: sprintf(msg, "Error %d: %s", code, string); break;
#include "errors.dat" #include "errors.dat"
#undef DAT #undef DAT
default: default:
@@ -4670,26 +4712,12 @@ void errmsg(EN_Project *p, int errcode)
{ {
if (errcode == 309) /* Report file write error - */ if (errcode == 309) /* Report file write error - */
{ /* Do not write msg to file. */ { /* Do not write msg to file. */
writecon("\n ");
writecon(geterrmsg(errcode,p->Msg));
} else if (p->report.RptFile != NULL && p->report.Messageflag) { } else if (p->report.RptFile != NULL && p->report.Messageflag) {
writeline(p, geterrmsg(errcode,p->Msg)); writeline(p, geterrmsg(errcode,p->Msg));
} }
} }
void writecon(const char *s)
/*----------------------------------------------------------------
** Input: text string
** Output: none
** Purpose: writes string of characters to console
**----------------------------------------------------------------
*/
{
fprintf(stdout, "%s", s);
fflush(stdout);
}
void writewin(void (*vp)(char *), char *s) void writewin(void (*vp)(char *), char *s)
/*---------------------------------------------------------------- /*----------------------------------------------------------------
** Input: text string ** Input: text string
@@ -4809,8 +4837,6 @@ int DLLEXPORT EN_setdemandname(EN_ProjectHandle ph, int nodeIndex, int demandIdx
const int Nnodes = net->Nnodes; const int Nnodes = net->Nnodes;
const int Njuncs = net->Njuncs; const int Njuncs = net->Njuncs;
double *Ucf = pr->Ucf;
Pdemand d; Pdemand d;
int n = 1; int n = 1;
/* Check for valid arguments */ /* Check for valid arguments */
@@ -4902,43 +4928,50 @@ int DLLEXPORT EN_getaveragepatternvalue(EN_ProjectHandle ph, int index, EN_API_F
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, char *id, EN_LinkType toType) { int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, int *index, EN_LinkType type) {
int i;
EN_LinkType fromType;
int i = *index, n1, n2;
char id[MAXID+1];
char id1[MAXID+1];
char id2[MAXID+1];
int errcode;
EN_LinkType oldtype;
EN_Project *p = (EN_Project*)ph; EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network; EN_Network *net = &p->network;
if (!p->Openflag) if (!p->Openflag) return set_error(p->error_handle, 102);
return set_error(p->error_handle, 102); if (type < 0 || type > EN_GPV) return set_error(p->error_handle, 211);
/* Check if a link with the id exists */ // Check if a link with the id exists
if (EN_getlinkindex(p, id, &i) != 0) if (i <= 0 || i > net->Nlinks) return set_error(p->error_handle, 204);
return set_error(p->error_handle, 215);
/* Get the current type of the link */ // Get the current type of the link
EN_getlinktype(p, i, &fromType); EN_getlinktype(p, i, &oldtype);
if (fromType == toType) if (oldtype == type) return set_error(p->error_handle, 0);
// Pipe changing from or to having a check valve
if (oldtype <= EN_PIPE && type <= EN_PIPE)
{
net->Link[i].Type = type;
if (type == EN_CVPIPE) net->Link[i].Stat = OPEN;
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
/* Change link from Pipe */
if (toType <= EN_PIPE) {
net->Npipes++;
} else if (toType == EN_PUMP) {
net->Npumps++;
net->Pump[net->Npumps].Link = i;
} else {
net->Nvalves++;
net->Valve[net->Nvalves].Link = i;
} }
if (fromType <= EN_PIPE) { // Get ID's of link & its end nodes
net->Npipes--; EN_getlinkid(ph, i, id);
} else if (fromType == EN_PUMP) { EN_getlinknodes(ph, i, &n1, &n2);
net->Npumps--; EN_getnodeid(ph, n1, id1);
} EN_getnodeid(ph, n2, id2);
return set_error(p->error_handle, 0);
// Delete the original link
EN_deletelink(ph, i);
// Create a new link of new type and old id
errcode = EN_addlink(ph, id, type, id1, id2);
// Find the index of this new link
EN_getlinkindex(ph, id, index);
return set_error(p->error_handle, errcode);
} }
int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) { int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
@@ -4947,7 +4980,6 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
struct Sdemand *demand; struct Sdemand *demand;
EN_Project *p = (EN_Project*)ph; EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network; EN_Network *net = &p->network;
hydraulics_t *hyd = &p->hydraulics; hydraulics_t *hyd = &p->hydraulics;
quality_t *qu = &p->quality; quality_t *qu = &p->quality;
@@ -4955,9 +4987,6 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
Snode *node; Snode *node;
Scoord *coord; Scoord *coord;
Scontrol *control; Scontrol *control;
// rules_t *rule;
Premise *pchain, *pnext;
/* Check if a node with same id already exists */ /* Check if a node with same id already exists */
if (!p->Openflag) if (!p->Openflag)
@@ -4976,6 +5005,7 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
qu->NodeQual = (double *)realloc(qu->NodeQual, (net->Nnodes + 2) * sizeof(double)); qu->NodeQual = (double *)realloc(qu->NodeQual, (net->Nnodes + 2) * sizeof(double));
hyd->NodeHead = (double *)realloc(hyd->NodeHead, (net->Nnodes + 2) * sizeof(double)); hyd->NodeHead = (double *)realloc(hyd->NodeHead, (net->Nnodes + 2) * sizeof(double));
// Actions taken when a new Junction is added
if (nodeType == EN_JUNCTION) { if (nodeType == EN_JUNCTION) {
net->Njuncs++; net->Njuncs++;
nIdx = net->Njuncs; nIdx = net->Njuncs;
@@ -4985,12 +5015,13 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
demand = (struct Sdemand *)malloc(sizeof(struct Sdemand)); demand = (struct Sdemand *)malloc(sizeof(struct Sdemand));
demand->Base = 0.0; demand->Base = 0.0;
demand->Pat = hyd->DefPat; // Use default pattern demand->Pat = hyd->DefPat; // Use default pattern
strcpy(demand->Name, "");
demand->next = NULL; demand->next = NULL;
node->D = demand; node->D = demand;
// shift rest of Node array // shift rest of Node array
for (index = net->Nnodes; index >= net->Njuncs; index--) { for (index = net->Nnodes; index >= net->Njuncs; index--) {
ENHashTableUpdate(net->NodeHashTable, net->Node[index].ID, index + 1); hashtable_update(net->NodeHashTable, net->Node[index].ID, index + 1);
net->Node[index + 1] = net->Node[index]; net->Node[index + 1] = net->Node[index];
net->Coord[index + 1] = net->Coord[index]; net->Coord[index + 1] = net->Coord[index];
} }
@@ -5018,43 +5049,10 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
} }
} }
// shift indices of Rules for tanks/reservoirs // adjust indices of tanks/reservoirs in Rule premises (see RULES.C)
for (index = 1; index <= net->Nrules; ++index) { adjusttankrules(p);
pchain = (&p->rules)->Rule[i].Pchain;
while (pchain != NULL) {
pnext = pchain->next;
// object types are: (duplicated here from rules.c --> TODO: move these to external definition?
// enum Objects {
// r_JUNC,
// r_RESERV,
// r_TANK,
// r_PIPE,
// r_PUMP,
// r_VALVE,
// r_NODE,
// r_LINK,
// r_SYSTEM
// };
// if object is a node
switch (pchain->object) {
case 0: // junc
case 1: // reservoir
case 2: // tank
case 6: // node
// if the junction needs to be re-indexed:
if (pchain->index > net->Njuncs) {
pchain->index += 1;
}
break;
default:
break;
}
// next premise in the chain
pchain = pnext;
}
}
// Actions taken when a new Tank/Reservoir is added
} else { } else {
nIdx = net->Nnodes+1; nIdx = net->Nnodes+1;
node = &net->Node[nIdx]; node = &net->Node[nIdx];
@@ -5106,7 +5104,7 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
coord->Y = 0; coord->Y = 0;
/* Insert new node into hash table */ /* Insert new node into hash table */
ENHashTableInsert(net->NodeHashTable, node->ID, nIdx); /* see HASH.C */ hashtable_insert(net->NodeHashTable, node->ID, nIdx); /* see HASH.C */
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
@@ -5129,8 +5127,8 @@ int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, ch
return set_error(p->error_handle, 215); return set_error(p->error_handle, 215);
/* Lookup the from and to nodes */ /* Lookup the from and to nodes */
N1 = ENHashTableFind(net->NodeHashTable, fromNode); N1 = hashtable_find(net->NodeHashTable, fromNode);
N2 = ENHashTableFind(net->NodeHashTable, toNode); N2 = hashtable_find(net->NodeHashTable, toNode);
if (N1 == 0 || N2 == 0) { if (N1 == 0 || N2 == 0) {
return set_error(p->error_handle, 203); return set_error(p->error_handle, 203);
@@ -5212,141 +5210,235 @@ int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, ch
link->Rpt = 0; link->Rpt = 0;
strcpy(link->Comment, ""); strcpy(link->Comment, "");
ENHashTableInsert(net->LinkHashTable, link->ID, n); hashtable_insert(net->LinkHashTable, link->ID, n);
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) { int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a link from a project.
**----------------------------------------------------------------
*/
{
int i; int i;
int pumpindex;
int valveindex;
EN_LinkType linkType; EN_LinkType linkType;
EN_Project *p = (EN_Project*)ph; EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network; EN_Network *net = &p->network;
Slink *link; Slink *link;
if (!p->Openflag) // Check that link exists
return set_error(p->error_handle, 102); if (!p->Openflag) return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nlinks) if (index <= 0 || index > net->Nlinks) return set_error(p->error_handle, 203);
return set_error(p->error_handle, 203);
// Get references to the link and its type
link = &net->Link[index];
EN_getlinktype(p, index, &linkType); EN_getlinktype(p, index, &linkType);
link = &net->Link[index]; // Remove link from hash table
hashtable_delete(net->LinkHashTable, link->ID);
// remove from hash table // Shift position of higher entries in Link array down one
ENHashTableDelete(net->LinkHashTable, link->ID); for (i = index; i <= net->Nlinks - 1; i++)
ENHashTableFind(net->LinkHashTable, link->ID); {
// shift link and pump arrays to re-sort link indices
net->Nlinks--;
for (i = index; i <= net->Nlinks - 1; i++) {
net->Link[i] = net->Link[i + 1]; net->Link[i] = net->Link[i + 1];
// update hashtable // ... update hashtable
ENHashTableUpdate(net->LinkHashTable, net->Link[i].ID, i); hashtable_update(net->LinkHashTable, net->Link[i].ID, i);
}
for (i = 1; i <= net->Npumps; i++) {
if (net->Pump[i].Link > index) {
net->Pump[i].Link -= 1;
}
}
for (i = 1; i <= net->Nvalves; i++) {
if (net->Valve[i].Link > index) {
net->Valve[i].Link -= 1;
}
} }
// Adjust references to higher numbered links for pumps & valves
for (i = 1; i <= net->Npumps; i++)
{
if (net->Pump[i].Link > index) net->Pump[i].Link -= 1;
}
for (i = 1; i <= net->Nvalves; i++)
{
if (net->Valve[i].Link > index) net->Valve[i].Link -= 1;
}
// update pumps // Delete any pump associated with the deleted link
if (linkType == EN_PUMP) { if (linkType == EN_PUMP)
int pumpindex = findpump(net,index); {
for (i = pumpindex; i <= net->Npumps - 1; i++) { pumpindex = findpump(net,index);
for (i = pumpindex; i <= net->Npumps - 1; i++)
{
net->Pump[i] = net->Pump[i + 1]; net->Pump[i] = net->Pump[i + 1];
} }
net->Npumps--; net->Npumps--;
} }
// update valves // Delete any valve (linkType > EN_PUMP) associated with the deleted link
if (linkType > EN_PUMP) { if (linkType > EN_PUMP)
int valveindex = findvalve(net,index); {
for (i = valveindex; i <= net->Nvalves - 1; i++) { valveindex = findvalve(net,index);
for (i = valveindex; i <= net->Nvalves - 1; i++)
{
net->Valve[i] = net->Valve[i + 1]; net->Valve[i] = net->Valve[i + 1];
} }
net->Nvalves--; net->Nvalves--;
} }
// Delete any control containing the link
for (i = net->Ncontrols; i >= 1; i--)
{
if (net->Control[i].Link == index) EN_deletecontrol(ph, i);
}
// Adjust higher numbered link indices in remaining controls
for (i = 1; i <= net->Ncontrols; i++)
{
if (net->Control[i].Link > index) net->Control[i].Link--;
}
// Make necessary adjustments to rule-based controls (r_LINK = 7)
adjustrules(p, 7, index); // see RULES.C
// Reduce link count by one
net->Nlinks--;
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index) { int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a node from a project.
**----------------------------------------------------------------
*/
{
int i, nodeType, tankindex;
EN_Project *p = (EN_Project*)ph; EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network; EN_Network *net = &p->network;
Snode *node;
Pdemand demand, nextdemand;
Psource source;
int i, nodeType; // Check that node exists
if (!p->Openflag) return set_error(p->error_handle, 102);
if (!p->Openflag)
return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nnodes) if (index <= 0 || index > net->Nnodes)
{
return set_error(p->error_handle, 203); return set_error(p->error_handle, 203);
EN_getnodetype(p, index, &nodeType);
// TODO: check for existing controls/rules that reference this node?
// remove from hash table
ENHashTableDelete(net->NodeHashTable, net->Node[index].ID);
// shift node and coord array to remove node
for (i = index; i <= net->Nnodes - 1; i++) {
net->Node[i] = net->Node[i + 1];
net->Coord[i] = net->Coord[i + 1];
// update hashtable
ENHashTableUpdate(net->NodeHashTable, net->Node[i].ID, i);
} }
// update tank array // Get a reference to the node & its type
if (nodeType != EN_JUNCTION) { node = &net->Node[index];
int tankindex = findtank(net, index); EN_getnodetype(ph, index, &nodeType);
for (i = tankindex; i <= net->Ntanks - 1; i++) {
// Remove node from hash table
hashtable_delete(net->NodeHashTable, node->ID);
// Free memory allocated to node's demands & WQ source
demand = node->D;
while (demand != NULL)
{
nextdemand = demand->next;
free(demand);
demand = nextdemand;
}
source = node->S;
if (source != NULL) free(source);
// Shift position of higher entries in Node 7 Cord arrays down one
for (i = index; i <= net->Nnodes - 1; i++)
{
net->Node[i] = net->Node[i + 1];
net->Coord[i] = net->Coord[i + 1];
// ... update hashtable
hashtable_update(net->NodeHashTable, net->Node[i].ID, i);
}
// Remove references to demands & source in last (inactive) Node array entry
net->Node[net->Nnodes].D = NULL;
net->Node[net->Nnodes].S = NULL;
// If deleted node is a tank, remove it from the Tank array
if (nodeType != EN_JUNCTION)
{
tankindex = findtank(net, index);
for (i = tankindex; i <= net->Ntanks - 1; i++)
{
net->Tank[i] = net->Tank[i + 1]; net->Tank[i] = net->Tank[i + 1];
} }
} }
// update tank node indices // Shift higher node indices in Tank array down one
for (i = 1; i <= net->Ntanks; i++) { for (i = 1; i <= net->Ntanks; i++)
if (net->Tank[i].Node > index) { {
net->Tank[i].Node -= 1; if (net->Tank[i].Node > index) net->Tank[i].Node -= 1;
}
} }
// gather a list of link ids to remove in reverse order, // Delete any links connected to the deleted node
// so that re-shuffling doesn't destroy the indexing // (Process links in reverse order to maintain their indexing)
for (i = net->Nlinks; i >= 1; i--) { for (i = net->Nlinks; i >= 1; i--)
if (net->Link[i].N1 == index || net->Link[i].N2 == index) { {
EN_deletelink(p,i); if (net->Link[i].N1 == index ||
} net->Link[i].N2 == index) EN_deletelink(ph, i);
} }
for (i = 1; i <= net->Nlinks; i++) { // Adjust indices of all link end nodes
if (net->Link[i].N1 > index) { for (i = 1; i <= net->Nlinks; i++)
net->Link[i].N1 -= 1; {
} if (net->Link[i].N1 > index) net->Link[i].N1 -= 1;
if (net->Link[i].N2 > index) { if (net->Link[i].N2 > index) net->Link[i].N2 -= 1;
net->Link[i].N2 -= 1;
}
} }
// update counters // Delete any control containing the node
if (nodeType == EN_JUNCTION) { for (i = net->Ncontrols; i >= 1; i--)
net->Njuncs--; {
} else { if (net->Control[i].Node == index) EN_deletecontrol(ph, i);
net->Ntanks--;
} }
// Adjust higher numbered link indices in remaining controls
for (i = 1; i <= net->Ncontrols; i++)
{
if (net->Control[i].Node > index) net->Control[i].Node--;
}
// Make necessary adjustments to rule-based controls (r_NODE = 6)
adjustrules(p, 6, index);
// Set water quality analysis to NONE if deleted node is trace node
if (p->quality.Qualflag == TRACE && p->quality.TraceNode == index)
{
p->quality.TraceNode = 0;
p->quality.Qualflag = NONE;
}
// Reduce counts of node types
if (nodeType == EN_JUNCTION) net->Njuncs--;
else net->Ntanks--;
net->Nnodes--; net->Nnodes--;
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_deletecontrol(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a simple control from a project.
**----------------------------------------------------------------
*/
{
int i;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
if (index <= 0 || index > net->Ncontrols)
{
return set_error(p->error_handle, 241);
}
for (i = index; i <= net->Ncontrols - 1; i++)
{
net->Control[i] = net->Control[i + 1];
}
net->Ncontrols--;
return set_error(p->error_handle, 0); return set_error(p->error_handle, 0);
} }

View File

@@ -52,7 +52,6 @@ int findvalve(EN_Network *n, int); /* Find valve index from node
int findpump(EN_Network *n, int); /* Find pump index from node index */ // (AH) int findpump(EN_Network *n, int); /* Find pump index from node index */ // (AH)
char *geterrmsg(int errcode, char *msg); /* Gets text of error message */ char *geterrmsg(int errcode, char *msg); /* Gets text of error message */
void errmsg(EN_Project *p, int); /* Reports program error */ void errmsg(EN_Project *p, int); /* Reports program error */
void writecon(const char *); /* Writes text to console */
void writewin(void (*vp)(char *), char *); /* Passes text to calling app */ void writewin(void (*vp)(char *), char *); /* Passes text to calling app */
/* ------- INPUT1.C --------------------*/ /* ------- INPUT1.C --------------------*/
@@ -75,6 +74,7 @@ int addcurve(parser_data_t *par, char *); /* Adds curve to data base
STmplist *findID(char *, STmplist *); /* Locates ID on linked list */ STmplist *findID(char *, STmplist *); /* Locates ID on linked list */
int unlinked(EN_Project *pr); /* Checks for unlinked nodes */ int unlinked(EN_Project *pr); /* Checks for unlinked nodes */
int getpumpparams(EN_Project *pr); /* Computes pump curve coeffs.*/ int getpumpparams(EN_Project *pr); /* Computes pump curve coeffs.*/
int updatepumpparams(EN_Project *pr, int); // Updates pump curve coeffs.
int getpatterns(EN_Project *pr); /* Gets pattern data from list*/ int getpatterns(EN_Project *pr); /* Gets pattern data from list*/
int getcurves(EN_Project *pr); /* Gets curve data from list */ int getcurves(EN_Project *pr); /* Gets curve data from list */
int findmatch(char *, char *[]); /* Finds keyword in line */ int findmatch(char *, char *[]); /* Finds keyword in line */
@@ -121,6 +121,8 @@ void changestatus(EN_Network *net, int, StatType,
void initrules(rules_t *rules); /* Initializes rule base */ void initrules(rules_t *rules); /* Initializes rule base */
void addrule(parser_data_t *par, char *); /* Adds rule to rule base */ void addrule(parser_data_t *par, char *); /* Adds rule to rule base */
int allocrules(EN_Project *pr); /* Allocates memory for rule */ int allocrules(EN_Project *pr); /* Allocates memory for rule */
void adjustrules(EN_Project *pr, int, int); // Shifts object indices down
void adjusttankrules(EN_Project *pr); // Shifts tank indices up
int ruledata(EN_Project *pr); /* Processes rule input data */ int ruledata(EN_Project *pr); /* Processes rule input data */
int checkrules(EN_Project *pr, long); /* Checks all rules */ int checkrules(EN_Project *pr, long); /* Checks all rules */
void freerules(EN_Project *pr); /* Frees rule base memory */ void freerules(EN_Project *pr); /* Frees rule base memory */

View File

@@ -1,21 +1,20 @@
/*----------------------------------------------------------------------------- /*-----------------------------------------------------------------------------
** hash.c ** hash.c
** **
** Implementation of a simple Hash Table for string storage & retrieval ** Implementation of a simple Hash Table that uses a string as a key
** and an associated integer as data.
** **
** Written by L. Rossman ** Written by L. Rossman
** Last Updated on 6/19/03 ** Last Updated on 10/19/18
** **
** The hash table data structure (HTable) is defined in "hash.h".
** Interface Functions: ** Interface Functions:
** HTcreate() - creates a hash table ** hashtable_create - creates a hash table
** HTinsert() - inserts a string & its index value into a hash table ** hashtable_insert - inserts a string & its data value into a table
** HTfind() - retrieves the index value of a string from a table ** hashtable_find - retrieves the data value associated with a string
** HTfree() - frees a hash table ** hashtable_findkey - retrieves the key associated with a data value
** hashtable_delete - deletes an entry from a table
** hashtable_free - frees a hash table
** **
*********************************************************************
** NOTE: This is a modified version of the original HASH.C module.
*********************************************************************
*/ */
#ifndef __APPLE__ #ifndef __APPLE__
@@ -26,135 +25,143 @@
#include <string.h> #include <string.h>
#include "hash.h" #include "hash.h"
unsigned int _enHash(char *str); #define HASHTABLEMAXSIZE 128000
unsigned int _enHash(char *str)
typedef struct DataEntryStruct
{
char *key;
int data;
struct DataEntryStruct *next;
} DataEntry;
unsigned int gethash(char *str)
{ {
unsigned int hash = 5381; unsigned int hash = 5381;
unsigned int retHash; unsigned int retHash;
int c; int c;
while ((c = *str++)) { while ((c = *str++))
{
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
} }
retHash = hash % ENHASHTABLEMAXSIZE; retHash = hash % HASHTABLEMAXSIZE;
return retHash; return retHash;
} }
ENHashTable *ENHashTableCreate() char *dupstr(const char *s)
{ {
int i; size_t size = strlen(s) + 1;
ENHashTable *ht = (ENHashTable *) calloc(ENHASHTABLEMAXSIZE, sizeof(ENHashTable)); char *p = malloc(size);
if (ht != NULL) { if (p) memcpy(p, s, size);
for (i=0; i<ENHASHTABLEMAXSIZE; i++) { return p;
ht[i] = NULL;
}
}
return(ht);
} }
int ENHashTableInsert(ENHashTable *ht, char *key, int data) HashTable *hashtable_create()
{ {
size_t len; int i;
unsigned int i = _enHash(key); HashTable *ht = (HashTable *) calloc(HASHTABLEMAXSIZE, sizeof(HashTable));
ENHashEntry *entry; if (ht != NULL)
if ( i >= ENHASHTABLEMAXSIZE ) { {
return(0); for (i = 0; i < HASHTABLEMAXSIZE; i++) ht[i] = NULL;
} }
entry = (ENHashEntry *) malloc(sizeof(ENHashEntry)); return ht;
if (entry == NULL) { }
return(0);
} int hashtable_insert(HashTable *ht, char *key, int data)
len = strlen(key) + 1; {
entry->key = calloc(len, sizeof(char)); unsigned int i = gethash(key);
strncpy(entry->key, key, len); DataEntry *entry;
if ( i >= HASHTABLEMAXSIZE ) return 0;
entry = (DataEntry *) malloc(sizeof(DataEntry));
if (entry == NULL) return(0);
entry->key = dupstr(key);
entry->data = data; entry->data = data;
entry->next = ht[i]; entry->next = ht[i];
ht[i] = entry; ht[i] = entry;
return(1); return 1;
} }
/* Abel Heinsbroek: Added function to update the hash table value for a given key */ int hashtable_update(HashTable *ht, char *key, int new_data)
int ENHashTableUpdate(ENHashTable *ht, char *key, int new_data)
{ {
unsigned int i = _enHash(key); unsigned int i = gethash(key);
ENHashEntry *entry; DataEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) {
return(NOTFOUND); if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
}
entry = ht[i]; entry = ht[i];
while (entry != NULL) while (entry != NULL)
{ {
if ( strcmp(entry->key,key) == 0 ) { if ( strcmp(entry->key, key) == 0 )
{
entry->data = new_data; entry->data = new_data;
return(1); return 1;
} }
entry = entry->next; entry = entry->next;
} }
return(NOTFOUND); return NOTFOUND;
} }
int ENHashTableDelete(ENHashTable *ht, char *key) { int hashtable_delete(HashTable *ht, char *key)
unsigned int i = _enHash(key); {
ENHashEntry *entry; unsigned int i = gethash(key);
if ( i >= ENHASHTABLEMAXSIZE ) { DataEntry *entry, *preventry;
return(NOTFOUND);
} if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
preventry = NULL;
entry = ht[i]; entry = ht[i];
while (entry != NULL) while (entry != NULL)
{ {
if (strcmp(entry->key, key) == 0) { if (strcmp(entry->key, key) == 0)
entry->key = ""; {
return(1); if (preventry == NULL) ht[i] = entry->next;
else preventry->next = entry->next;
free(entry->key);
free(entry);
return 1;
} }
preventry = entry;
entry = entry->next; entry = entry->next;
} }
return NOTFOUND;
return(NOTFOUND);
} }
int ENHashTableFind(ENHashTable *ht, char *key) int hashtable_find(HashTable *ht, char *key)
{ {
unsigned int i = _enHash(key); unsigned int i = gethash(key);
DataEntry *entry;
ENHashEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) {
return(NOTFOUND);
}
if ( i >= HASHTABLEMAXSIZE ) return NOTFOUND;
entry = ht[i]; entry = ht[i];
while (entry != NULL) while (entry != NULL)
{ {
if ( strcmp(entry->key,key) == 0 ) { if ( strcmp(entry->key, key) == 0 )
return(entry->data); {
return entry->data;
} }
entry = entry->next; entry = entry->next;
} }
return(NOTFOUND); return NOTFOUND;
} }
char *ENHashTableFindKey(ENHashTable *ht, char *key) char *hashtable_findkey(HashTable *ht, char *key)
{ {
unsigned int i = _enHash(key); unsigned int i = gethash(key);
ENHashEntry *entry; DataEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) { if ( i >= HASHTABLEMAXSIZE ) return NULL;
return(NULL);
}
entry = ht[i]; entry = ht[i];
while (entry != NULL) while (entry != NULL)
{ {
if ( strcmp(entry->key,key) == 0 ) { if ( strcmp(entry->key, key) == 0 ) return entry->key;
return(entry->key);
}
entry = entry->next; entry = entry->next;
} }
return(NULL); return NULL;
} }
void ENHashTableFree(ENHashTable *ht) void hashtable_free(HashTable *ht)
{ {
ENHashEntry *entry, *nextentry; DataEntry *entry, *nextentry;
int i; int i;
for (i=0; i<ENHASHTABLEMAXSIZE; i++)
for (i = 0; i < HASHTABLEMAXSIZE; i++)
{ {
entry = ht[i]; entry = ht[i];
while (entry != NULL) while (entry != NULL)
@@ -164,6 +171,7 @@ void ENHashTableFree(ENHashTable *ht)
free(entry); free(entry);
entry = nextentry; entry = nextentry;
} }
ht[i] = NULL;
} }
free(ht); free(ht);
} }

View File

@@ -7,24 +7,16 @@
#ifndef HASH_H #ifndef HASH_H
#define HASH_H #define HASH_H
#define ENHASHTABLEMAXSIZE 128000
#define NOTFOUND 0 #define NOTFOUND 0
typedef struct HTentryStruct typedef struct DataEntryStruct *HashTable;
{
char *key;
int data;
struct HTentryStruct *next;
} ENHashEntry;
typedef ENHashEntry *ENHashTable; HashTable *hashtable_create(void);
int hashtable_insert(HashTable *, char *, int);
ENHashTable *ENHashTableCreate(void); int hashtable_find(HashTable *, char *);
int ENHashTableInsert(ENHashTable *, char *, int); char *hashtable_findkey(HashTable *, char *);
int ENHashTableFind(ENHashTable *, char *); void hashtable_free(HashTable *);
char *ENHashTableFindKey(ENHashTable *, char *); int hashtable_update(HashTable *ht, char *key, int new_data);
void ENHashTableFree(ENHashTable *); int hashtable_delete(HashTable *ht, char *key);
int ENHashTableUpdate(ENHashTable *ht, char *key, int new_data);
int ENHashTableDelete(ENHashTable *ht, char *key);
#endif #endif

View File

@@ -104,9 +104,9 @@ void setdefaults(EN_Project *pr)
time_options_t *time = &pr->time_options; time_options_t *time = &pr->time_options;
out_file_t *out = &pr->out_files; out_file_t *out = &pr->out_files;
strncpy(pr->Title[0], "", MAXMSG); strncpy(pr->Title[0], "", TITLELEN);
strncpy(pr->Title[1], "", MAXMSG); strncpy(pr->Title[1], "", TITLELEN);
strncpy(pr->Title[2], "", MAXMSG); strncpy(pr->Title[2], "", TITLELEN);
strncpy(out->TmpDir, "", MAXFNAME); strncpy(out->TmpDir, "", MAXFNAME);
strncpy(out->TmpFname, "", MAXFNAME); strncpy(out->TmpFname, "", MAXFNAME);
strncpy(out->HydFname, "", MAXFNAME); strncpy(out->HydFname, "", MAXFNAME);
@@ -356,6 +356,7 @@ void adjustdata(EN_Project *pr)
for (demand = node->D; demand != NULL; demand = demand->next) { for (demand = node->D; demand != NULL; demand = demand->next) {
if (demand->Pat == 0) { if (demand->Pat == 0) {
demand->Pat = hyd->DefPat; demand->Pat = hyd->DefPat;
strcpy(demand->Name, "");
} }
} }
} }

View File

@@ -40,10 +40,10 @@ The following utility functions are all called from INPUT3.C
#define MAXERRS 10 /* Max. input errors reported */ #define MAXERRS 10 /* Max. input errors reported */
/* Defined in enumstxt.h in EPANET.C */ /* Defined in enumstxt.h in EPANET.C */
extern char *SectTxt[]; /* Input section keywords */ extern char *SectTxt[]; /* Input section keywords */
int netsize(EN_Project *pr) int netsize(EN_Project *pr)
/* /*
**-------------------------------------------------------------- **--------------------------------------------------------------
@@ -206,9 +206,10 @@ int readdata(EN_Project *pr)
/* Check if max. length exceeded */ /* Check if max. length exceeded */
if (strlen(line) >= MAXLINE) { if (strlen(line) >= MAXLINE) {
char errMsg[MAXMSG+1]; // char errMsg[MAXMSG+1];
EN_geterror(214, errMsg, MAXMSG); // EN_geterror(214, errMsg, MAXMSG);
sprintf(pr->Msg, "%s section: %s", errMsg, SectTxt[sect]); // sprintf(pr->Msg, "%s section: %s", errMsg, SectTxt[sect]);
sprintf(pr->Msg, "%s section: %s", geterrmsg(214, pr->Msg), SectTxt[sect]);
writeline(pr, pr->Msg); writeline(pr, pr->Msg);
writeline(pr, line); writeline(pr, line);
errsum++; errsum++;
@@ -292,7 +293,7 @@ int newline(EN_Project *pr, int sect, char *line)
n = (int)strlen(line); n = (int)strlen(line);
if (line[n - 1] == 10) if (line[n - 1] == 10)
line[n - 1] = ' '; line[n - 1] = ' ';
strncpy(pr->Title[par->Ntitle], line, MAXMSG); strncpy(pr->Title[par->Ntitle], line, TITLELEN);
par->Ntitle++; par->Ntitle++;
} }
return (0); return (0);
@@ -363,72 +364,108 @@ int getpumpparams(EN_Project *pr)
**------------------------------------------------------------- **-------------------------------------------------------------
** Input: none ** Input: none
** Output: returns error code ** Output: returns error code
** Purpose: computes & checks pump curve parameters ** Purpose: computes pump curve coefficients for all pumps
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
int i, j = 0, k, m, n = 0; int i, k, errcode = 0;
double a, b, c, h0 = 0.0, h1 = 0.0, h2 = 0.0, q1 = 0.0, q2 = 0.0;
char errMsg[MAXMSG+1];
Spump *pump;
Slink *link;
Scurve *curve;
EN_Network *net = &pr->network; EN_Network *net = &pr->network;
for (i = 1; i <= net->Npumps; i++) { for (i = 1; i <= net->Npumps; i++)
pump = &net->Pump[i]; {
k = pump->Link; errcode = updatepumpparams(pr, i);
link = &net->Link[k]; if (errcode)
if (pump->Ptype == CONST_HP) { /* Constant Hp pump */ {
pump->H0 = 0.0; k = net->Pump[i].Link;
pump->R = -8.814 * link->Km; sprintf(pr->Msg, "%s link: %s", geterrmsg(errcode, pr->Msg),
pump->N = -1.0; net->Link[k].ID);
pump->Hmax = BIG; /* No head limit */
pump->Qmax = BIG; /* No flow limit */
pump->Q0 = 1.0; /* Init. flow = 1 cfs */
continue;
}
else if (pump->Ptype == NOCURVE) { /* Pump curve specified */
j = pump->Hcurve; /* Get index of head curve */
if (j == 0) { /* Error: No head curve */
EN_geterror(226, errMsg, MAXMSG);
sprintf(pr->Msg, "%s link: %s", errMsg, link->ID);
writeline(pr, pr->Msg); writeline(pr, pr->Msg);
return (200); return 200;
} }
curve = &net->Curve[j]; }
return 0;
}
int updatepumpparams(EN_Project *pr, int pumpindex)
/*
**-------------------------------------------------------------
** Input: pumpindex = index of a pump
** Output: returns error code
** Purpose: computes & checks a pump's head curve coefficients
**--------------------------------------------------------------
*/
{
int m;
int curveindex;
int npts = 0;
int errcode = 0;
double a, b, c, h0 = 0.0, h1 = 0.0, h2 = 0.0, q1 = 0.0, q2 = 0.0;
EN_Network *net = &pr->network;
Spump *pump;
Scurve *curve;
pump = &net->Pump[pumpindex];
if (pump->Ptype == CONST_HP) // Constant Hp pump
{
pump->H0 = 0.0;
pump->R = -8.814 * net->Link[pump->Link].Km;
pump->N = -1.0;
pump->Hmax = BIG; // No head limit
pump->Qmax = BIG; // No flow limit
pump->Q0 = 1.0; // Init. flow = 1 cfs
return errcode;
}
else if (pump->Ptype == NOCURVE) // Pump curve specified
{
curveindex = pump->Hcurve;
if (curveindex == 0) return 226;
curve = &net->Curve[curveindex];
curve->Type = P_CURVE; curve->Type = P_CURVE;
n = curve->Npts; npts = curve->Npts;
if (n == 1) { /* Only a single h-q point supplied so use generic */
pump->Ptype = POWER_FUNC; /* power function curve. */ // Generic power function curve
if (npts == 1)
{
pump->Ptype = POWER_FUNC;
q1 = curve->X[0]; q1 = curve->X[0];
h1 = curve->Y[0]; h1 = curve->Y[0];
h0 = 1.33334 * h1; h0 = 1.33334 * h1;
q2 = 2.0 * q1; q2 = 2.0 * q1;
h2 = 0.0; h2 = 0.0;
} else if (n == 3 && curve->X[0] == 0.0) /* 3 h-q points supplied with */ }
{ /* shutoff head so use fitted */
pump->Ptype = POWER_FUNC; /* power function curve. */ // 3 point curve with shutoff head
else if (npts == 3 && curve->X[0] == 0.0)
{
pump->Ptype = POWER_FUNC;
h0 = curve->Y[0]; h0 = curve->Y[0];
q1 = curve->X[1]; q1 = curve->X[1];
h1 = curve->Y[1]; h1 = curve->Y[1];
q2 = curve->X[2]; q2 = curve->X[2];
h2 = curve->Y[2]; h2 = curve->Y[2];
} }
else { // use a custom curve, referenced by ID
pump->Ptype = CUSTOM; /* Else use custom pump curve.*/ // Custom pump curve
// at this point, j is set to that curve's index. else
{
pump->Ptype = CUSTOM;
for (m = 1; m < npts; m++)
{
if (curve->Y[m] >= curve->Y[m - 1]) return 227;
}
pump->Qmax = curve->X[npts - 1];
pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0;
pump->Hmax = curve->Y[0];
} }
/* Compute shape factors & limits of power function pump curves */ // Compute shape factors & limits of power function curves
if (pump->Ptype == POWER_FUNC) { if (pump->Ptype == POWER_FUNC)
if (!powercurve(h0, h1, h2, q1, q2, &a, &b, &c)) { /* Error: Invalid curve */ {
EN_geterror(227, errMsg, MAXMSG); if (!powercurve(h0, h1, h2, q1, q2, &a, &b, &c)) return 227;
sprintf(pr->Msg, "%s link: %s", errMsg, link->ID); else
writeline(pr, pr->Msg); {
return (200);
} else {
pump->H0 = -a; pump->H0 = -a;
pump->R = -b; pump->R = -b;
pump->N = c; pump->N = c;
@@ -438,26 +475,10 @@ int getpumpparams(EN_Project *pr)
} }
} }
} }
return 0;
/* Assign limits to custom pump curves */
if (pump->Ptype == CUSTOM) {
curve = &net->Curve[j];
for (m = 1; m < n; m++) {
if (curve->Y[m] >= curve->Y[m - 1]) { /* Error: Invalid curve */
EN_geterror(227, errMsg, MAXMSG);
sprintf(pr->Msg, "%s link: %s", errMsg, link->ID);
writeline(pr, pr->Msg);
return (200);
}
}
pump->Qmax = curve->X[n - 1];
pump->Q0 = (curve->X[0] + pump->Qmax) / 2.0;
pump->Hmax = curve->Y[0];
}
} /* Next pump */
return (0);
} }
int addnodeID(EN_Network *net, int n, char *id) int addnodeID(EN_Network *net, int n, char *id)
/* /*
**------------------------------------------------------------- **-------------------------------------------------------------
@@ -472,7 +493,7 @@ int addnodeID(EN_Network *net, int n, char *id)
return (0); /* see EPANET.C */ return (0); /* see EPANET.C */
} }
strncpy(net->Node[n].ID, id, MAXID); strncpy(net->Node[n].ID, id, MAXID);
ENHashTableInsert(net->NodeHashTable, net->Node[n].ID, n); /* see HASH.C */ hashtable_insert(net->NodeHashTable, net->Node[n].ID, n); /* see HASH.C */
return (1); return (1);
} }
@@ -490,7 +511,7 @@ int addlinkID(EN_Network *net, int n, char *id)
return (0); /* see EPANET.C */ return (0); /* see EPANET.C */
} }
strncpy(net->Link[n].ID, id, MAXID); strncpy(net->Link[n].ID, id, MAXID);
ENHashTableInsert(net->LinkHashTable, net->Link[n].ID, n); /* see HASH.C */ hashtable_insert(net->LinkHashTable, net->Link[n].ID, n); /* see HASH.C */
return (1); return (1);
} }
@@ -603,7 +624,6 @@ int unlinked(EN_Project *pr)
EN_Network *net = &pr->network; EN_Network *net = &pr->network;
int *marked; int *marked;
int i, err, errcode; int i, err, errcode;
char errMsg[MAXMSG+1];
errcode = 0; errcode = 0;
err = 0; err = 0;
@@ -621,8 +641,7 @@ int unlinked(EN_Project *pr)
if (marked[i] == 0) /* If not marked then error */ if (marked[i] == 0) /* If not marked then error */
{ {
err++; err++;
EN_geterror(233, errMsg, MAXMSG); sprintf(pr->Msg, "%s link: %s", geterrmsg(233, pr->Msg), net->Node[i].ID);
sprintf(pr->Msg, "%s node: %s", errMsg, net->Node[i].ID);
writeline(pr, pr->Msg); writeline(pr, pr->Msg);
} }
if (err >= MAXERRS) if (err >= MAXERRS)
@@ -732,9 +751,7 @@ int getcurves(EN_Project *pr)
/* Check that curve has data points */ /* Check that curve has data points */
if (curve->Npts <= 0) { if (curve->Npts <= 0) {
char errMsg[MAXMSG+1]; sprintf(pr->Msg, "%s link: %s", geterrmsg(230, pr->Msg), curve->ID);
EN_geterror(230, errMsg, MAXMSG);
sprintf(pr->Msg, "%s curve: %s", errMsg, curve->ID);
writeline(pr, pr->Msg); writeline(pr, pr->Msg);
return (200); return (200);
} }
@@ -754,9 +771,7 @@ int getcurves(EN_Project *pr)
/* Check that x data is in ascending order */ /* Check that x data is in ascending order */
if (fx->value >= x) { if (fx->value >= x) {
char errMsg[MAXMSG+1]; sprintf(pr->Msg, "%s link: %s", geterrmsg(230, pr->Msg), curve->ID);
EN_geterror(230, errMsg, MAXMSG);
sprintf(pr->Msg, "%s node: %s", errMsg, curve->ID);
writeline(pr, pr->Msg); writeline(pr, pr->Msg);
return (200); return (200);
} }
@@ -1012,10 +1027,8 @@ void inperrmsg(EN_Project *pr, int err, int sect, char *line)
char errStr[MAXMSG + 1]; char errStr[MAXMSG + 1];
char id[MAXMSG + 1]; char id[MAXMSG + 1];
EN_geterror(err, errStr, MAXMSG);
/* get text for error message */ /* get text for error message */
sprintf(pr->Msg, "%s - section: %s", errStr, SectTxt[sect]); sprintf(pr->Msg, "%s - section: %s", geterrmsg(err, errStr), SectTxt[sect]);
// append ID? // append ID?
/* Retrieve ID label of object with input error */ /* Retrieve ID label of object with input error */

View File

@@ -87,9 +87,9 @@ int savenetdata(EN_Project *pr)
fwrite(ibuf, sizeof(INT4), 15, outFile); fwrite(ibuf, sizeof(INT4), 15, outFile);
/* Write string variables to outFile */ /* Write string variables to outFile */
fwrite(pr->Title[0], sizeof(char), MAXMSG + 1, outFile); fwrite(pr->Title[0], sizeof(char), TITLELEN + 1, outFile);
fwrite(pr->Title[1], sizeof(char), MAXMSG + 1, outFile); fwrite(pr->Title[1], sizeof(char), TITLELEN + 1, outFile);
fwrite(pr->Title[2], sizeof(char), MAXMSG + 1, outFile); fwrite(pr->Title[2], sizeof(char), TITLELEN + 1, outFile);
fwrite(par->InpFname, sizeof(char), MAXFNAME + 1, outFile); fwrite(par->InpFname, sizeof(char), MAXFNAME + 1, outFile);
fwrite(rep->Rpt2Fname, sizeof(char), MAXFNAME + 1, outFile); fwrite(rep->Rpt2Fname, sizeof(char), MAXFNAME + 1, outFile);
fwrite(qu->ChemName, sizeof(char), MAXID + 1, outFile); fwrite(qu->ChemName, sizeof(char), MAXID + 1, outFile);

View File

@@ -82,8 +82,6 @@ int writereport(EN_Project *pr)
/* write formatted output to primary report file. */ /* write formatted output to primary report file. */
rep->Fprinterr = FALSE; rep->Fprinterr = FALSE;
if (rep->Rptflag && strlen(rep->Rpt2Fname) == 0 && rep->RptFile != NULL) { if (rep->Rptflag && strlen(rep->Rpt2Fname) == 0 && rep->RptFile != NULL) {
writecon(FMT17);
writecon(rep->Rpt1Fname);
if (rep->Energyflag) if (rep->Energyflag)
writeenergy(pr); writeenergy(pr);
errcode = writeresults(pr); errcode = writeresults(pr);
@@ -95,8 +93,6 @@ int writereport(EN_Project *pr)
/* If secondary report file has same name as either input */ /* If secondary report file has same name as either input */
/* or primary report file then use primary report file. */ /* or primary report file then use primary report file. */
if (strcomp(rep->Rpt2Fname, par->InpFname) || strcomp(rep->Rpt2Fname, rep->Rpt1Fname)) { if (strcomp(rep->Rpt2Fname, par->InpFname) || strcomp(rep->Rpt2Fname, rep->Rpt1Fname)) {
writecon(FMT17);
writecon(rep->Rpt1Fname);
if (rep->Energyflag) if (rep->Energyflag)
writeenergy(pr); writeenergy(pr);
errcode = writeresults(pr); errcode = writeresults(pr);
@@ -117,8 +113,6 @@ int writereport(EN_Project *pr)
/* Write full formatted report to file */ /* Write full formatted report to file */
else { else {
rep->Rptflag = 1; rep->Rptflag = 1;
writecon(FMT17);
writecon(rep->Rpt2Fname);
writelogo(pr); writelogo(pr);
if (rep->Summaryflag) if (rep->Summaryflag)
writesummary(pr); writesummary(pr);

View File

@@ -90,29 +90,24 @@ char *Operator[] = {"=", "<>", "<=", ">=", "<", ">",
enum Values { IS_NUMBER, IS_OPEN, IS_CLOSED, IS_ACTIVE }; enum Values { IS_NUMBER, IS_OPEN, IS_CLOSED, IS_ACTIVE };
char *Value[] = {"XXXX", w_OPEN, w_CLOSED, w_ACTIVE, NULL}; char *Value[] = {"XXXX", w_OPEN, w_CLOSED, w_ACTIVE, NULL};
/* External variables declared in INPUT2.C */ // Local Functions
static void newrule(EN_Project *pr);
static int newpremise(EN_Project *pr, int);
static int newaction(EN_Project *pr);
static int newpriority(EN_Project *pr);
static int evalpremises(EN_Project *pr, int);
static void updateactlist(rules_t *rules, int, Action *);
static int checkaction(rules_t *rules, int, Action *);
static int checkpremise(EN_Project *pr, Premise *);
static int checktime(EN_Project *pr, Premise *);
static int checkstatus(EN_Project *pr, Premise *);
static int checkvalue(EN_Project *pr, Premise *);
static int takeactions(EN_Project *pr);
static void clearactlist(rules_t *rules);
static void ruleerrmsg(EN_Project *pr, int);
static void clearrule(EN_Project *pr, int);
static void deleterule(EN_Project *pr, int);
/*
** Local function prototypes are defined here and not in FUNCS.H
** because some of them utilize the Premise and Action structures
** defined locally in this module.
*/
void newrule(EN_Project *pr);
int newpremise(EN_Project *pr, int);
int newaction(EN_Project *pr);
int newpriority(EN_Project *pr);
int evalpremises(EN_Project *pr, int);
void updateactlist(rules_t *rules, int, Action *);
int checkaction(rules_t *rules, int, Action *);
int checkpremise(EN_Project *pr, Premise *);
int checktime(EN_Project *pr, Premise *);
int checkstatus(EN_Project *pr, Premise *);
int checkvalue(EN_Project *pr, Premise *);
int takeactions(EN_Project *pr);
void clearactlist(rules_t *rules);
void clearrules(EN_Project *pr);
void ruleerrmsg(EN_Project *pr, int);
//int writeRuleinInp(EN_Project *pr, FILE *f, int RuleIdx);
void initrules(rules_t *rules) void initrules(rules_t *rules)
/* /*
@@ -166,7 +161,8 @@ void freerules(EN_Project *pr)
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
clearrules(pr); int i;
for (i = 1; i <= pr->network.Nrules; i++) clearrule(pr, i);
free(pr->rules.Rule); free(pr->rules.Rule);
} }
@@ -217,7 +213,7 @@ int ruledata(EN_Project *pr)
**-------------------------------------------------------------- **--------------------------------------------------------------
** Parses a line from [RULES] section of input. ** Parses a line from [RULES] section of input.
** Called by newline() in INPUT2.C module. ** Called by newline() in INPUT2.C module.
** Tok[] is global array of tokens parsed from input line. ** Tok[] is an array of tokens parsed from input line.
**-------------------------------------------------------------- **--------------------------------------------------------------
*/ */
{ {
@@ -305,6 +301,132 @@ int ruledata(EN_Project *pr)
return (err); return (err);
} }
void adjustrules(EN_Project *pr, int objtype, int index)
/*
**-----------------------------------------------------------
** Adjusts rules when a specific node or link is deleted.
** Called by EN_deletenode & EN_deletelink in EPANET.C.
**-----------------------------------------------------------
*/
{
int i, delete;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
Premise *p;
Action *a;
// Delete rules that refer to objtype and index
for (i = net->Nrules; i >= 1; i--)
{
delete = FALSE;
p = rules->Rule[i].Pchain;
while (p != NULL && !delete)
{
if (objtype == p->object && p->index == index) delete = TRUE;
p = p->next;
}
if (objtype == r_LINK)
{
a = rules->Rule[i].Tchain;
while (a != NULL && !delete)
{
if (a->link == index) delete = TRUE;
a = a->next;
}
a = rules->Rule[i].Fchain;
while (a != NULL && !delete)
{
if (a->link == index) delete = TRUE;
a = a->next;
}
}
if (delete) deleterule(pr, i);
}
// Adjust all higher object indices to reflect deletion of object index
for (i = 1; i <= net->Nrules; i++)
{
p = rules->Rule[i].Pchain;
while (p != NULL)
{
if (objtype == p->object && p->index > index) p->index--;
p = p->next;
}
if (objtype == r_LINK)
{
a = rules->Rule[i].Tchain;
while (a != NULL)
{
if (a->link > index) a->link--;
a = a->next;
}
a = rules->Rule[i].Fchain;
while (a != NULL)
{
if (a->link > index) a->link--;
a = a->next;
}
}
}
}
void adjusttankrules(EN_Project *pr)
/*
**-----------------------------------------------------------
** Adjusts tank indices in rule premises.
** Called by EN_addnode in EPANET.C.
**-----------------------------------------------------------
*/
{
int i, njuncs;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
Premise *p;
njuncs = net->Njuncs;
for (i = 1; i <= net->Nrules; i++)
{
p = rules->Rule[i].Pchain;
while (p != NULL)
{
if (p->object == r_NODE && p->index > njuncs) p->index++;
p = p->next;
}
}
}
void deleterule(EN_Project *pr, int index)
/*
**-----------------------------------------------------------
** Deletes a specific rule
**-----------------------------------------------------------
*/
{
int i;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
aRule *lastRule;
// Free memory allocated to rule's premises & actions
clearrule(pr, index);
// Shift position of higher indexed rules down one
for (i = index; i <= net->Nrules - 1; i++)
{
rules->Rule[i] = rules->Rule[i + 1];
}
// Remove premises & actions from last (inactive) entry in Rule array
lastRule = &rules->Rule[net->Nrules];
lastRule->Pchain = NULL;
lastRule->Tchain = NULL;
lastRule->Fchain = NULL;
// Reduce active rule count by one
net->Nrules--;
}
void clearactlist(rules_t *rules) void clearactlist(rules_t *rules)
/* /*
**---------------------------------------------------------- **----------------------------------------------------------
@@ -322,23 +444,19 @@ void clearactlist(rules_t *rules)
} }
} }
void clearrules(EN_Project *pr) void clearrule(EN_Project *pr, int i)
/* /*
**----------------------------------------------------------- **-----------------------------------------------------------
** Clears memory used for premises & actions for all rules ** Clears memory used by a rule for premises & actions
**----------------------------------------------------------- **-----------------------------------------------------------
*/ */
{ {
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules; rules_t *rules = &pr->rules;
Premise *p; Premise *p;
Premise *pnext; Premise *pnext;
Action *a; Action *a;
Action *anext; Action *anext;
int i;
for (i = 1; i <= net->Nrules; i++) {
p = rules->Rule[i].Pchain; p = rules->Rule[i].Pchain;
while (p != NULL) { while (p != NULL) {
pnext = p->next; pnext = p->next;
@@ -357,7 +475,6 @@ void clearrules(EN_Project *pr)
free(a); free(a);
a = anext; a = anext;
} }
}
} }
void newrule(EN_Project *pr) void newrule(EN_Project *pr)

View File

@@ -449,19 +449,15 @@ AUTHOR: L. Rossman
#define FMT82 "\n\f\n Page %-d %60.60s\n" #define FMT82 "\n\f\n Page %-d %60.60s\n"
/* ------------------- Progress Messages ---------------------- */ /* ------------------- Progress Messages ---------------------- */
#define FMT100 "Retrieving network data..." #define FMT100 " Retrieving network data ... "
#define FMT101 "Computing hydraulics at hour %s" #define FMT101 " Computing hydraulics at hour %-10s "
#define FMT102 "Computing water quality at hour %s" #define FMT102 " Computing water quality at hour %-10s "
#define FMT103 "Saving results to file..." #define FMT103 " Writing output report ... "
#define FMT106 " Transferring results to file ... "
#define FMT104 "Analysis begun %s" #define FMT104 "Analysis begun %s"
#define FMT105 "Analysis ended %s" #define FMT105 "Analysis ended %s"
/*------------------- Error Messages --------------------*/ /*------------------- Error Messages --------------------*/
#define R_ERR201 "Input Error 201: syntax error in following line of " #define R_ERR201 "Input Error 201: syntax error in following line of "
#define R_ERR202 "Input Error 202: illegal numeric value in following line of " #define R_ERR202 "Input Error 202: illegal numeric value in following line of "
#define R_ERR203 "Input Error 203: undefined node in following line of " #define R_ERR203 "Input Error 203: undefined node in following line of "

View File

@@ -48,9 +48,10 @@ typedef int INT4;
#define ENGINE_VERSION 201 #define ENGINE_VERSION 201
#define EOFMARK 0x1A /* Use 0x04 for UNIX systems */ #define EOFMARK 0x1A /* Use 0x04 for UNIX systems */
#define MAXTITLE 3 /* Max. # title lines */ #define MAXTITLE 3 /* Max. # title lines */
#define TITLELEN 79 // Max. # characters in a title line
#define MAXID 31 /* Max. # characters in ID name */ #define MAXID 31 /* Max. # characters in ID name */
#define MAXMSG 79 /* Max. # characters in message text */ #define MAXMSG 255 /* Max. # characters in message text */
#define MAXLINE 255 /* Max. # characters read from input line */ #define MAXLINE 1024 /* Max. # characters read from input line */
#define MAXFNAME 259 /* Max. # characters in file name */ #define MAXFNAME 259 /* Max. # characters in file name */
#define MAXTOKS 40 /* Max. items per line of input */ #define MAXTOKS 40 /* Max. items per line of input */
#define TZERO 1.E-4 /* Zero time tolerance */ #define TZERO 1.E-4 /* Zero time tolerance */
@@ -530,7 +531,7 @@ typedef struct s_aRule /* Control Rule Structure */
Premise *Pchain; /* Linked list of premises */ Premise *Pchain; /* Linked list of premises */
Action *Tchain; /* Linked list of actions if true */ Action *Tchain; /* Linked list of actions if true */
Action *Fchain; /* Linked list of actions if false */ Action *Fchain; /* Linked list of actions if false */
struct s_aRule *next; //struct s_aRule *next;
} aRule; } aRule;
typedef struct s_ActItem /* Action list item */ typedef struct s_ActItem /* Action list item */
@@ -873,7 +874,8 @@ typedef struct {
Scurve *Curve; /* Curve data */ Scurve *Curve; /* Curve data */
Scoord *Coord; /* Coordinate data */ Scoord *Coord; /* Coordinate data */
Scontrol *Control; /* Control data */ Scontrol *Control; /* Control data */
ENHashTable *NodeHashTable, HashTable
*NodeHashTable,
*LinkHashTable; /* Hash tables for ID labels */ *LinkHashTable; /* Hash tables for ID labels */
Padjlist *Adjlist; /* Node adjacency lists */ Padjlist *Adjlist; /* Node adjacency lists */
@@ -900,7 +902,7 @@ typedef struct EN_Project {
Openflag, /// Toolkit open flag Openflag, /// Toolkit open flag
Warnflag, /// Warning flag Warnflag, /// Warning flag
Msg[MAXMSG+1], /// General-purpose string: errors, messages Msg[MAXMSG+1], /// General-purpose string: errors, messages
Title[MAXTITLE][MAXMSG+1], /// Problem title Title[MAXTITLE][TITLELEN+1],/// Project title
MapFname[MAXFNAME+1]; /// Map file name MapFname[MAXFNAME+1]; /// Map file name
error_handle_t* error_handle; //Simple error manager error_handle_t* error_handle; //Simple error manager

87
tests/test_setid.cpp Normal file
View File

@@ -0,0 +1,87 @@
// Test of ENsetid EPANET API Function
#define _CRT_SECURE_NO_DEPRECATE
/*
This is a test for the API functions that change a node or link ID name.
A node and link name are changed, the network is saved, reopened and the new names are checked.
*/
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#include <string>
#include "epanet2.h"
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
using namespace std;
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setid)
{
int error = 0;
int index;
string newid;
EN_ProjectHandle ph = NULL;
EN_createproject(&ph);
std::string path_inp = std::string(DATA_PATH_INP);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Test of illegal node name change
newid = "Illegal; node name";
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal node name change
newid = "Node3";
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Test of illegal link name change
newid = "Illegal; link name";
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal link name change
newid = "Link3";
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Save the project
error = EN_saveinpfile(ph, "net1_setid.inp");
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
// Re-open the saved project
EN_createproject(&ph);
error = EN_open(ph, "net1_setid.inp", path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Check that 3rd node has its new name
error = EN_getnodeindex(ph, "Node3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
// Check that 3rd link has its new name
error = EN_getlinkindex(ph, "Link3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_SUITE_END()

100
tests/test_setlinktype.cpp Normal file
View File

@@ -0,0 +1,100 @@
// Test of ENsetlinktype EPANET API Function
#define _CRT_SECURE_NO_DEPRECATE
/*
This is a test for the API function that changes a link's type.
Two links in Net1.inp are changed: Pipe 113 is reversed with a CV added
and Pipe 121 is changed to a 100 psi PRV. After running the revised model,
at hour 0 the flow in Pipe 113 should be zero and the pressure at node 31
of the PRV 121 should be 100.
*/
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#include <string>
#include "epanet2.h"
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
using namespace std;
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setlinktype)
{
int error = 0;
int p113, n31, p121, n113_1, n113_2;
float q113 = 0.0f, p31 = 0.0f, diam;
EN_ProjectHandle ph = NULL;
EN_createproject(&ph);
std::string path_inp = std::string(DATA_PATH_INP);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Change duration to 0
error = EN_settimeparam(ph, EN_DURATION, 0);
BOOST_REQUIRE(error == 0);
// Get indexes of pipe 113 and node 31
error = EN_getlinkindex(ph, (char *)"113", &p113);
BOOST_REQUIRE(error == 0);
error = EN_getnodeindex(ph, (char *)"31", &n31);
BOOST_REQUIRE(error == 0);
// Reverse pipe 113 and give it a check valve
error = EN_getlinknodes(ph, p113, &n113_1, &n113_2);
BOOST_REQUIRE(error == 0);
error = EN_setlinknodes(ph, p113, n113_2, n113_1);
BOOST_REQUIRE(error == 0);
error = EN_setlinktype(ph, &p113, EN_CVPIPE);
BOOST_REQUIRE(error == 0);
// Get index & diameter of pipe 121 connected to node 31
error = EN_getlinkindex(ph, (char *)"121", &p121);
BOOST_REQUIRE(error == 0);
error = EN_getlinkvalue(ph, p121, EN_DIAMETER, &diam);
BOOST_REQUIRE(error == 0);
// Replace it with a PRV
error = EN_setlinktype(ph, &p121, EN_PRV);
BOOST_REQUIRE(error == 0);
// Set diameter & setting of new PRV
error = EN_setlinkvalue(ph, p121, EN_INITSETTING, 100);
BOOST_REQUIRE(error == 0);
error = EN_setlinkvalue(ph, p121, EN_DIAMETER, diam);
BOOST_REQUIRE(error == 0);
// Solve for hydraulics
error = EN_solveH(ph);
BOOST_REQUIRE(error == 0);
// Get flow in link 113 and pressure at node 31
error = EN_getlinkvalue(ph, p113, EN_FLOW, &q113);
BOOST_REQUIRE(error == 0);
error = EN_getnodevalue(ph, n31, EN_PRESSURE, &p31);
BOOST_REQUIRE(error == 0);
// Require that link 113 flow be 0
q113 = fabs(q113);
BOOST_REQUIRE(q113 < 0.001);
// Require that node 31 pressure be 100
p31 = fabs(p31 - 100.0f);
BOOST_REQUIRE(p31 < 0.001);
// Close and delete project
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -13,6 +13,7 @@ EXPORTS
ENgetlinkid = _ENgetlinkid@8 ENgetlinkid = _ENgetlinkid@8
ENgetlinkindex = _ENgetlinkindex@8 ENgetlinkindex = _ENgetlinkindex@8
ENgetlinknodes = _ENgetlinknodes@12 ENgetlinknodes = _ENgetlinknodes@12
ENsetlinknodes = _ENsetlinknodes@12
ENgetlinktype = _ENgetlinktype@8 ENgetlinktype = _ENgetlinktype@8
ENgetlinkvalue = _ENgetlinkvalue@12 ENgetlinkvalue = _ENgetlinkvalue@12
ENgetnodeid = _ENgetnodeid@8 ENgetnodeid = _ENgetnodeid@8