Commit the EPANET2.00.12 to trunk, the changes are summarized at \EPANET\BASE\trunk\doc\changes.txt.

git-svn-id: https://epanet.svn.sourceforge.net/svnroot/epanet/BASE/trunk@95 c320cabd-cc23-0410-96d8-e60fbf53ed7f
This commit is contained in:
Feng Shang
2008-03-06 20:06:03 +00:00
parent 48d806d9da
commit c38b8d0ac8
40 changed files with 18221 additions and 18252 deletions

270
src/enumstxt.h Normal file → Executable file
View File

@@ -1,135 +1,135 @@
/*
***********************************************************************
ENUMSTXT.H -- Text strings for enumerated data types in EPANET
VERSION: 2.00
DATE: 5/8/00
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
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};
char *LogoTxt[] = {LOGO1,LOGO2,LOGO3,LOGO4,LOGO5,LOGO6,NULL};
/*
***********************************************************************
ENUMSTXT.H -- Text strings for enumerated data types in EPANET
VERSION: 2.00
DATE: 5/8/00
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
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};
char *LogoTxt[] = {LOGO1,LOGO2,LOGO3,LOGO4,LOGO5,LOGO6,NULL};

6246
src/epanet.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

562
src/funcs.h Normal file → Executable file
View File

@@ -1,281 +1,281 @@
/*
**************************************************************************
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.
*/
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 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 */
/*
**************************************************************************
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.
*/
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 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 */

220
src/hash.c Normal file → Executable file
View File

@@ -1,110 +1,110 @@
/*-----------------------------------------------------------------------------
** hash.c
**
** Implementation of a simple Hash Table for string storage & retrieval
**
** Written by L. Rossman
** Last Updated on 6/19/03
**
** The hash table data structure (HTable) is defined in "hash.h".
** Interface Functions:
** HTcreate() - creates a hash table
** HTinsert() - inserts a string & its index value into a hash table
** HTfind() - retrieves the index value of a string from a table
** HTfree() - frees a hash table
**
*********************************************************************
** NOTE: This is a modified version of the original HASH.C module.
*********************************************************************
*/
#include <malloc.h>
#include <string.h>
#include "hash.h"
/* Use Fletcher's checksum to compute 2-byte hash of string */
unsigned int hash(char *str)
{
unsigned int sum1= 0, check1;
unsigned long sum2= 0L;
while( '\0' != *str )
{
sum1 += (*str);
str++;
if ( 255 <= sum1 ) sum1 -= 255;
sum2 += sum1;
}
check1= sum2;
check1 %= 255;
check1= 255 - (sum1+check1) % 255;
sum1= 255 - (sum1+check1) % 255;
return( ( ( check1 << 8 ) | sum1 ) % HTMAXSIZE);
}
HTtable *HTcreate()
{
int i;
HTtable *ht = (HTtable *) calloc(HTMAXSIZE, sizeof(HTtable));
if (ht != NULL) for (i=0; i<HTMAXSIZE; i++) ht[i] = NULL;
return(ht);
}
int HTinsert(HTtable *ht, char *key, int data)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(0);
entry = (struct HTentry *) malloc(sizeof(struct HTentry));
if (entry == NULL) return(0);
entry->key = key;
entry->data = data;
entry->next = ht[i];
ht[i] = entry;
return(1);
}
int HTfind(HTtable *ht, char *key)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(NOTFOUND);
entry = ht[i];
while (entry != NULL)
{
if ( strcmp(entry->key,key) == 0 ) return(entry->data);
entry = entry->next;
}
return(NOTFOUND);
}
char *HTfindKey(HTtable *ht, char *key)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(NULL);
entry = ht[i];
while (entry != NULL)
{
if ( strcmp(entry->key,key) == 0 ) return(entry->key);
entry = entry->next;
}
return(NULL);
}
void HTfree(HTtable *ht)
{
struct HTentry *entry,
*nextentry;
int i;
for (i=0; i<HTMAXSIZE; i++)
{
entry = ht[i];
while (entry != NULL)
{
nextentry = entry->next;
free(entry);
entry = nextentry;
}
}
free(ht);
}
/*-----------------------------------------------------------------------------
** hash.c
**
** Implementation of a simple Hash Table for string storage & retrieval
**
** Written by L. Rossman
** Last Updated on 6/19/03
**
** The hash table data structure (HTable) is defined in "hash.h".
** Interface Functions:
** HTcreate() - creates a hash table
** HTinsert() - inserts a string & its index value into a hash table
** HTfind() - retrieves the index value of a string from a table
** HTfree() - frees a hash table
**
*********************************************************************
** NOTE: This is a modified version of the original HASH.C module.
*********************************************************************
*/
#include <malloc.h>
#include <string.h>
#include "hash.h"
/* Use Fletcher's checksum to compute 2-byte hash of string */
unsigned int hash(char *str)
{
unsigned int sum1= 0, check1;
unsigned long sum2= 0L;
while( '\0' != *str )
{
sum1 += (*str);
str++;
if ( 255 <= sum1 ) sum1 -= 255;
sum2 += sum1;
}
check1= sum2;
check1 %= 255;
check1= 255 - (sum1+check1) % 255;
sum1= 255 - (sum1+check1) % 255;
return( ( ( check1 << 8 ) | sum1 ) % HTMAXSIZE);
}
HTtable *HTcreate()
{
int i;
HTtable *ht = (HTtable *) calloc(HTMAXSIZE, sizeof(HTtable));
if (ht != NULL) for (i=0; i<HTMAXSIZE; i++) ht[i] = NULL;
return(ht);
}
int HTinsert(HTtable *ht, char *key, int data)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(0);
entry = (struct HTentry *) malloc(sizeof(struct HTentry));
if (entry == NULL) return(0);
entry->key = key;
entry->data = data;
entry->next = ht[i];
ht[i] = entry;
return(1);
}
int HTfind(HTtable *ht, char *key)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(NOTFOUND);
entry = ht[i];
while (entry != NULL)
{
if ( strcmp(entry->key,key) == 0 ) return(entry->data);
entry = entry->next;
}
return(NOTFOUND);
}
char *HTfindKey(HTtable *ht, char *key)
{
unsigned int i = hash(key);
struct HTentry *entry;
if ( i >= HTMAXSIZE ) return(NULL);
entry = ht[i];
while (entry != NULL)
{
if ( strcmp(entry->key,key) == 0 ) return(entry->key);
entry = entry->next;
}
return(NULL);
}
void HTfree(HTtable *ht)
{
struct HTentry *entry,
*nextentry;
int i;
for (i=0; i<HTMAXSIZE; i++)
{
entry = ht[i];
while (entry != NULL)
{
nextentry = entry->next;
free(entry);
entry = nextentry;
}
}
free(ht);
}

48
src/hash.h Normal file → Executable file
View File

