Code cleanup
1. Added a standard header to each code module and removed obsolete comments. 2. Re-named several of the sub-structs in the project struct and re-arranged some of their contents. 3. Re-named _defaultModel to _defaultProject. 4. Removed the need to call EN_createproject and EN_deleteproject when working with the default project. 5. Made X & Y coords. part of Snode properties instead of a separate struct. 6. Moved the non-API functions in epanet.c into a new module named project.c. 7. Re-factored the quality module so that it uses the same nodal adjacency lists as the hydraulics solver. 8. Re-factored the sparse matrix module (smatrix.c) to be more memory efficient. 9. Restricted line lengths to < 90 columns. 10. Grouped the placement of functions in EPANET2.H and EPANET.C by category.
This commit is contained in:
362
src/funcs.h
362
src/funcs.h
@@ -1,227 +1,175 @@
|
||||
/*
|
||||
**************************************************************************
|
||||
|
||||
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
|
||||
|
||||
**************************************************************************
|
||||
******************************************************************************
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Module: funcs.h
|
||||
Description: prototypes of external functions called by various modules
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
Last Updated: 11/27/2018
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*****************************************************************/
|
||||
/* Most float arguments have been changed to double - 7/3/07 */
|
||||
/*****************************************************************/
|
||||
|
||||
/* ------- EPANET.C --------------------*/
|
||||
/*
|
||||
** NOTE: The exportable functions that can be called
|
||||
** via the DLL are prototyped in TOOLKIT.H.
|
||||
*/
|
||||
|
||||
#ifndef FUNCS_H
|
||||
#define FUNCS_H
|
||||
|
||||
void initpointers(EN_Project *pr); /* Initializes pointers */
|
||||
int allocdata(EN_Project *pr); /* Allocates memory */
|
||||
void freeTmplist(STmplist *); /* Frees items in linked list */
|
||||
void freeFloatlist(SFloatlist *); /* Frees list of floats */
|
||||
void freedata(EN_Project *pr); /* Frees allocated memory */
|
||||
int openfiles(EN_Project *pr, const char *,
|
||||
const char *,const char *); /* Opens input & report files */
|
||||
int openhydfile(EN_Project *pr); /* Opens hydraulics file */
|
||||
int openoutfile(EN_Project *pr); /* Opens binary output file */
|
||||
int strcomp(const char *, const char *); /* Compares two strings */
|
||||
char* getTmpName(char* fname); /* Gets temporary file name */
|
||||
double interp(int n, double x[], double y[],
|
||||
double xx); /* Interpolates a data curve */
|
||||
|
||||
int findnode(EN_Network *n, char *); /* Finds node's index from ID */
|
||||
int findlink(EN_Network *n, char *); /* Finds link's index from ID */
|
||||
int findtank(EN_Network *n, int); /* Find tank index from node index */ // (AH)
|
||||
int findvalve(EN_Network *n, int); /* Find valve index from node index */ // (AH)
|
||||
int findpump(EN_Network *n, int); /* Find pump index from node index */ // (AH)
|
||||
char *geterrmsg(int errcode, char *msg); /* Gets text of error message */
|
||||
void errmsg(EN_Project *p, int); /* Reports program error */
|
||||
void writewin(void (*vp)(char *), char *); /* Passes text to calling app */
|
||||
// ------- PROJECT.C ------------
|
||||
|
||||
/* ------- INPUT1.C --------------------*/
|
||||
int getdata(EN_Project *pr); /* Gets network data */
|
||||
void setdefaults(EN_Project *pr); /* Sets default values */
|
||||
void initreport(report_options_t *r); /* Initializes report options */
|
||||
void adjustdata(EN_Project *pr); /* Adjusts input data */
|
||||
int inittanks(EN_Project *pr); /* Initializes tank levels */
|
||||
void initunits(EN_Project *pr); /* Determines reporting units */
|
||||
void convertunits(EN_Project *pr); /* Converts data to std. units*/
|
||||
void initpointers(Project *);
|
||||
int allocdata(Project *);
|
||||
void freeTmplist(STmplist *);
|
||||
void freeFloatlist(SFloatlist *);
|
||||
void freedata(Project *);
|
||||
|
||||
/* -------- INPUT2.C -------------------*/
|
||||
int netsize(EN_Project *pr); /* Determines network size */
|
||||
int readdata(EN_Project *pr); /* Reads in network data */
|
||||
int newline(EN_Project *pr, int, char *); /* Processes new line of data */
|
||||
int addnodeID(EN_Network *n, int, char *); /* Adds node ID to data base */
|
||||
int addlinkID(EN_Network *n, int, char *); /* Adds link ID to data base */
|
||||
int addpattern(parser_data_t *par, char *); /* Adds pattern to data base */
|
||||
int addcurve(parser_data_t *par, char *); /* Adds curve to data base */
|
||||
STmplist *findID(char *, STmplist *); /* Locates ID on linked list */
|
||||
int unlinked(EN_Project *pr); /* Checks for unlinked nodes */
|
||||
int getpumpparams(EN_Project *pr); /* Computes pump curve coeffs.*/
|
||||
int updatepumpparams(EN_Project *pr, int); // Updates pump curve coeffs.
|
||||
int getpatterns(EN_Project *pr); /* Gets pattern data from list*/
|
||||
int getcurves(EN_Project *pr); /* Gets curve data from list */
|
||||
int findmatch(char *, char *[]); /* Finds keyword in line */
|
||||
int match(const char *, const char *); /* Checks for word match */
|
||||
int gettokens(char *s, char** Tok, int maxToks,
|
||||
char *comment); /* Tokenizes input line */
|
||||
int getfloat(char *, double *); /* Converts string to double */
|
||||
double hour(char *, char *); /* Converts time to hours */
|
||||
int setreport(EN_Project *pr, char *); /* Processes reporting command*/
|
||||
void inperrmsg(EN_Project *pr, int,int,char *); /* Input error message */
|
||||
int openfiles(Project *, const char *, const char *,const char *);
|
||||
int openhydfile(Project *);
|
||||
int openoutfile(Project *);
|
||||
|
||||
/* ---------- INPUT3.C -----------------*/
|
||||
int juncdata(EN_Project *pr); /* Processes junction data */
|
||||
int tankdata(EN_Project *pr); /* Processes tank data */
|
||||
int pipedata(EN_Project *pr); /* Processes pipe data */
|
||||
int pumpdata(EN_Project *pr); /* Processes pump data */
|
||||
int valvedata(EN_Project *pr); /* Processes valve data */
|
||||
int patterndata(EN_Project *pr); /* Processes pattern data */
|
||||
int curvedata(EN_Project *pr); /* Processes curve data */
|
||||
int coordata(EN_Project *pr); /* Processes coordinate data */
|
||||
int demanddata(EN_Project *pr); /* Processes demand data */
|
||||
int controldata(EN_Project *pr); /* Processes simple controls */
|
||||
int energydata(EN_Project *pr); /* Processes energy data */
|
||||
int sourcedata(EN_Project *pr); /* Processes source data */
|
||||
int emitterdata(EN_Project *pr); /* Processes emitter data */
|
||||
int qualdata(EN_Project *pr); /* Processes quality data */
|
||||
int reactdata(EN_Project *pr); /* Processes reaction data */
|
||||
int mixingdata(EN_Project *pr); /* Processes tank mixing data */
|
||||
int statusdata(EN_Project *pr); /* Processes link status data */
|
||||
int reportdata(EN_Project *pr); /* Processes report options */
|
||||
int timedata(EN_Project *pr); /* Processes time options */
|
||||
int optiondata(EN_Project *pr); /* Processes analysis options */
|
||||
int optionchoice(EN_Project *pr, int); /* Processes option choices */
|
||||
int optionvalue(EN_Project *pr, int); /* Processes option values */
|
||||
int getpumpcurve(EN_Project *pr, int); /* Constructs a pump curve */
|
||||
int powercurve(double, double, double, /* Coeffs. of power pump curve*/
|
||||
double, double, double *,
|
||||
double *, double *);
|
||||
int valvecheck(EN_Project *pr, int, int, int); /* Checks valve placement */
|
||||
void changestatus(EN_Network *net, int, StatType,
|
||||
double); /* Changes status of a link */
|
||||
int buildadjlists(Network *);
|
||||
void freeadjlists(Network *);
|
||||
|
||||
/* -------------- RULES.C --------------*/
|
||||
void initrules(EN_Project *pr); /* Initializes rule base */
|
||||
void addrule(parser_data_t *par, char *); /* Adds rule to rule base */
|
||||
int allocrules(EN_Project *pr); /* Allocates memory for rule */
|
||||
void adjustrules(EN_Project *pr, int, int); // Shifts object indices down
|
||||
void adjusttankrules(EN_Project *pr); // Shifts tank indices up
|
||||
int ruledata(EN_Project *pr); /* Processes rule input data */
|
||||
int checkrules(EN_Project *pr, long); /* Checks all rules */
|
||||
void deleterule(EN_Project *pr, int); // Deletes a rule
|
||||
void freerules(EN_Project *pr); /* Frees rule base memory */
|
||||
int writerule(EN_Project *pr, FILE *, int); /* Writes rule to an INP file */
|
||||
void ruleerrmsg(EN_Project *pr); /* Reports rule parser error */
|
||||
Spremise *getpremise(Spremise *, int); // Retrieves a rule's premise
|
||||
Saction *getaction(Saction *, int); // Retrieves a rule's action
|
||||
int incontrols(Project *, int, int);
|
||||
int findnode(Network *, char *);
|
||||
int findlink(Network *, char *);
|
||||
int findtank(Network *, int);
|
||||
int findvalve(Network *, int);
|
||||
int findpump(Network *, int);
|
||||
|
||||
/* ------------- REPORT.C --------------*/
|
||||
int writereport(EN_Project *pr); /* Writes formatted report */
|
||||
void writelogo(EN_Project *pr); /* Writes program logo */
|
||||
void writesummary(EN_Project *pr); /* Writes network summary */
|
||||
void writehydstat(EN_Project *pr, int,double); /* Writes hydraulic status */
|
||||
void writeenergy(EN_Project *pr); /* Writes energy usage */
|
||||
int writeresults(EN_Project *pr); /* Writes node/link results */
|
||||
void writeheader(EN_Project *pr, int,int); /* Writes heading on report */
|
||||
void writeline(EN_Project *pr, char *); /* Writes line to report file */
|
||||
void writerelerr(EN_Project *pr, int, double); /* Writes convergence error */
|
||||
void writestatchange(EN_Project *pr, int,char,char); /* Writes link status change */
|
||||
void writecontrolaction(EN_Project *pr, int, int); /* Writes control action taken*/
|
||||
void writeruleaction(EN_Project *pr, int, char *); /* Writes rule action taken */
|
||||
int writehydwarn(EN_Project *pr, int,double); /* Writes hydraulic warnings */
|
||||
void writehyderr(EN_Project *pr, int); /* Writes hydraulic error msg.*/
|
||||
void writemassbalance(EN_Project *pr); // Writes mass balance ratio
|
||||
int disconnected(EN_Project *pr); /* Checks for disconnections */
|
||||
void marknodes(EN_Project *pr, int, int *, char *); /* Identifies connected nodes */
|
||||
void getclosedlink(EN_Project *pr, int, char *); /* Finds a disconnecting link */
|
||||
void writelimits(EN_Project *pr, int,int); /* Writes reporting limits */
|
||||
int checklimits(report_options_t *rep, double *,
|
||||
int,int); /* Checks variable limits */
|
||||
void writetime(EN_Project *pr, char *); /* Writes current clock time */
|
||||
char *clocktime(char *, long); /* Converts time to hrs:min */
|
||||
char *fillstr(char *, char, int); /* Fills string with character*/
|
||||
int getnodetype(EN_Network *net, int); /* Determines node type */
|
||||
char *getTmpName(char *);
|
||||
int strcomp(const char *, const char *);
|
||||
double interp(int, double [], double [], double);
|
||||
char *geterrmsg(int, char *);
|
||||
void errmsg(Project *, int);
|
||||
void writewin(void (*vp)(char *), char *);
|
||||
|
||||
/* --------- HYDRAUL.C -----------------*/
|
||||
int openhyd(EN_Project *pr); /* Opens hydraulics solver */
|
||||
void inithyd(EN_Project *pr, int initFlags); /* Re-sets initial conditions */
|
||||
int runhyd(EN_Project *pr, long *); /* Solves 1-period hydraulics */
|
||||
int nexthyd(EN_Project *pr, long *); /* Moves to next time period */
|
||||
void closehyd(EN_Project *pr); /* Closes hydraulics solver */
|
||||
void setlinkstatus(EN_Project *pr, int, char,
|
||||
StatType *, double *); /* Sets link status */
|
||||
void setlinksetting(EN_Project *pr, int, double,
|
||||
StatType *, double *); /* Sets pump/valve setting */
|
||||
int tanktimestep(EN_Project *pr, long *); /* Time till tanks fill/drain */
|
||||
void getenergy(EN_Project *pr, int, double *,
|
||||
double *); /* Computes link energy use */
|
||||
double tankvolume(EN_Project *pr, int, double); /* Finds tank vol. from grade */
|
||||
double tankgrade(EN_Project *pr, int, double); /* Finds tank grade from vol. */
|
||||
// ------- INPUT1.C ----------------
|
||||
|
||||
/* ----------- HYDSOLVER.C - ----------*/
|
||||
int hydsolve(EN_Project *pr, int *,double *); /* Solves network equations */
|
||||
int getdata(Project *);
|
||||
void setdefaults(Project *);
|
||||
void initreport(Report *);
|
||||
void adjustdata(Project *);
|
||||
int inittanks(Project *);
|
||||
void initunits(Project *);
|
||||
void convertunits(Project *);
|
||||
|
||||
/* ----------- HYDCOEFFS.C --------------*/
|
||||
void resistcoeff(EN_Project *pr, int k); /* Finds pipe flow resistance */
|
||||
void headlosscoeffs(EN_Project *pr); // Finds link head loss coeffs.
|
||||
void matrixcoeffs(EN_Project *pr); /* Finds hyd. matrix coeffs. */
|
||||
void emitheadloss(EN_Project *pr, int, // Finds emitter head loss
|
||||
double *, double *);
|
||||
double demandflowchange(EN_Project *pr, int, // Change in demand outflow
|
||||
double, double);
|
||||
void demandparams(EN_Project *pr, double *, // PDA function parameters
|
||||
double *);
|
||||
//-------- INPUT2.C -----------------
|
||||
|
||||
/* ----------- SMATRIX.C ---------------*/
|
||||
int createsparse(EN_Project *pr); /* Creates sparse matrix */
|
||||
void freesparse(EN_Project *pr); /* Frees matrix memory */
|
||||
int linsolve(EN_Project *pr, int); /* Solves set of linear eqns. */
|
||||
int netsize(Project *);
|
||||
int readdata(Project *);
|
||||
int updatepumpparams(Project *, int);
|
||||
int getpatterns(Project *);
|
||||
int getcurves(Project *);
|
||||
int findmatch(char *, char *[]);
|
||||
int match(const char *, const char *);
|
||||
int gettokens(char *, char **, int, char *);
|
||||
int getfloat(char *, double *);
|
||||
double hour(char *, char *);
|
||||
int setreport(Project *, char *);
|
||||
|
||||
/* ----------- QUALITY.C ---------------*/
|
||||
int openqual(EN_Project *pr); /* Opens WQ solver system */
|
||||
int initqual(EN_Project *pr); /* Initializes WQ solver */
|
||||
int runqual(EN_Project *pr, long *); /* Gets current WQ results */
|
||||
int nextqual(EN_Project *pr, long *); /* Updates WQ by hyd.timestep */
|
||||
int stepqual(EN_Project *pr, long *); /* Updates WQ by WQ time step */
|
||||
int closequal(EN_Project *pr); /* Closes WQ solver system */
|
||||
double avgqual(EN_Project *pr, int); /* Finds avg. quality in pipe */
|
||||
// ------- INPUT3.C -----------------
|
||||
|
||||
/* ------------ OUTPUT.C ---------------*/
|
||||
int savenetdata(EN_Project *pr); /* Saves basic data to file */
|
||||
int savehyd(EN_Project *pr, long *); /* Saves hydraulic solution */
|
||||
int savehydstep(EN_Project *pr, long *); /* Saves hydraulic timestep */
|
||||
int saveenergy(EN_Project *pr); /* Saves energy usage */
|
||||
int readhyd(EN_Project *pr, long *); /* Reads hydraulics from file */
|
||||
int readhydstep(EN_Project *pr, long *); /* Reads time step from file */
|
||||
int saveoutput(EN_Project *pr); /* Saves results to file */
|
||||
int nodeoutput(EN_Project *pr, int, REAL4 *,
|
||||
double); /* Saves node results to file */
|
||||
int linkoutput(EN_Project *pr, int, REAL4 *,
|
||||
double); /* Saves link results to file */
|
||||
int savefinaloutput(EN_Project *pr); /* Finishes saving output */
|
||||
int savetimestat(EN_Project *pr, REAL4 *,
|
||||
HdrType); /* Saves time stats to file */
|
||||
int savenetreacts(EN_Project *pr, double,
|
||||
double,double, double); /* Saves react. rates to file */
|
||||
int saveepilog(EN_Project *pr); /* Saves output file epilog */
|
||||
int juncdata(Project *);
|
||||
int tankdata(Project *);
|
||||
int pipedata(Project *);
|
||||
int pumpdata(Project *);
|
||||
int valvedata(Project *);
|
||||
int patterndata(Project *);
|
||||
int curvedata(Project *);
|
||||
int coordata(Project *);
|
||||
int demanddata(Project *);
|
||||
int controldata(Project *);
|
||||
int energydata(Project *);
|
||||
int sourcedata(Project *);
|
||||
int emitterdata(Project *);
|
||||
int qualdata(Project *);
|
||||
int reactdata(Project *);
|
||||
int mixingdata(Project *);
|
||||
int statusdata(Project *);
|
||||
int reportdata(Project *);
|
||||
int timedata(Project *);
|
||||
int optiondata(Project *);
|
||||
int valvecheck(Project *, int, int, int);
|
||||
|
||||
// ------- RULES.C ------------------
|
||||
|
||||
/* ------------ INPFILE.C --------------*/
|
||||
int saveinpfile(EN_Project *pr, const char *); /* Saves network to text file */
|
||||
void initrules(Project *);
|
||||
void addrule(Parser *, char *);
|
||||
void deleterule(Project *, int);
|
||||
int allocrules(Project *);
|
||||
void freerules(Project *);
|
||||
int ruledata(Project *);
|
||||
void ruleerrmsg(Project *);
|
||||
void adjustrules(Project *, int, int);
|
||||
void adjusttankrules(Project *);
|
||||
Spremise *getpremise(Spremise *, int);
|
||||
Saction *getaction(Saction *, int);
|
||||
int writerule(Project *, FILE *, int);
|
||||
int checkrules(Project *, long);
|
||||
|
||||
// ------- REPORT.C -----------------
|
||||
|
||||
int writereport(Project *);
|
||||
void writelogo(Project *);
|
||||
void writesummary(Project *);
|
||||
void writehydstat(Project *, int, double);
|
||||
void writeheader(Project *, int,int);
|
||||
void writeline(Project *, char *);
|
||||
void writerelerr(Project *, int, double);
|
||||
void writestatchange(Project *, int,char,char);
|
||||
void writecontrolaction(Project *, int, int);
|
||||
void writeruleaction(Project *, int, char *);
|
||||
int writehydwarn(Project *, int,double);
|
||||
void writehyderr(Project *, int);
|
||||
void writemassbalance(Project *);
|
||||
void writetime(Project *, char *);
|
||||
char *clocktime(char *, long);
|
||||
|
||||
// ------- HYDRAUL.C -----------------
|
||||
|
||||
int openhyd(Project *);
|
||||
void inithyd(Project *, int initFlags);
|
||||
int runhyd(Project *, long *);
|
||||
int nexthyd(Project *, long *);
|
||||
void closehyd(Project *);
|
||||
void setlinkstatus(Project *, int, char, StatusType *, double *);
|
||||
void setlinksetting(Project *, int, double, StatusType *, double *);
|
||||
int tanktimestep(Project *, long *);
|
||||
void getenergy(Project *, int, double *, double *);
|
||||
double tankvolume(Project *, int, double);
|
||||
double tankgrade(Project *, int, double);
|
||||
|
||||
// ------- HYDCOEFFS.C -----------------
|
||||
|
||||
void resistcoeff(Project *, int);
|
||||
void headlosscoeffs(Project *);
|
||||
void matrixcoeffs(Project *);
|
||||
void emitheadloss(Project *, int, double *, double *);
|
||||
double demandflowchange(Project *, int, double, double);
|
||||
void demandparams(Project *, double *, double *);
|
||||
|
||||
// ------- QUALITY.C --------------------
|
||||
|
||||
int openqual(Project *);
|
||||
int initqual(Project *);
|
||||
int runqual(Project *, long *);
|
||||
int nextqual(Project *, long *);
|
||||
int stepqual(Project *, long *);
|
||||
int closequal(Project *);
|
||||
double avgqual(Project *, int);
|
||||
|
||||
// ------- OUTPUT.C ---------------------
|
||||
|
||||
int savenetdata(Project *);
|
||||
int savehyd(Project *, long *);
|
||||
int savehydstep(Project *, long *);
|
||||
int saveenergy(Project *);
|
||||
int readhyd(Project *, long *);
|
||||
int readhydstep(Project *, long *);
|
||||
int saveoutput(Project *);
|
||||
int savefinaloutput(Project *);
|
||||
|
||||
// ------- INPFILE.C --------------------
|
||||
|
||||
int saveinpfile(Project *, const char *);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user