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
This commit is contained in:
Tom Taxon
2011-12-06 18:25:02 +00:00
parent a41cdbd540
commit 3336c4119c
15 changed files with 158 additions and 35 deletions

View File

@@ -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,11 +148,15 @@
// --- define DLLEXPORT
#ifdef WINDOWS
#ifndef DLLEXPORT
#ifdef DLL
#if defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(WINDOWS)
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport) __stdcall
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#define DLLEXPORT __declspec(dllexport)
#endif
#else
#ifdef __cplusplus
@@ -157,10 +165,15 @@
#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

View File

@@ -132,7 +132,9 @@ execute function x and set the error code equal to its return value.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <math.h>
#include <float.h> //(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; n<demandIdx && d != NULL; d=d->next) 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; n<demandIdx && d != NULL; d=d->next) n++;
if(n!=demandIdx) return(253);
*pattIdx=d->Pat;
return 0;
}
/*************************** END OF EPANET.C ***************************/

View File

@@ -18,7 +18,11 @@
*********************************************************************
*/
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <string.h>
#include "hash.h"

View File

@@ -48,7 +48,11 @@ AUTHOR: L. Rossman
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -21,7 +21,11 @@ data describing a piping network to a file in EPANET's text format.
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -24,7 +24,9 @@ AUTHOR: L. Rossman
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -28,7 +28,9 @@ The following utility functions are all called from INPUT3.C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <math.h>
#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 */

View File

@@ -23,7 +23,9 @@ All functions in this module are called from newline() in INPUT2.C.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -16,7 +16,9 @@
*/
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#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);

View File

@@ -14,7 +14,11 @@ AUTHOR: L. Rossman
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "text.h"
#include "types.h"

View File

@@ -49,7 +49,11 @@ AUTHOR: L. Rossman
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -27,7 +27,11 @@ formatted string S to the report file.
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include <time.h>
#include "hash.h"

View File

@@ -24,7 +24,11 @@ AUTHOR: L. Rossman
*/
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include "hash.h"
#include "text.h"
#include "types.h"

View File

@@ -32,7 +32,11 @@ Linsolve() solves the linearized system of hydraulic equations.
#include <stdio.h>
#include <string.h>
#ifndef __APPLE__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <math.h>
#include "hash.h"
#include "text.h"

View File

@@ -15,21 +15,24 @@ AUTHOR: L. Rossman
*******************************************************************
*/
// --- Define DLLEXPORT
#ifndef DLLEXPORT
#ifdef DLL
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport) __stdcall
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#define DLLEXPORT __declspec(dllexport)
#endif
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#else
#ifdef __cplusplus
#define DLLEXPORT extern "C"
#define DLLEXPORT
#else
#define DLLEXPORT
#endif
#endif
#endif
// --- Define the EPANET toolkit constants
@@ -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