Changes to pass reg tests

Revised getTmpName() in EPANET.C
This commit is contained in:
Lew Rossman
2018-06-05 10:31:18 -04:00
parent 598f080f52
commit f0c9684871
4 changed files with 165 additions and 146 deletions

View File

@@ -129,7 +129,6 @@ execute function x and set the error code equal to its return value.
#include "text.h" #include "text.h"
#include "types.h" #include "types.h"
#define EXTERN #define EXTERN
#include "epanet2.h"
#include "vars.h" #include "vars.h"
/**************************************************************** /****************************************************************
@@ -3420,7 +3419,7 @@ int openhydfile(EN_Project *p)
out->HydFile = NULL; out->HydFile = NULL;
switch (out->Hydflag) { switch (out->Hydflag) {
case SCRATCH: case SCRATCH:
getTmpName(p, out->HydFname); getTmpName(out->HydFname);
out->HydFile = fopen(out->HydFname, "w+b"); out->HydFile = fopen(out->HydFname, "w+b");
break; break;
case SAVE: case SAVE:
@@ -3513,7 +3512,7 @@ int openoutfile(EN_Project *p)
// else if ( (OutFile = tmpfile()) == NULL) // else if ( (OutFile = tmpfile()) == NULL)
else else
{ {
getTmpName(p, out->OutFname); getTmpName(out->OutFname);
if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL) if ((out->OutFile = fopen(out->OutFname, "w+b")) == NULL)
{ {
writecon(FMT08); writecon(FMT08);
@@ -3531,7 +3530,7 @@ int openoutfile(EN_Project *p)
if (!errcode) { if (!errcode) {
if (rep->Tstatflag != SERIES) { if (rep->Tstatflag != SERIES) {
// if ( (TmpOutFile = tmpfile()) == NULL) errcode = 304; // if ( (TmpOutFile = tmpfile()) == NULL) errcode = 304;
getTmpName(p, out->TmpFname); getTmpName(out->TmpFname);
out->TmpOutFile = fopen(out->TmpFname, "w+b"); out->TmpOutFile = fopen(out->TmpFname, "w+b");
if (out->TmpOutFile == NULL) if (out->TmpOutFile == NULL)
errcode = 304; errcode = 304;
@@ -3838,30 +3837,35 @@ void freedata(EN_Project *p)
---------------------------------------------------------------- ----------------------------------------------------------------
*/ */
/*** New function for 2.00.12 ***/ // DEPRECATED char *getTmpName(char *fname)
char *getTmpName(EN_Project *p, char *fname)
// //
// Input: fname = file name string // Input: fname = file name string
// Output: returns pointer to file name // Output: returns pointer to file name
// Purpose: creates a temporary file name with path prepended to it. // Purpose: creates a temporary file name with path prepended to it.
// //
{ {
out_file_t *out = &p->out_files;
#ifdef _WIN32 #ifdef _WIN32
TCHAR tmpFileName[MAXFNAME];
TCHAR tmpPathName[MAXFNAME];
int rtnValue = GetTempPath(MAXFNAME, tmpPathName);
if (rtnValue == 0 || rtnValue > MAXFNAME) return 0;
rtnValue = GetTempFileName(tmpPathName, TEXT("EN"), 0, tmpFileName);
if (rtnValue > 0) strncpy(fname, tmpFileName, MAXFNAME);
char* name = NULL;
// --- use Windows _tempnam function to get a pointer to an
// unused file name that begins with "en"
name = _tempnam(NULL, "en");
if (name == NULL) return NULL;
// --- copy the file name to fname
if (strlen(name) < MAXFNAME) strncpy(fname, name, MAXFNAME);
else fname = NULL;
// --- free the pointer returned by _tempnam
if (name) free(name);
/////////////////// DEPRECATED /////////////////////////////////////
// There is an OS limit on the number of times tmpnam will return a
// unique file name and it is not thread safe.
/* /*
/////////////////// DEPRECATED /////////////////////////////////////
// --- for Windows systems: // --- for Windows systems:
#ifdef WINDOWS #ifdef WINDOWS
out_file_t *out = &p->out_files;
// --- use system function tmpnam() to create a temporary file name // --- use system function tmpnam() to create a temporary file name
char name[MAXFNAME + 1]; char name[MAXFNAME + 1];
int n; int n;

View File

@@ -40,7 +40,7 @@ int openfiles(EN_Project *p, char *,char *,char *); /* Opens input & report
int openhydfile(EN_Project *p); /* Opens hydraulics file */ int openhydfile(EN_Project *p); /* Opens hydraulics file */
int openoutfile(EN_Project *p); /* Opens binary output file */ int openoutfile(EN_Project *p); /* Opens binary output file */
int strcomp(char *, char *); /* Compares two strings */ int strcomp(char *, char *); /* Compares two strings */
char* getTmpName(EN_Project *p, char* fname); /* Gets temporary file name */ char* getTmpName(char* fname); /* Gets temporary file name */
double interp(int, double *,double *, double); /* Interpolates a data curve */ double interp(int, double *,double *, double); /* Interpolates a data curve */
int findnode(EN_Network *n, char *); /* Finds node's index from ID */ int findnode(EN_Network *n, char *); /* Finds node's index from ID */
@@ -107,7 +107,7 @@ int optiondata(EN_Project *pr); /* Processes analysis option
int optionchoice(EN_Project *pr, int); /* Processes option choices */ int optionchoice(EN_Project *pr, int); /* Processes option choices */
int optionvalue(EN_Project *pr, int); /* Processes option values */ int optionvalue(EN_Project *pr, int); /* Processes option values */
int getpumpcurve(EN_Project *pr, int); /* Constructs a pump curve */ int getpumpcurve(EN_Project *pr, int); /* Constructs a pump curve */
int powercurve(double, double, double,/* Coeffs. of power pump curve*/ int powercurve(double, double, double, /* Coeffs. of power pump curve*/
double, double, double *, double, double, double *,
double *, double *); double *, double *);
int valvecheck(EN_Project *pr, int, int, int); /* Checks valve placement */ int valvecheck(EN_Project *pr, int, int, int); /* Checks valve placement */
@@ -159,11 +159,14 @@ int nexthyd(EN_Project *pr, long *); /* Moves to next time
void closehyd(EN_Project *pr); /* Closes hydraulics solver */ void closehyd(EN_Project *pr); /* Closes hydraulics solver */
int allocmatrix(EN_Project *pr); /* Allocates matrix coeffs. */ int allocmatrix(EN_Project *pr); /* Allocates matrix coeffs. */
void freematrix(EN_Project *pr); /* Frees matrix coeffs. */ void freematrix(EN_Project *pr); /* Frees matrix coeffs. */
void initlinkflow(EN_Project *pr, int, char, double); /* Initializes link flow */ void initlinkflow(EN_Project *pr, int, char,
double); /* Initializes link flow */
void setlinkflow(EN_Project *pr, int, double); /* Sets link flow via headloss*/ void setlinkflow(EN_Project *pr, int, double); /* Sets link flow via headloss*/
void setlinkstatus(EN_Project *pr, int, char, StatType *, double *); /* Sets link status */ void setlinkstatus(EN_Project *pr, int, char,
StatType *, double *); /* Sets link status */
void setlinksetting(EN_Project *pr, int, double, StatType *, double *); /* Sets pump/valve setting */ void setlinksetting(EN_Project *pr, int, double,
StatType *, double *); /* Sets pump/valve setting */
void resistance(EN_Project *pr, int); /* Computes resistance coeff. */ void resistance(EN_Project *pr, int); /* Computes resistance coeff. */
void demands(EN_Project *pr); /* Computes current demands */ void demands(EN_Project *pr); /* Computes current demands */
@@ -173,7 +176,8 @@ int tanktimestep(EN_Project *pr, long *); /* Time till tanks fil
void controltimestep(EN_Project *pr, long *); /* Time till control action */ void controltimestep(EN_Project *pr, long *); /* Time till control action */
void ruletimestep(EN_Project *pr, long *); /* Time till rule action */ void ruletimestep(EN_Project *pr, long *); /* Time till rule action */
void addenergy(EN_Project *pr, long); /* Accumulates energy usage */ void addenergy(EN_Project *pr, long); /* Accumulates energy usage */
void getenergy(EN_Project *pr, int, double *, double *); /* Computes link energy use */ void getenergy(EN_Project *pr, int, double *,
double *); /* Computes link energy use */
void tanklevels(EN_Project *pr, long); /* Computes new tank levels */ void tanklevels(EN_Project *pr, long); /* Computes new tank levels */
double tankvolume(EN_Project *pr, int,double); /* Finds tank vol. from grade */ double tankvolume(EN_Project *pr, int,double); /* Finds tank vol. from grade */
double tankgrade(EN_Project *pr, int,double); /* Finds tank grade from vol. */ double tankgrade(EN_Project *pr, int,double); /* Finds tank grade from vol. */
@@ -181,13 +185,17 @@ int netsolve(EN_Project *pr, int *,double *); /* Solves network equa
int badvalve(EN_Project *pr, int); /* Checks for bad valve */ int badvalve(EN_Project *pr, int); /* Checks for bad valve */
int valvestatus(EN_Project *pr); /* Updates valve status */ int valvestatus(EN_Project *pr); /* Updates valve status */
int linkstatus(EN_Project *pr); /* Updates link status */ int linkstatus(EN_Project *pr); /* Updates link status */
StatType cvstatus(EN_Project *pr, StatType,double,double); /* Updates CV status */ StatType cvstatus(EN_Project *pr, StatType,
double,double); /* Updates CV status */
StatType pumpstatus(EN_Project *pr, int,double); /* Updates pump status */ StatType pumpstatus(EN_Project *pr, int,double); /* Updates pump status */
StatType prvstatus(EN_Project *pr, int,StatType,double,double,double); /* Updates PRV status */ StatType prvstatus(EN_Project *pr, int,StatType,
double,double,double); /* Updates PRV status */
StatType psvstatus(EN_Project *pr, int,StatType,double,double,double); /* Updates PSV status */ StatType psvstatus(EN_Project *pr, int,StatType,
double,double,double); /* Updates PSV status */
StatType fcvstatus(EN_Project *pr, int,StatType,double,double); /* Updates FCV status */ StatType fcvstatus(EN_Project *pr, int,StatType,
double,double); /* Updates FCV status */
void tankstatus(EN_Project *pr, int,int,int); /* Checks if tank full/empty */ void tankstatus(EN_Project *pr, int,int,int); /* Checks if tank full/empty */
int pswitch(EN_Project *pr); /* Pressure switch controls */ int pswitch(EN_Project *pr); /* Pressure switch controls */
@@ -202,7 +210,8 @@ void pumpcoeff(EN_Project *pr, int); /* Computes pump coeff
/*** Updated 10/25/00 ***/ /*** Updated 10/25/00 ***/
/*** Updated 12/29/00 ***/ /*** Updated 12/29/00 ***/
void curvecoeff(EN_Project *pr, int,double,double *,double *); /* Computes curve coeffs. */ void curvecoeff(EN_Project *pr, int,double,
double *,double *); /* Computes curve coeffs. */
void gpvcoeff(EN_Project *pr, int iLink); /* Computes GPV coeff. */ void gpvcoeff(EN_Project *pr, int iLink); /* Computes GPV coeff. */
@@ -233,7 +242,7 @@ int storesparse(EN_Project *pr, int); /* Stores sparse matri
int ordersparse(hydraulics_t *h, int); /* Orders matrix storage */ int ordersparse(hydraulics_t *h, int); /* Orders matrix storage */
void transpose(int,int *,int *, /* Transposes sparse matrix */ void transpose(int,int *,int *, /* Transposes sparse matrix */
int *,int *,int *,int *,int *); int *,int *,int *,int *,int *);
int linsolve(solver_t *s, int); /* via Cholesky factorization */ int linsolve(solver_t *s, int); /* Solves set of linear eqns. */
/* ----------- QUALITY.C ---------------*/ /* ----------- QUALITY.C ---------------*/
int openqual(EN_Project *pr); /* Opens WQ solver system */ int openqual(EN_Project *pr); /* Opens WQ solver system */
@@ -264,10 +273,14 @@ double sourcequal(EN_Project *pr, Psource); /* Finds WQ input from
double avgqual(EN_Project *pr, int); /* Finds avg. quality in pipe */ double avgqual(EN_Project *pr, int); /* Finds avg. quality in pipe */
void ratecoeffs(EN_Project *pr); /* Finds wall react. coeffs. */ void ratecoeffs(EN_Project *pr); /* Finds wall react. coeffs. */
double piperate(EN_Project *pr, int); /* Finds wall react. coeff. */ double piperate(EN_Project *pr, int); /* Finds wall react. coeff. */
double pipereact(EN_Project *pr, int,double,double,long);/* Reacts water in a pipe */ double pipereact(EN_Project *pr, int,double,
double tankreact(EN_Project *pr, double,double,double,long); /* Reacts water in a tank */ double,long); /* Reacts water in a pipe */
double bulkrate(EN_Project *pr, double,double,double); /* Finds bulk reaction rate */ double tankreact(EN_Project *pr, double,double,
double wallrate(EN_Project *pr, double,double,double,double);/* Finds wall reaction rate */ double,long); /* Reacts water in a tank */
double bulkrate(EN_Project *pr, double,double,
double); /* Finds bulk reaction rate */
double wallrate(EN_Project *pr, double,double,
double,double); /* Finds wall reaction rate */
/* ------------ OUTPUT.C ---------------*/ /* ------------ OUTPUT.C ---------------*/
@@ -278,12 +291,15 @@ int saveenergy(EN_Project *pr); /* Saves energy usage
int readhyd(EN_Project *pr, long *); /* Reads hydraulics from file */ int readhyd(EN_Project *pr, long *); /* Reads hydraulics from file */
int readhydstep(FILE *hydFile, long *); /* Reads time step from file */ int readhydstep(FILE *hydFile, long *); /* Reads time step from file */
int saveoutput(EN_Project *pr); /* Saves results to file */ int saveoutput(EN_Project *pr); /* Saves results to file */
int nodeoutput(EN_Project *pr, int, REAL4 *, double); /* Saves node results to file */ int nodeoutput(EN_Project *pr, int, REAL4 *,
int linkoutput(EN_Project *pr, int, REAL4 *, double); /* Saves link results to file */ 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 savefinaloutput(EN_Project *pr); /* Finishes saving output */
int savetimestat(EN_Project *pr, REAL4 *, HdrType); /* Saves time stats to file */ int savetimestat(EN_Project *pr, REAL4 *,
int savenetreacts(EN_Project *pr, double, double,double, double); HdrType); /* Saves time stats to file */
/* Saves react. rates 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 saveepilog(EN_Project *pr); /* Saves output file epilog */

View File

@@ -40,8 +40,7 @@ AUTHOR: L. Rossman
--------------------- Module Global Variables ---------------------- --------------------- Module Global Variables ----------------------
*/ */
#define MAXITER \ #define MAXITER 200 /* Default max. # hydraulic iterations */
200 /* Default max. # hydraulic iterations */
#define HACC 0.001 /* Default hydraulics convergence ratio */ #define HACC 0.001 /* Default hydraulics convergence ratio */
#define HTOL 0.0005 /* Default hydraulic head tolerance (ft) */ #define HTOL 0.0005 /* Default hydraulic head tolerance (ft) */
@@ -62,8 +61,7 @@ AUTHOR: L. Rossman
#define RQTOL 1E-7 /* Default low flow resistance tolerance */ #define RQTOL 1E-7 /* Default low flow resistance tolerance */
#define CHECKFREQ 2 /* Default status check frequency */ #define CHECKFREQ 2 /* Default status check frequency */
#define MAXCHECK 10 /* Default # iterations for status checks */ #define MAXCHECK 10 /* Default # iterations for status checks */
#define DAMPLIMIT \ #define DAMPLIMIT 0 /* Default damping threshold */
0 /* Default damping threshold */
extern char *Fldname[]; /* Defined in enumstxt.h in EPANET.C */ extern char *Fldname[]; /* Defined in enumstxt.h in EPANET.C */
extern char *RptFlowUnitsTxt[]; extern char *RptFlowUnitsTxt[];

View File

@@ -23,6 +23,7 @@ AUTHOR: L. Rossman
#include "epanet2.h" #include "epanet2.h"
#include "hash.h" #include "hash.h"
#include "mempool.h" #include "mempool.h"
#include <stdio.h>
/*********************************************************/ /*********************************************************/
/* All floats have been re-declared as doubles (7/3/07). */ /* All floats have been re-declared as doubles (7/3/07). */
@@ -49,7 +50,7 @@ typedef int INT4;
#define MAXID 31 /* Max. # characters in ID name */ #define MAXID 31 /* Max. # characters in ID name */
#define MAXMSG 79 /* Max. # characters in message text */ #define MAXMSG 79 /* Max. # characters in message text */
#define MAXLINE 255 /* Max. # characters read from input line */ #define MAXLINE 255 /* Max. # characters read from input line */
#define MAXFNAME 259 /* Max. # characters in file name */ #define MAXFNAME L_tmpnam_s /* Max. # characters in file name */
#define MAXTOKS 40 /* Max. items per line of input */ #define MAXTOKS 40 /* Max. items per line of input */
#define TZERO 1.E-4 /* Zero time tolerance */ #define TZERO 1.E-4 /* Zero time tolerance */
#define TRUE 1 #define TRUE 1