From 3336c4119c27dd1585b49722e4a9d35cb1df8490 Mon Sep 17 00:00:00 2001 From: Tom Taxon Date: Tue, 6 Dec 2011 18:25:02 +0000 Subject: [PATCH] All files in this commit: Added ifdef for Apple compilation - it does not have a malloc.h include file. epanet.c reset file variables to NULL so if the code is executed again without termination, the variables will be in a valid initial state. Added retrieval of EN_STARTTIME to ENgettimeparam. Added retrieval of EN_TANKVOLUME to ENgetnodevalue Added retrieval of EN_LINKQUAL to ENgetlinkvalue Fixed the check for identical filenames so it now allows for an empty (not generated) report file and outfile. Added ENgetbasedemand and ENgetdemandpattern functions input2.c Fixed some compiler warnings git-svn-id: https://epanet.svn.sourceforge.net/svnroot/epanet/BASE/trunk@424 c320cabd-cc23-0410-96d8-e60fbf53ed7f --- include/epanet2.h | 42 +++++++++++++++++++++++--------- src/epanet.c | 62 +++++++++++++++++++++++++++++++++++++++++------ src/hash.c | 4 +++ src/hydraul.c | 4 +++ src/inpfile.c | 4 +++ src/input1.c | 2 ++ src/input2.c | 10 +++++--- src/input3.c | 2 ++ src/mempool.c | 3 ++- src/output.c | 4 +++ src/quality.c | 4 +++ src/report.c | 4 +++ src/rules.c | 4 +++ src/smatrix.c | 4 +++ src/toolkit.h | 40 +++++++++++++++++++++--------- 15 files changed, 158 insertions(+), 35 deletions(-) diff --git a/include/epanet2.h b/include/epanet2.h index 4cbb348..cdaba1e 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -37,6 +37,8 @@ #define EN_MIXFRACTION 22 #define EN_TANK_KBULK 23 +#define EN_TANKVOLUME 24 /* TNT */ + #define EN_DIAMETER 0 /* Link parameters */ #define EN_LENGTH 1 #define EN_ROUGHNESS 2 @@ -51,6 +53,7 @@ #define EN_STATUS 11 #define EN_SETTING 12 #define EN_ENERGY 13 +#define EN_LINKQUAL 14 /* TNT */ #define EN_DURATION 0 /* Time parameters */ #define EN_HYDSTEP 1 @@ -62,6 +65,7 @@ #define EN_RULESTEP 7 #define EN_STATISTIC 8 #define EN_PERIODS 9 +#define EN_STARTTIME 10 /* Added TNT 10/2/2009 */ #define EN_NODECOUNT 0 /* Component counts */ #define EN_TANKCOUNT 1 @@ -144,23 +148,32 @@ // --- define DLLEXPORT -#ifdef WINDOWS - #ifdef __cplusplus - #define DLLEXPORT extern "C" __declspec(dllexport) __stdcall - #else - #define DLLEXPORT __declspec(dllexport) __stdcall - #endif -#else - #ifdef __cplusplus - #define DLLEXPORT extern "C" +#ifndef DLLEXPORT + #ifdef DLL + #if defined(CYGWIN) + #define DLLEXPORT __stdcall + #elif defined(WINDOWS) + #ifdef __cplusplus + #define DLLEXPORT extern "C" __declspec(dllexport) + #else + #define DLLEXPORT __declspec(dllexport) + #endif + #else + #ifdef __cplusplus + #define DLLEXPORT extern "C" + #else + #define DLLEXPORT + #endif + #endif #else #define DLLEXPORT #endif #endif - // --- declare the EPANET toolkit functions - +#ifdef __cplusplus +extern "C" { +#endif int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *)); int DLLEXPORT ENopen(char *, char *, char *); int DLLEXPORT ENsaveinpfile(char *); @@ -207,6 +220,10 @@ int DLLEXPORT ENgetnodetype(int, int *); int DLLEXPORT ENgetnodevalue(int, int, float *); + int DLLEXPORT ENgetnumdemands(int, int *); + int DLLEXPORT ENgetbasedemand(int, int, float *); + int DLLEXPORT ENgetdemandpattern(int, int, int *); + int DLLEXPORT ENgetlinkindex(char *, int *); int DLLEXPORT ENgetlinkid(int, char *); int DLLEXPORT ENgetlinktype(int, int *); @@ -225,5 +242,8 @@ int DLLEXPORT ENsetoption(int, float); int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetqualtype(int, char *, char *, char *); +#ifdef __cplusplus +}; +#endif #endif diff --git a/src/epanet.c b/src/epanet.c index b38a5f6..febdbd9 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -132,7 +132,9 @@ execute function x and set the error code equal to its return value. #include #include #include +#ifndef __APPLE__ #include +#endif #include #include //(2.00.12 - LR) #include "hash.h" @@ -361,13 +363,14 @@ int DLLEXPORT ENclose() if (TmpOutFile != OutFile) //(2.00.12 - LR) { //(2.00.12 - LR) if (TmpOutFile != NULL) fclose(TmpOutFile); //(2.00.12 - LR) + TmpOutFile=NULL; remove(TmpFname); //(2.00.12 - LR) } //(2.00.12 - LR) - if (InFile != NULL) fclose(InFile); - if (RptFile != NULL) fclose(RptFile); - if (HydFile != NULL) fclose(HydFile); - if (OutFile != NULL) fclose(OutFile); + if (InFile != NULL) { fclose(InFile); InFile=NULL; } + if (RptFile != NULL) { fclose(RptFile); RptFile=NULL; } + if (HydFile != NULL) { fclose(HydFile); HydFile=NULL; } + if (OutFile != NULL) { fclose(OutFile); OutFile=NULL; } if (Hydflag == SCRATCH) remove(HydFname); //(2.00.12 - LR) if (Outflag == SCRATCH) remove(OutFname); //(2.00.12 - LR) @@ -1092,7 +1095,7 @@ int DLLEXPORT ENgettimeparam(int code, long *value) { *value = 0; if (!Openflag) return(102); - if (code < EN_DURATION || code > EN_PERIODS) return(251); + if (code < EN_DURATION || code > EN_STARTTIME) return(251); switch (code) { case EN_DURATION: *value = Dur; break; @@ -1104,6 +1107,7 @@ int DLLEXPORT ENgettimeparam(int code, long *value) case EN_REPORTSTART: *value = Rstart; break; case EN_STATISTIC: *value = Tstatflag; break; case EN_PERIODS: *value = Nperiods; break; + case EN_STARTTIME: *value = Tstart; break; /* Added TNT 10/2/2009 */ } return(0); } @@ -1475,6 +1479,11 @@ int DLLEXPORT ENgetnodevalue(int index, int code, float *value) /*** New parameter additions ends here. ***/ //(2.00.12 - LR) + case EN_TANKVOLUME: + if (index <= Njuncs) return(251); + v = tankvolume(index-Njuncs, H[index])*Ucf[VOLUME]; + break; + default: return(251); } *value = (float)v; @@ -1694,6 +1703,10 @@ int DLLEXPORT ENgetlinkvalue(int index, int code, float *value) getenergy(index, &v, &a); break; + case EN_LINKQUAL: + v = avgqual(index) * Ucf[LINKQUAL]; + break; + default: return(251); } *value = (float)v; @@ -2450,7 +2463,7 @@ int openfiles(char *f1, char *f2, char *f3) else Outflag = SCRATCH; //(2.00.12 - LR) /* Check that file names are not identical */ - if (strcomp(f1,f2) || strcomp(f1,f3) || strcomp(f2,f3)) + and outfile if (strcomp(f1,f2) || strcomp(f1,f3) || (strcomp(f2,f3) && (strlen(f2) > 0 || strlen(f3) > 0))) { writecon(FMT04); return(301); @@ -2898,7 +2911,7 @@ char* getTmpName(char* fname) // --- if user supplied the name of a temporary directory, // then make it be the prefix of the full file name - n = strlen(TmpDir); + n = (int)strlen(TmpDir); if ( n > 0 ) { strcpy(fname, TmpDir); @@ -3118,6 +3131,41 @@ void writewin(char *s) } #endif } +int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) +{ + Pdemand d; + int n=0; + /* Check for valid arguments */ + if (!Openflag) return(102); + if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + for(d=Node[nodeIndex].D; d != NULL; d=d->next) n++; + *numDemands=n; + return 0; +} +int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, float *baseDemand) +{ + Pdemand d; + int n=0; + /* Check for valid arguments */ + if (!Openflag) return(102); + if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + for(d=Node[nodeIndex].D; nnext) n++; + if(n!=demandIdx) return(253); + *baseDemand=d->Base*Ucf[FLOW]; + return 0; +} +int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) +{ + Pdemand d; + int n=0; + /* Check for valid arguments */ + if (!Openflag) return(102); + if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + for(d=Node[nodeIndex].D; nnext) n++; + if(n!=demandIdx) return(253); + *pattIdx=d->Pat; + return 0; +} /*************************** END OF EPANET.C ***************************/ diff --git a/src/hash.c b/src/hash.c index 8989869..64af9a7 100755 --- a/src/hash.c +++ b/src/hash.c @@ -18,7 +18,11 @@ ********************************************************************* */ +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "hash.h" diff --git a/src/hydraul.c b/src/hydraul.c index de553df..53b77f4 100755 --- a/src/hydraul.c +++ b/src/hydraul.c @@ -48,7 +48,11 @@ AUTHOR: L. Rossman #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/inpfile.c b/src/inpfile.c index fc6631f..e21fa98 100755 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -21,7 +21,11 @@ data describing a piping network to a file in EPANET's text format. #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/input1.c b/src/input1.c index 4c9c929..15e1ae8 100755 --- a/src/input1.c +++ b/src/input1.c @@ -24,7 +24,9 @@ AUTHOR: L. Rossman #include #include #include +#ifndef __APPLE__ #include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/input2.c b/src/input2.c index 9fd136f..a0fa344 100755 --- a/src/input2.c +++ b/src/input2.c @@ -28,7 +28,9 @@ The following utility functions are all called from INPUT3.C #include #include #include +#ifndef __APPLE__ #include +#endif #include #include "hash.h" #include "text.h" @@ -261,7 +263,7 @@ int newline(int sect, char *line) { case _TITLE: if (Ntitle < 3) { - n = strlen(line); + n = (int)strlen(line); if (line[n-1] == 10) line[n-1] = ' '; strncpy(Title[Ntitle],line,MAXMSG); Ntitle++; @@ -783,12 +785,12 @@ int gettokens(char *s) /* Truncate s at start of comment */ c = strchr(s,';'); if (c) *c = '\0'; - len = strlen(s); + len = (int)strlen(s); /* Scan s for tokens until nothing left */ while (len > 0 && n < MAXTOKS) { - m = strcspn(s,SEPSTR); /* Find token length */ + m = (int)strcspn(s,SEPSTR); /* Find token length */ len -= m+1; /* Update length of s */ if (m == 0) s++; /* No token found */ else @@ -796,7 +798,7 @@ int gettokens(char *s) if (*s == '"') /* Token begins with quote */ { s++; /* Start token after quote */ - m = strcspn(s,"\"\n\r"); /* Find end quote (or EOL) */ + m = (int)strcspn(s,"\"\n\r"); /* Find end quote (or EOL) */ } s[m] = '\0'; /* Null-terminate the token */ Tok[n] = s; /* Save pointer to token */ diff --git a/src/input3.c b/src/input3.c index 1c025c9..0d72c37 100755 --- a/src/input3.c +++ b/src/input3.c @@ -23,7 +23,9 @@ All functions in this module are called from newline() in INPUT2.C. #include #include #include +#ifndef __APPLE__ #include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/mempool.c b/src/mempool.c index 41853bd..b31ba13 100755 --- a/src/mempool.c +++ b/src/mempool.c @@ -16,7 +16,9 @@ */ #include +#ifndef __APPLE__ #include +#endif #include "mempool.h" /* @@ -91,7 +93,6 @@ static alloc_hdr_t * AllocHdr() DLLEXPORT alloc_handle_t * AllocInit() { alloc_handle_t *newpool; - root = (alloc_root_t *) malloc(sizeof(alloc_root_t)); if (root == NULL) return(NULL); if ( (root->first = AllocHdr()) == NULL) return(NULL); diff --git a/src/output.c b/src/output.c index d614acb..e25a5d3 100755 --- a/src/output.c +++ b/src/output.c @@ -14,7 +14,11 @@ AUTHOR: L. Rossman #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "text.h" #include "types.h" diff --git a/src/quality.c b/src/quality.c index f74f950..8cc1ffe 100755 --- a/src/quality.c +++ b/src/quality.c @@ -49,7 +49,11 @@ AUTHOR: L. Rossman #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/report.c b/src/report.c index 3184a4c..b021461 100755 --- a/src/report.c +++ b/src/report.c @@ -27,7 +27,11 @@ formatted string S to the report file. #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include #include "hash.h" diff --git a/src/rules.c b/src/rules.c index 3de6810..aa2e003 100755 --- a/src/rules.c +++ b/src/rules.c @@ -24,7 +24,11 @@ AUTHOR: L. Rossman */ #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include "hash.h" #include "text.h" #include "types.h" diff --git a/src/smatrix.c b/src/smatrix.c index a39f1e8..7b0e7f3 100755 --- a/src/smatrix.c +++ b/src/smatrix.c @@ -32,7 +32,11 @@ Linsolve() solves the linearized system of hydraulic equations. #include #include +#ifndef __APPLE__ #include +#else +#include +#endif #include #include "hash.h" #include "text.h" diff --git a/src/toolkit.h b/src/toolkit.h index da036d7..8507c77 100755 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -15,19 +15,22 @@ AUTHOR: L. Rossman ******************************************************************* */ -// --- Define DLLEXPORT -#ifdef DLL - #ifdef __cplusplus - #define DLLEXPORT extern "C" __declspec(dllexport) __stdcall +#ifndef DLLEXPORT + #ifdef DLL + #ifdef __cplusplus + #define DLLEXPORT extern "C" __declspec(dllexport) + #else + #define DLLEXPORT __declspec(dllexport) + #endif + #elif defined(CYGWIN) + #define DLLEXPORT __stdcall #else - #define DLLEXPORT __declspec(dllexport) __stdcall - #endif -#else - #ifdef __cplusplus - #define DLLEXPORT extern "C" - #else - #define DLLEXPORT + #ifdef __cplusplus + #define DLLEXPORT + #else + #define DLLEXPORT + #endif #endif #endif @@ -59,6 +62,8 @@ AUTHOR: L. Rossman #define EN_MIXFRACTION 22 #define EN_TANK_KBULK 23 +#define EN_TANKVOLUME 24 /* TNT */ + #define EN_DIAMETER 0 /* Link parameters */ #define EN_LENGTH 1 #define EN_ROUGHNESS 2 @@ -73,6 +78,7 @@ AUTHOR: L. Rossman #define EN_STATUS 11 #define EN_SETTING 12 #define EN_ENERGY 13 +#define EN_LINKQUAL 14 /* TNT */ #define EN_DURATION 0 /* Time parameters */ #define EN_HYDSTEP 1 @@ -84,6 +90,7 @@ AUTHOR: L. Rossman #define EN_RULESTEP 7 #define EN_STATISTIC 8 #define EN_PERIODS 9 +#define EN_STARTTIME 10 /* Added TNT 10/2/2009 */ #define EN_NODECOUNT 0 /* Component counts */ #define EN_TANKCOUNT 1 @@ -155,7 +162,9 @@ AUTHOR: L. Rossman // --- Declare the EPANET toolkit functions - +#if defined(__LINUX__) && defined(__cplusplus) +extern "C" { +#endif int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *)); int DLLEXPORT ENopen(char *, char *, char *); @@ -203,6 +212,10 @@ AUTHOR: L. Rossman int DLLEXPORT ENgetnodetype(int, int *); int DLLEXPORT ENgetnodevalue(int, int, float *); + int DLLEXPORT ENgetnumdemands(int, int *); + int DLLEXPORT ENgetbasedemand(int, int, float *); + int DLLEXPORT ENgetdemandpattern(int, int, int *); + int DLLEXPORT ENgetlinkindex(char *, int *); int DLLEXPORT ENgetlinkid(int, char *); int DLLEXPORT ENgetlinktype(int, int *); @@ -222,3 +235,6 @@ AUTHOR: L. Rossman int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetqualtype(int, char *, char *, char *); +#if defined(__LINUX__) && defined(__cplusplus) +} +#endif