@@ -1,24 +1,24 @@
/* HASH.H
**
** Header file for Hash Table module HASH.C
**
*/
#define HTMAXSIZE 1999
#define NOTFOUND 0
struct HTentry
{
char *key;
int data;
struct HTentry *next;
};
typedef struct HTentry *HTtable;
HTtable *HTcreate(void);
int HTinsert(HTtable *, char *, int);
int HTfind(HTtable *, char *);
char *HTfindKey(HTtable *, char *);
void HTfree(HTtable *);
/* HASH.H
**
** Header file for Hash Table module HASH.C
**
*/
#define HTMAXSIZE 1999
#define NOTFOUND 0
struct HTentry
{
char *key;
int data;
struct HTentry *next;
};
typedef struct HTentry *HTtable;
HTtable *HTcreate(void);
int HTinsert(HTtable *, char *, int);
int HTfind(HTtable *, char *);
char *HTfindKey(HTtable *, char *);
void HTfree(HTtable *);

4972
src/hydraul.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1242
src/inpfile.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1278
src/input1.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1932
src/input2.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

3726
src/input3.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

408
src/mempool.c Normal file → Executable file
View File

@@ -1,204 +1,204 @@
/* 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>
#include <malloc.h>
#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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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>
#include <malloc.h>
#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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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;
}

38
src/mempool.h Normal file → Executable file
View File

@@ -1,19 +1,19 @@
/*
** mempool.h
**
** Header for mempool.c
**
** The type alloc_handle_t provides an opaque reference to the
** alloc pool - only the alloc routines know its structure.
*/
typedef struct
{
long dummy;
} alloc_handle_t;
alloc_handle_t *AllocInit(void);
char *Alloc(long);
alloc_handle_t *AllocSetPool(alloc_handle_t *);
void AllocReset(void);
void AllocFreePool(void);
/*
** mempool.h
**
** Header for mempool.c
**
** The type alloc_handle_t provides an opaque reference to the
** alloc pool - only the alloc routines know its structure.
*/
typedef struct
{
long dummy;
} alloc_handle_t;
alloc_handle_t *AllocInit(void);
char *Alloc(long);
alloc_handle_t *AllocSetPool(alloc_handle_t *);
void AllocReset(void);
void AllocFreePool(void);

1394
src/output.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

3304
src/quality.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

2444
src/report.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1934
src/rules.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1500
src/smatrix.c Normal file → Executable file

File diff suppressed because it is too large Load Diff

1060
src/text.h Normal file → Executable file

File diff suppressed because it is too large Load Diff

448
src/toolkit.h Normal file → Executable file
View File

