Feature wrapper (#136)

this quite sizable commit does several things, but is primarily
focussed on building a toolkit that can run simultaneous
simulations/analyses within a shared memory space. Versions <=2.1 use a
long list of global variables that prevent multiple instantiations on
linux systems without resorting to compilation tricks (like duplicate
binaries or similar via static linkage). This version uses a single "Project" pointer to encapsulate
the network and analysis data. There are no changes to existing algo
implementations other than to accomodate dereferencing of the passed-in
pointers. A more detailed list of major changes below:

- mirrors all “ENxxxx” function calls with “EN_xxxx” versions (note the
underscore) that take an extra first parameter: a pointer to an
EN_Project struct, which contains all network, hydraulic, quality, and
associated data.
- tweaks some code formatting to make it more readable
- removes some deprecated/commented code that was sufficiently old
- fixes implicit type-cast warnings

* Added ENaddnode and ENaddlink functions

* More memory reallocations

* Added ENInit, ENsetheadcurveindex

* Added ENdeletelink and ENdeletenode

* restored default behavior for float types

* fixed type

* Added docstrings for ENinit

* cleanup change

* moves global rule variables to vars.h

* migrates rule structs to typedefs

for better readability

* char types to proper enums

fixes #93

* Change some variable declarations for compatibility

Changes to keep compatibility with C89 compilers: variables must be
declared at the top of the functions. Remove the use of EN_LinkType in
function call as it is not compatible with ENgetnodetype.

* Moved declaration of idstodelete to top of function

* Updated ENinit function and headers

Updated header files with new functions
Updated def file with new functions
For ENinit changes names of parameters #98
Added enum for headloss formula

* Missed these files in 1a033fc

* migrates char types to enums fixes #93,

supports unified link/node type enums, rather than public/private
redefinitions

* removing links in reverse-index order maintains proper indexing fixes #96

* style

* clarifies curve getter units issue (dox)

closes #95

* fixes link/node confusion in ENsetlinktype

partially reverts a3bce95dc330a5a297634a303d438e2e1bc41cc9

* partial compilation fix

* fixes dox issue

* fixes allocation issues with enums

- updates style in various places
- introduces FlowDirection enum
- use snprintf to prevent overflow

* fixes enum type cast

* updated mac project settings

* Use of _snprintf on Windows and remove DLLEXPORT from mempool.h

snprintf it not compatible on Windows so we use _snprintf
mempool gave starnge compilation errors while removing DLLEXPORT worked.
Not sure why these functions needed to be exposed in the DLL?

* Revert "Use of _snprintf on Windows and remove DLLEXPORT from mempool.h"

This reverts commit 6238f77d47fa0feaabe5836043c006937de433a2.

* use of _snprintf instead of snprintf on Windows and removed DLLEXPORT from mempool.h

Had compilation errors on mempool.h. Removed DLLEXPORT so solve it. Not
sure why there was a need to expose these functions?

* Shift indices for Links in ENaddnode

Need to shift indices for Links not just Pipes since a pump could be
connected directly to a reservoir. Also set the defult base demand to
zero (was 5).

* Set defualts for madatory link properties in ENaddlink and small fix for ENsetheadcurveindex

Relates to #102 and closes #103

* wraps globals into structs, duplicates api functions with objective versions



* parse and serialize Comment field for network elements

related to #47

* adds getter for head/efficiency curve

in EN_getlinkvalue

* adds getter for event node index

… to return the index of the junction (tank) that triggered the event.

* fixes edge case in parsing

… where inp files without demands in [JUNCTIONS] and without any
[DEMAND] categories will fail.

* adds freeing function for project pointer

* removes redundant string literals, fixes overrun issue in error message getter function

* check for hydraulics already closed

* moving error definitions to data file

* deprecates ENR err message getter (unused)

* updates location of errors data file

also begins to expose blind structs to curves and patterns,
anticipating buildout of APIs for those.

* updates CLI output to reflect executable name as invoked

relates to #109

* Feature nrtest (#131)

* Initial commit EPANET testing tools.

* Initial commit for epanet-nrtestsuite

* SWIG wrapper for EPANET outputapi (#118)

* Removed pervious version of outputapi and wrapper

* SWIG wrapper for EPANET outputapi

* Patching cmake build script fixed target for outputapi

* Build failing on deprecated test script

* Minor changes. Responding to review comments.

* Feature nrtest (#121)

* Configured python setup to automatically build nrtest tools.

* Working on build / testing automation

* Adding EPANET 2.0.12 benchmark

* Updated Travis yml to run nrtest

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning again

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning

* Fixing InsecurePlatformWarning

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Update .travis.yml

* Working on configuring python environment and building test tools under Travis CI.

* Making gen-config.sh and run-nrtest.sh executable

* Debugging .travis.yml

* Debugging .travis.yml

* Debugging .travis.yml again

* Debugging .travis.yml again

* debugging travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* debugging Travis setup

* Fixing bug with __strncpy_chk destlen < len

* nrtesting clean up

* re-implements fixes from:

5eead5ae40
3c788567a4

* removes extraneous build files, moves cmake and updates travis

* mirror of 9b37035560f9683f1514b439f7586a5c17bca5bf

* Move some variable declarations

* More variable declarations

* Fix TmpDir

* Allocate _defaultModel

* Fix EN_addcurve funcrion

* Fix for inpfile

* Fix writeRuleinInp call

* Set MAXMSG to 79 chars

* Fix for flow direction

* Refactoring testing related python packages and SWIG wrapper bug fix (#139)

* Eliminated epanet-reader package. Removed numpy dependency from epanet-output. Fixed reference counting bug in SWIG wrapper. Added error checking to run_nrtest.sh. Added nrtest package to requirements file.

* changing buildhome directory

* Fixing bug related to preprocessor definition of PI
This commit is contained in:
Sam Hatchett
2018-01-09 16:56:42 -05:00
committed by GitHub
parent 5eead5ae40
commit f97d837231
77 changed files with 37683 additions and 20504 deletions

View File

@@ -1,137 +1,129 @@
/*
***********************************************************************
ENUMSTXT.H -- Text strings for enumerated data types in EPANET
VERSION: 2.00
DATE: 5/8/00
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
#ifndef ENUMSTXT_H
#define ENUMSTXT_H
char *NodeTxt[] = {t_JUNCTION,
t_RESERVOIR,
t_TANK};
char *LinkTxt[] = {w_CV,
w_PIPE,
w_PUMP,
w_PRV,
w_PSV,
w_PBV,
w_FCV,
w_TCV,
w_GPV};
char *StatTxt[] = {t_XHEAD,
t_TEMPCLOSED,
t_CLOSED,
t_OPEN,
t_ACTIVE,
t_XFLOW,
t_XFCV,
t_XPRESSURE,
t_FILLING,
t_EMPTYING};
char *FormTxt[] = {w_HW,
w_DW,
w_CM};
char *RptFormTxt[] = {t_HW,
t_DW,
t_CM};
char *RptFlowUnitsTxt[] = {u_CFS,
u_GPM,
u_MGD,
u_IMGD,
u_AFD,
u_LPS,
u_LPM,
u_MLD,
u_CMH,
u_CMD};
char *FlowUnitsTxt[] = {w_CFS,
w_GPM,
w_MGD,
w_IMGD,
w_AFD,
w_LPS,
w_LPM,
w_MLD,
w_CMH,
w_CMD};
char *PressUnitsTxt[] = {w_PSI,
w_KPA,
w_METERS};
char *QualTxt[] = {w_NONE,
w_CHEM,
w_AGE,
w_TRACE};
char *SourceTxt[] = {w_CONCEN,
w_MASS,
w_SETPOINT,
w_FLOWPACED};
char *ControlTxt[] = {w_BELOW,
w_ABOVE,
w_TIME,
w_CLOCKTIME};
char *TstatTxt[] = {w_NONE,
w_AVG,
w_MIN,
w_MAX,
w_RANGE};
char *MixTxt[] = {w_MIXED,
w_2COMP,
w_FIFO,
w_LIFO,
NULL};
char *RptFlagTxt[] = {w_NO,
w_YES,
w_FULL};
char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS,
s_TANKS, s_PIPES, s_PUMPS,
s_VALVES, s_CONTROLS, s_RULES,
s_DEMANDS, s_SOURCES, s_EMITTERS,
s_PATTERNS, s_CURVES, s_QUALITY,
s_STATUS, s_ROUGHNESS, s_ENERGY,
s_REACTIONS, s_MIXING, s_REPORT,
s_TIMES, s_OPTIONS, s_COORDS,
s_VERTICES, s_LABELS, s_BACKDROP,
s_TAGS, s_END,
NULL};
char *RptSectTxt[] = {NULL, t_JUNCTION, t_RESERVOIR,
t_TANK, t_PIPE, t_PUMP,
t_VALVE, t_CONTROL, t_RULE,
t_DEMANDFOR,t_SOURCE, t_EMITTER,
t_PATTERN, t_CURVE, t_QUALITY,
t_STATUS, t_ROUGHNESS,t_ENERGY,
t_REACTION, t_MIXING, t_REPORT,
t_TIME, t_OPTION};
char *Fldname[] = {t_ELEV, t_DEMAND, t_HEAD,
t_PRESSURE, t_QUALITY, t_LENGTH,
t_DIAM, t_FLOW, t_VELOCITY,
t_HEADLOSS, t_LINKQUAL, t_LINKSTATUS,
t_SETTING, t_REACTRATE, t_FRICTION,
"", "", "", "", "", "", NULL};
#endif
/*
***********************************************************************
ENUMSTXT.H -- Text strings for enumerated data types in EPANET
VERSION: 2.00
DATE: 5/8/00
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
#ifndef ENUMSTXT_H
#define ENUMSTXT_H
#include "text.h"
char *NodeTxt[] = {t_JUNCTION,
t_RESERVOIR,
t_TANK};
char *LinkTxt[] = {w_CV,
w_PIPE,
w_PUMP,
w_PRV,
w_PSV,
w_PBV,
w_FCV,
w_TCV,
w_GPV};
char *StatTxt[] = {t_XHEAD,
t_TEMPCLOSED,
t_CLOSED,
t_OPEN,
t_ACTIVE,
t_XFLOW,
t_XFCV,
t_XPRESSURE,
t_FILLING,
t_EMPTYING};
char *FormTxt[] = {w_HW,
w_DW,
w_CM};
char *RptFormTxt[] = {t_HW,
t_DW,
t_CM};
char *RptFlowUnitsTxt[] = {u_CFS,
u_GPM,
u_MGD,
u_IMGD,
u_AFD,
u_LPS,
u_LPM,
u_MLD,
u_CMH,
u_CMD};
char *FlowUnitsTxt[] = {w_CFS,
w_GPM,
w_MGD,
w_IMGD,
w_AFD,
w_LPS,
w_LPM,
w_MLD,
w_CMH,
w_CMD};
char *PressUnitsTxt[] = {w_PSI,
w_KPA,
w_METERS};
char *QualTxt[] = {w_NONE,
w_CHEM,
w_AGE,
w_TRACE};
char *SourceTxt[] = {w_CONCEN,
w_MASS,
w_SETPOINT,
w_FLOWPACED};
char *ControlTxt[] = {w_BELOW,
w_ABOVE,
w_TIME,
w_CLOCKTIME};
char *TstatTxt[] = {w_NONE,
w_AVG,
w_MIN,
w_MAX,
w_RANGE};
char *MixTxt[] = {w_MIXED,
w_2COMP,
w_FIFO,
w_LIFO,
NULL};
char *RptFlagTxt[] = {w_NO,
w_YES,
w_FULL};
char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS,
s_TANKS, s_PIPES, s_PUMPS,
s_VALVES, s_CONTROLS, s_RULES,
s_DEMANDS, s_SOURCES, s_EMITTERS,
s_PATTERNS, s_CURVES, s_QUALITY,
s_STATUS, s_ROUGHNESS, s_ENERGY,
s_REACTIONS, s_MIXING, s_REPORT,
s_TIMES, s_OPTIONS, s_COORDS,
s_VERTICES, s_LABELS, s_BACKDROP,
s_TAGS, s_END,
NULL};
char *Fldname[] = {t_ELEV, t_DEMAND, t_HEAD,
t_PRESSURE, t_QUALITY, t_LENGTH,
t_DIAM, t_FLOW, t_VELOCITY,
t_HEADLOSS, t_LINKQUAL, t_LINKSTATUS,
t_SETTING, t_REACTRATE, t_FRICTION,
"", "", "", "", "", "", NULL};
#endif

8173
src/epanet.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

75
src/errors.dat Normal file
View File

@@ -0,0 +1,75 @@
DAT(0,EN_OK,"ok")
DAT(101,ENERR_INSUF_MEM,"insufficient memory available")
DAT(102,ENERR_NO_NET_DATA,"no network data available")
DAT(103,ENERR_HYD_NOT_INIT,"hydraulics not initialized")
DAT(104,ENERR_NO_HYD,"no hydraulics for water quality analysis")
DAT(105,ENERR_WQ_NOT_INIT,"water quality not initialized")
DAT(106,ENERR_NO_RESULT,"no results saved to report on")
DAT(107,ENERR_HYD_EXT_FILE,"hydraulics supplied from external file")
DAT(108,ENERR_CANT_USE_EXT_FILE,"cannot use external file while hydraulics solver is active")
DAT(109,ENERR_CANT_CHANGE_TIME_PARAM,"cannot change time parameter when solver is active")
DAT(110,ENERR_CANT_SOLVE_HYD,"cannot solve network hydraulic equations")
DAT(120,ENERR_CANT_SOLVE_WQ,"cannot solve water quality transport equations")
DAT(200,ENERR_INP_ERR,"one or more errors in input file")
DAT(201,ENERR_SYNTAX_LINE,"syntax error in following line of section")
DAT(202,ENERR_ILLEGAL_NUM,"function call contains illegal numeric value")
DAT(203,ENERR_UNDEF_NODE,"function call refers to undefined node")
DAT(204,ENERR_UNDEF_LINK,"function call refers to undefined link")
DAT(205,ENERR_UNDEF_PAT,"function call refers to undefined time pattern")
DAT(206,ENERR_UNDEF_CURVE,"function call refers to undefined curve")
DAT(207,ENERR_CANT_CONTROL_CV,"function call attempts to control a CV")
DAT(208,ENERR_SPEC_UNDEF_NODE,"undefined Node")
DAT(209,ENERR_ILLEGAL_VAL_NODE,"illegal value for Node")
DAT(210,ENERR_SPEC_UNDEF_LINK,"specified for undefined Link")
DAT(211,ENERR_ILLEGAL_VAL_LINK,"illegal value for Link")
DAT(212,ENERR_TRACE_NODE,"trace node")
DAT(213,ENERR_ILLEGAL_OPT,"illegal option value in section")
DAT(214,ENERR_TOO_MANY_CHAR,"following line of section contains too many characters")
DAT(215,ENERR_DUPLICATE_ID,"duplicate ID")
DAT(216,ENERR_UNDEF_PUMP,"data specified for undefined Pump")
DAT(217,ENERR_INVALID_DATA_PUMP,"invalid data for Pump")
DAT(219,ENERR_ILLEGAL_CON_TANK,"illegally connected to a tank")
DAT(220,ENERR_ILLEGAL_CON_VALVE,"illegally connected to another valve")
DAT(222,ENERR_SAME_START_END,"same start and end nodes")
DAT(223,ENERR_NOT_ENOUGH_NODES,"not enough nodes in network")
DAT(224,ENERR_NO_TANKS_RES,"no tanks or reservoirs in network")
DAT(225,ENERR_INVALID_LEVELS,"invalid lower/upper levels for Tank")
DAT(226,ENERR_NO_HEAD_CURVE,"no head curve supplied for Pump")
DAT(227,ENERR_INVALID_HEAD_CURVE,"invalid head curve for Pump")
DAT(230,ENERR_X_NONINCREASING,"Curve has nonincreasing x-values")
DAT(233,ENERR_NODE_UNCONNECTED,"Node is unconnected")
DAT(240,ENERR_UNDEF_SOURCE,"undefined source")
DAT(241,ENERR_UNDEF_CONTROL,"refers to undefined control")
DAT(250,ENERR_INVALID_FORMAT,"function call contains invalid format")
DAT(251,ENERR_INVALID_CODE,"function call contains invalid parameter code")
DAT(253,ENERR_NO_DEMAND_CAT,"Function call error - No such demand category index")
DAT(254,ENERR_NO_COORDS,"Function call error - Node have no coordinates")
DAT(255,ENERR_COORDS_NOT_LOADED,"Function call error - Coordinates were not loaded")
DAT(257,ENERR_NO_RULE,"rule does not exist")
DAT(258,ENERR_NO_CONDITION_ACTION,"condition or action index specified in rule does not exist")
DAT(301,ENERR_FILES_ARE_SAME,"identical file names")
DAT(302,ENERR_CANT_OPEN_INP,"cannot open input file")
DAT(303,ENERR_CANT_OPEN_RPT,"cannot open report file")
DAT(304,ENERR_CANT_OPEN_BIN,"cannot open binary output file")
DAT(305,ENERR_CANT_OPEN_HYD,"cannot open hydraulics file")
DAT(306,ENERR_HYD_FILE_NOMATCH,"hydraulics file does not match network data")
DAT(307,ENERR_CANT_READ_HYD,"cannot read hydraulics file")
DAT(308,ENERR_CANT_SAVE_RES,"cannot save results to file")
DAT(309,ENERR_CANT_SAVE_RPT,"cannot save results to report file")
DAT(401,ENERR_QSTEP_NOT_DIVISIBLE,"Qstep is not dividable by Hstep")
DAT(411,ENERR_NO_MEM_ALLOC,"no memory allocated for results")
DAT(412,ENERR_NO_RESULTS_NO_FILE,"no results; binary file hasn't been opened")
DAT(435,ENERR_RUN_TERMINATED,"run terminated; no results in binary file")

View File

@@ -1,288 +1,291 @@
/*
**************************************************************************
FUNCS.H -- Function Prototypes for EPANET Program
VERSION: 2.00
DATE: 5/8/00
9/25/00
10/25/00
12/29/00
3/1/01
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
**************************************************************************
*/
/*****************************************************************/
/* Most float arguments have been changed to double - 7/3/07 */
/*****************************************************************/
/* ------- EPANET.C --------------------*/
/*
** NOTE: The exportable functions that can be called
** via the DLL are prototyped in TOOLKIT.H.
*/
#ifndef FUNCS_H
#define FUNCS_H
void initpointers(void); /* Initializes pointers */
int allocdata(void); /* Allocates memory */
void freeTmplist(STmplist *); /* Frees items in linked list */
void freeFloatlist(SFloatlist *); /* Frees list of floats */
void freedata(void); /* Frees allocated memory */
int openfiles(char *,char *,char *); /* Opens input & report files */
int openhydfile(void); /* Opens hydraulics file */
int openoutfile(void); /* Opens binary output file */
int strcomp(char *, char *); /* Compares two strings */
char* getTmpName(char* fname); /* Gets temporary file name */ //(2.00.12 - LR)
double interp(int, double *, /* Interpolates a data curve */
double *, double);
int findnode(char *); /* Finds node's index from ID */
int findlink(char *); /* Finds link's index from ID */
char* geterrmsg(int); /* Gets text of error message */
void errmsg(int); /* Reports program error */
void writecon(char *); /* Writes text to console */
void writewin(char *); /* Passes text to calling app */
/* ------- INPUT1.C --------------------*/
int getdata(void); /* Gets network data */
void setdefaults(void); /* Sets default values */
void initreport(void); /* Initializes report options */
void adjustdata(void); /* Adjusts input data */
int inittanks(void); /* Initializes tank levels */
void initunits(void); /* Determines reporting units */
void convertunits(void); /* Converts data to std. units*/
/* -------- INPUT2.C -------------------*/
int netsize(void); /* Determines network size */
int readdata(void); /* Reads in network data */
int newline(int, char *); /* Processes new line of data */
int addnodeID(int, char *); /* Adds node ID to data base */
int addlinkID(int, char *); /* Adds link ID to data base */
int addpattern(char *); /* Adds pattern to data base */
int addcurve(char *); /* Adds curve to data base */
STmplist *findID(char *, STmplist *); /* Locates ID on linked list */
int unlinked(void); /* Checks for unlinked nodes */
int getpumpparams(void); /* Computes pump curve coeffs.*/
int getpatterns(void); /* Gets pattern data from list*/
int getcurves(void); /* Gets curve data from list */
int findmatch(char *,char *[]); /* Finds keyword in line */
int match(char *, char *); /* Checks for word match */
int gettokens(char *); /* Tokenizes input line */
int getfloat(char *, double *); /* Converts string to double */
double hour(char *, char *); /* Converts time to hours */
int setreport(char *); /* Processes reporting command*/
void inperrmsg(int,int,char *); /* Input error message */
/* ---------- INPUT3.C -----------------*/
int juncdata(void); /* Processes junction data */
int tankdata(void); /* Processes tank data */
int pipedata(void); /* Processes pipe data */
int pumpdata(void); /* Processes pump data */
int valvedata(void); /* Processes valve data */
int patterndata(void); /* Processes pattern data */
int curvedata(void); /* Processes curve data */
int coordata(void); /* Processes coordinate data */
int demanddata(void); /* Processes demand data */
int controldata(void); /* Processes simple controls */
int energydata(void); /* Processes energy data */
int sourcedata(void); /* Processes source data */
int emitterdata(void); /* Processes emitter data */
int qualdata(void); /* Processes quality data */
int reactdata(void); /* Processes reaction data */
int mixingdata(void); /* Processes tank mixing data */
int statusdata(void); /* Processes link status data */
int reportdata(void); /* Processes report options */
int timedata(void); /* Processes time options */
int optiondata(void); /* Processes analysis options */
int optionchoice(int); /* Processes option choices */
int optionvalue(int); /* Processes option values */
int getpumpcurve(int); /* Constructs a pump curve */
int powercurve(double, double, double,/* Coeffs. of power pump curve*/
double, double, double *,
double *, double *);
int valvecheck(int, int, int); /* Checks valve placement */
void changestatus(int, char, double); /* Changes status of a link */
/* -------------- RULES.C --------------*/
void initrules(void); /* Initializes rule base */
void addrule(char *); /* Adds rule to rule base */
int allocrules(void); /* Allocates memory for rule */
int ruledata(void); /* Processes rule input data */
int checkrules(long); /* Checks all rules */
void freerules(void); /* Frees rule base memory */
/* ------------- REPORT.C --------------*/
int writereport(void); /* Writes formatted report */
void writelogo(void); /* Writes program logo */
void writesummary(void); /* Writes network summary */
void writehydstat(int,double); /* Writes hydraulic status */
void writeenergy(void); /* Writes energy usage */
int writeresults(void); /* Writes node/link results */
void writeheader(int,int); /* Writes heading on report */
void writeline(char *); /* Writes line to report file */
void writerelerr(int, double); /* Writes convergence error */
void writestatchange(int,char,char); /* Writes link status change */
void writecontrolaction(int, int); /* Writes control action taken*/
void writeruleaction(int, char *); /* Writes rule action taken */
int writehydwarn(int,double); /* Writes hydraulic warnings */
void writehyderr(int); /* Writes hydraulic error msg.*/
int disconnected(void); /* Checks for disconnections */
void marknodes(int, int *, char *); /* Identifies connected nodes */
void getclosedlink(int, char *); /* Finds a disconnecting link */
void writelimits(int,int); /* Writes reporting limits */
int checklimits(double *,int,int); /* Checks variable limits */
void writetime(char *); /* Writes current clock time */
char *clocktime(char *, long); /* Converts time to hrs:min */
char *fillstr(char *, char, int); /* Fills string with character*/
int getnodetype(int); /* Determines node type */
/* --------- HYDRAUL.C -----------------*/
int openhyd(void); /* Opens hydraulics solver */
/*** Updated 3/1/01 ***/
void inithyd(int); /* Re-sets initial conditions */
int runhyd(long *); /* Solves 1-period hydraulics */
int nexthyd(long *); /* Moves to next time period */
void closehyd(void); /* Closes hydraulics solver */
int allocmatrix(void); /* Allocates matrix coeffs. */
void freematrix(void); /* Frees matrix coeffs. */
void initlinkflow(int, char, double); /* Initializes link flow */
void setlinkflow(int, double); /* Sets link flow via headloss*/
void setlinkstatus(int, char, char *, /* Sets link status */
double *);
void setlinksetting(int, double, /* Sets pump/valve setting */
char *, double *);
void resistance(int); /* Computes resistance coeff. */
void demands(void); /* Computes current demands */
int controls(void); /* Controls link settings */
long timestep(void); /* Computes new time step */
void tanktimestep(long *); /* Time till tanks fill/drain */
void controltimestep(long *); /* Time till control action */
void ruletimestep(long *); /* Time till rule action */
void addenergy(long); /* Accumulates energy usage */
void getenergy(int, double *, double *); /* Computes link energy use */
void tanklevels(long); /* Computes new tank levels */
double tankvolume(int,double); /* Finds tank vol. from grade */
double tankgrade(int,double); /* Finds tank grade from vol. */
int netsolve(int *,double *); /* Solves network equations */
int badvalve(int); /* Checks for bad valve */
int valvestatus(void); /* Updates valve status */
int linkstatus(void); /* Updates link status */
char cvstatus(char,double,double); /* Updates CV status */
char pumpstatus(int,double); /* Updates pump status */
char prvstatus(int,char,double, /* Updates PRV status */
double,double);
char psvstatus(int,char,double, /* Updates PSV status */
double,double);
char fcvstatus(int,char,double, /* Updates FCV status */
double);
void tankstatus(int,int,int); /* Checks if tank full/empty */
int pswitch(void); /* Pressure switch controls */
double newflows(void); /* Updates link flows */
void newcoeffs(void); /* Computes matrix coeffs. */
void linkcoeffs(void); /* Computes link coeffs. */
void nodecoeffs(void); /* Computes node coeffs. */
void valvecoeffs(void); /* Computes valve coeffs. */
void pipecoeff(int); /* Computes pipe coeff. */
double DWcoeff(int, double *); /* Computes D-W coeff. */
void pumpcoeff(int); /* Computes pump coeff. */
/*** Updated 10/25/00 ***/
/*** Updated 12/29/00 ***/
void curvecoeff(int,double,double *, /* Computes curve coeffs. */
double *);
void gpvcoeff(int); /* Computes GPV coeff. */
void pbvcoeff(int); /* Computes PBV coeff. */
void tcvcoeff(int); /* Computes TCV coeff. */
void prvcoeff(int,int,int); /* Computes PRV coeff. */
void psvcoeff(int,int,int); /* Computes PSV coeff. */
void fcvcoeff(int,int,int); /* Computes FCV coeff. */
void emittercoeffs(void); /* Computes emitter coeffs. */
double emitflowchange(int); /* Computes new emitter flow */
/* ----------- SMATRIX.C ---------------*/
int createsparse(void); /* Creates sparse matrix */
int allocsparse(void); /* Allocates matrix memory */
void freesparse(void); /* Frees matrix memory */
int buildlists(int); /* Builds adjacency lists */
int paralink(int, int, int); /* Checks for parallel links */
void xparalinks(void); /* Removes parallel links */
void freelists(void); /* Frees adjacency lists */
void countdegree(void); /* Counts links at each node */
int reordernodes(void); /* Finds a node re-ordering */
int mindegree(int, int); /* Finds min. degree node */
int growlist(int); /* Augments adjacency list */
int newlink(Padjlist); /* Adds fill-ins for a node */
int linked(int, int); /* Checks if 2 nodes linked */
int addlink(int, int, int); /* Creates new fill-in */
int storesparse(int); /* Stores sparse matrix */
int ordersparse(int); /* Orders matrix storage */
void transpose(int,int *,int *, /* Transposes sparse matrix */
int *,int *,int *,int *,int *);
int linsolve(int, double *, double *, /* Solution of linear eqns. */
double *); /* via Cholesky factorization */
/* ----------- QUALITY.C ---------------*/
int openqual(void); /* Opens WQ solver system */
void initqual(void); /* Initializes WQ solver */
int runqual(long *); /* Gets current WQ results */
int nextqual(long *); /* Updates WQ by hyd.timestep */
int stepqual(long *); /* Updates WQ by WQ time step */
int closequal(void); /* Closes WQ solver system */
int gethyd(long *, long *); /* Gets next hyd. results */
char setReactflag(void); /* Checks for reactive chem. */
void transport(long); /* Transports mass in network */
void initsegs(void); /* Initializes WQ segments */
void reorientsegs(void); /* Re-orients WQ segments */
void updatesegs(long); /* Updates quality in segments*/
void removesegs(int); /* Removes a WQ segment */
void addseg(int,double,double); /* Adds a WQ segment to pipe */
void accumulate(long); /* Sums mass flow into node */
void updatenodes(long); /* Updates WQ at nodes */
void sourceinput(long); /* Computes source inputs */
void release(long); /* Releases mass from nodes */
void updatetanks(long); /* Updates WQ in tanks */
void updatesourcenodes(long); /* Updates WQ at source nodes */
void tankmix1(int, long); /* Complete mix tank model */
void tankmix2(int, long); /* 2-compartment tank model */
void tankmix3(int, long); /* FIFO tank model */
void tankmix4(int, long); /* LIFO tank model */
double sourcequal(Psource); /* Finds WQ input from source */
double avgqual(int); /* Finds avg. quality in pipe */
void ratecoeffs(void); /* Finds wall react. coeffs. */
double piperate(int); /* Finds wall react. coeff. */
double pipereact(int,double,double,long);/* Reacts water in a pipe */
double tankreact(double,double,double,
long); /* Reacts water in a tank */
double bulkrate(double,double,double); /* Finds bulk reaction rate */
double wallrate(double,double,double,double);/* Finds wall reaction rate */
/* ------------ OUTPUT.C ---------------*/
int savenetdata(void); /* Saves basic data to file */
int savehyd(long *); /* Saves hydraulic solution */
int savehydstep(long *); /* Saves hydraulic timestep */
int saveenergy(void); /* Saves energy usage */
int readhyd(long *); /* Reads hydraulics from file */
int readhydstep(long *); /* Reads time step from file */
int saveoutput(void); /* Saves results to file */
int nodeoutput(int, REAL4 *, double); /* Saves node results to file */
int linkoutput(int, REAL4 *, double); /* Saves link results to file */
int savefinaloutput(void); /* Finishes saving output */
int savetimestat(REAL4 *, char); /* Saves time stats to file */
int savenetreacts(double, double,
double, double); /* Saves react. rates to file */
int saveepilog(void); /* Saves output file epilog */
/* ------------ INPFILE.C --------------*/
int saveinpfile(char *); /* Saves network to text file */
#endif
/*
**************************************************************************
FUNCS.H -- Function Prototypes for EPANET Program
VERSION: 2.00
DATE: 5/8/00
9/25/00
10/25/00
12/29/00
3/1/01
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
**************************************************************************
*/
/*****************************************************************/
/* Most float arguments have been changed to double - 7/3/07 */
/*****************************************************************/
/* ------- EPANET.C --------------------*/
/*
** NOTE: The exportable functions that can be called
** via the DLL are prototyped in TOOLKIT.H.
*/
#ifndef FUNCS_H
#define FUNCS_H
#include "types.h"
void initpointers(EN_Project *p); /* Initializes pointers */
int allocdata(EN_Project *p); /* Allocates memory */
void freeTmplist(STmplist *); /* Frees items in linked list */
void freeFloatlist(SFloatlist *); /* Frees list of floats */
void freedata(EN_Project *p); /* Frees allocated memory */
int openfiles(EN_Project *p, char *,char *,char *); /* Opens input & report files */
int openhydfile(EN_Project *p); /* Opens hydraulics file */
int openoutfile(EN_Project *p); /* Opens binary output file */
int strcomp(char *, char *); /* Compares two strings */
char* getTmpName(EN_Project *p, char* fname); /* Gets temporary file name */
double interp(int, double *,double *, double); /* Interpolates a data curve */
int findnode(EN_Network *n, char *); /* Finds node's index from ID */
int findlink(EN_Network *n, char *); /* Finds link's index from ID */
int findtank(EN_Network *n, int); /* Find tank index from node index */ // (AH)
int findvalve(EN_Network *n, int); /* Find valve 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 */
void errmsg(EN_Project *p, int); /* Reports program error */
void writecon(char *); /* Writes text to console */
void writewin(void (*vp)(char *), char *); /* Passes text to calling app */
/* ------- INPUT1.C --------------------*/
int getdata(EN_Project *pr); /* Gets network data */
void setdefaults(EN_Project *pr); /* Sets default values */
void initreport(report_options_t *r); /* Initializes report options */
void adjustdata(EN_Project *pr); /* Adjusts input data */
int inittanks(EN_Project *pr); /* Initializes tank levels */
void initunits(EN_Project *pr); /* Determines reporting units */
void convertunits(EN_Project *pr); /* Converts data to std. units*/
/* -------- INPUT2.C -------------------*/
int netsize(EN_Project *pr); /* Determines network size */
int readdata(EN_Project *pr); /* Reads in network data */
int newline(EN_Project *pr, int, char *); /* Processes new line of data */
int addnodeID(EN_Network *n, int, char *); /* Adds node ID to data base */
int addlinkID(EN_Network *n, int, char *); /* Adds link ID to data base */
int addpattern(parser_data_t *par, char *); /* Adds pattern to data base */
int addcurve(parser_data_t *par, char *); /* Adds curve to data base */
STmplist *findID(char *, STmplist *); /* Locates ID on linked list */
int unlinked(EN_Project *pr); /* Checks for unlinked nodes */
int getpumpparams(EN_Project *pr); /* Computes pump curve coeffs.*/
int getpatterns(EN_Project *pr); /* Gets pattern data from list*/
int getcurves(EN_Project *pr); /* Gets curve data from list */
int findmatch(char *, char *[]); /* Finds keyword in line */
int match(const char *, const char *); /* Checks for word match */
int gettokens(char *s, char** Tok, int maxToks, char *comment); /* Tokenizes input line */
int getfloat(char *, double *); /* Converts string to double */
double hour(char *, char *); /* Converts time to hours */
int setreport(EN_Project *pr, char *); /* Processes reporting command*/
void inperrmsg(EN_Project *pr, int,int,char *); /* Input error message */
/* ---------- INPUT3.C -----------------*/
int juncdata(EN_Project *pr); /* Processes junction data */
int tankdata(EN_Project *pr); /* Processes tank data */
int pipedata(EN_Project *pr); /* Processes pipe data */
int pumpdata(EN_Project *pr); /* Processes pump data */
int valvedata(EN_Project *pr); /* Processes valve data */
int patterndata(EN_Project *pr); /* Processes pattern data */
int curvedata(EN_Project *pr); /* Processes curve data */
int coordata(EN_Project *pr); /* Processes coordinate data */
int demanddata(EN_Project *pr); /* Processes demand data */
int controldata(EN_Project *pr); /* Processes simple controls */
int energydata(EN_Project *pr); /* Processes energy data */
int sourcedata(EN_Project *pr); /* Processes source data */
int emitterdata(EN_Project *pr); /* Processes emitter data */
int qualdata(EN_Project *pr); /* Processes quality data */
int reactdata(EN_Project *pr); /* Processes reaction data */
int mixingdata(EN_Project *pr); /* Processes tank mixing data */
int statusdata(EN_Project *pr); /* Processes link status data */
int reportdata(EN_Project *pr); /* Processes report options */
int timedata(EN_Project *pr); /* Processes time options */
int optiondata(EN_Project *pr); /* Processes analysis options */
int optionchoice(EN_Project *pr, int); /* Processes option choices */
int optionvalue(EN_Project *pr, int); /* Processes option values */
int getpumpcurve(EN_Project *pr, int); /* Constructs a pump curve */
int powercurve(double, double, double,/* Coeffs. of power pump curve*/
double, double, double *,
double *, double *);
int valvecheck(EN_Project *pr, int, int, int); /* Checks valve placement */
void changestatus(EN_Network *net, int, StatType, double); /* Changes status of a link */
/* -------------- RULES.C --------------*/
void initrules(rules_t *rules); /* Initializes rule base */
void addrule(parser_data_t *par, char *); /* Adds rule to rule base */
int allocrules(EN_Project *pr); /* Allocates memory for rule */
int ruledata(EN_Project *pr); /* Processes rule input data */
int checkrules(EN_Project *pr, long); /* Checks all rules */
void freerules(EN_Project *pr); /* Frees rule base memory */
/* ------------- REPORT.C --------------*/
int writereport(EN_Project *pr); /* Writes formatted report */
void writelogo(EN_Project *pr); /* Writes program logo */
void writesummary(EN_Project *pr); /* Writes network summary */
void writehydstat(EN_Project *pr, int,double); /* Writes hydraulic status */
void writeenergy(EN_Project *pr); /* Writes energy usage */
int writeresults(EN_Project *pr); /* Writes node/link results */
void writeheader(EN_Project *pr, int,int); /* Writes heading on report */
void writeline(EN_Project *pr, char *); /* Writes line to report file */
void writerelerr(EN_Project *pr, int, double); /* Writes convergence error */
void writestatchange(EN_Project *pr, int,char,char); /* Writes link status change */
void writecontrolaction(EN_Project *pr, int, int); /* Writes control action taken*/
void writeruleaction(EN_Project *pr, int, char *); /* Writes rule action taken */
int writehydwarn(EN_Project *pr, int,double); /* Writes hydraulic warnings */
void writehyderr(EN_Project *pr, int); /* Writes hydraulic error msg.*/
int disconnected(EN_Project *pr); /* Checks for disconnections */
void marknodes(EN_Project *pr, int, int *, char *); /* Identifies connected nodes */
void getclosedlink(EN_Project *pr, int, char *); /* Finds a disconnecting link */
void writelimits(EN_Project *pr, int,int); /* Writes reporting limits */
int checklimits(report_options_t *rep, double *,int,int); /* Checks variable limits */
void writetime(EN_Project *pr, char *); /* Writes current clock time */
char *clocktime(char *, long); /* Converts time to hrs:min */
char *fillstr(char *, char, int); /* Fills string with character*/
int getnodetype(EN_Network *net, int); /* Determines node type */
/* --------- HYDRAUL.C -----------------*/
int openhyd(EN_Project *pr); /* Opens hydraulics solver */
/*** Updated 3/1/01 ***/
void inithyd(EN_Project *pr, int initFlags); /* Re-sets initial conditions */
int runhyd(EN_Project *pr, long *); /* Solves 1-period hydraulics */
int nexthyd(EN_Project *pr, long *); /* Moves to next time period */
void closehyd(EN_Project *pr); /* Closes hydraulics solver */
int allocmatrix(EN_Project *pr); /* Allocates matrix coeffs. */
void freematrix(EN_Project *pr); /* Frees matrix coeffs. */
void initlinkflow(EN_Project *pr, int, char, double); /* Initializes link flow */
void setlinkflow(EN_Project *pr, int, double); /* Sets link flow via headloss*/
void setlinkstatus(EN_Project *pr, int, char, StatType *, double *); /* Sets link status */
void setlinksetting(EN_Project *pr, int, double, StatType *, double *); /* Sets pump/valve setting */
void resistance(EN_Project *pr, int); /* Computes resistance coeff. */
void demands(EN_Project *pr); /* Computes current demands */
int controls(EN_Project *pr); /* Controls link settings */
long timestep(EN_Project *pr); /* Computes new time step */
int tanktimestep(EN_Project *pr, long *); /* Time till tanks fill/drain */
void controltimestep(EN_Project *pr, long *); /* Time till control action */
void ruletimestep(EN_Project *pr, long *); /* Time till rule action */
void addenergy(EN_Project *pr, long); /* Accumulates energy usage */
void getenergy(EN_Project *pr, int, double *, double *); /* Computes link energy use */
void tanklevels(EN_Project *pr, long); /* Computes new tank levels */
double tankvolume(EN_Project *pr, int,double); /* Finds tank vol. from grade */
double tankgrade(EN_Project *pr, int,double); /* Finds tank grade from vol. */
int netsolve(EN_Project *pr, int *,double *); /* Solves network equations */
int badvalve(EN_Project *pr, int); /* Checks for bad valve */
int valvestatus(EN_Project *pr); /* Updates valve status */
int linkstatus(EN_Project *pr); /* Updates link status */
StatType cvstatus(EN_Project *pr, StatType,double,double); /* Updates CV status */
StatType pumpstatus(EN_Project *pr, int,double); /* Updates pump status */
StatType prvstatus(EN_Project *pr, int,StatType,double,double,double); /* Updates PRV status */
StatType psvstatus(EN_Project *pr, int,StatType,double,double,double); /* Updates PSV status */
StatType fcvstatus(EN_Project *pr, int,StatType,double,double); /* Updates FCV status */
void tankstatus(EN_Project *pr, int,int,int); /* Checks if tank full/empty */
int pswitch(EN_Project *pr); /* Pressure switch controls */
double newflows(EN_Project *pr); /* Updates link flows */
void newcoeffs(EN_Project *pr); /* Computes matrix coeffs. */
void linkcoeffs(EN_Project *pr); /* Computes link coeffs. */
void nodecoeffs(EN_Project *pr); /* Computes node coeffs. */
void valvecoeffs(EN_Project *pr); /* Computes valve coeffs. */
void pipecoeff(EN_Project *pr, int); /* Computes pipe coeff. */
double DWcoeff(EN_Project *pr, int, double *); /* Computes D-W coeff. */
void pumpcoeff(EN_Project *pr, int); /* Computes pump coeff. */
/*** Updated 10/25/00 ***/
/*** Updated 12/29/00 ***/
void curvecoeff(EN_Project *pr, int,double,double *,double *); /* Computes curve coeffs. */
void gpvcoeff(EN_Project *pr, int iLink); /* Computes GPV coeff. */
void pbvcoeff(EN_Project *pr, int iLink); /* Computes PBV coeff. */
void tcvcoeff(EN_Project *pr, int iLink); /* Computes TCV coeff. */
void prvcoeff(EN_Project *pr, int iLink, int n1, int n2); /* Computes PRV coeff. */
void psvcoeff(EN_Project *pr, int iLink, int n1, int n2); /* Computes PSV coeff. */
void fcvcoeff(EN_Project *pr, int iLink, int n1, int n2); /* Computes FCV coeff. */
void emittercoeffs(EN_Project *pr); /* Computes emitter coeffs. */
double emitflowchange(EN_Project *pr, int); /* Computes new emitter flow */
/* ----------- SMATRIX.C ---------------*/
int createsparse(EN_Project *pr); /* Creates sparse matrix */
int allocsparse(EN_Project *pr); /* Allocates matrix memory */
void freesparse(EN_Project *pr); /* Frees matrix memory */
int buildlists(EN_Project *pr, int); /* Builds adjacency lists */
int paralink(EN_Project *pr, int, int, int); /* Checks for parallel links */
void xparalinks(EN_Project *pr); /* Removes parallel links */
void freelists(EN_Project *pr); /* Frees adjacency lists */
void countdegree(EN_Project *pr); /* Counts links at each node */
int reordernodes(EN_Project *pr); /* Finds a node re-ordering */
int mindegree(solver_t *s, int, int); /* Finds min. degree node */
int growlist(EN_Project *pr, int); /* Augments adjacency list */
int newlink(EN_Project *pr, Padjlist); /* Adds fill-ins for a node */
int linked(EN_Network *net, int, int); /* Checks if 2 nodes linked */
int addlink(EN_Network *net, int, int, int); /* Creates new fill-in */
int storesparse(EN_Project *pr, int); /* Stores sparse matrix */
int ordersparse(hydraulics_t *h, int); /* Orders matrix storage */
void transpose(int,int *,int *, /* Transposes sparse matrix */
int *,int *,int *,int *,int *);
int linsolve(solver_t *s, int); /* via Cholesky factorization */
/* ----------- QUALITY.C ---------------*/
int openqual(EN_Project *pr); /* Opens WQ solver system */
void initqual(EN_Project *pr); /* Initializes WQ solver */
int runqual(EN_Project *pr, long *); /* Gets current WQ results */
int nextqual(EN_Project *pr, long *); /* Updates WQ by hyd.timestep */
int stepqual(EN_Project *pr, long *); /* Updates WQ by WQ time step */
int closequal(EN_Project *pr); /* Closes WQ solver system */
int gethyd(EN_Project *pr, long *, long *); /* Gets next hyd. results */
char setReactflag(EN_Project *pr); /* Checks for reactive chem. */
void transport(EN_Project *pr, long); /* Transports mass in network */
void initsegs(EN_Project *pr); /* Initializes WQ segments */
void reorientsegs(EN_Project *pr); /* Re-orients WQ segments */
void updatesegs(EN_Project *pr, long); /* Updates quality in segments*/
void removesegs(EN_Project *pr, int); /* Removes a WQ segment */
void addseg(EN_Project *pr, int,double,double); /* Adds a WQ segment to pipe */
void accumulate(EN_Project *pr, long); /* Sums mass flow into node */
void updatenodes(EN_Project *pr, long); /* Updates WQ at nodes */
void sourceinput(EN_Project *pr, long); /* Computes source inputs */
void release(EN_Project *pr, long); /* Releases mass from nodes */
void updatetanks(EN_Project *pr, long); /* Updates WQ in tanks */
void updatesourcenodes(EN_Project *pr, long); /* Updates WQ at source nodes */
void tankmix1(EN_Project *pr, int, long); /* Complete mix tank model */
void tankmix2(EN_Project *pr, int, long); /* 2-compartment tank model */
void tankmix3(EN_Project *pr, int, long); /* FIFO tank model */
void tankmix4(EN_Project *pr, int, long); /* LIFO tank model */
double sourcequal(EN_Project *pr, Psource); /* Finds WQ input from source */
double avgqual(EN_Project *pr, int); /* Finds avg. quality in pipe */
void ratecoeffs(EN_Project *pr); /* Finds wall react. coeffs. */
double piperate(EN_Project *pr, int); /* Finds wall react. coeff. */
double pipereact(EN_Project *pr, int,double,double,long);/* Reacts water in a pipe */
double tankreact(EN_Project *pr, double,double,double,long); /* Reacts water in a tank */
double bulkrate(EN_Project *pr, double,double,double); /* Finds bulk reaction rate */
double wallrate(EN_Project *pr, double,double,double,double);/* Finds wall reaction rate */
/* ------------ OUTPUT.C ---------------*/
int savenetdata(EN_Project *pr); /* Saves basic data to file */
int savehyd(EN_Project *pr, long *); /* Saves hydraulic solution */
int savehydstep(EN_Project *pr, long *); /* Saves hydraulic timestep */
int saveenergy(EN_Project *pr); /* Saves energy usage */
int readhyd(EN_Project *pr, long *); /* Reads hydraulics from file */
int readhydstep(FILE *hydFile, long *); /* Reads time step from file */
int saveoutput(EN_Project *pr); /* Saves results to file */
int nodeoutput(EN_Project *pr, int, REAL4 *, double); /* Saves node results to file */
int linkoutput(EN_Project *pr, int, REAL4 *, double); /* Saves link results to file */
int savefinaloutput(EN_Project *pr); /* Finishes saving output */
int savetimestat(EN_Project *pr, REAL4 *, HdrType); /* Saves time stats to file */
int savenetreacts(EN_Project *pr, double, double,double, double);
/* Saves react. rates to file */
int saveepilog(EN_Project *pr); /* Saves output file epilog */
/* ------------ INPFILE.C --------------*/
int saveinpfile(EN_Project *pr, char *); /* Saves network to text file */
#endif

View File

@@ -36,6 +36,7 @@ unsigned int _enHash(char *str)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
retHash = hash % ENHASHTABLEMAXSIZE;
return retHash;
}
@@ -72,13 +73,54 @@ int ENHashTableInsert(ENHashTable *ht, char *key, int data)
return(1);
}
int ENHashTableFind(ENHashTable *ht, char *key)
/* Abel Heinsbroek: Added function to update the hash table value for a given key */
int ENHashTableUpdate(ENHashTable *ht, char *key, int new_data)
{
unsigned int i = _enHash(key);
ENHashEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) {
return(NOTFOUND);
}
entry = ht[i];
while (entry != NULL)
{
if ( strcmp(entry->key,key) == 0 ) {
entry->data = new_data;
return(1);
}
entry = entry->next;
}
return(NOTFOUND);
}
int ENHashTableDelete(ENHashTable *ht, char *key) {
unsigned int i = _enHash(key);
ENHashEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) {
return(NOTFOUND);
}
entry = ht[i];
while (entry != NULL)
{
if (strcmp(entry->key, key) == 0) {
entry->key = "";
return(1);
}
entry = entry->next;
}
return(NOTFOUND);
}
int ENHashTableFind(ENHashTable *ht, char *key)
{
unsigned int i = _enHash(key);
ENHashEntry *entry;
if ( i >= ENHASHTABLEMAXSIZE ) {
return(NOTFOUND);
}
entry = ht[i];
while (entry != NULL)
{

View File

@@ -24,5 +24,7 @@ int ENHashTableInsert(ENHashTable *, char *, int);
int ENHashTableFind(ENHashTable *, char *);
char *ENHashTableFindKey(ENHashTable *, char *);
void ENHashTableFree(ENHashTable *);
int ENHashTableUpdate(ENHashTable *ht, char *key, int new_data);
int ENHashTableDelete(ENHashTable *ht, char *key);
#endif
#endif

File diff suppressed because it is too large Load Diff

1371
src/inpfile.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

1361
src/input1.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

2028
src/input2.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

4090
src/input3.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,205 +1,209 @@
/* mempool.c
**
** A simple fast memory allocation package.
**
** By Steve Hill in Graphics Gems III, David Kirk (ed.),
** Academic Press, Boston, MA, 1992
**
** Modified by Lew Rossman, 8/13/94.
**
** AllocInit() - create an alloc pool, returns the old pool handle
** Alloc() - allocate memory
** AllocReset() - reset the current pool
** AllocSetPool() - set the current pool
** AllocFree() - free the memory used by the current pool.
**
*/
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include "mempool.h"
/*
** ALLOC_BLOCK_SIZE - adjust this size to suit your installation - it
** should be reasonably large otherwise you will be mallocing a lot.
*/
#define ALLOC_BLOCK_SIZE 64000 /*(62*1024)*/
/*
** alloc_hdr_t - Header for each block of memory.
*/
typedef struct alloc_hdr_s
{
struct alloc_hdr_s *next; /* Next Block */
char *block, /* Start of block */
*free, /* Next free in block */
*end; /* block + block size */
} alloc_hdr_t;
/*
** alloc_root_t - Header for the whole pool.
*/
typedef struct alloc_root_s
{
alloc_hdr_t *first, /* First header in pool */
*current; /* Current header */
} alloc_root_t;
/*
** root - Pointer to the current pool.
*/
static alloc_root_t *root;
/*
** AllocHdr()
**
** Private routine to allocate a header and memory block.
*/
static alloc_hdr_t *AllocHdr(void);
static alloc_hdr_t * AllocHdr()
{
alloc_hdr_t *hdr;
char *block;
block = (char *) malloc(ALLOC_BLOCK_SIZE);
hdr = (alloc_hdr_t *) malloc(sizeof(alloc_hdr_t));
if (hdr == NULL || block == NULL) return(NULL);
hdr->block = block;
hdr->free = block;
hdr->next = NULL;
hdr->end = block + ALLOC_BLOCK_SIZE;
return(hdr);
}
/*
** AllocInit()
**
** Create a new memory pool with one block.
** Returns pointer to the new pool.
*/
DLLEXPORT alloc_handle_t * AllocInit()
{
alloc_handle_t *newpool;
root = (alloc_root_t *) malloc(sizeof(alloc_root_t));
if (root == NULL) return(NULL);
if ( (root->first = AllocHdr()) == NULL) return(NULL);
root->current = root->first;
newpool = (alloc_handle_t *) root;
return(newpool);
}
/*
** Alloc()
**
** Use as a direct replacement for malloc(). Allocates
** memory from the current pool.
*/
DLLEXPORT char *Alloc(long size)
{
alloc_hdr_t *hdr = root->current;
char *ptr;
/*
** Align to 4 byte boundary - should be ok for most machines.
** Change this if your machine has weird alignment requirements.
*/
size = (size + 3) & 0xfffffffc;
ptr = hdr->free;
hdr->free += size;
/* Check if the current block is exhausted. */
if (hdr->free >= hdr->end)
{
/* Is the next block already allocated? */
if (hdr->next != NULL)
{
/* re-use block */
hdr->next->free = hdr->next->block;
root->current = hdr->next;
}
else
{
/* extend the pool with a new block */
if ( (hdr->next = AllocHdr()) == NULL) return(NULL);
root->current = hdr->next;
}
/* set ptr to the first location in the next block */
ptr = root->current->free;
root->current->free += size;
}
/* Return pointer to allocated memory. */
return(ptr);
}
/*
** AllocSetPool()
**
** Change the current pool. Return the old pool.
*/
DLLEXPORT alloc_handle_t * AllocSetPool(alloc_handle_t *newpool)
{
alloc_handle_t *old = (alloc_handle_t *) root;
root = (alloc_root_t *) newpool;
return(old);
}
/*
** AllocReset()
**
** Reset the current pool for re-use. No memory is freed,
** so this is very fast.
*/
DLLEXPORT void AllocReset()
{
root->current = root->first;
root->current->free = root->current->block;
}
/*
** AllocFreePool()
**
** Free the memory used by the current pool.
** Don't use where AllocReset() could be used.
*/
DLLEXPORT void AllocFreePool()
{
alloc_hdr_t *tmp,
*hdr = root->first;
while (hdr != NULL)
{
tmp = hdr->next;
free((char *) hdr->block);
free((char *) hdr);
hdr = tmp;
}
free((char *) root);
root = NULL;
}
/* mempool.c
**
** A simple fast memory allocation package.
**
** By Steve Hill in Graphics Gems III, David Kirk (ed.),
** Academic Press, Boston, MA, 1992
**
** Modified by Lew Rossman, 8/13/94.
**
** AllocInit() - create an alloc pool, returns the old pool handle
** Alloc() - allocate memory
** AllocReset() - reset the current pool
** AllocSetPool() - set the current pool
** AllocFree() - free the memory used by the current pool.
**
*/
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include "mempool.h"
/*
** ALLOC_BLOCK_SIZE - adjust this size to suit your installation - it
** should be reasonably large otherwise you will be mallocing a lot.
*/
#define ALLOC_BLOCK_SIZE 64000 /*(62*1024)*/
/*
** alloc_hdr_t - Header for each block of memory.
*/
typedef struct alloc_hdr_s
{
struct alloc_hdr_s *next; /* Next Block */
char *block, /* Start of block */
*free, /* Next free in block */
*end; /* block + block size */
} alloc_hdr_t;
/*
** alloc_root_t - Header for the whole pool.
*/
typedef struct alloc_root_s
{
alloc_hdr_t *first, /* First header in pool */
*current; /* Current header */
} alloc_root_t;
/*
** root - Pointer to the current pool.
*/
static alloc_root_t *root;
/*
** AllocHdr()
**
** Private routine to allocate a header and memory block.
*/
static alloc_hdr_t *AllocHdr(void);
static alloc_hdr_t * AllocHdr()
{
alloc_hdr_t *hdr;
char *block;
block = (char *) malloc(ALLOC_BLOCK_SIZE);
hdr = (alloc_hdr_t *) malloc(sizeof(alloc_hdr_t));
if (hdr == NULL || block == NULL) return(NULL);
hdr->block = block;
hdr->free = block;
hdr->next = NULL;
hdr->end = block + ALLOC_BLOCK_SIZE;
return(hdr);
}
/*
** AllocInit()
**
** Create a new memory pool with one block.
** Returns pointer to the new pool.
*/
DLLEXPORT alloc_handle_t * AllocInit()
{
alloc_handle_t *newpool;
root = (alloc_root_t *) malloc(sizeof(alloc_root_t));
if (root == NULL) {
return(NULL);
}
if ( (root->first = AllocHdr()) == NULL) {
return(NULL);
}
root->current = root->first;
newpool = (alloc_handle_t *) root;
return(newpool);
}
/*
** Alloc()
**
** Use as a direct replacement for malloc(). Allocates
** memory from the current pool.
*/
DLLEXPORT char *Alloc(long size)
{
alloc_hdr_t *hdr = root->current;
char *ptr;
/*
** Align to 4 byte boundary - should be ok for most machines.
** Change this if your machine has weird alignment requirements.
*/
size = (size + 3) & 0xfffffffc;
ptr = hdr->free;
hdr->free += size;
/* Check if the current block is exhausted. */
if (hdr->free >= hdr->end)
{
/* Is the next block already allocated? */
if (hdr->next != NULL)
{
/* re-use block */
hdr->next->free = hdr->next->block;
root->current = hdr->next;
}
else
{
/* extend the pool with a new block */
if ( (hdr->next = AllocHdr()) == NULL) return(NULL);
root->current = hdr->next;
}
/* set ptr to the first location in the next block */
ptr = root->current->free;
root->current->free += size;
}
/* Return pointer to allocated memory. */
return(ptr);
}
/*
** AllocSetPool()
**
** Change the current pool. Return the old pool.
*/
DLLEXPORT alloc_handle_t * AllocSetPool(alloc_handle_t *newpool)
{
alloc_handle_t *old = (alloc_handle_t *) root;
root = (alloc_root_t *) newpool;
return(old);
}
/*
** AllocReset()
**
** Reset the current pool for re-use. No memory is freed,
** so this is very fast.
*/
DLLEXPORT void AllocReset()
{
root->current = root->first;
root->current->free = root->current->block;
}
/*
** AllocFreePool()
**
** Free the memory used by the current pool.
** Don't use where AllocReset() could be used.
*/
DLLEXPORT void AllocFreePool()
{
alloc_hdr_t *tmp,
*hdr = root->first;
while (hdr != NULL)
{
tmp = hdr->next;
free((char *) hdr->block);
free((char *) hdr);
hdr = tmp;
}
free((char *) root);
root = NULL;
}

View File

@@ -15,7 +15,7 @@
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
@@ -34,10 +34,10 @@ typedef struct
long dummy;
} alloc_handle_t;
DLLEXPORT alloc_handle_t *AllocInit(void);
DLLEXPORT char *Alloc(long);
DLLEXPORT alloc_handle_t *AllocSetPool(alloc_handle_t *);
DLLEXPORT void AllocReset(void);
DLLEXPORT void AllocFreePool(void);
alloc_handle_t *AllocInit(void);
char *Alloc(long);
alloc_handle_t *AllocSetPool(alloc_handle_t *);
void AllocReset(void);
void AllocFreePool(void);
#endif

1546
src/output.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

3638
src/quality.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

2595
src/report.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

2573
src/rules.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

1020
src/text.h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,211 +1,16 @@
/*
************************************************************************
Global Variables for EPANET Program
VERSION: 2.00
DATE: 5/8/00
6/24/02
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
************************************************************************
*/
#ifndef VARS_H
#define VARS_H
#include <stdio.h>
#include "hash.h"
EXTERN FILE *InFile, /* Input file pointer */
*OutFile, /* Output file pointer */
*RptFile, /* Report file pointer */
*HydFile, /* Hydraulics file pointer */
*TmpOutFile; /* Temporary file handle */
EXTERN long HydOffset, /* Hydraulics file byte offset */
OutOffset1, /* 1st output file byte offset */
OutOffset2; /* 2nd output file byte offset */
EXTERN char Msg[MAXMSG+1], /* Text of output message */
InpFname[MAXFNAME+1], /* Input file name */
Rpt1Fname[MAXFNAME+1], /* Primary report file name */
Rpt2Fname[MAXFNAME+1], /* Secondary report file name */
HydFname[MAXFNAME+1], /* Hydraulics file name */
OutFname[MAXFNAME+1], /* Binary output file name */
MapFname[MAXFNAME+1], /* Map file name */
TmpFname[MAXFNAME+1], /* Temporary file name */ //(2.00.12 - LR)
TmpDir[MAXFNAME+1], /* Temporary directory name */ //(2.00.12 - LR)
Title[MAXTITLE][MAXMSG+1], /* Problem title */
ChemName[MAXID+1], /* Name of chemical */
ChemUnits[MAXID+1], /* Units of chemical */
DefPatID[MAXID+1], /* Default demand pattern ID */
/*** Updated 6/24/02 ***/
Atime[13], /* Clock time (hrs:min:sec) */
Outflag, /* Output file flag */ //(2.00.12 - LR)
Hydflag, /* Hydraulics flag */
Qualflag, /* Water quality flag */
Reactflag, /* Reaction indicator */ //(2.00.12 - LR)
Unitsflag, /* Unit system flag */
Flowflag, /* Flow units flag */
Pressflag, /* Pressure units flag */
Formflag, /* Hydraulic formula flag */
Rptflag, /* Report flag */
Summaryflag, /* Report summary flag */
Messageflag, /* Error/warning message flag */
Statflag, /* Status report flag */
Energyflag, /* Energy report flag */
Nodeflag, /* Node report flag */
Linkflag, /* Link report flag */
Tstatflag, /* Time statistics flag */
Warnflag, /* Warning flag */
Openflag, /* Input processed flag */
OpenHflag, /* Hydraul. system opened flag */
SaveHflag, /* Hydraul. results saved flag */
OpenQflag, /* Quality system opened flag */
SaveQflag, /* Quality results saved flag */
Saveflag, /* General purpose save flag */
Coordflag; /* Load coordinates flag */
EXTERN int MaxNodes, /* Node count from input file */
MaxLinks, /* Link count from input file */
MaxJuncs, /* Junction count */
MaxPipes, /* Pipe count */
MaxTanks, /* Tank count */
MaxPumps, /* Pump count */
MaxValves, /* Valve count */
MaxControls, /* Control count */
MaxRules, /* Rule count */
MaxPats, /* Pattern count */
MaxCurves, /* Curve count */
Nnodes, /* Number of network nodes */
Ntanks, /* Number of tanks */
Njuncs, /* Number of junction nodes */
Nlinks, /* Number of network links */
Npipes, /* Number of pipes */
Npumps, /* Number of pumps */
Nvalves, /* Number of valves */
Ncontrols, /* Number of simple controls */
Nrules, /* Number of control rules */
Npats, /* Number of time patterns */
Ncurves, /* Number of data curves */
Nperiods, /* Number of reporting periods */
Ncoeffs, /* Number of non-0 matrix coeffs*/
DefPat, /* Default demand pattern */
Epat, /* Energy cost time pattern */
MaxIter, /* Max. hydraulic trials */
ExtraIter, /* Extra hydraulic trials */
TraceNode, /* Source node for flow tracing */
PageSize, /* Lines/page in output report */
CheckFreq, /* Hydraulics solver parameter */
MaxCheck; /* Hydraulics solver parameter */
EXTERN double Ucf[MAXVAR], /* Unit conversion factors */
Ctol, /* Water quality tolerance */
Htol, /* Hydraulic head tolerance */
Qtol, /* Flow rate tolerance */
RQtol, /* Flow resistance tolerance */
Hexp, /* Exponent in headloss formula */
Qexp, /* Exponent in orifice formula */
Dmult, /* Demand multiplier */
Hacc, /* Hydraulics solution accuracy */
DampLimit, /* Solution damping threshold */ //(2.00.12 - LR)
BulkOrder, /* Bulk flow reaction order */
WallOrder, /* Pipe wall reaction order */
TankOrder, /* Tank reaction order */
Kbulk, /* Global bulk reaction coeff. */
Kwall, /* Global wall reaction coeff. */
Climit, /* Limiting potential quality */
Rfactor, /* Roughness-reaction factor */
Diffus, /* Diffusivity (sq ft/sec) */
Viscos, /* Kin. viscosity (sq ft/sec) */
SpGrav, /* Specific gravity */
Ecost, /* Base energy cost per kwh */
Dcost, /* Energy demand charge/kw/day */
Epump, /* Global pump efficiency */
Emax, /* Peak energy usage */
Dsystem, /* Total system demand */
Wbulk, /* Avg. bulk reaction rate */
Wwall, /* Avg. wall reaction rate */
Wtank, /* Avg. tank reaction rate */
Wsource; /* Avg. mass inflow */
EXTERN long Tstart, /* Starting time of day (sec) */
Hstep, /* Nominal hyd. time step (sec) */
Qstep, /* Quality time step (sec) */
Pstep, /* Time pattern time step (sec) */
Pstart, /* Starting pattern time (sec) */
Rstep, /* Reporting time step (sec) */
Rstart, /* Time when reporting starts */
Rtime, /* Next reporting time */
Htime, /* Current hyd. time (sec) */
Qtime, /* Current quality time (sec) */
Hydstep, /* Actual hydraulic time step */
Rulestep, /* Rule evaluation time step */
Dur; /* Duration of simulation (sec) */
EXTERN SField Field[MAXVAR]; /* Output reporting fields */
/* Array pointers not allocated and freed in same routine */
EXTERN char *LinkStatus, /* Link status */
*OldStat; /* Previous link/tank status */
EXTERN double *NodeDemand, /* Node actual demand */
*NodeQual, /* Node actual quality */
*E, /* Emitter flows */
*LinkSetting, /* Link settings */
*Q, /* Link flows */
*PipeRateCoeff, /* Pipe reaction rate */
*X, /* General purpose array */
*TempQual; /* General purpose array for water quality */
EXTERN double *NodeHead; /* Node heads */
EXTERN double *QTankVolumes;
EXTERN double *QLinkFlow;
EXTERN STmplist *Patlist; /* Temporary time pattern list */
EXTERN STmplist *Curvelist; /* Temporary list of curves */
EXTERN Spattern *Pattern; /* Time patterns */
EXTERN Scurve *Curve; /* Curve data */
EXTERN Scoord *Coord; /* Coordinate data */
EXTERN Snode *Node; /* Node data */
EXTERN Slink *Link; /* Link data */
EXTERN Stank *Tank; /* Tank data */
EXTERN Spump *Pump; /* Pump data */
EXTERN Svalve *Valve; /* Valve data */
EXTERN Scontrol *Control; /* Control data */
EXTERN ENHashTable *NodeHashTable, *LinkHashTable; /* Hash tables for ID labels */
EXTERN Padjlist *Adjlist; /* Node adjacency lists */
EXTERN double _relativeError;
EXTERN int _iterations; /* Info about hydraulic solution */
/*
** NOTE: Hydraulic analysis of the pipe network at a given point in time
** is done by repeatedly solving a linearized version of the
** equations for conservation of flow & energy:
**
** A*H = F
**
** where H = vector of heads (unknowns) at each node,
** F = vector of right-hand side coeffs.
** A = square matrix of coeffs.
** and both A and F are updated at each iteration until there is
** negligible change in pipe flows.
**
** Each row (or column) of A corresponds to a junction in the pipe
** network. Each link (pipe, pump or valve) in the network has a
** non-zero entry in the row-column of A that corresponds to its
** end points. This results in A being symmetric and very sparse.
** The following arrays are used to efficiently manage this sparsity:
*/
EXTERN double *Aii, /* Diagonal coeffs. of A */
*Aij, /* Non-zero, off-diagonal coeffs. of A */
*F; /* Right hand side coeffs. */
EXTERN double *P, /* Inverse headloss derivatives */
*Y; /* Flow correction factors */
EXTERN int *Order, /* Node-to-row of A */
*Row, /* Row-to-node of A */
*Ndx; /* Index of link's coeff. in Aij */
/*
** The following arrays store the positions of the non-zero coeffs.
** of the lower triangular portion of A whose values are stored in Aij:
*/
EXTERN int *XLNZ, /* Start position of each column in NZSUB */
*NZSUB, /* Row index of each coeff. in each column */
*LNZ; /* Position of each coeff. in Aij array */
#endif
/*
************************************************************************
Global Variables for EPANET Program
************************************************************************
*/
#ifndef VARS_H
#define VARS_H
#include <stdio.h>
#include "hash.h"
// this single global variable is used only when the library is called in "legacy mode"
// with the 2.1-style API.
EXTERN EN_Project *_defaultModel;
#endif