From 4c1155745b1daf7e028eb75b7af05557fccb20f8 Mon Sep 17 00:00:00 2001 From: sam hatchett Date: Thu, 23 May 2013 19:53:26 -0400 Subject: [PATCH] setting float type by define --- .../epanet/epanet.xcodeproj/project.pbxproj | 4 -- src/epanet.c | 58 +++++++++---------- src/toolkit.h | 32 +++++----- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj index b5b34ba..b3d2027 100644 --- a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj +++ b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj @@ -42,7 +42,6 @@ 22322FA51068369500641384 /* rules.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7F1068369500641384 /* rules.c */; }; 22322FA61068369500641384 /* smatrix.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F801068369500641384 /* smatrix.c */; }; 22322FAA106836BC00641384 /* epanet2.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322FA9106836B000641384 /* epanet2.h */; }; - 22322FAE106836D900641384 /* malloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322FAD106836D900641384 /* malloc.h */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -79,7 +78,6 @@ 22322F831068369500641384 /* types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = types.h; path = ../../../src/types.h; sourceTree = SOURCE_ROOT; }; 22322F841068369500641384 /* vars.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = vars.h; path = ../../../src/vars.h; sourceTree = SOURCE_ROOT; }; 22322FA9106836B000641384 /* epanet2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = epanet2.h; path = ../../../include/epanet2.h; sourceTree = SOURCE_ROOT; }; - 22322FAD106836D900641384 /* malloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = malloc.h; path = macinclude/malloc.h; sourceTree = ""; }; D2AAC0630554660B00DB518D /* libepanet.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libepanet.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -151,7 +149,6 @@ 22322FA8106836A000641384 /* Include */ = { isa = PBXGroup; children = ( - 22322FAD106836D900641384 /* malloc.h */, 22322FA9106836B000641384 /* epanet2.h */, ); name = Include; @@ -173,7 +170,6 @@ 22322F971068369500641384 /* toolkit.h in Headers */, 22322F981068369500641384 /* types.h in Headers */, 22322F991068369500641384 /* vars.h in Headers */, - 22322FAE106836D900641384 /* malloc.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/epanet.c b/src/epanet.c index 3512b04..f193147 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -975,7 +975,7 @@ int DLLEXPORT ENgetversion(int *v) int DLLEXPORT ENgetcontrol(int cindex, int *ctype, int *lindex, - float *setting, int *nindex, float *level) + EN_API_FLOAT_TYPE *setting, int *nindex, EN_API_FLOAT_TYPE *level) /*---------------------------------------------------------------- ** Input: cindex = control index (position of control statement ** in the input file, starting from 1) @@ -1021,9 +1021,9 @@ int DLLEXPORT ENgetcontrol(int cindex, int *ctype, int *lindex, else if (*nindex > 0) lvl = (Control[cindex].Grade - Node[*nindex].El)*Ucf[PRESSURE]; else - lvl = (float)Control[cindex].Time; - *setting = (float)s; - *level = (float)lvl; + lvl = (EN_API_FLOAT_TYPE)Control[cindex].Time; + *setting = (EN_API_FLOAT_TYPE)s; + *level = (EN_API_FLOAT_TYPE)lvl; return(0); } @@ -1054,7 +1054,7 @@ int DLLEXPORT ENgetcount(int code, int *count) } -int DLLEXPORT ENgetoption(int code, float *value) +int DLLEXPORT ENgetoption(int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: code = option code (see TOOLKIT.H) ** Output: *value = option value @@ -1064,7 +1064,7 @@ int DLLEXPORT ENgetoption(int code, float *value) */ { double v = 0.0; - *value = 0.0f; + *value = 0.0; if (!Openflag) return(102); switch (code) { @@ -1080,7 +1080,7 @@ int DLLEXPORT ENgetoption(int code, float *value) break; default: return(251); } - *value = (float)v; + *value = (EN_API_FLOAT_TYPE)v; return(0); } @@ -1196,7 +1196,7 @@ int DLLEXPORT ENgetpatternlen(int index, int *len) } -int DLLEXPORT ENgetpatternvalue(int index, int period, float *value) +int DLLEXPORT ENgetpatternvalue(int index, int period, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: index = index of time pattern ** period = pattern time period @@ -1206,11 +1206,11 @@ int DLLEXPORT ENgetpatternvalue(int index, int period, float *value) ** and pattern **---------------------------------------------------------------- */ -{ *value = 0.0f; +{ *value = 0.0; if (!Openflag) return(102); if (index < 1 || index > Npats) return(205); if (period < 1 || period > Pattern[index].Length) return(251); - *value = (float)Pattern[index].F[period-1]; + *value = (EN_API_FLOAT_TYPE)Pattern[index].F[period-1]; return(0); } @@ -1345,7 +1345,7 @@ int DLLEXPORT ENgetnodetype(int index, int *code) } -int DLLEXPORT ENgetnodevalue(int index, int code, float *value) +int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: index = node index ** code = node parameter code (see TOOLKIT.H) @@ -1360,7 +1360,7 @@ int DLLEXPORT ENgetnodevalue(int index, int code, float *value) Psource source; /* Check for valid arguments */ - *value = 0.0f; + *value = 0.0; if (!Openflag) return(102); if (index <= 0 || index > Nnodes) return(203); @@ -1518,7 +1518,7 @@ int DLLEXPORT ENgetnodevalue(int index, int code, float *value) default: return(251); } - *value = (float)v; + *value = (EN_API_FLOAT_TYPE)v; return(0); } @@ -1603,7 +1603,7 @@ int DLLEXPORT ENgetlinknodes(int index, int *node1, int *node2) } -int DLLEXPORT ENgetlinkvalue(int index, int code, float *value) +int DLLEXPORT ENgetlinkvalue(int index, int code, EN_API_FLOAT_TYPE *value) /*------------------------------------------------------------------ ** Input: index = link index ** code = link parameter code (see TOOLKIT.H) @@ -1616,7 +1616,7 @@ int DLLEXPORT ENgetlinkvalue(int index, int code, float *value) double a,h,q, v = 0.0; /* Check for valid arguments */ - *value = 0.0f; + *value = 0.0; if (!Openflag) return(102); if (index <= 0 || index > Nlinks) return(204); @@ -1740,12 +1740,12 @@ int DLLEXPORT ENgetlinkvalue(int index, int code, float *value) default: return(251); } - *value = (float)v; + *value = (EN_API_FLOAT_TYPE)v; return(0); } -int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues) // !sph +int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues) // !sph /*---------------------------------------------------------------- ** Input: curveIndex = curve index ** Output: *nValues = number of points on curve @@ -1761,14 +1761,14 @@ int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float * Scurve curve = Curve[curveIndex]; int nPoints = curve.Npts; - float *pointX = calloc(nPoints, sizeof(float)); - float *pointY = calloc(nPoints, sizeof(float)); + EN_API_FLOAT_TYPE *pointX = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); + EN_API_FLOAT_TYPE *pointY = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); for (int iPoint = 0; iPoint < nPoints; iPoint++) { double x = curve.X[iPoint] * Ucf[LENGTH]; double y = curve.Y[iPoint] * Ucf[VOLUME]; - pointX[iPoint] = (float)x; - pointY[iPoint] = (float)y; + pointX[iPoint] = (EN_API_FLOAT_TYPE)x; + pointY[iPoint] = (EN_API_FLOAT_TYPE)y; } *nValues = nPoints; @@ -1786,7 +1786,7 @@ int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float * int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, - float setting, int nindex, float level) + EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level) /*---------------------------------------------------------------- ** Input: cindex = control index (position of control statement ** in the input file, starting from 1) @@ -1874,7 +1874,7 @@ int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, } -int DLLEXPORT ENsetnodevalue(int index, int code, float v) +int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- ** Input: index = node index ** code = node parameter code (see TOOLKIT.H) @@ -2083,7 +2083,7 @@ int DLLEXPORT ENsetnodevalue(int index, int code, float v) } -int DLLEXPORT ENsetlinkvalue(int index, int code, float v) +int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- ** Input: index = link index ** code = link parameter code (see TOOLKIT.H) @@ -2270,7 +2270,7 @@ int DLLEXPORT ENaddpattern(char *id) } -int DLLEXPORT ENsetpattern(int index, float *f, int n) +int DLLEXPORT ENsetpattern(int index, EN_API_FLOAT_TYPE *f, int n) /*---------------------------------------------------------------- ** Input: index = time pattern index ** *f = array of pattern multipliers @@ -2299,7 +2299,7 @@ int DLLEXPORT ENsetpattern(int index, float *f, int n) } -int DLLEXPORT ENsetpatternvalue(int index, int period, float value) +int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value) /*---------------------------------------------------------------- ** Input: index = time pattern index ** period = time pattern period @@ -2379,7 +2379,7 @@ int DLLEXPORT ENsettimeparam(int code, long value) } -int DLLEXPORT ENsetoption(int code, float v) +int DLLEXPORT ENsetoption(int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- ** Input: code = option code (see TOOLKIT.H) ** v = option value @@ -3215,7 +3215,7 @@ int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) *numDemands=n; return 0; } -int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, float *baseDemand) +int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE *baseDemand) { Pdemand d; int n=0; @@ -3224,7 +3224,7 @@ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, float *baseDemand) if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); for(d=Node[nodeIndex].D; nnext) n++; if(n!=demandIdx) return(253); - *baseDemand=(float)(d->Base*Ucf[FLOW]); + *baseDemand=(EN_API_FLOAT_TYPE)(d->Base*Ucf[FLOW]); return 0; } int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) diff --git a/src/toolkit.h b/src/toolkit.h index eb54528..814fc39 100755 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -18,6 +18,10 @@ AUTHOR: L. Rossman #ifndef TOOLKIT_H #define TOOLKIT_H +#ifndef EN_API_FLOAT_TYPE + #define EN_API_FLOAT_TYPE float +#endif + #ifndef DLLEXPORT #ifdef DLL #ifdef __cplusplus @@ -202,16 +206,16 @@ extern "C" { int DLLEXPORT ENresetreport(void); int DLLEXPORT ENsetreport(char *); - int DLLEXPORT ENgetcontrol(int, int *, int *, float *, - int *, float *); + int DLLEXPORT ENgetcontrol(int, int *, int *, EN_API_FLOAT_TYPE *, + int *, EN_API_FLOAT_TYPE *); int DLLEXPORT ENgetcount(int, int *); - int DLLEXPORT ENgetoption(int, float *); + int DLLEXPORT ENgetoption(int, EN_API_FLOAT_TYPE *); 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 ENgetpatternvalue(int, int, EN_API_FLOAT_TYPE *); int DLLEXPORT ENgetqualtype(int *, int *); int DLLEXPORT ENgeterror(int, char *, int); int DLLEXPORT ENgetstatistic(int code, int* value); @@ -219,30 +223,30 @@ extern "C" { int DLLEXPORT ENgetnodeindex(char *, int *); int DLLEXPORT ENgetnodeid(int, char *); int DLLEXPORT ENgetnodetype(int, int *); - int DLLEXPORT ENgetnodevalue(int, int, float *); + int DLLEXPORT ENgetnodevalue(int, int, EN_API_FLOAT_TYPE *); int DLLEXPORT ENgetnumdemands(int, int *); - int DLLEXPORT ENgetbasedemand(int, int, float *); + int DLLEXPORT ENgetbasedemand(int, int, EN_API_FLOAT_TYPE *); int DLLEXPORT ENgetdemandpattern(int, int, int *); 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 ENgetlinkvalue(int, int, EN_API_FLOAT_TYPE *); - int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **yValues); + int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues); 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 ENsetcontrol(int, int, int, EN_API_FLOAT_TYPE, int, EN_API_FLOAT_TYPE); + int DLLEXPORT ENsetnodevalue(int, int, EN_API_FLOAT_TYPE); + int DLLEXPORT ENsetlinkvalue(int, int, EN_API_FLOAT_TYPE); int DLLEXPORT ENaddpattern(char *); - int DLLEXPORT ENsetpattern(int, float *, int); - int DLLEXPORT ENsetpatternvalue(int, int, float); + int DLLEXPORT ENsetpattern(int, EN_API_FLOAT_TYPE *, int); + int DLLEXPORT ENsetpatternvalue(int, int, EN_API_FLOAT_TYPE); int DLLEXPORT ENsettimeparam(int, long); - int DLLEXPORT ENsetoption(int, float); + int DLLEXPORT ENsetoption(int, EN_API_FLOAT_TYPE); int DLLEXPORT ENsetstatusreport(int); int DLLEXPORT ENsetqualtype(int, char *, char *, char *);