@@ -1,224 +1,224 @@
/*
*******************************************************************
TOOLKIT.H - Prototypes for EPANET Functions Exported to DLL Toolkit
VERSION: 2.00
DATE: 5/8/00
10/25/00
3/1/01
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
*******************************************************************
*/
// --- Define DLLEXPORT
#ifdef DLL
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport) __stdcall
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif
#else
#ifdef __cplusplus
#define DLLEXPORT extern "C"
#else
#define DLLEXPORT
#endif
#endif
// --- Define the EPANET toolkit constants
#define EN_ELEVATION 0 /* Node parameters */
#define EN_BASEDEMAND 1
#define EN_PATTERN 2
#define EN_EMITTER 3
#define EN_INITQUAL 4
#define EN_SOURCEQUAL 5
#define EN_SOURCEPAT 6
#define EN_SOURCETYPE 7
#define EN_TANKLEVEL 8
#define EN_DEMAND 9
#define EN_HEAD 10
#define EN_PRESSURE 11
#define EN_QUALITY 12
#define EN_SOURCEMASS 13
#define EN_INITVOLUME 14
#define EN_MIXMODEL 15
#define EN_MIXZONEVOL 16
#define EN_TANKDIAM 17
#define EN_MINVOLUME 18
#define EN_VOLCURVE 19
#define EN_MINLEVEL 20
#define EN_MAXLEVEL 21
#define EN_MIXFRACTION 22
#define EN_TANK_KBULK 23
#define EN_DIAMETER 0 /* Link parameters */
#define EN_LENGTH 1
#define EN_ROUGHNESS 2
#define EN_MINORLOSS 3
#define EN_INITSTATUS 4
#define EN_INITSETTING 5
#define EN_KBULK 6
#define EN_KWALL 7
#define EN_FLOW 8
#define EN_VELOCITY 9
#define EN_HEADLOSS 10
#define EN_STATUS 11
#define EN_SETTING 12
#define EN_ENERGY 13
#define EN_DURATION 0 /* Time parameters */
#define EN_HYDSTEP 1
#define EN_QUALSTEP 2
#define EN_PATTERNSTEP 3
#define EN_PATTERNSTART 4
#define EN_REPORTSTEP 5
#define EN_REPORTSTART 6
#define EN_RULESTEP 7
#define EN_STATISTIC 8
#define EN_PERIODS 9
#define EN_NODECOUNT 0 /* Component counts */
#define EN_TANKCOUNT 1
#define EN_LINKCOUNT 2
#define EN_PATCOUNT 3
#define EN_CURVECOUNT 4
#define EN_CONTROLCOUNT 5
#define EN_JUNCTION 0 /* Node types */
#define EN_RESERVOIR 1
#define EN_TANK 2
#define EN_CVPIPE 0 /* Link types. */
#define EN_PIPE 1 /* See LinkType in TYPES.H */
#define EN_PUMP 2
#define EN_PRV 3
#define EN_PSV 4
#define EN_PBV 5
#define EN_FCV 6
#define EN_TCV 7
#define EN_GPV 8
#define EN_NONE 0 /* Quality analysis types. */
#define EN_CHEM 1 /* See QualType in TYPES.H */
#define EN_AGE 2
#define EN_TRACE 3
#define EN_CONCEN 0 /* Source quality types. */
#define EN_MASS 1 /* See SourceType in TYPES.H. */
#define EN_SETPOINT 2
#define EN_FLOWPACED 3
#define EN_CFS 0 /* Flow units types. */
#define EN_GPM 1 /* See FlowUnitsType */
#define EN_MGD 2 /* in TYPES.H. */
#define EN_IMGD 3
#define EN_AFD 4
#define EN_LPS 5
#define EN_LPM 6
#define EN_MLD 7
#define EN_CMH 8
#define EN_CMD 9
#define EN_TRIALS 0 /* Misc. options */
#define EN_ACCURACY 1
#define EN_TOLERANCE 2
#define EN_EMITEXPON 3
#define EN_DEMANDMULT 4
#define EN_LOWLEVEL 0 /* Control types. */
#define EN_HILEVEL 1 /* See ControlType */
#define EN_TIMER 2 /* in TYPES.H. */
#define EN_TIMEOFDAY 3
#define EN_AVERAGE 1 /* Time statistic types. */
#define EN_MINIMUM 2 /* See TstatType in TYPES.H */
#define EN_MAXIMUM 3
#define EN_RANGE 4
#define EN_MIX1 0 /* Tank mixing models */
#define EN_MIX2 1
#define EN_FIFO 2
#define EN_LIFO 3
#define EN_NOSAVE 0 /* Save-results-to-file flag */
#define EN_SAVE 1
#define EN_INITFLOW 10 /* Re-initialize flows flag */
// --- Declare the EPANET toolkit functions
int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *));
int DLLEXPORT ENopen(char *, char *, char *);
int DLLEXPORT ENsaveinpfile(char *);
int DLLEXPORT ENclose(void);
int DLLEXPORT ENsolveH(void);
int DLLEXPORT ENsaveH(void);
int DLLEXPORT ENopenH(void);
int DLLEXPORT ENinitH(int);
int DLLEXPORT ENrunH(long *);
int DLLEXPORT ENnextH(long *);
int DLLEXPORT ENcloseH(void);
int DLLEXPORT ENsavehydfile(char *);
int DLLEXPORT ENusehydfile(char *);
int DLLEXPORT ENsolveQ(void);
int DLLEXPORT ENopenQ(void);
int DLLEXPORT ENinitQ(int);
int DLLEXPORT ENrunQ(long *);
int DLLEXPORT ENnextQ(long *);
int DLLEXPORT ENstepQ(long *);
int DLLEXPORT ENcloseQ(void);
int DLLEXPORT ENwriteline(char *);
int DLLEXPORT ENreport(void);
int DLLEXPORT ENresetreport(void);
int DLLEXPORT ENsetreport(char *);
int DLLEXPORT ENgetcontrol(int, int *, int *, float *,
int *, float *);
int DLLEXPORT ENgetcount(int, int *);
int DLLEXPORT ENgetoption(int, float *);
int DLLEXPORT ENgettimeparam(int, long *);
int DLLEXPORT ENgetflowunits(int *);
int DLLEXPORT ENgetpatternindex(char *, int *);
int DLLEXPORT ENgetpatternid(int, char *);
int DLLEXPORT ENgetpatternlen(int, int *);
int DLLEXPORT ENgetpatternvalue(int, int, float *);
int DLLEXPORT ENgetqualtype(int *, int *);
int DLLEXPORT ENgeterror(int, char *, int);
int DLLEXPORT ENgetnodeindex(char *, int *);
int DLLEXPORT ENgetnodeid(int, char *);
int DLLEXPORT ENgetnodetype(int, int *);
int DLLEXPORT ENgetnodevalue(int, int, float *);
int DLLEXPORT ENgetlinkindex(char *, int *);
int DLLEXPORT ENgetlinkid(int, char *);
int DLLEXPORT ENgetlinktype(int, int *);
int DLLEXPORT ENgetlinknodes(int, int *, int *);
int DLLEXPORT ENgetlinkvalue(int, int, float *);
int DLLEXPORT ENgetversion(int *);
int DLLEXPORT ENsetcontrol(int, int, int, float, int, float);
int DLLEXPORT ENsetnodevalue(int, int, float);
int DLLEXPORT ENsetlinkvalue(int, int, float);
int DLLEXPORT ENaddpattern(char *);
int DLLEXPORT ENsetpattern(int, float *, int);
int DLLEXPORT ENsetpatternvalue(int, int, float);
int DLLEXPORT ENsettimeparam(int, long);
int DLLEXPORT ENsetoption(int, float);
int DLLEXPORT ENsetstatusreport(int);
int DLLEXPORT ENsetqualtype(int, char *, char *, char *);
/*
*******************************************************************
TOOLKIT.H - Prototypes for EPANET Functions Exported to DLL Toolkit
VERSION: 2.00
DATE: 5/8/00
10/25/00
3/1/01
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
*******************************************************************
*/
// --- Define DLLEXPORT
#ifdef DLL
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport) __stdcall
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif
#else
#ifdef __cplusplus
#define DLLEXPORT extern "C"
#else
#define DLLEXPORT
#endif
#endif
// --- Define the EPANET toolkit constants
#define EN_ELEVATION 0 /* Node parameters */
#define EN_BASEDEMAND 1
#define EN_PATTERN 2
#define EN_EMITTER 3
#define EN_INITQUAL 4
#define EN_SOURCEQUAL 5
#define EN_SOURCEPAT 6
#define EN_SOURCETYPE 7
#define EN_TANKLEVEL 8
#define EN_DEMAND 9
#define EN_HEAD 10
#define EN_PRESSURE 11
#define EN_QUALITY 12
#define EN_SOURCEMASS 13
#define EN_INITVOLUME 14
#define EN_MIXMODEL 15
#define EN_MIXZONEVOL 16
#define EN_TANKDIAM 17
#define EN_MINVOLUME 18
#define EN_VOLCURVE 19
#define EN_MINLEVEL 20
#define EN_MAXLEVEL 21
#define EN_MIXFRACTION 22
#define EN_TANK_KBULK 23
#define EN_DIAMETER 0 /* Link parameters */
#define EN_LENGTH 1
#define EN_ROUGHNESS 2
#define EN_MINORLOSS 3
#define EN_INITSTATUS 4
#define EN_INITSETTING 5
#define EN_KBULK 6
#define EN_KWALL 7
#define EN_FLOW 8
#define EN_VELOCITY 9
#define EN_HEADLOSS 10
#define EN_STATUS 11
#define EN_SETTING 12
#define EN_ENERGY 13
#define EN_DURATION 0 /* Time parameters */
#define EN_HYDSTEP 1
#define EN_QUALSTEP 2
#define EN_PATTERNSTEP 3
#define EN_PATTERNSTART 4
#define EN_REPORTSTEP 5
#define EN_REPORTSTART 6
#define EN_RULESTEP 7
#define EN_STATISTIC 8
#define EN_PERIODS 9
#define EN_NODECOUNT 0 /* Component counts */
#define EN_TANKCOUNT 1
#define EN_LINKCOUNT 2
#define EN_PATCOUNT 3
#define EN_CURVECOUNT 4
#define EN_CONTROLCOUNT 5
#define EN_JUNCTION 0 /* Node types */
#define EN_RESERVOIR 1
#define EN_TANK 2
#define EN_CVPIPE 0 /* Link types. */
#define EN_PIPE 1 /* See LinkType in TYPES.H */
#define EN_PUMP 2
#define EN_PRV 3
#define EN_PSV 4
#define EN_PBV 5
#define EN_FCV 6
#define EN_TCV 7
#define EN_GPV 8
#define EN_NONE 0 /* Quality analysis types. */
#define EN_CHEM 1 /* See QualType in TYPES.H */
#define EN_AGE 2
#define EN_TRACE 3
#define EN_CONCEN 0 /* Source quality types. */
#define EN_MASS 1 /* See SourceType in TYPES.H. */
#define EN_SETPOINT 2
#define EN_FLOWPACED 3
#define EN_CFS 0 /* Flow units types. */
#define EN_GPM 1 /* See FlowUnitsType */
#define EN_MGD 2 /* in TYPES.H. */
#define EN_IMGD 3
#define EN_AFD 4
#define EN_LPS 5
#define EN_LPM 6
#define EN_MLD 7
#define EN_CMH 8
#define EN_CMD 9
#define EN_TRIALS 0 /* Misc. options */
#define EN_ACCURACY 1
#define EN_TOLERANCE 2
#define EN_EMITEXPON 3
#define EN_DEMANDMULT 4
#define EN_LOWLEVEL 0 /* Control types. */
#define EN_HILEVEL 1 /* See ControlType */
#define EN_TIMER 2 /* in TYPES.H. */
#define EN_TIMEOFDAY 3
#define EN_AVERAGE 1 /* Time statistic types. */
#define EN_MINIMUM 2 /* See TstatType in TYPES.H */
#define EN_MAXIMUM 3
#define EN_RANGE 4
#define EN_MIX1 0 /* Tank mixing models */
#define EN_MIX2 1
#define EN_FIFO 2
#define EN_LIFO 3
#define EN_NOSAVE 0 /* Save-results-to-file flag */
#define EN_SAVE 1
#define EN_INITFLOW 10 /* Re-initialize flows flag */
// --- Declare the EPANET toolkit functions
int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *));
int DLLEXPORT ENopen(char *, char *, char *);
int DLLEXPORT ENsaveinpfile(char *);
int DLLEXPORT ENclose(void);
int DLLEXPORT ENsolveH(void);
int DLLEXPORT ENsaveH(void);
int DLLEXPORT ENopenH(void);
int DLLEXPORT ENinitH(int);
int DLLEXPORT ENrunH(long *);
int DLLEXPORT ENnextH(long *);
int DLLEXPORT ENcloseH(void);
int DLLEXPORT ENsavehydfile(char *);
int DLLEXPORT ENusehydfile(char *);
int DLLEXPORT ENsolveQ(void);
int DLLEXPORT ENopenQ(void);
int DLLEXPORT ENinitQ(int);
int DLLEXPORT ENrunQ(long *);
int DLLEXPORT ENnextQ(long *);
int DLLEXPORT ENstepQ(long *);
int DLLEXPORT ENcloseQ(void);
int DLLEXPORT ENwriteline(char *);
int DLLEXPORT ENreport(void);
int DLLEXPORT ENresetreport(void);
int DLLEXPORT ENsetreport(char *);
int DLLEXPORT ENgetcontrol(int, int *, int *, float *,
int *, float *);
int DLLEXPORT ENgetcount(int, int *);
int DLLEXPORT ENgetoption(int, float *);
int DLLEXPORT ENgettimeparam(int, long *);
int DLLEXPORT ENgetflowunits(int *);
int DLLEXPORT ENgetpatternindex(char *, int *);
int DLLEXPORT ENgetpatternid(int, char *);
int DLLEXPORT ENgetpatternlen(int, int *);
int DLLEXPORT ENgetpatternvalue(int, int, float *);
int DLLEXPORT ENgetqualtype(int *, int *);
int DLLEXPORT ENgeterror(int, char *, int);
int DLLEXPORT ENgetnodeindex(char *, int *);
int DLLEXPORT ENgetnodeid(int, char *);
int DLLEXPORT ENgetnodetype(int, int *);
int DLLEXPORT ENgetnodevalue(int, int, float *);
int DLLEXPORT ENgetlinkindex(char *, int *);
int DLLEXPORT ENgetlinkid(int, char *);
int DLLEXPORT ENgetlinktype(int, int *);
int DLLEXPORT ENgetlinknodes(int, int *, int *);
int DLLEXPORT ENgetlinkvalue(int, int, float *);
int DLLEXPORT ENgetversion(int *);
int DLLEXPORT ENsetcontrol(int, int, int, float, int, float);
int DLLEXPORT ENsetnodevalue(int, int, float);
int DLLEXPORT ENsetlinkvalue(int, int, float);
int DLLEXPORT ENaddpattern(char *);
int DLLEXPORT ENsetpattern(int, float *, int);
int DLLEXPORT ENsetpatternvalue(int, int, float);
int DLLEXPORT ENsettimeparam(int, long);
int DLLEXPORT ENsetoption(int, float);
int DLLEXPORT ENsetstatusreport(int);
int DLLEXPORT ENsetqualtype(int, char *, char *, char *);

