diff --git a/README.md b/README.md new file mode 100644 index 0000000..9aab049 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +epanet +====== + +epanet base code + +__Note:__ This is not the "official" release of EPANET -- for that, please go to [the USEPA website](http://www.epa.gov/nrmrl/wswrd/dw/epanet.html). + +However, if you are interested in extending EPANET for academic, personal, or commercial use, then this is probably a good place to be. diff --git a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj index 0404df9..f2d2e6f 100644 --- a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj +++ b/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ 22322F941068369500641384 /* rules.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7F1068369500641384 /* rules.c */; }; 22322F951068369500641384 /* smatrix.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F801068369500641384 /* smatrix.c */; }; 22322F961068369500641384 /* text.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322F811068369500641384 /* text.h */; }; - 22322F971068369500641384 /* toolkit.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322F821068369500641384 /* toolkit.h */; }; 22322F981068369500641384 /* types.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322F831068369500641384 /* types.h */; }; 22322F991068369500641384 /* vars.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322F841068369500641384 /* vars.h */; }; 22322F9A1068369500641384 /* epanet.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F711068369500641384 /* epanet.c */; }; @@ -42,8 +41,19 @@ 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 */; }; - 22EF555716BC744C00F3988A /* testLemonTiger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 22EF555516BC744C00F3988A /* testLemonTiger.cpp */; }; - 22EF555A16BC7FF500F3988A /* libepanet.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC0630554660B00DB518D /* libepanet.dylib */; }; + 2255753F17551234009946B1 /* epanet.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F711068369500641384 /* epanet.c */; }; + 2255754017551234009946B1 /* hash.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F731068369500641384 /* hash.c */; }; + 2255754117551234009946B1 /* hydraul.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F751068369500641384 /* hydraul.c */; }; + 2255754217551234009946B1 /* inpfile.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F761068369500641384 /* inpfile.c */; }; + 2255754317551234009946B1 /* input1.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F771068369500641384 /* input1.c */; }; + 2255754417551234009946B1 /* input2.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F781068369500641384 /* input2.c */; }; + 2255754517551234009946B1 /* input3.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F791068369500641384 /* input3.c */; }; + 2255754617551234009946B1 /* mempool.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7A1068369500641384 /* mempool.c */; }; + 2255754717551234009946B1 /* output.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7C1068369500641384 /* output.c */; }; + 2255754817551234009946B1 /* quality.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7D1068369500641384 /* quality.c */; }; + 2255754917551234009946B1 /* report.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7E1068369500641384 /* report.c */; }; + 2255754A17551234009946B1 /* rules.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7F1068369500641384 /* rules.c */; }; + 2255754B17551234009946B1 /* smatrix.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F801068369500641384 /* smatrix.c */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -54,31 +64,12 @@ remoteGlobalIDString = D2AAC0620554660B00DB518D; remoteInfo = epanet; }; - 2259CEF416C0A54F00A35F5E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; - proxyType = 1; - remoteGlobalIDString = D2AAC0620554660B00DB518D; - remoteInfo = epanet; - }; /* End PBXContainerItemProxy section */ -/* Begin PBXCopyFilesBuildPhase section */ - 22EF554A16BC740400F3988A /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - /* Begin PBXFileReference section */ 22322F66106833BB00641384 /* runepanet */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = runepanet; sourceTree = BUILT_PRODUCTS_DIR; }; 22322F701068369500641384 /* enumstxt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = enumstxt.h; path = ../../../src/enumstxt.h; sourceTree = SOURCE_ROOT; }; - 22322F711068369500641384 /* epanet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = epanet.c; path = ../../../src/epanet.c; sourceTree = SOURCE_ROOT; }; + 22322F711068369500641384 /* epanet.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 2; name = epanet.c; path = ../../../src/epanet.c; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.c; }; 22322F721068369500641384 /* funcs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = funcs.h; path = ../../../src/funcs.h; sourceTree = SOURCE_ROOT; }; 22322F731068369500641384 /* hash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hash.c; path = ../../../src/hash.c; sourceTree = SOURCE_ROOT; }; 22322F741068369500641384 /* hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hash.h; path = ../../../src/hash.h; sourceTree = SOURCE_ROOT; }; @@ -90,18 +81,15 @@ 22322F7A1068369500641384 /* mempool.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mempool.c; path = ../../../src/mempool.c; sourceTree = SOURCE_ROOT; }; 22322F7B1068369500641384 /* mempool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mempool.h; path = ../../../src/mempool.h; sourceTree = SOURCE_ROOT; }; 22322F7C1068369500641384 /* output.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = output.c; path = ../../../src/output.c; sourceTree = SOURCE_ROOT; }; - 22322F7D1068369500641384 /* quality.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = quality.c; path = ../../../src/quality.c; sourceTree = SOURCE_ROOT; }; + 22322F7D1068369500641384 /* quality.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 2; name = quality.c; path = ../../../src/quality.c; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.c; }; 22322F7E1068369500641384 /* report.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = report.c; path = ../../../src/report.c; sourceTree = SOURCE_ROOT; }; 22322F7F1068369500641384 /* rules.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = rules.c; path = ../../../src/rules.c; sourceTree = SOURCE_ROOT; }; 22322F801068369500641384 /* smatrix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = smatrix.c; path = ../../../src/smatrix.c; sourceTree = SOURCE_ROOT; }; 22322F811068369500641384 /* text.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = text.h; path = ../../../src/text.h; sourceTree = SOURCE_ROOT; }; - 22322F821068369500641384 /* toolkit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = toolkit.h; path = ../../../src/toolkit.h; sourceTree = SOURCE_ROOT; }; 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; }; - 22EF554C16BC740400F3988A /* TestLemonTiger */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestLemonTiger; sourceTree = BUILT_PRODUCTS_DIR; }; - 22EF555516BC744C00F3988A /* testLemonTiger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testLemonTiger.cpp; path = ../../../src/testLemonTiger.cpp; sourceTree = ""; }; - 22EF555616BC744C00F3988A /* testLemonTiger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testLemonTiger.h; path = ../../../src/testLemonTiger.h; sourceTree = ""; }; + 22322FA9106836B000641384 /* epanet2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 2; name = epanet2.h; path = ../../../include/epanet2.h; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 2255753B17551217009946B1 /* libepanet-static.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libepanet-static.a"; sourceTree = BUILT_PRODUCTS_DIR; }; D2AAC0630554660B00DB518D /* libepanet.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libepanet.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -113,11 +101,10 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 22EF554916BC740400F3988A /* Frameworks */ = { + 2255753817551217009946B1 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 22EF555A16BC7FF500F3988A /* libepanet.dylib in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -163,7 +150,6 @@ 22322F7F1068369500641384 /* rules.c */, 22322F801068369500641384 /* smatrix.c */, 22322F811068369500641384 /* text.h */, - 22322F821068369500641384 /* toolkit.h */, 22322F831068369500641384 /* types.h */, 22322F841068369500641384 /* vars.h */, ); @@ -175,7 +161,7 @@ children = ( D2AAC0630554660B00DB518D /* libepanet.dylib */, 22322F66106833BB00641384 /* runepanet */, - 22EF554C16BC740400F3988A /* TestLemonTiger */, + 2255753B17551217009946B1 /* libepanet-static.a */, ); name = Products; sourceTree = ""; @@ -191,8 +177,6 @@ 2298EBDB16B17DBD0088A6DC /* LemonTiger */ = { isa = PBXGroup; children = ( - 22EF555516BC744C00F3988A /* testLemonTiger.cpp */, - 22EF555616BC744C00F3988A /* testLemonTiger.h */, ); name = LemonTiger; sourceTree = ""; @@ -200,6 +184,13 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ + 2255753917551217009946B1 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; D2AAC0600554660B00DB518D /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -210,7 +201,6 @@ 22322F891068369500641384 /* hash.h in Headers */, 22322F901068369500641384 /* mempool.h in Headers */, 22322F961068369500641384 /* text.h in Headers */, - 22322F971068369500641384 /* toolkit.h in Headers */, 22322F981068369500641384 /* types.h in Headers */, 22322F991068369500641384 /* vars.h in Headers */, ); @@ -236,23 +226,22 @@ productReference = 22322F66106833BB00641384 /* runepanet */; productType = "com.apple.product-type.tool"; }; - 22EF554B16BC740400F3988A /* TestLemonTiger */ = { + 2255753A17551217009946B1 /* epanet-static */ = { isa = PBXNativeTarget; - buildConfigurationList = 22EF555416BC740400F3988A /* Build configuration list for PBXNativeTarget "TestLemonTiger" */; + buildConfigurationList = 2255753E17551217009946B1 /* Build configuration list for PBXNativeTarget "epanet-static" */; buildPhases = ( - 22EF554816BC740400F3988A /* Sources */, - 22EF554916BC740400F3988A /* Frameworks */, - 22EF554A16BC740400F3988A /* CopyFiles */, + 2255753717551217009946B1 /* Sources */, + 2255753817551217009946B1 /* Frameworks */, + 2255753917551217009946B1 /* Headers */, ); buildRules = ( ); dependencies = ( - 2259CEF516C0A54F00A35F5E /* PBXTargetDependency */, ); - name = TestLemonTiger; - productName = TestLemonTiger; - productReference = 22EF554C16BC740400F3988A /* TestLemonTiger */; - productType = "com.apple.product-type.tool"; + name = "epanet-static"; + productName = "epanet-static"; + productReference = 2255753B17551217009946B1 /* libepanet-static.a */; + productType = "com.apple.product-type.library.static"; }; D2AAC0620554660B00DB518D /* epanet */ = { isa = PBXNativeTarget; @@ -295,7 +284,7 @@ targets = ( D2AAC0620554660B00DB518D /* epanet */, 22322F65106833BB00641384 /* runepanet */, - 22EF554B16BC740400F3988A /* TestLemonTiger */, + 2255753A17551217009946B1 /* epanet-static */, ); }; /* End PBXProject section */ @@ -321,11 +310,23 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 22EF554816BC740400F3988A /* Sources */ = { + 2255753717551217009946B1 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 22EF555716BC744C00F3988A /* testLemonTiger.cpp in Sources */, + 2255753F17551234009946B1 /* epanet.c in Sources */, + 2255754017551234009946B1 /* hash.c in Sources */, + 2255754117551234009946B1 /* hydraul.c in Sources */, + 2255754217551234009946B1 /* inpfile.c in Sources */, + 2255754317551234009946B1 /* input1.c in Sources */, + 2255754417551234009946B1 /* input2.c in Sources */, + 2255754517551234009946B1 /* input3.c in Sources */, + 2255754617551234009946B1 /* mempool.c in Sources */, + 2255754717551234009946B1 /* output.c in Sources */, + 2255754817551234009946B1 /* quality.c in Sources */, + 2255754917551234009946B1 /* report.c in Sources */, + 2255754A17551234009946B1 /* rules.c in Sources */, + 2255754B17551234009946B1 /* smatrix.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -357,11 +358,6 @@ target = D2AAC0620554660B00DB518D /* epanet */; targetProxy = 22322FAF1068370B00641384 /* PBXContainerItemProxy */; }; - 2259CEF516C0A54F00A35F5E /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = D2AAC0620554660B00DB518D /* epanet */; - targetProxy = 2259CEF416C0A54F00A35F5E /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -375,6 +371,7 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INSTALL_PATH = /usr/local/lib; PRODUCT_NAME = epanet; @@ -390,6 +387,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; EXECUTABLE_PREFIX = lib; GCC_MODEL_TUNING = G5; + GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INSTALL_PATH = /usr/local/lib; PRODUCT_NAME = epanet; @@ -413,7 +411,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = macinclude; ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; + SDKROOT = ""; }; name = Debug; }; @@ -431,7 +429,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = macinclude; - SDKROOT = macosx; + SDKROOT = ""; }; name = Release; }; @@ -467,54 +465,44 @@ }; name = Release; }; - 22EF555216BC740400F3988A /* Debug */ = { + 2255753C17551217009946B1 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + EXECUTABLE_PREFIX = lib; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); + GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = ""; + SDKROOT = macosx; }; name = Debug; }; - 22EF555316BC740400F3988A /* Release */ = { + 2255753D17551217009946B1 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; - CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + EXECUTABLE_PREFIX = lib; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = ""; + SDKROOT = macosx; }; name = Release; }; @@ -548,11 +536,11 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 22EF555416BC740400F3988A /* Build configuration list for PBXNativeTarget "TestLemonTiger" */ = { + 2255753E17551217009946B1 /* Build configuration list for PBXNativeTarget "epanet-static" */ = { isa = XCConfigurationList; buildConfigurations = ( - 22EF555216BC740400F3988A /* Debug */, - 22EF555316BC740400F3988A /* Release */, + 2255753C17551217009946B1 /* Debug */, + 2255753D17551217009946B1 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/src/toolkit.h b/include/epanet2.h old mode 100755 new mode 100644 similarity index 50% rename from src/toolkit.h rename to include/epanet2.h index 679e7f8..f54ff9b --- a/src/toolkit.h +++ b/include/epanet2.h @@ -1,34 +1,43 @@ /* -******************************************************************* + ******************************************************************* + + TOOLKIT.H - Prototypes for EPANET Functions Exported to DLL Toolkit + + VERSION: 2.00 + DATE: 5/8/00 + 10/25/00 + 3/1/01 + 8/15/07 (2.00.11) + 2/14/08 (2.00.12) + AUTHOR: L. Rossman + US EPA - NRMRL + + ******************************************************************* + */ -TOOLKIT.H - Prototypes for EPANET Functions Exported to DLL Toolkit +#ifndef EPANET2_H +#define EPANET2_H -VERSION: 2.00 -DATE: 5/8/00 - 10/25/00 - 3/1/01 - 8/15/07 (2.00.11) - 2/14/08 (2.00.12) -AUTHOR: L. Rossman - US EPA - NRMRL +#ifndef EN_API_FLOAT_TYPE +#define EN_API_FLOAT_TYPE float +#endif -******************************************************************* -*/ - -#ifndef TOOLKIT_H -#define TOOLKIT_H - -/*** New compile directives ***/ //(2.00.11 - LR) -//#define CLE /* Compile as a command line executable */ -//#define SOL /* Compile as a shared object library */ -//#define DLL /* Compile as a Windows DLL */ - -//#define CLE_LT /* LemonTiger test */ //Jinduan Chen -#define DLL_LT /* Compile as a Windows DLL of LemonTiger */ -#ifdef __APPLE__ - #define DLLEXPORT +#ifndef DLLEXPORT +#ifdef DLL +#ifdef __cplusplus +#define DLLEXPORT extern "C" __declspec(dllexport) #else - #define DLLEXPORT __declspec(dllexport) +#define DLLEXPORT __declspec(dllexport) +#endif +#elif defined(CYGWIN) +#define DLLEXPORT __stdcall +#else +#ifdef __cplusplus +#define DLLEXPORT +#else +#define DLLEXPORT +#endif +#endif #endif // --- Define the EPANET toolkit constants @@ -167,94 +176,97 @@ AUTHOR: L. Rossman #if defined(__cplusplus) extern "C" { #endif - int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *)); - - int DLLEXPORT ENopen(char *, char *, char *); - int DLLEXPORT ENsaveinpfile(char *); - int DLLEXPORT ENclose(void); - - int DLLEXPORT ENsolveH(void); - int DLLEXPORT ENsaveH(void); - int DLLEXPORT ENopenH(void); - int DLLEXPORT ENinitH(int); - int DLLEXPORT ENrunH(long *); - int DLLEXPORT ENnextH(long *tstep); - int DLLEXPORT ENcloseH(void); - int DLLEXPORT ENsavehydfile(char *); - int DLLEXPORT ENusehydfile(char *); - - int DLLEXPORT ENsolveQ(void); - int DLLEXPORT ENopenQ(void); - int DLLEXPORT ENinitQ(int); - int DLLEXPORT ENrunQ(long *); - int DLLEXPORT ENnextQ(long *); - int DLLEXPORT ENstepQ(long *); - int DLLEXPORT ENcloseQ(void); - - int DLLEXPORT ENwriteline(char *); - int DLLEXPORT ENreport(void); - int DLLEXPORT ENresetreport(void); - int DLLEXPORT ENsetreport(char *); - - int DLLEXPORT ENgetcontrol(int, int *, int *, float *, - int *, float *); - int DLLEXPORT ENgetcount(int, int *); - int DLLEXPORT ENgetoption(int, float *); - 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 ENgetqualtype(int *, int *); - int DLLEXPORT ENgeterror(int, char *, int); - int DLLEXPORT ENgetstatistic(int code, int* value); - - int DLLEXPORT ENgetnodeindex(char *, int *); - int DLLEXPORT ENgetnodeid(int, char *); - 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 *); - int DLLEXPORT ENgetlinknodes(int, int *, int *); - int DLLEXPORT ENgetlinkvalue(int, int, float *); - - int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float **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 ENaddpattern(char *); - int DLLEXPORT ENsetpattern(int, float *, int); - int DLLEXPORT ENsetpatternvalue(int, int, float); - int DLLEXPORT ENsettimeparam(int, long); - int DLLEXPORT ENsetoption(int, float); - int DLLEXPORT ENsetstatusreport(int); - int DLLEXPORT ENsetqualtype(int, char *, char *, char *); + int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *)); + + int DLLEXPORT ENopen(char *, char *, char *); + int DLLEXPORT ENsaveinpfile(char *); + int DLLEXPORT ENclose(void); + + int DLLEXPORT ENsolveH(void); + int DLLEXPORT ENsaveH(void); + int DLLEXPORT ENopenH(void); + int DLLEXPORT ENinitH(int); + int DLLEXPORT ENrunH(long *); + int DLLEXPORT ENnextH(long *tstep); + int DLLEXPORT ENcloseH(void); + int DLLEXPORT ENsavehydfile(char *); + int DLLEXPORT ENusehydfile(char *); + + int DLLEXPORT ENsolveQ(void); + int DLLEXPORT ENopenQ(void); + int DLLEXPORT ENinitQ(int); + int DLLEXPORT ENrunQ(long *); + int DLLEXPORT ENnextQ(long *); + int DLLEXPORT ENstepQ(long *); + int DLLEXPORT ENcloseQ(void); + + int DLLEXPORT ENwriteline(char *); + int DLLEXPORT ENreport(void); + int DLLEXPORT ENresetreport(void); + int DLLEXPORT ENsetreport(char *); + + int DLLEXPORT ENgetcontrol(int, int *, int *, EN_API_FLOAT_TYPE *, + int *, EN_API_FLOAT_TYPE *); + int DLLEXPORT ENgetcount(int, int *); + 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, EN_API_FLOAT_TYPE *); + int DLLEXPORT ENgetaveragepatternvalue(int index, EN_API_FLOAT_TYPE *value); + int DLLEXPORT ENgetqualtype(int *, int *); + int DLLEXPORT ENgeterror(int, char *, int); + int DLLEXPORT ENgetstatistic(int code, int* value); + + int DLLEXPORT ENgetnodeindex(char *, int *); + int DLLEXPORT ENgetnodeid(int, char *); + int DLLEXPORT ENgetnodetype(int, int *); + int DLLEXPORT ENgetnodevalue(int, int, EN_API_FLOAT_TYPE *); + int DLLEXPORT ENgetcoord(int , EN_API_FLOAT_TYPE *, EN_API_FLOAT_TYPE *); + + int DLLEXPORT ENgetnumdemands(int, int *); + 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, EN_API_FLOAT_TYPE *); + + 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, 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, EN_API_FLOAT_TYPE *, int); + int DLLEXPORT ENsetpatternvalue(int, int, EN_API_FLOAT_TYPE); + int DLLEXPORT ENsettimeparam(int, long); + int DLLEXPORT ENsetoption(int, EN_API_FLOAT_TYPE); + int DLLEXPORT ENsetstatusreport(int); + int DLLEXPORT ENsetqualtype(int, char *, char *, char *); + //LemonTiger functions - /* See testLT.c for a LemonTiger test */ - + /* See testLT.c for a LemonTiger test */ + //LT equivalent to ENopenH() + ENopenQ() + ENinitH() + ENinitQ() int DLLEXPORT ENopeninitHQ(); - + //LT equivalent to ENrunQ() + ENnextQ(); int DLLEXPORT ENrunnextHQ(long*, long*); - + //LT equivalent to ENrunQ() + ENstepQ(); int DLLEXPORT ENrunstepHQ(long*, long*); - + //LT equivalent to ENcloseH() + ENcloseQ(); int DLLEXPORT ENcloseHQ(); - + #if defined(__cplusplus) } #endif diff --git a/src/epanet.c b/src/epanet.c index d45da30..998dd44 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -131,8 +131,9 @@ execute function x and set the error code equal to its return value. #include "types.h" #include "enumstxt.h" #include "funcs.h" +#define EXTERN #include "vars.h" -#include "toolkit.h" +#include "epanet2.h" void (* viewprog) (char *); /* Pointer to progress viewing function */ @@ -306,6 +307,7 @@ int DLLEXPORT ENopen(char *f1, char *f2, char *f3) /* Free temporary linked lists used for Patterns & Curves */ freeTmplist(Patlist); freeTmplist(Curvelist); + freeTmplist(Coordlist); /* If using previously saved hydraulics then open its file */ if (Hydflag == USE) ERRCODE(openhydfile()); @@ -963,7 +965,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) @@ -1009,9 +1011,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); } @@ -1042,7 +1044,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 @@ -1052,7 +1054,7 @@ int DLLEXPORT ENgetoption(int code, float *value) */ { double v = 0.0; - *value = 0.0f; + *value = 0.0; if (!Openflag) return(102); switch (code) { @@ -1068,7 +1070,7 @@ int DLLEXPORT ENgetoption(int code, float *value) break; default: return(251); } - *value = (float)v; + *value = (EN_API_FLOAT_TYPE)v; return(0); } @@ -1184,7 +1186,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 @@ -1194,11 +1196,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); } @@ -1333,7 +1335,22 @@ int DLLEXPORT ENgetnodetype(int index, int *code) } -int DLLEXPORT ENgetnodevalue(int index, int code, float *value) +int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y) +/*---------------------------------------------------------------- + ** Input: index = node index + ** Output: *x = value of node's coordinate + ** *x = value of node's coordinate + ** Returns: error code + ** Purpose: retrieves coordinate x, y for a node + **---------------------------------------------------------------- + */ +{ + *x = Coord[index].X[0]; + *y = Coord[index].Y[0]; + return 0; +} + +int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: index = node index ** code = node parameter code (see TOOLKIT.H) @@ -1348,7 +1365,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); @@ -1449,7 +1466,7 @@ int DLLEXPORT ENgetnodevalue(int index, int code, float *value) v = 0.0; if ( index > Njuncs ) { - v = 4.0/PI*sqrt(Tank[index-Njuncs].A)*Ucf[ELEV]; + v = sqrt(4.0/PI*Tank[index-Njuncs].A)*Ucf[ELEV]; } break; @@ -1506,7 +1523,7 @@ int DLLEXPORT ENgetnodevalue(int index, int code, float *value) default: return(251); } - *value = (float)v; + *value = (EN_API_FLOAT_TYPE)v; return(0); } @@ -1591,7 +1608,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) @@ -1604,7 +1621,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); @@ -1728,14 +1745,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) /*---------------------------------------------------------------- ** Input: curveIndex = curve index ** Output: *nValues = number of points on curve @@ -1744,21 +1759,21 @@ int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float * ** Returns: error code ** Purpose: retrieves end nodes of a specific link **---------------------------------------------------------------- - */ /* + */ { int err = 0; 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; @@ -1767,7 +1782,7 @@ int DLLEXPORT ENgetcurve(int curveIndex, int *nValues, float **xValues, float * return err; } -*/ + /* ---------------------------------------------------------------- @@ -1777,7 +1792,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) @@ -1865,7 +1880,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) @@ -2074,7 +2089,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) @@ -2261,7 +2276,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 @@ -2290,7 +2305,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 @@ -2321,10 +2336,16 @@ int DLLEXPORT ENsettimeparam(int code, long value) { if (!Openflag) return(102); if (OpenHflag || OpenQflag) { - // --> there's nothing wrong with changing certain time parameters during a simulation run - if (code != EN_DURATION) { + // --> there's nothing wrong with changing certain time parameters during a simulation run, or before the run has started. + // todo -- how to tell? + /* + if (code == EN_DURATION || code == EN_HTIME || code == EN_REPORTSTEP || code == EN_DURATION || Htime == 0) { + // it's ok + } + else { return(109); } + */ } if (value < 0) return(202); switch(code) @@ -2370,7 +2391,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 @@ -2721,10 +2742,12 @@ void initpointers() Pattern = NULL; Curve = NULL; Control = NULL; + Coord = NULL; X = NULL; Patlist = NULL; Curvelist = NULL; + Coordlist = NULL; Adjlist = NULL; Aii = NULL; Aij = NULL; @@ -2804,12 +2827,14 @@ int allocdata() Control = (Scontrol *) calloc(MaxControls+1,sizeof(Scontrol)); Pattern = (Spattern *) calloc(MaxPats+1, sizeof(Spattern)); Curve = (Scurve *) calloc(MaxCurves+1, sizeof(Scurve)); + Coord = (Scoord *) calloc(MaxNodes+1, sizeof(Scoord)); ERRCODE(MEMCHECK(Tank)); ERRCODE(MEMCHECK(Pump)); ERRCODE(MEMCHECK(Valve)); ERRCODE(MEMCHECK(Control)); ERRCODE(MEMCHECK(Pattern)); ERRCODE(MEMCHECK(Curve)); + ERRCODE(MEMCHECK(Coord)); } /* Initialize pointers used in patterns, curves, and demand category lists */ @@ -2827,7 +2852,19 @@ int allocdata() Curve[n].X = NULL; Curve[n].Y = NULL; } - for (n=0; n<=MaxNodes; n++) Node[n].D = NULL; + + for (n=0; n<=MaxNodes; n++) + { + // node demand + Node[n].D = NULL; + /* Allocate memory for coord data */ + Coord[n].X = (double *) calloc(1, sizeof(double)); + Coord[n].Y = (double *) calloc(1, sizeof(double)); + if (Coord[n].X == NULL || Coord[n].Y == NULL) return(101); + Coord[n].X[0] = 0; + Coord[n].Y[0] = 0; + } + } /* Allocate memory for rule base (see RULES.C) */ @@ -3206,22 +3243,27 @@ 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; - /* Check for valid arguments */ - if (!Openflag) return(102); - if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + Pdemand d; + int n=1; + /* Check for valid arguments */ + if (!Openflag) return(102); + if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); + if (nodeIndex <= Njuncs) { for(d=Node[nodeIndex].D; nnext) n++; if(n!=demandIdx) return(253); - *baseDemand=(float)(d->Base*Ucf[FLOW]); - return 0; + *baseDemand=(EN_API_FLOAT_TYPE)(d->Base*Ucf[FLOW]); + } + else { + *baseDemand=(EN_API_FLOAT_TYPE)(0.0); + } + return 0; } int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) { Pdemand d; - int n=0; + int n=1; /* Check for valid arguments */ if (!Openflag) return(102); if (nodeIndex <= 0 || nodeIndex > Nnodes) return(203); @@ -3231,5 +3273,27 @@ int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) return 0; } +int DLLEXPORT ENgetaveragepatternvalue(int index, EN_API_FLOAT_TYPE *value) +/*---------------------------------------------------------------- + ** Input: index = index of time pattern + ** period = pattern time period + ** Output: *value = pattern multiplier + ** Returns: error code + ** Purpose: retrieves multiplier for a specific time period + ** and pattern + **---------------------------------------------------------------- + */ +{ *value = 0.0; + if (!Openflag) return(102); + if (index < 1 || index > Npats) return(205); + //if (period < 1 || period > Pattern[index].Length) return(251); + for (int i=0; iID) == 0) return(0); + + /* Check that coordinate was not already created */ + if (findID(id,Coordlist) == NULL) + { + + /* Update coordinate count & create new list element */ + (MaxCoords)++; + c = (STmplist *) malloc(sizeof(STmplist)); + if (c == NULL) { + return(101); + } + else { + /* Initialize list element properties */ + // c->i = MaxCoords; // bug! if coordinates are not in the same order as junctions, then this is a BAD assumption + // do this later: c->i = findnode(id); + strncpy(c->ID,id,MAXID); + c->x = NULL; + c->y = NULL; + c->next = Coordlist; + Coordlist = c; + } + } + return(0); +} STmplist *findID(char *id, STmplist *list) /* @@ -704,6 +749,65 @@ int getcurves(void) return(0); } +int getcoords(void) +/* + **----------------------------------------------------------- + ** Input: none + ** Output: returns error code + ** Purpose: retrieves curve data from temporary linked list + **----------------------------------------------------------- + */ +{ + int i,j,n; + double x; + SFloatlist *xFloatList, *yFloatList; + STmplist *coordinateList; + + /* Start at head of coordinate list */ + coordinateList = Coordlist; + + /* Traverse list of coordinates */ + while (coordinateList != NULL) + { + // BAD! ---> i = coordinateList->i; + i = findnode(coordinateList->ID); + if (i >= 1 && i <= MaxNodes) + { + /* Save coordinate ID */ + strcpy(Coord[i].ID, coordinateList->ID); + + n = 1; //Coord[i].Npts + + /* Traverse list of x,y data */ + x = BIG; + xFloatList = coordinateList->x; + yFloatList = coordinateList->y; + j = n - 1; + while (xFloatList != NULL && yFloatList != NULL && j >= 0) + { + + /* Check that x data is in ascending order */ + if (xFloatList->value >= x) + { + sprintf(Msg,ERR230,coordinateList->ID); + writeline(Msg); + return(200); + } + x = xFloatList->value; + + /* Save x,y data in Curve structure */ + Coord[i].X[j] = xFloatList->value; + xFloatList = xFloatList->next; + Coord[i].Y[j] = yFloatList->value; + yFloatList = yFloatList->next; + j--; + } + } + coordinateList = coordinateList->next; + } + return(0); +} + int findmatch(char *line, char *keyword[]) /* diff --git a/src/input3.c b/src/input3.c index 8954d78..a19bfdc 100755 --- a/src/input3.c +++ b/src/input3.c @@ -31,6 +31,7 @@ All functions in this module are called from newline() in INPUT2.C. #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "vars.h" /* Defined in enumstxt.h in EPANET.C */ @@ -41,6 +42,8 @@ extern char *Fldname[]; extern char *Tok[MAXTOKS]; extern STmplist *PrevPat; extern STmplist *PrevCurve; + +extern STmplist *PrevCoord; extern int Ntokens; @@ -576,6 +579,59 @@ int curvedata() return(0); } +int coordata() +/* + **-------------------------------------------------------------- + ** Input: none + ** Output: returns error code + ** Purpose: processes coordinate data + ** Format: + ** [COORD] + ** id x y + **-------------------------------------------------------------- + */ +{ + double x,y; + SFloatlist *fx, *fy; + STmplist *c; + + /* Check for valid curve ID */ + if (Ntokens < 3) return(201); + + if ( + PrevCoord != NULL && + strcmp(Tok[0],PrevCoord->ID) == 0 + ) c = PrevCoord; + else c = findID(Tok[0],Coordlist); + + // c = findID(Tok[0],Coordlist); + if (c == NULL) return(205); + + /* Check for valid data */ + if (!getfloat(Tok[1],&x)) return(202); + if (!getfloat(Tok[2],&y)) return(202); + + /* Add new data point to curve's linked list */ + fx = (SFloatlist *) malloc(sizeof(SFloatlist)); + fy = (SFloatlist *) malloc(sizeof(SFloatlist)); + if (fx == NULL || fy == NULL) return(101); + fx->value = x; + fx->next = c->x; + c->x = fx; + fy->value = y; + fy->next = c->y; + c->y = fy; + //Curve[c->i].Npts++; + + /* Save the pointer to this curve */ + PrevCoord = c; + return(0); + + /* Save coordn data */ + //Coord[Njuncs].X = x; + //Coord[Njuncs].Y = y; + +} /* end of coordata */ int demanddata() /* diff --git a/src/output.c b/src/output.c index 8ade442..7c7516a 100755 --- a/src/output.c +++ b/src/output.c @@ -23,6 +23,7 @@ AUTHOR: L. Rossman #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "hash.h" #include "vars.h" diff --git a/src/quality.c b/src/quality.c index ef3a7ec..f7925df 100755 --- a/src/quality.c +++ b/src/quality.c @@ -59,6 +59,7 @@ AUTHOR: L. Rossman #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "vars.h" #include "mempool.h" @@ -150,8 +151,9 @@ void initqual() for (i=1; i<=Nnodes; i++) C[i] = Node[i].C0; for (i=1; i<=Ntanks; i++) Tank[i].C = Node[Tank[i].Node].C0; for (i=1; i<=Ntanks; i++) Tank[i].V = Tank[i].V0; - for (i=1; i<=Nnodes; i++) - if (Node[i].S != NULL) Node[i].S->Smass = 0.0; + for (i=1; i<=Nnodes; i++) { + if (Node[i].S != NULL) Node[i].S->Smass = 0.0; + } QTankVolumes = calloc(Ntanks, sizeof(double)); // keep track of previous step's tank volumes. QLinkFlow = calloc(Nlinks, sizeof(double)); // keep track of previous step's link flows. @@ -192,7 +194,7 @@ void initqual() /* Re-position hydraulics file */ if (!OpenHflag) { - fseek(HydFile,HydOffset,SEEK_SET); + fseek(HydFile,HydOffset,SEEK_SET); } @@ -245,6 +247,21 @@ int runqual(long *t) } } + else { + // stepwise calculation + for (int i=1; i<= Ntanks; ++i) { + QTankVolumes[i-1] = Tank[i].V; + } + + for (int i=1; i<= Nlinks; ++i) + { + if (S[i] <= CLOSED) { + QLinkFlow[i-1] = Q[i]; + } + } + + } + return(errcode); } @@ -1080,13 +1097,11 @@ void updatetanks(long dt) for (i=1; i<=Ntanks; i++) { n = Tank[i].Node; - /* Use initial quality for reservoirs */ if (Tank[i].A == 0.0) { C[n] = Node[n].C0; } - /* Update tank WQ based on mixing model */ else { switch(Tank[i].MixModel) diff --git a/src/report.c b/src/report.c index d74c1a7..b021461 100755 --- a/src/report.c +++ b/src/report.c @@ -38,6 +38,7 @@ formatted string S to the report file. #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "vars.h" #define MAXCOUNT 10 /* Max. # of disconnected nodes listed */ diff --git a/src/rules.c b/src/rules.c index e6ac10a..aa2e003 100755 --- a/src/rules.c +++ b/src/rules.c @@ -33,6 +33,7 @@ AUTHOR: L. Rossman #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "vars.h" struct Premise /* Rule Premise Clause */ diff --git a/src/smatrix.c b/src/smatrix.c index f95dada..7b0e7f3 100755 --- a/src/smatrix.c +++ b/src/smatrix.c @@ -42,6 +42,7 @@ Linsolve() solves the linearized system of hydraulic equations. #include "text.h" #include "types.h" #include "funcs.h" +#define EXTERN extern #include "vars.h" int *Degree; /* Number of links adjacent to each node */ diff --git a/src/types.h b/src/types.h index 343b11f..f9bcfab 100755 --- a/src/types.h +++ b/src/types.h @@ -167,6 +167,13 @@ typedef struct /* CURVE OBJECT */ double *Y; /* Y-values */ } Scurve; +typedef struct /* Coord OBJECT */ +{ + char ID[MAXID+1]; /* Coord ID */ + double *X; /* X-values */ + double *Y; /* Y-values */ +} Scoord; + struct Sdemand /* DEMAND CATEGORY OBJECT */ { double Base; /* Baseline demand */ @@ -208,7 +215,7 @@ typedef struct /* LINK OBJECT */ double Kb; /* Bulk react. coeff */ double Kw; /* Wall react. coeff */ double R; /* Flow resistance */ - double Rc; /* Reaction cal */ //woohn 2/11/13 + double Rc; /* Reaction cal */ char Type; /* Link type */ char Stat; /* Initial status */ char Rpt; /* Reporting flag */ diff --git a/src/vars.h b/src/vars.h index 47e638b..4378123 100755 --- a/src/vars.h +++ b/src/vars.h @@ -76,6 +76,7 @@ AUTHOR: L. Rossman MaxRules, /* Rule count */ MaxPats, /* Pattern count */ MaxCurves, /* Curve count */ + MaxCoords, /* Coords count */ Nnodes, /* Number of network nodes */ Ntanks, /* Number of tanks */ Njuncs, /* Number of junction nodes */ @@ -87,6 +88,7 @@ AUTHOR: L. Rossman Nrules, /* Number of control rules */ Npats, /* Number of time patterns */ Ncurves, /* Number of data curves */ + Ncoords, /* Number of Coords */ Nperiods, /* Number of reporting periods */ Ncoeffs, /* Number of non-0 matrix coeffs*/ DefPat, /* Default demand pattern */ @@ -151,23 +153,25 @@ AUTHOR: L. Rossman *Q, /* Link flows */ *R, /* Pipe reaction rate */ *X, /* General purpose array */ - *XC; /* General Purpose array - WQ */ - double *H; /* Node heads */ - double *QTankVolumes; - double *QLinkFlow; //woohn 03112013 - STmplist *Patlist; /* Temporary time pattern list */ - STmplist *Curvelist; /* Temporary list of curves */ - Spattern *Pattern; /* Time patterns */ - Scurve *Curve; /* Curve data */ - Snode *Node; /* Node data */ - Slink *Link; /* Link data */ - Stank *Tank; /* Tank data */ - Spump *Pump; /* Pump data */ - Svalve *Valve; /* Valve data */ - Scontrol *Control; /* Control data */ - HTtable *Nht, *Lht; /* Hash tables for ID labels */ - Padjlist *Adjlist; /* Node adjacency lists */ - int _relativeError, _iterations; /* Info about hydraulic solution */ + *XC; /* General purpose array */ +EXTERN double *H; /* Node heads */ +EXTERN double *QTankVolumes; +EXTERN double *QLinkFlow; +EXTERN STmplist *Patlist; /* Temporary time pattern list */ +EXTERN STmplist *Curvelist; /* Temporary list of curves */ +EXTERN STmplist *Coordlist; /* Temporary list of coordinates*/ +EXTERN Spattern *Pattern; /* Time patterns */ +EXTERN Scurve *Curve; /* Curve data */ +EXTERN Scoord *Coord; /* Coordinate data */ +EXTERN Snode *Node; /* Node data */ +EXTERN Slink *Link; /* Link data */ +EXTERN Stank *Tank; /* Tank data */ +EXTERN Spump *Pump; /* Pump data */ +EXTERN Svalve *Valve; /* Valve data */ +EXTERN Scontrol *Control; /* Control data */ +EXTERN HTtable *Nht, *Lht; /* Hash tables for ID labels */ +EXTERN Padjlist *Adjlist; /* Node adjacency lists */ +EXTERN int _relativeError, _iterations; /* Info about hydraulic solution */ /* ** NOTE: Hydraulic analysis of the pipe network at a given point in time