906
src/types.h Normal file → Executable file
View File

@@ -1,453 +1,453 @@
/*
***********************************************************************
TYPES.H -- Global constants and data types for EPANET program
VERSION: 2.00
DATE: 5/8/00
9/7/00
10/25/00
3/1/01
12/6/01
6/24/02
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
/*********************************************************/
/* All floats have been re-declared as doubles (7/3/07). */
/*********************************************************/
/*
-------------------------------------------
Definition of 4-byte integers & reals
-------------------------------------------
*/
typedef float REAL4; //(2.00.11 - LR)
typedef int INT4; //(2.00.12 - LR)
/*
-----------------------------
Global Constants
-----------------------------
*/
/*** Updated ***/
#define CODEVERSION 20012 //(2.00.12 - LR)
#define MAGICNUMBER 516114521
#define VERSION 200
#define EOFMARK 0x1A /* Use 0x04 for UNIX systems */
#define MAXTITLE 3 /* Max. # title lines */
#define MAXID 31 /* Max. # characters in ID name */ //(2.00.11 - LR)
#define MAXMSG 79 /* Max. # characters in message text */
#define MAXLINE 255 /* Max. # characters read from input line */
#define MAXFNAME 259 /* Max. # characters in file name */
#define MAXTOKS 40 /* Max. items per line of input */
#define TZERO 1.E-4 /* Zero time tolerance */
#define TRUE 1
#define FALSE 0
#define FULL 2
#define BIG 1.E10
#define TINY 1.E-6
#define MISSING -1.E10
#define PI 3.141592654
/*** Updated 9/7/00 ***/
/* Various conversion factors */
#define GPMperCFS 448.831
#define AFDperCFS 1.9837
#define MGDperCFS 0.64632
#define IMGDperCFS 0.5382
#define LPSperCFS 28.317
#define LPMperCFS 1699.0
#define CMHperCFS 101.94
#define CMDperCFS 2446.6
#define MLDperCFS 2.4466
#define M3perFT3 0.028317
#define LperFT3 28.317
#define MperFT 0.3048
#define PSIperFT 0.4333
#define KPAperPSI 6.895
#define KWperHP 0.7457
#define SECperDAY 86400
#define DIFFUS 1.3E-8 /* Diffusivity of chlorine */
/* @ 20 deg C (sq ft/sec) */
#define VISCOS 1.1E-5 /* Kinematic viscosity of water */
/* @ 20 deg C (sq ft/sec) */
#define SEPSTR " \t\n\r" /* Token separator characters */
/*
---------------------------------------------------------------------
Macro to test for successful allocation of memory
---------------------------------------------------------------------
*/
#define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
#define FREE(x) (free((x)))
/*
---------------------------------------------------------------------
Conversion macros to be used in place of functions
---------------------------------------------------------------------
*/
#define INT(x) ((int)(x)) /* integer portion of x */
#define FRAC(x) ((x)-(int)(x)) /* fractional part of x */
#define ABS(x) (((x)<0) ? -(x) : (x)) /* absolute value of x */
#define MIN(x,y) (((x)<=(y)) ? (x) : (y)) /* minimum of x and y */
#define MAX(x,y) (((x)>=(y)) ? (x) : (y)) /* maximum of x and y */
#define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))
/* round-off of x */
#define MOD(x,y) ((x)%(y)) /* x modulus y */
#define SQR(x) ((x)*(x)) /* x-squared */
#define SGN(x) (((x)<0) ? (-1) : (1)) /* sign of x */
#define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
/* uppercase char of x */
/*
------------------------------------------------------
Macro to evaluate function x with error checking
(Fatal errors are numbered higher than 100)
------------------------------------------------------
*/
#define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
/*
------------------------------------------------------
Macro to find Pump index of Link[x]
(Diameter = pump index for pump links)
------------------------------------------------------
*/
#define PUMPINDEX(x) (ROUND(Link[(x)].Diam))
/*
------------------------------------------------------
Global Data Structures
------------------------------------------------------
*/
struct IDstring /* Holds component ID labels */
{
char ID[MAXID+1];
};
struct Floatlist /* Element of list of floats */
{
double value;
struct Floatlist *next;
};
typedef struct Floatlist SFloatlist;
struct Tmplist /* Element of temp list for Pattern & Curve data */
{
int i;
char ID[MAXID+1];
SFloatlist *x;
SFloatlist *y;
struct Tmplist *next;
};
typedef struct Tmplist STmplist;
typedef struct /* TIME PATTERN OBJECT */
{
char ID[MAXID+1]; /* Pattern ID */
int Length; /* Pattern length */
double *F; /* Pattern factors */
} Spattern;
typedef struct /* CURVE OBJECT */
{
char ID[MAXID+1]; /* Curve ID */
int Type; /* Curve type */
int Npts; /* Number of points */
double *X; /* X-values */
double *Y; /* Y-values */
} Scurve;
struct Sdemand /* DEMAND CATEGORY OBJECT */
{
double Base; /* Baseline demand */
int Pat; /* Pattern index */
struct Sdemand *next; /* Next record */
};
typedef struct Sdemand *Pdemand; /* Pointer to demand object */
struct Ssource /* WQ SOURCE OBJECT */
{
/*int Node;*/ /* Node index of source */
double C0; /* Base concentration/mass */
int Pat; /* Pattern index */
double Smass; /* Actual mass flow rate */
char Type; /* SourceType (see below) */
};
typedef struct Ssource *Psource; /* Pointer to WQ source object */
typedef struct /* NODE OBJECT */
{
char ID[MAXID+1]; /* Node ID */
double El; /* Elevation */
Pdemand D; /* Demand pointer */
Psource S; /* Source pointer */
double C0; /* Initial quality */
double Ke; /* Emitter coeff. */
char Rpt; /* Reporting flag */
} Snode;
typedef struct /* LINK OBJECT */
{
char ID[MAXID+1]; /* Link ID */
int N1; /* Start node index */
int N2; /* End node index */
double Diam; /* Diameter */
double Len; /* Length */
double Kc; /* Roughness */
double Km; /* Minor loss coeff. */
double Kb; /* Bulk react. coeff */
double Kw; /* Wall react. coeff */
double R; /* Flow resistance */
char Type; /* Link type */
char Stat; /* Initial status */
char Rpt; /* Reporting flag */
} Slink;
typedef struct /* TANK OBJECT */
{
int Node; /* Node index of tank */
double A; /* Tank area */
double Hmin; /* Minimum water elev */
double Hmax; /* Maximum water elev */
double H0; /* Initial water elev */
double Vmin; /* Minimum volume */
double Vmax; /* Maximum volume */
double V0; /* Initial volume */
double Kb; /* Reaction coeff. (1/days) */
double V; /* Tank volume */
double C; /* Concentration */
int Pat; /* Fixed grade time pattern */
int Vcurve; /* Vol.- elev. curve index */
char MixModel; /* Type of mixing model */
/* (see MixType below) */
double V1max; /* Mixing compartment size */
} Stank;
typedef struct /* PUMP OBJECT */
{
int Link; /* Link index of pump */
int Ptype; /* Pump curve type */
/* (see PumpType below) */
double Q0; /* Initial flow */
double Qmax; /* Maximum flow */
double Hmax; /* Maximum head */
double H0; /* Shutoff head */
double R; /* Flow coeffic. */
double N; /* Flow exponent */
int Hcurve; /* Head v. flow curve index */
int Ecurve; /* Effic. v. flow curve index */
int Upat; /* Utilization pattern index */
int Epat; /* Energy cost pattern index */
double Ecost; /* Unit energy cost */
double Energy[6]; /* Energy usage statistics: */
/* 0 = pump utilization */
/* 1 = avg. efficiency */
/* 2 = avg. kW/flow */
/* 3 = avg. kwatts */
/* 4 = peak kwatts */
/* 5 = cost/day */
} Spump;
typedef struct /* VALVE OBJECT */
{
int Link; /* Link index of valve */
} Svalve;
typedef struct /* CONTROL STATEMENT */
{
int Link; /* Link index */
int Node; /* Control node index */
long Time; /* Control time */
double Grade; /* Control grade */
double Setting; /* New link setting */
char Status; /* New link status */
char Type; /* Control type */
/* (see ControlType below) */
} Scontrol;
struct Sadjlist /* NODE ADJACENCY LIST ITEM */
{
int node; /* Index of connecting node */
int link; /* Index of connecting link */
struct Sadjlist *next; /* Next item in list */
};
/* Pointer to adjacency list item */
typedef struct Sadjlist *Padjlist;
struct Sseg /* PIPE SEGMENT record used */
{ /* for WQ routing */
double v; /* Segment volume */
double c; /* Water quality value */
struct Sseg *prev; /* Record for previous segment */
};
typedef struct Sseg *Pseg; /* Pointer to pipe segment */
typedef struct /* FIELD OBJECT of report table */
{
char Name[MAXID+1]; /* Name of reported variable */
char Units[MAXID+1]; /* Units of reported variable */
char Enabled; /* Enabled if in table */
int Precision; /* Number of decimal places */
double RptLim[2]; /* Lower/upper report limits */
} SField;
/*
----------------------------------------------
Global Enumeration Variables
----------------------------------------------
*/
enum Hydtype /* Hydraulics solution option: */
{USE, /* use from previous run */
SAVE, /* save after current run */
SCRATCH}; /* use temporary file */
enum QualType /* Water quality analysis option: */
{NONE, /* no quality analysis */
CHEM, /* analyze a chemical */
AGE, /* analyze water age */
TRACE}; /* trace % of flow from a source */
enum NodeType /* Type of node: */
{JUNC, /* junction */
RESERV, /* reservoir */
TANK}; /* tank */
enum LinkType /* Type of link: */
{CV, /* pipe with check valve */
PIPE, /* regular pipe */
PUMP, /* pump */
PRV, /* pressure reducing valve */
PSV, /* pressure sustaining valve */
PBV, /* pressure breaker valve */
FCV, /* flow control valve */
TCV, /* throttle control valve */
GPV}; /* general purpose valve */
enum CurveType /* Type of curve: */
{V_CURVE, /* volume curve */
P_CURVE, /* pump curve */
E_CURVE, /* efficiency curve */
H_CURVE}; /* head loss curve */
enum PumpType /* Type of pump curve: */
{CONST_HP, /* constant horsepower */
POWER_FUNC, /* power function */
CUSTOM, /* user-defined custom curve */
NOCURVE};
enum SourceType /* Type of source quality input */
{CONCEN, /* inflow concentration */
MASS, /* mass inflow booster */
SETPOINT, /* setpoint booster */
FLOWPACED}; /* flow paced booster */
enum ControlType /* Control condition type: */
{LOWLEVEL, /* act when grade below set level */
HILEVEL, /* act when grade above set level */
TIMER, /* act when set time reached */
TIMEOFDAY}; /* act when time of day occurs */
enum StatType /* Link/Tank status: */
{XHEAD, /* pump cannot deliver head (closed) */
TEMPCLOSED, /* temporarily closed */
CLOSED, /* closed */
OPEN, /* open */
ACTIVE, /* valve active (partially open) */
XFLOW, /* pump exceeds maximum flow */
XFCV, /* FCV cannot supply flow */
XPRESSURE, /* valve cannot supply pressure */
FILLING, /* tank filling */
EMPTYING}; /* tank emptying */
enum FormType /* Head loss formula: */
{HW, /* Hazen-Williams */
DW, /* Darcy-Weisbach */
CM}; /* Chezy-Manning */
enum UnitsType /* Unit system: */
{US, /* US */
SI}; /* SI (metric) */
enum FlowUnitsType /* Flow units: */
{CFS, /* cubic feet per second */
GPM, /* gallons per minute */
MGD, /* million gallons per day */
IMGD, /* imperial million gal. per day */
AFD, /* acre-feet per day */
LPS, /* liters per second */
LPM, /* liters per minute */
MLD, /* megaliters per day */
CMH, /* cubic meters per hour */
CMD}; /* cubic meters per day */
enum PressUnitsType /* Pressure units: */
{PSI, /* pounds per square inch */
KPA, /* kiloPascals */
METERS}; /* meters */
enum RangeType /* Range limits: */
{LOW, /* lower limit */
HI, /* upper limit */
PREC}; /* precision */
enum MixType /* Tank mixing regimes */
{MIX1, /* 1-compartment model */
MIX2, /* 2-compartment model */
FIFO, /* First in, first out model */
LIFO}; /* Last in, first out model */
enum TstatType /* Time series statistics */
{SERIES, /* none */
AVG, /* time-averages */
MIN, /* minimum values */
MAX, /* maximum values */
RANGE}; /* max - min values */
#define MAXVAR 21 /* Max. # types of network variables */
/* (equals # items enumed below) */
enum FieldType /* Network variables: */
{ELEV, /* nodal elevation */
DEMAND, /* nodal demand flow */
HEAD, /* nodal hydraulic head */
PRESSURE, /* nodal pressure */
QUALITY, /* nodal water quality */
LENGTH, /* link length */
DIAM, /* link diameter */
FLOW, /* link flow rate */
VELOCITY, /* link flow velocity */
HEADLOSS, /* link head loss */
LINKQUAL, /* avg. water quality in link */
STATUS, /* link status */
SETTING, /* pump/valve setting */
REACTRATE, /* avg. reaction rate in link */
FRICTION, /* link friction factor */
POWER, /* pump power output */
TIME, /* simulation time */
VOLUME, /* tank volume */
CLOCKTIME, /* simulation time of day */
FILLTIME, /* time to fill a tank */
DRAINTIME}; /* time to drain a tank */
enum SectType {_TITLE,_JUNCTIONS,_RESERVOIRS,_TANKS,_PIPES,_PUMPS,
_VALVES,_CONTROLS,_RULES,_DEMANDS,_SOURCES,_EMITTERS,
_PATTERNS,_CURVES,_QUALITY,_STATUS,_ROUGHNESS,_ENERGY,
_REACTIONS,_MIXING,_REPORT,_TIMES,_OPTIONS,
_COORDS,_VERTICES,_LABELS,_BACKDROP,_TAGS,_END};
enum HdrType /* Type of table heading */
{STATHDR, /* Hydraulic Status */
ENERHDR, /* Energy Usage */
NODEHDR, /* Node Results */
LINKHDR}; /* Link Results */
/*
***********************************************************************
TYPES.H -- Global constants and data types for EPANET program
VERSION: 2.00
DATE: 5/8/00
9/7/00
10/25/00
3/1/01
12/6/01
6/24/02
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
**********************************************************************
*/
/*********************************************************/
/* All floats have been re-declared as doubles (7/3/07). */
/*********************************************************/
/*
-------------------------------------------
Definition of 4-byte integers & reals
-------------------------------------------
*/
typedef float REAL4; //(2.00.11 - LR)
typedef int INT4; //(2.00.12 - LR)
/*
-----------------------------
Global Constants
-----------------------------
*/
/*** Updated ***/
#define CODEVERSION 20012 //(2.00.12 - LR)
#define MAGICNUMBER 516114521
#define VERSION 200
#define EOFMARK 0x1A /* Use 0x04 for UNIX systems */
#define MAXTITLE 3 /* Max. # title lines */
#define MAXID 31 /* Max. # characters in ID name */ //(2.00.11 - LR)
#define MAXMSG 79 /* Max. # characters in message text */
#define MAXLINE 255 /* Max. # characters read from input line */
#define MAXFNAME 259 /* Max. # characters in file name */
#define MAXTOKS 40 /* Max. items per line of input */
#define TZERO 1.E-4 /* Zero time tolerance */
#define TRUE 1
#define FALSE 0
#define FULL 2
#define BIG 1.E10
#define TINY 1.E-6
#define MISSING -1.E10
#define PI 3.141592654
/*** Updated 9/7/00 ***/
/* Various conversion factors */
#define GPMperCFS 448.831
#define AFDperCFS 1.9837
#define MGDperCFS 0.64632
#define IMGDperCFS 0.5382
#define LPSperCFS 28.317
#define LPMperCFS 1699.0
#define CMHperCFS 101.94
#define CMDperCFS 2446.6
#define MLDperCFS 2.4466
#define M3perFT3 0.028317
#define LperFT3 28.317
#define MperFT 0.3048
#define PSIperFT 0.4333
#define KPAperPSI 6.895
#define KWperHP 0.7457
#define SECperDAY 86400
#define DIFFUS 1.3E-8 /* Diffusivity of chlorine */
/* @ 20 deg C (sq ft/sec) */
#define VISCOS 1.1E-5 /* Kinematic viscosity of water */
/* @ 20 deg C (sq ft/sec) */
#define SEPSTR " \t\n\r" /* Token separator characters */
/*
---------------------------------------------------------------------
Macro to test for successful allocation of memory
---------------------------------------------------------------------
*/
#define MEMCHECK(x) (((x) == NULL) ? 101 : 0 )
#define FREE(x) (free((x)))
/*
---------------------------------------------------------------------
Conversion macros to be used in place of functions
---------------------------------------------------------------------
*/
#define INT(x) ((int)(x)) /* integer portion of x */
#define FRAC(x) ((x)-(int)(x)) /* fractional part of x */
#define ABS(x) (((x)<0) ? -(x) : (x)) /* absolute value of x */
#define MIN(x,y) (((x)<=(y)) ? (x) : (y)) /* minimum of x and y */
#define MAX(x,y) (((x)>=(y)) ? (x) : (y)) /* maximum of x and y */
#define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))
/* round-off of x */
#define MOD(x,y) ((x)%(y)) /* x modulus y */
#define SQR(x) ((x)*(x)) /* x-squared */
#define SGN(x) (((x)<0) ? (-1) : (1)) /* sign of x */
#define UCHAR(x) (((x) >= 'a' && (x) <= 'z') ? ((x)&~32) : (x))
/* uppercase char of x */
/*
------------------------------------------------------
Macro to evaluate function x with error checking
(Fatal errors are numbered higher than 100)
------------------------------------------------------
*/
#define ERRCODE(x) (errcode = ((errcode>100) ? (errcode) : (x)))
/*
------------------------------------------------------
Macro to find Pump index of Link[x]
(Diameter = pump index for pump links)
------------------------------------------------------
*/
#define PUMPINDEX(x) (ROUND(Link[(x)].Diam))
/*
------------------------------------------------------
Global Data Structures
------------------------------------------------------
*/
struct IDstring /* Holds component ID labels */
{
char ID[MAXID+1];
};
struct Floatlist /* Element of list of floats */
{
double value;
struct Floatlist *next;
};
typedef struct Floatlist SFloatlist;
struct Tmplist /* Element of temp list for Pattern & Curve data */
{
int i;
char ID[MAXID+1];
SFloatlist *x;
SFloatlist *y;
struct Tmplist *next;
};
typedef struct Tmplist STmplist;
typedef struct /* TIME PATTERN OBJECT */
{
char ID[MAXID+1]; /* Pattern ID */
int Length; /* Pattern length */
double *F; /* Pattern factors */
} Spattern;
typedef struct /* CURVE OBJECT */
{
char ID[MAXID+1]; /* Curve ID */
int Type; /* Curve type */
int Npts; /* Number of points */
double *X; /* X-values */
double *Y; /* Y-values */
} Scurve;
struct Sdemand /* DEMAND CATEGORY OBJECT */
{
double Base; /* Baseline demand */
int Pat; /* Pattern index */
struct Sdemand *next; /* Next record */
};
typedef struct Sdemand *Pdemand; /* Pointer to demand object */
struct Ssource /* WQ SOURCE OBJECT */
{
/*int Node;*/ /* Node index of source */
double C0; /* Base concentration/mass */
int Pat; /* Pattern index */
double Smass; /* Actual mass flow rate */
char Type; /* SourceType (see below) */
};
typedef struct Ssource *Psource; /* Pointer to WQ source object */
typedef struct /* NODE OBJECT */
{
char ID[MAXID+1]; /* Node ID */
double El; /* Elevation */
Pdemand D; /* Demand pointer */
Psource S; /* Source pointer */
double C0; /* Initial quality */
double Ke; /* Emitter coeff. */
char Rpt; /* Reporting flag */
} Snode;
typedef struct /* LINK OBJECT */
{
char ID[MAXID+1]; /* Link ID */
int N1; /* Start node index */
int N2; /* End node index */
double Diam; /* Diameter */
double Len; /* Length */
double Kc; /* Roughness */
double Km; /* Minor loss coeff. */
double Kb; /* Bulk react. coeff */
double Kw; /* Wall react. coeff */
double R; /* Flow resistance */
char Type; /* Link type */
char Stat; /* Initial status */
char Rpt; /* Reporting flag */
} Slink;
typedef struct /* TANK OBJECT */
{
int Node; /* Node index of tank */
double A; /* Tank area */
double Hmin; /* Minimum water elev */
double Hmax; /* Maximum water elev */
double H0; /* Initial water elev */
double Vmin; /* Minimum volume */
double Vmax; /* Maximum volume */
double V0; /* Initial volume */
double Kb; /* Reaction coeff. (1/days) */
double V; /* Tank volume */
double C; /* Concentration */
int Pat; /* Fixed grade time pattern */
int Vcurve; /* Vol.- elev. curve index */
char MixModel; /* Type of mixing model */
/* (see MixType below) */
double V1max; /* Mixing compartment size */
} Stank;
typedef struct /* PUMP OBJECT */
{
int Link; /* Link index of pump */
int Ptype; /* Pump curve type */
/* (see PumpType below) */
double Q0; /* Initial flow */
double Qmax; /* Maximum flow */
double Hmax; /* Maximum head */
double H0; /* Shutoff head */
double R; /* Flow coeffic. */
double N; /* Flow exponent */
int Hcurve; /* Head v. flow curve index */
int Ecurve; /* Effic. v. flow curve index */
int Upat; /* Utilization pattern index */
int Epat; /* Energy cost pattern index */
double Ecost; /* Unit energy cost */
double Energy[6]; /* Energy usage statistics: */
/* 0 = pump utilization */
/* 1 = avg. efficiency */
/* 2 = avg. kW/flow */
/* 3 = avg. kwatts */
/* 4 = peak kwatts */
/* 5 = cost/day */
} Spump;
typedef struct /* VALVE OBJECT */
{
int Link; /* Link index of valve */
} Svalve;
typedef struct /* CONTROL STATEMENT */
{
int Link; /* Link index */
int Node; /* Control node index */
long Time; /* Control time */
double Grade; /* Control grade */
double Setting; /* New link setting */
char Status; /* New link status */
char Type; /* Control type */
/* (see ControlType below) */
} Scontrol;
struct Sadjlist /* NODE ADJACENCY LIST ITEM */
{
int node; /* Index of connecting node */
int link; /* Index of connecting link */
struct Sadjlist *next; /* Next item in list */
};
/* Pointer to adjacency list item */
typedef struct Sadjlist *Padjlist;
struct Sseg /* PIPE SEGMENT record used */
{ /* for WQ routing */
double v; /* Segment volume */
double c; /* Water quality value */
struct Sseg *prev; /* Record for previous segment */
};
typedef struct Sseg *Pseg; /* Pointer to pipe segment */
typedef struct /* FIELD OBJECT of report table */
{
char Name[MAXID+1]; /* Name of reported variable */
char Units[MAXID+1]; /* Units of reported variable */
char Enabled; /* Enabled if in table */
int Precision; /* Number of decimal places */
double RptLim[2]; /* Lower/upper report limits */
} SField;
/*
----------------------------------------------
Global Enumeration Variables
----------------------------------------------
*/
enum Hydtype /* Hydraulics solution option: */
{USE, /* use from previous run */
SAVE, /* save after current run */
SCRATCH}; /* use temporary file */
enum QualType /* Water quality analysis option: */
{NONE, /* no quality analysis */
CHEM, /* analyze a chemical */
AGE, /* analyze water age */
TRACE}; /* trace % of flow from a source */
enum NodeType /* Type of node: */
{JUNC, /* junction */
RESERV, /* reservoir */
TANK}; /* tank */
enum LinkType /* Type of link: */
{CV, /* pipe with check valve */
PIPE, /* regular pipe */
PUMP, /* pump */
PRV, /* pressure reducing valve */
PSV, /* pressure sustaining valve */
PBV, /* pressure breaker valve */
FCV, /* flow control valve */
TCV, /* throttle control valve */
GPV}; /* general purpose valve */
enum CurveType /* Type of curve: */
{V_CURVE, /* volume curve */
P_CURVE, /* pump curve */
E_CURVE, /* efficiency curve */
H_CURVE}; /* head loss curve */
enum PumpType /* Type of pump curve: */
{CONST_HP, /* constant horsepower */
POWER_FUNC, /* power function */
CUSTOM, /* user-defined custom curve */
NOCURVE};
enum SourceType /* Type of source quality input */
{CONCEN, /* inflow concentration */
MASS, /* mass inflow booster */
SETPOINT, /* setpoint booster */
FLOWPACED}; /* flow paced booster */
enum ControlType /* Control condition type: */
{LOWLEVEL, /* act when grade below set level */
HILEVEL, /* act when grade above set level */
TIMER, /* act when set time reached */
TIMEOFDAY}; /* act when time of day occurs */
enum StatType /* Link/Tank status: */
{XHEAD, /* pump cannot deliver head (closed) */
TEMPCLOSED, /* temporarily closed */
CLOSED, /* closed */
OPEN, /* open */
ACTIVE, /* valve active (partially open) */
XFLOW, /* pump exceeds maximum flow */
XFCV, /* FCV cannot supply flow */
XPRESSURE, /* valve cannot supply pressure */
FILLING, /* tank filling */
EMPTYING}; /* tank emptying */
enum FormType /* Head loss formula: */
{HW, /* Hazen-Williams */
DW, /* Darcy-Weisbach */
CM}; /* Chezy-Manning */
enum UnitsType /* Unit system: */
{US, /* US */
SI}; /* SI (metric) */
enum FlowUnitsType /* Flow units: */
{CFS, /* cubic feet per second */
GPM, /* gallons per minute */
MGD, /* million gallons per day */
IMGD, /* imperial million gal. per day */
AFD, /* acre-feet per day */
LPS, /* liters per second */
LPM, /* liters per minute */
MLD, /* megaliters per day */
CMH, /* cubic meters per hour */
CMD}; /* cubic meters per day */
enum PressUnitsType /* Pressure units: */
{PSI, /* pounds per square inch */
KPA, /* kiloPascals */
METERS}; /* meters */
enum RangeType /* Range limits: */
{LOW, /* lower limit */
HI, /* upper limit */
PREC}; /* precision */
enum MixType /* Tank mixing regimes */
{MIX1, /* 1-compartment model */
MIX2, /* 2-compartment model */
FIFO, /* First in, first out model */
LIFO}; /* Last in, first out model */
enum TstatType /* Time series statistics */
{SERIES, /* none */
AVG, /* time-averages */
MIN, /* minimum values */
MAX, /* maximum values */
RANGE}; /* max - min values */
#define MAXVAR 21 /* Max. # types of network variables */
/* (equals # items enumed below) */
enum FieldType /* Network variables: */
{ELEV, /* nodal elevation */
DEMAND, /* nodal demand flow */
HEAD, /* nodal hydraulic head */
PRESSURE, /* nodal pressure */
QUALITY, /* nodal water quality */
LENGTH, /* link length */
DIAM, /* link diameter */
FLOW, /* link flow rate */
VELOCITY, /* link flow velocity */
HEADLOSS, /* link head loss */
LINKQUAL, /* avg. water quality in link */
STATUS, /* link status */
SETTING, /* pump/valve setting */
REACTRATE, /* avg. reaction rate in link */
FRICTION, /* link friction factor */
POWER, /* pump power output */
TIME, /* simulation time */
VOLUME, /* tank volume */
CLOCKTIME, /* simulation time of day */
FILLTIME, /* time to fill a tank */
DRAINTIME}; /* time to drain a tank */
enum SectType {_TITLE,_JUNCTIONS,_RESERVOIRS,_TANKS,_PIPES,_PUMPS,
_VALVES,_CONTROLS,_RULES,_DEMANDS,_SOURCES,_EMITTERS,
_PATTERNS,_CURVES,_QUALITY,_STATUS,_ROUGHNESS,_ENERGY,
_REACTIONS,_MIXING,_REPORT,_TIMES,_OPTIONS,
_COORDS,_VERTICES,_LABELS,_BACKDROP,_TAGS,_END};
enum HdrType /* Type of table heading */
{STATHDR, /* Hydraulic Status */
ENERHDR, /* Energy Usage */
NODEHDR, /* Node Results */
LINKHDR}; /* Link Results */

392
src/vars.h Normal file → Executable file
View File

@@ -1,196 +1,196 @@
/*
************************************************************************
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
************************************************************************
*/
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 */
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 *S, /* Link status */
*OldStat; /* Previous link/tank status */
EXTERN double *D, /* Node actual demand */
*C, /* Node actual quality */
*E, /* Emitter flows */
*K, /* Link settings */
*Q, /* Link flows */
*R, /* Pipe reaction rate */
*X; /* General purpose array */
EXTERN double *H; /* Node heads */
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 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 HTtable *Nht, *Lht; /* Hash tables for ID labels */
EXTERN Padjlist *Adjlist; /* Node adjacency lists */
/*
** 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 */
/*
************************************************************************
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
************************************************************************
*/
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 */
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 *S, /* Link status */
*OldStat; /* Previous link/tank status */
EXTERN double *D, /* Node actual demand */
*C, /* Node actual quality */
*E, /* Emitter flows */
*K, /* Link settings */
*Q, /* Link flows */
*R, /* Pipe reaction rate */
*X; /* General purpose array */
EXTERN double *H; /* Node heads */
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 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 HTtable *Nht, *Lht; /* Hash tables for ID labels */
EXTERN Padjlist *Adjlist; /* Node adjacency lists */
/*
** 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 */