From 2d064c60ece7759bc78b0e17563cbfe60c67d2ae Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:34:06 -0400 Subject: [PATCH 01/33] build files --- build/Linux/Makefile | 108 ------------- build/Linux/Makefile_Rev | 111 ------------- build/MSVS/LemonTigerJ.sln | 20 --- build/MSVS/LemonTigerJ.vcxproj | 105 ------------ build/WinSDK/Readme.txt | 17 ++ build/WinSDK/dll_win_make.bat | 11 ++ build/WinSDK/exe_win_make.bat | 11 ++ .../epanet.xcodeproj/project.pbxproj | 151 +++++++----------- .../contents.xcworkspacedata | 7 - 9 files changed, 98 insertions(+), 443 deletions(-) delete mode 100755 build/Linux/Makefile delete mode 100755 build/Linux/Makefile_Rev delete mode 100755 build/MSVS/LemonTigerJ.sln delete mode 100755 build/MSVS/LemonTigerJ.vcxproj create mode 100644 build/WinSDK/Readme.txt create mode 100644 build/WinSDK/dll_win_make.bat create mode 100644 build/WinSDK/exe_win_make.bat rename build/Xcode/{epanet => }/epanet.xcodeproj/project.pbxproj (79%) delete mode 100755 build/Xcode/epanet/epanet.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/build/Linux/Makefile b/build/Linux/Makefile deleted file mode 100755 index d08b6df..0000000 --- a/build/Linux/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -# Linux Makefile for EPANET - -# This will build EPANET as a shared object library -# (libepanet2.so) under Linux/Unix, and a standalone -# executable (epanet2). - -# The following targets are defined: -# make -# -Builds libepanet2.so, epanet2 -# make install -# -Creates shell wrapper runepanet2.sh that executes epanet2. -# The runepanet2.sh wrapper simply exports -# environment variables that help locate the runtime library, -# allowing you to specify your own library locations. -# -Installs epanet2 and runepanet2.sh -# in /bin, where defaults to ~ (and can be set -# below to something different - see "Install directories") -# -Installs libepanet2.so in /lib -# -Installs epanet2.h in /include. This is the required -# header file for the EPANET programmer's toolkit, and thus -# /include should be on your CPP include search path -# for subsequent use of the toolkit and linking with the -# library libepanet2.so -# make clean -# -Removes object and library files, returning the build directory -# to its pristine state. - -# You may wish to change the install path 'prefix', -# or the compiler flags, but these defaults should be fine. - -SHELL = /bin/sh - -# Target filenames -epanetrootname := epanet2 -libname := lib$(epanetrootname).so -exename := $(epanetrootname) -# Shell wrapper -runcmdtemplate = runepanet.sh.template -runcmdname = runepanet2.sh -# Location of EPANET toolkit includes -epanetincludedir = ../../include -# Search path for sources -epanetsrcdir = ../../src -VPATH = $(epanetsrcdir):$(epanetincludedir) - -# Install directories -prefix = ~ -exec_prefix = $(prefix) -libdir = $(exec_prefix)/lib -bindir = $(exec_prefix)/bin -includedir = $(prefix)/include -datarootdir = $(prefix)/share -docdir = $(datarootdir)/doc/epanet - -# Compiler and flags -CC = gcc -CFLAGS = -g -O3 -fPIC -CPPFLAGS = -I $(epanetincludedir) -LDFLAGS = -L . -Wl,-rpath,$(libdir) -lm - -# Installer -INSTALL = install -INSTALL_PROGRAM = $(INSTALL) -INSTALL_DATA = $(INSTALL) -m 644 - -# Files for the shared object library -epanet_objs=hash.o hydraul.o inpfile.o input1.o input2.o \ - input3.o mempool.o output.o quality.o report.o \ - rules.o smatrix.o -# Epanet header files -epanet_heads=enumstxt.h funcs.h hash.h mempool.h text.h toolkit.h types.h vars.h -# Epanet main program -epanet_main=epanet -# Epanet main program header files -epanet_main_heads=epanet2.h - -.PHONY: all -all: $(libname) $(exename) - -$(libname): $(epanet_objs) - $(CC) $(CFLAGS) $(CPPFLAGS) -D SOL -c $(epanetsrcdir)/$(epanet_main).c - $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(epanet_main).o $^ - -$(exename): $(libname) $(epanet_main_heads) - $(CC) $(CFLAGS) $(CPPFLAGS) -D CLE -c $(epanetsrcdir)/$(epanet_main).c - $(CC) $(CFLAGS) -o $@ $(epanet_main).o -l$(epanetrootname) $(LDFLAGS) - -$(epanet_objs): $(epanet_heads) - -.PHONY: install -install: - cat $(runcmdtemplate) | sed 's|libdir|$(libdir)|' \ - | sed 's|exename|$(bindir)/$(exename)|' \ - > $(runcmdname) - $(INSTALL_PROGRAM) -D $(exename) $(bindir)/$(exename) - $(INSTALL_PROGRAM) -D $(libname) $(libdir)/$(libname) - $(INSTALL_DATA) -D $(epanetincludedir)/epanet2.h $(includedir)/epanet2.h - $(INSTALL_PROGRAM) -D $(runcmdname) $(bindir)/$(runcmdname) - -.PHONY: uninstall -uninstall: - -.PHONY: check -check: - -.PHONY: clean -clean: - -/bin/rm *.o $(libname) $(exename) $(runcmdname) diff --git a/build/Linux/Makefile_Rev b/build/Linux/Makefile_Rev deleted file mode 100755 index 488e471..0000000 --- a/build/Linux/Makefile_Rev +++ /dev/null @@ -1,111 +0,0 @@ -# Linux Makefile for EPANET - -# This will build EPANET as a shared object library -# (libepanet_gcc_.so) under Linux/Unix, and a standalone -# executable (epanet_gcc_). - -# The following targets are defined: -# make -# -Builds libepanet_gcc_.so, epanet_gcc_ -# make install -# -Creates shell wrapper runepanet_.sh that executes epanet_gcc_.exe. -# The runepanet_.sh wrapper simply exports -# environment variables that help locate the runtime library, -# allowing you to specify your own library locations. -# -Installs epanet_gcc_ and runepanet_.sh -# in /bin, where defaults to ~ (and can be set -# below to something different - see "Install directories") -# -Installs libepanet_gcc_.so in /lib -# -Installs epanet2.h in /include. This is the required -# header file for the EPANET programmer's toolkit, and thus -# /include should be on your CPP include search path -# for subsequent use of the toolkit and linking with the -# library libepanet_gcc_.so -# make clean -# -Removes object and library files, returning the build directory -# to its pristine state. - -# You may wish to change the install path 'prefix', -# or the compiler flags, but these defaults should be fine. - -SHELL = /bin/sh - -# Target filenames -# svnname.sh constructs a name: -# where is the atomic revision number of the svn repo. -epanetsvnpath = ../../.. -epanetrootname := $(shell ../svnname.sh $(epanetsvnpath) "" epanet_gcc_ "") -libname := lib$(epanetrootname).so -exename := $(epanetrootname) -# Shell wrapper -runcmdtemplate = runepanet.sh.template -runcmdname = $(shell ../svnname.sh $(epanetsvnpath) "" runepanet_ .sh) -# Location of EPANET toolkit includes -epanetincludedir = ../../include -# Search path for sources -epanetsrcdir = ../../src -VPATH = $(epanetsrcdir):$(epanetincludedir) - -# Install directories -prefix = ~ -exec_prefix = $(prefix) -libdir = $(exec_prefix)/lib -bindir = $(exec_prefix)/bin -includedir = $(prefix)/include -datarootdir = $(prefix)/share -docdir = $(datarootdir)/doc/epanet - -# Compiler and flags -CC = gcc -CFLAGS = -g -O3 -fPIC -CPPFLAGS = -I $(epanetincludedir) -LDFLAGS = -L . -Wl,-rpath,$(libdir) -lm - -# Installer -INSTALL = install -INSTALL_PROGRAM = $(INSTALL) -INSTALL_DATA = $(INSTALL) -m 644 - -# Files for the shared object library -epanet_objs=hash.o hydraul.o inpfile.o input1.o input2.o \ - input3.o mempool.o output.o quality.o report.o \ - rules.o smatrix.o -# Epanet header files -epanet_heads=enumstxt.h funcs.h hash.h mempool.h text.h toolkit.h types.h vars.h -# Epanet main program -epanet_main=epanet -# Epanet main program header files -epanet_main_heads=epanet2.h - -.PHONY: all -all: $(libname) $(exename) - -$(libname): $(epanet_objs) - $(CC) $(CFLAGS) $(CPPFLAGS) -D SOL -c $(epanetsrcdir)/$(epanet_main).c - $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(epanet_main).o $^ - -$(exename): $(libname) $(epanet_main_heads) - $(CC) $(CFLAGS) $(CPPFLAGS) -D CLE -c $(epanetsrcdir)/$(epanet_main).c - $(CC) $(CFLAGS) -o $@ $(epanet_main).o -l$(epanetrootname) $(LDFLAGS) - -$(epanet_objs): $(epanet_heads) - -.PHONY: install -install: - cat $(runcmdtemplate) | sed 's|libdir|$(libdir)|' \ - | sed 's|exename|$(bindir)/$(exename)|' \ - > $(runcmdname) - $(INSTALL_PROGRAM) -D $(exename) $(bindir)/$(exename) - $(INSTALL_PROGRAM) -D $(libname) $(libdir)/$(libname) - $(INSTALL_DATA) -D $(epanetincludedir)/epanet2.h $(includedir)/epanet2.h - $(INSTALL_PROGRAM) -D $(runcmdname) $(bindir)/$(runcmdname) - -.PHONY: uninstall -uninstall: - -.PHONY: check -check: - -.PHONY: clean -clean: - -/bin/rm *.o $(libname) $(exename) $(runcmdname) diff --git a/build/MSVS/LemonTigerJ.sln b/build/MSVS/LemonTigerJ.sln deleted file mode 100755 index f61001a..0000000 --- a/build/MSVS/LemonTigerJ.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LemonTigerJ", "LemonTigerJ.vcxproj", "{4B66D9F0-407B-4995-B625-1CA1B72662C6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4B66D9F0-407B-4995-B625-1CA1B72662C6}.Debug|Win32.ActiveCfg = Debug|Win32 - {4B66D9F0-407B-4995-B625-1CA1B72662C6}.Debug|Win32.Build.0 = Debug|Win32 - {4B66D9F0-407B-4995-B625-1CA1B72662C6}.Release|Win32.ActiveCfg = Release|Win32 - {4B66D9F0-407B-4995-B625-1CA1B72662C6}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/build/MSVS/LemonTigerJ.vcxproj b/build/MSVS/LemonTigerJ.vcxproj deleted file mode 100755 index 7ffa87b..0000000 --- a/build/MSVS/LemonTigerJ.vcxproj +++ /dev/null @@ -1,105 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {4B66D9F0-407B-4995-B625-1CA1B72662C6} - Win32Proj - - - - DynamicLibrary - true - v110 - - - Application - false - v110 - - - - - - - - - - - - - true - - - true - - - - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - .\include - - - MachineX86 - true - Console - - - - - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - MultiThreadedDLL - Level3 - ProgramDatabase - - - MachineX86 - true - Console - true - true - - - - - - \ No newline at end of file diff --git a/build/WinSDK/Readme.txt b/build/WinSDK/Readme.txt new file mode 100644 index 0000000..c7d5f1c --- /dev/null +++ b/build/WinSDK/Readme.txt @@ -0,0 +1,17 @@ +For compiling EPANET2.DLL : + +Open the EPANET.C file and make sure that the line + #define DLL + is not commented out while the lines + #define CLE + #define SOL + are commented out. + +For compiling EPANET2.EXE : + +Open the EPANET.C file and make sure that the line + #define CLE + is not commented out while the lines + #define DLL + #define SOL + are commented out. diff --git a/build/WinSDK/dll_win_make.bat b/build/WinSDK/dll_win_make.bat new file mode 100644 index 0000000..611b64f --- /dev/null +++ b/build/WinSDK/dll_win_make.bat @@ -0,0 +1,11 @@ +rem : set path to Windows SDK +SET SDK_PATH="C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\" + +rem : set path for source EPANET files +SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" + +CALL %SDK_PATH%SetEnv.cmd /x86 /release +CHDIR /D %SRC_PATH% + +rem : do the magic ... +cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:epanet2.def /MAP \ No newline at end of file diff --git a/build/WinSDK/exe_win_make.bat b/build/WinSDK/exe_win_make.bat new file mode 100644 index 0000000..d068859 --- /dev/null +++ b/build/WinSDK/exe_win_make.bat @@ -0,0 +1,11 @@ +rem : set path to Windows SDK +SET SDK_PATH="C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\" + +rem : set path for source EPANET files +SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" + +CALL %SDK_PATH%SetEnv.cmd /x86 /release +CHDIR /D %SRC_PATH% + +rem : do the magic ... +cl -o epanet2.exe ..\run\main.c /I ..\include /I ..\run /I ..\src /link \ No newline at end of file diff --git a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj b/build/Xcode/epanet.xcodeproj/project.pbxproj similarity index 79% rename from build/Xcode/epanet/epanet.xcodeproj/project.pbxproj rename to build/Xcode/epanet.xcodeproj/project.pbxproj index f7a110a..7d48c46 100755 --- a/build/Xcode/epanet/epanet.xcodeproj/project.pbxproj +++ b/build/Xcode/epanet.xcodeproj/project.pbxproj @@ -27,19 +27,6 @@ 22322F961068369500641384 /* text.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322F811068369500641384 /* text.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 */; }; - 22322F9B1068369500641384 /* hash.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F731068369500641384 /* hash.c */; }; - 22322F9C1068369500641384 /* hydraul.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F751068369500641384 /* hydraul.c */; }; - 22322F9D1068369500641384 /* inpfile.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F761068369500641384 /* inpfile.c */; }; - 22322F9E1068369500641384 /* input1.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F771068369500641384 /* input1.c */; }; - 22322F9F1068369500641384 /* input2.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F781068369500641384 /* input2.c */; }; - 22322FA01068369500641384 /* input3.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F791068369500641384 /* input3.c */; }; - 22322FA11068369500641384 /* mempool.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7A1068369500641384 /* mempool.c */; }; - 22322FA21068369500641384 /* output.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7C1068369500641384 /* output.c */; }; - 22322FA31068369500641384 /* quality.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7D1068369500641384 /* quality.c */; }; - 22322FA41068369500641384 /* report.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7E1068369500641384 /* report.c */; }; - 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 */; settings = {ATTRIBUTES = (Public, ); }; }; 2255753F17551234009946B1 /* epanet.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F711068369500641384 /* epanet.c */; }; 2255754017551234009946B1 /* hash.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F731068369500641384 /* hash.c */; }; @@ -55,42 +42,45 @@ 2255754A17551234009946B1 /* rules.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F7F1068369500641384 /* rules.c */; }; 2255754B17551234009946B1 /* smatrix.c in Sources */ = {isa = PBXBuildFile; fileRef = 22322F801068369500641384 /* smatrix.c */; }; 226537E0179EDEEB00258C60 /* epanet2.h in Headers */ = {isa = PBXBuildFile; fileRef = 22322FA9106836B000641384 /* epanet2.h */; }; + 22CD9A5E1B27898E00B65E83 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 22CD9A5D1B27898E00B65E83 /* main.c */; }; + 22CD9A611B278BB900B65E83 /* libepanet-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2255753B17551217009946B1 /* libepanet-static.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 22322FAF1068370B00641384 /* PBXContainerItemProxy */ = { + 22CD9A5F1B278B0400B65E83 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; proxyType = 1; - remoteGlobalIDString = D2AAC0620554660B00DB518D; - remoteInfo = epanet; + remoteGlobalIDString = 2255753A17551217009946B1; + remoteInfo = "epanet-static"; }; /* End PBXContainerItemProxy 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; 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; }; - 22322F751068369500641384 /* hydraul.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hydraul.c; path = ../../../src/hydraul.c; sourceTree = SOURCE_ROOT; }; - 22322F761068369500641384 /* inpfile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inpfile.c; path = ../../../src/inpfile.c; sourceTree = SOURCE_ROOT; }; - 22322F771068369500641384 /* input1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input1.c; path = ../../../src/input1.c; sourceTree = SOURCE_ROOT; }; - 22322F781068369500641384 /* input2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input2.c; path = ../../../src/input2.c; sourceTree = SOURCE_ROOT; }; - 22322F791068369500641384 /* input3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input3.c; path = ../../../src/input3.c; sourceTree = SOURCE_ROOT; }; - 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; 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; }; - 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; lineEnding = 2; name = epanet2.h; path = ../../../include/epanet2.h; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 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; 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; }; + 22322F751068369500641384 /* hydraul.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hydraul.c; path = ../../src/hydraul.c; sourceTree = SOURCE_ROOT; }; + 22322F761068369500641384 /* inpfile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = inpfile.c; path = ../../src/inpfile.c; sourceTree = SOURCE_ROOT; }; + 22322F771068369500641384 /* input1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input1.c; path = ../../src/input1.c; sourceTree = SOURCE_ROOT; }; + 22322F781068369500641384 /* input2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input2.c; path = ../../src/input2.c; sourceTree = SOURCE_ROOT; }; + 22322F791068369500641384 /* input3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input3.c; path = ../../src/input3.c; sourceTree = SOURCE_ROOT; }; + 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; 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; }; + 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; 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; }; + 22CD9A5D1B27898E00B65E83 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = main.c; path = ../../run/main.c; sourceTree = ""; }; D2AAC0630554660B00DB518D /* libepanet.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libepanet.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -99,6 +89,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 22CD9A611B278BB900B65E83 /* libepanet-static.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -122,6 +113,7 @@ 08FB7794FE84155DC02AAC07 /* epanet */ = { isa = PBXGroup; children = ( + 22CD9A5C1B27896200B65E83 /* run epanet */, 22322FA8106836A000641384 /* Include */, 08FB7795FE84155DC02AAC07 /* Source */, 1AB674ADFE9D54B511CA2CBB /* Products */, @@ -174,6 +166,14 @@ name = Include; sourceTree = ""; }; + 22CD9A5C1B27896200B65E83 /* run epanet */ = { + isa = PBXGroup; + children = ( + 22CD9A5D1B27898E00B65E83 /* main.c */, + ); + name = "run epanet"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -213,7 +213,7 @@ buildRules = ( ); dependencies = ( - 22322FB01068370B00641384 /* PBXTargetDependency */, + 22CD9A601B278B0400B65E83 /* PBXTargetDependency */, ); name = runepanet; productName = runepanet; @@ -260,7 +260,7 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0630; }; buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "epanet" */; compatibilityVersion = "Xcode 3.2"; @@ -288,19 +288,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 22322F9A1068369500641384 /* epanet.c in Sources */, - 22322F9B1068369500641384 /* hash.c in Sources */, - 22322F9C1068369500641384 /* hydraul.c in Sources */, - 22322F9D1068369500641384 /* inpfile.c in Sources */, - 22322F9E1068369500641384 /* input1.c in Sources */, - 22322F9F1068369500641384 /* input2.c in Sources */, - 22322FA01068369500641384 /* input3.c in Sources */, - 22322FA11068369500641384 /* mempool.c in Sources */, - 22322FA21068369500641384 /* output.c in Sources */, - 22322FA31068369500641384 /* quality.c in Sources */, - 22322FA41068369500641384 /* report.c in Sources */, - 22322FA51068369500641384 /* rules.c in Sources */, - 22322FA61068369500641384 /* smatrix.c in Sources */, + 22CD9A5E1B27898E00B65E83 /* main.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -347,10 +335,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 22322FB01068370B00641384 /* PBXTargetDependency */ = { + 22CD9A601B278B0400B65E83 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = D2AAC0620554660B00DB518D /* epanet */; - targetProxy = 22322FAF1068370B00641384 /* PBXContainerItemProxy */; + target = 2255753A17551217009946B1 /* epanet-static */; + targetProxy = 22CD9A5F1B278B0400B65E83 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -359,17 +347,11 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; EXECUTABLE_PREFIX = lib; - 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; - SDKROOT = ""; }; name = Debug; }; @@ -377,28 +359,28 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - COMBINE_HIDPI_IMAGES = YES; - 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; - SDKROOT = ""; }; name = Release; }; 1DEB914F08733D8E0010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LIBRARY = "libc++"; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = c89; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -407,7 +389,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = macinclude; + HEADER_SEARCH_PATHS = ""; ONLY_ACTIVE_ARCH = YES; SDKROOT = ""; }; @@ -416,13 +398,18 @@ 1DEB915008733D8E0010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LIBRARY = "libc++"; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = c89; + GCC_NO_COMMON_BLOCKS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -430,7 +417,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = macinclude; + HEADER_SEARCH_PATHS = ""; SDKROOT = ""; }; name = Release; @@ -439,14 +426,10 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = NO; - GCC_DYNAMIC_NO_PIC = NO; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = CLE; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_PREPROCESSOR_DEFINITIONS = ""; - INSTALL_PATH = /usr/local/bin; PRODUCT_NAME = runepanet; }; name = Debug; @@ -455,13 +438,9 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; GCC_PREPROCESSOR_DEFINITIONS = CLE; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_PREPROCESSOR_DEFINITIONS = ""; - INSTALL_PATH = /usr/local/bin; PRODUCT_NAME = runepanet; ZERO_LINK = NO; }; @@ -471,20 +450,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; CLANG_WARN_EMPTY_BODY = YES; - COPY_PHASE_STRIP = NO; + COMBINE_HIDPI_IMAGES = YES; EXECUTABLE_PREFIX = lib; - GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SKIP_INSTALL = YES; }; name = Debug; }; @@ -492,19 +465,13 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; CLANG_WARN_EMPTY_BODY = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + COMBINE_HIDPI_IMAGES = YES; EXECUTABLE_PREFIX = lib; GCC_ENABLE_OBJC_EXCEPTIONS = YES; GCC_PREPROCESSOR_DEFINITIONS = "EN_API_FLOAT_TYPE=double"; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - SKIP_INSTALL = YES; }; name = Release; }; diff --git a/build/Xcode/epanet/epanet.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/build/Xcode/epanet/epanet.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100755 index 052c6dc..0000000 --- a/build/Xcode/epanet/epanet.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - From 33edb5ba5775182bb6054fc91e121df225ffdd46 Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:34:12 -0400 Subject: [PATCH 02/33] cmake --- build/CMake/CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 build/CMake/CMakeLists.txt diff --git a/build/CMake/CMakeLists.txt b/build/CMake/CMakeLists.txt new file mode 100644 index 0000000..5aaa576 --- /dev/null +++ b/build/CMake/CMakeLists.txt @@ -0,0 +1,18 @@ +## cmake . +## make + +cmake_minimum_required (VERSION 2.6) + +SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) +SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) + +project (EPANET) + +# the library +include_directories(../../include) +add_library(epanet STATIC ../../src/epanet.c ../../src/hydraul.c ../../src/hash.c ../../src/inpfile.c ../../src/input1.c ../../src/input2.c ../../src/input3.c ../../src/mempool.c ../../src/output.c ../../src/quality.c ../../src/report.c ../../src/rules.c ../../src/smatrix.c) + +# the standalone executable +include_directories(../../src) +add_executable(runepanet ../../run/main.c) +target_link_libraries (runepanet LINK_PUBLIC epanet) From dfe879af19fe6609af73ab16c7c0ddf3ed11e86c Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:34:25 -0400 Subject: [PATCH 03/33] standalone utility --- run/main.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 run/main.c diff --git a/run/main.c b/run/main.c new file mode 100644 index 0000000..83949a7 --- /dev/null +++ b/run/main.c @@ -0,0 +1,75 @@ +#include +#include "epanet2.h" +#include "text.h" + +void writeConsole(char *s); + +extern char Warnflag; + +/* +---------------------------------------------------------------- + Entry point used to compile a stand-alone executable. +---------------------------------------------------------------- +*/ + + +int main(int argc, char *argv[]) +/*-------------------------------------------------------------- + ** Input: argc = number of command line arguments + ** *argv[] = array of command line arguments + ** Output: none + ** Purpose: main program segment + ** + ** Command line for stand-alone operation is: + ** progname f1 f2 f3 + ** where progname = name of executable this code was compiled to, + ** f1 = name of input file, f2 = name of report file, and + ** f3 = name of binary output file (optional). + **-------------------------------------------------------------- + */ +{ + char *f1,*f2,*f3; + char blank[] = ""; + int errcode; + + /* Check for proper number of command line arguments */ + if (argc < 3) { + writeConsole(FMT03); + } + else { + /* Call the main control function */ + f1 = argv[1]; + f2 = argv[2]; + if (argc > 3) { + f3 = argv[3]; + } + else { + f3 = blank; + } + writeConsole(FMT01); + errcode = ENepanet(f1,f2,f3,NULL); + if (errcode > 0) { + writeConsole(FMT11); + } + else if (Warnflag > 0) { + writeConsole(FMT10); + } + else { + writeConsole(FMT09); + } + } + return(0); +} /* End of main */ + + +void writeConsole(char *s) +/*---------------------------------------------------------------- + ** Input: text string + ** Output: none + ** Purpose: writes string of characters to console + **---------------------------------------------------------------- + */ +{ + fprintf(stdout,"%s",s); + fflush(stdout); +} From bee95a6ee223ef024575e8cdd10e62c2735a2aff Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:34:40 -0400 Subject: [PATCH 04/33] c89 conformance --- src/quality.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/quality.c b/src/quality.c index be9193d..48b58f2 100755 --- a/src/quality.c +++ b/src/quality.c @@ -222,7 +222,8 @@ int runqual(long *t) long hydtime; /* Hydraulic solution time */ long hydstep; /* Hydraulic time step */ int errcode = 0; - + int i; + /* Update reported simulation time */ *t = Qtime; @@ -240,7 +241,7 @@ int runqual(long *t) QTankVolumes[i-1] = Tank[i].V; } - for (int i=1; i<= Nlinks; ++i) + for (i=1; i<= Nlinks; ++i) { if (LinkStatus[i] <= CLOSED) { QLinkFlow[i-1] = Q[i]; @@ -251,11 +252,11 @@ int runqual(long *t) } else { // stepwise calculation - for (int i=1; i<= Ntanks; ++i) { + for (i=1; i<= Ntanks; ++i) { QTankVolumes[i-1] = Tank[i].V; } - for (int i=1; i<= Nlinks; ++i) + for (i=1; i<= Nlinks; ++i) { if (LinkStatus[i] <= CLOSED) { QLinkFlow[i-1] = Q[i]; @@ -281,7 +282,7 @@ int nextqual(long *tstep) { long hydstep; /* Hydraulic solution time step */ int errcode = 0; - + int i; /* Determine time step */ *tstep = 0; @@ -302,7 +303,7 @@ int nextqual(long *tstep) } // restore the previous step's tank volumes - for (int i=1; i<=Ntanks; i++) { + for (i=1; i<=Ntanks; i++) { if (Tank[i].A != 0) { // skip reservoirs again int n = Tank[i].Node; Tank[i].V = QTankVolumes[i-1]; @@ -311,7 +312,7 @@ int nextqual(long *tstep) } // restore the previous step's pipe link flows - for (int i=1; i<=Nlinks; i++) { + for (i=1; i<=Nlinks; i++) { if (LinkStatus[i] <= CLOSED) { Q[i] = 0.0; } @@ -332,7 +333,7 @@ int nextqual(long *tstep) // restore tank levels to post-runH state, if needed. if (OpenHflag) { - for (int i=1; i<=Ntanks; i++) { + for (i=1; i<=Ntanks; i++) { if (Tank[i].A != 0) { // skip reservoirs again int n = Tank[i].Node; Tank[i].V = tankVolumes[i-1]; @@ -340,7 +341,7 @@ int nextqual(long *tstep) } } - for (int i=1; i<=Nlinks; ++i) { + for (i=1; i<=Nlinks; ++i) { if (LinkStatus[i] <= CLOSED) { Q[i] = QLinkFlow[i-1]; } From 38bb3a57e0a4fe2f93666724905e1a3231a16b2f Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:34:50 -0400 Subject: [PATCH 05/33] remove old files --- src/testLemonTiger.cpp | 332 ----------------------------------------- src/testLemonTiger.h | 15 -- src/toolkit.h | 255 ------------------------------- 3 files changed, 602 deletions(-) delete mode 100755 src/testLemonTiger.cpp delete mode 100755 src/testLemonTiger.h delete mode 100755 src/toolkit.h diff --git a/src/testLemonTiger.cpp b/src/testLemonTiger.cpp deleted file mode 100755 index 0863e9a..0000000 --- a/src/testLemonTiger.cpp +++ /dev/null @@ -1,332 +0,0 @@ -#include -#include -#include -#include -#include -#include "testLemonTiger.h" -#include "toolkit.h" - -#define COLW 15 -#define OUTPRECISION 6 - -using namespace std; - -typedef struct { - double head; - double demand; - double quality; -} nodeState_t; - -typedef struct { - double flow; -} linkState_t; - -typedef map networkNodeState_t; // nodeIndex, state -typedef map networkLinkState_t; // linkIndex, state - -typedef struct { - networkNodeState_t nodeState; - networkLinkState_t linkState; -} networkState_t; -typedef map result_t; // time, networkState -// access results by, for instance, resultsContainer[time][nodeIndex].head - - - -void checkErr(int err, std::string function); -void saveHydResults(networkState_t* networkState); -void saveQualResults(networkState_t* networkState); -void printResults(result_t* state1, result_t* state2, std::ostream& out); -void compare(result_t* results1, result_t* results2, std::ostream &out); - -int main(int argc, char * argv[]) { - - // create storage structures for results. - result_t epanetResults, lemonTigerResults; - - cout << "Lemon Tiger TEST" << endl - << "________________" << endl; - - - long simulationTime = 0; - long nextEventH = 0, nextEventQ = 0; - long simTimeRemaining = 0; - - try { - - /* Batch solver (old epanet) */ - cout << "*****Original EPANET results******" << endl; - checkErr( ENopen(argv[1], argv[2], (char*)""), "ENopen" ); - - checkErr( ENopenH(), "ENopenH" ); - checkErr( ENinitH(EN_SAVE), "ENinitH" ); - - cout << "Running hydraulics..." << endl; - do { - - /* Solve for hydraulics & advance to next time period */ - checkErr( ENrunH(&simulationTime), "ENrunH" ); - checkErr( ENnextH(&nextEventH), "ENnextH" ); - - // gather hydraulic results - saveHydResults(&epanetResults[simulationTime]); - - - - } while (nextEventH > 0); - // hydraulics are done - checkErr( ENcloseH(), "ENcloseH" ); - cout << "\t\t\tdone." << endl; - cout << "Running WQ..." << endl; - - checkErr( ENopenQ(), "ENopenQ" ); - checkErr( ENinitQ(EN_NOSAVE), "ENinitQ" ); - - do { - - checkErr( ENrunQ(&simulationTime), "ENrunQ" ); - checkErr( ENnextQ(&nextEventH), "ENstepQ" ); - - // gather quality results - saveQualResults(&epanetResults[simulationTime]); - - } while (nextEventH > 0); - // water quality is done - checkErr( ENcloseQ(), "ENcloseQ" ); - cout << "\t\t\tdone." << endl; - - // everything is done - checkErr( ENclose(), "ENclose" ); - - - nextEventH = 0; - simTimeRemaining = 0; - simulationTime = 0; - - /* stepwise solver (LemonTiger) */ - cout << "*****LemonTiger results******" << endl; - - checkErr( ENopen(argv[1], argv[2], (char*)""), "ENopen" ); - - checkErr( ENopenH(), "ENopenH" ); - checkErr( ENinitH(EN_NOSAVE), "ENinitH" ); - checkErr( ENopenQ(), "ENopenQ" ); - checkErr( ENinitQ(EN_NOSAVE), "ENinitQ" ); - - cout << "Running stepwise hydraulics and water quality..." << endl; - do { - /* Solve for hydraulics & advance to next time period */ - checkErr( ENrunH(&simulationTime), "ENrunH" ); - checkErr( ENrunQ(&simulationTime), "ENrunQ" ); - - checkErr( ENnextH(&nextEventH), "ENnextH" ); - checkErr( ENnextQ(&nextEventQ), "ENstepQ" ); - - - saveHydResults(&lemonTigerResults[simulationTime]); - saveQualResults(&lemonTigerResults[simulationTime]); - - - } while (nextEventH > 0); - cout << "\t\t\tdone." << endl; - - // all done - checkErr( ENcloseH(), "ENcloseH" ); - checkErr( ENcloseQ(), "ENcloseQ" ); - checkErr( ENclose(), "ENclose" ); - - - // summarize the results - printResults(&epanetResults, &lemonTigerResults, cout); - compare(&epanetResults, &lemonTigerResults, cout); - - } catch (int err) { - cerr << "exiting with error " << err << endl; - } -} - - -void saveHydResults(networkState_t* networkState) { - int nNodes, nLinks; - float head, demand, flow; - ENgetcount(EN_NODECOUNT, &nNodes); - ENgetcount(EN_LINKCOUNT, &nLinks); - for (int iNode = 1; iNode <= nNodes; ++iNode) { - ENgetnodevalue(iNode, EN_HEAD, &head); - ENgetnodevalue(iNode, EN_DEMAND, &demand); - (*networkState).nodeState[iNode].head = head; - (*networkState).nodeState[iNode].demand = demand; - } - for (int iLink = 1; iLink <= nLinks; ++iLink) { - ENgetlinkvalue(iLink, EN_FLOW, &flow); - (*networkState).linkState[iLink].flow = flow; - } -} - - -void saveQualResults(networkState_t* networkState) { - int nNodes; - float quality; - ENgetcount(EN_NODECOUNT, &nNodes); - - for (int iNode = 1; iNode <= nNodes; iNode++) { - ENgetnodevalue(iNode, EN_QUALITY, &quality); - (*networkState).nodeState[iNode].quality = quality; - } -} - - -void printResults(result_t* results1, result_t* results2, std::ostream &out) { - - result_t::const_iterator resultIterator; - - for (resultIterator = (*results1).begin(); resultIterator != (*results1).end(); ++resultIterator) { - // get the current frame - const long time = resultIterator->first; - const networkNodeState_t networkNodeState1= resultIterator->second.nodeState; - //nodeState1 = resultIterator->second.nodeState; - const networkLinkState_t networkLinkState1 = resultIterator->second.linkState; - //linkState1 = resultIterator->second.linkState; - - // see if this time is indexed in the second state container - if ((*results2).find(time) == (*results2).end()) { - // nope. - out << "time " << time << " not found in second result set" << endl; - } - else { - // get the second result set's state - const networkNodeState_t networkNodeState2 = (*results2)[time].nodeState; - const networkLinkState_t networkLinkState2 = (*results2)[time].linkState; - // print the current simulation time - out << left; - out << setfill('*') << setw(100) << "*" << endl; - out << setfill(' '); - out << setw(4) << "T = " << setw(6) << time; - out << "|" << setw(3*COLW) << "EPANET"; - out << "|" << setw(3*COLW) << "LemonTiger" << endl; - out << setw(10) << "Index" << "|"; - out << setw(COLW) << "Demand" << setw(COLW) << "Head" << setw(COLW) << "Quality" << "|"; - out << setw(COLW) << "Demand" << setw(COLW) << "Head" << setw(COLW) << "Quality" << endl; - out << setprecision(OUTPRECISION); - - // loop through the nodes in the networkState objs, and print out the results for this time period - networkNodeState_t::const_iterator networkNodeIterator; - for (networkNodeIterator = networkNodeState1.begin(); networkNodeIterator != networkNodeState1.end(); ++networkNodeIterator) { - int nodeIndex = networkNodeIterator->first; - // trusting that all nodes are present... - const nodeState_t nodeState1 = networkNodeIterator->second; - const nodeState_t nodeState2 = networkNodeState2.at(nodeIndex); - - if (nodeState1.quality != nodeState2.quality ) { - // epanet - out << setw(10) << nodeIndex << "|"; - out << setw(COLW) << nodeState1.demand; - out << setw(COLW) << nodeState1.head; - out << setw(COLW) << nodeState1.quality; - - // lemontiger - out << "|"; - out << setw(COLW) << nodeState2.demand; - out << setw(COLW) << nodeState2.head; - out << setw(COLW) << nodeState2.quality; - out << endl; - } - } - - networkLinkState_t::const_iterator networkLinkIterator; - for (networkLinkIterator = networkLinkState1.begin(); networkLinkIterator != networkLinkState1.end(); ++networkLinkIterator) { - int linkIndex = networkLinkIterator->first; - // trusting that all nodes are present... - const linkState_t linkState1 = networkLinkIterator->second; - const linkState_t linkState2 = networkLinkState2.at(linkIndex); - - if ( linkState1.flow != linkState2.flow ) { - // epanet - out << setw(10) << linkIndex << "|"; - out << setw(COLW) << linkState1.flow; - - // lemontiger - out << "|"; - out << setw(COLW) << linkState2.flow; - out << endl; - } - } - - - } - } - -} - - - -void compare(result_t* results1, result_t* results2, std::ostream &out) { - - double sumHeadDiff=0, sumDemandDiff=0, sumQualDiff=0, sumFlowDiff=0; - - result_t::const_iterator resultIterator; - - for (resultIterator = (*results1).begin(); resultIterator != (*results1).end(); ++resultIterator) { - // get the current frame - const long time = resultIterator->first; - const networkNodeState_t nodeState1 = resultIterator->second.nodeState; - const networkLinkState_t linkState1 = resultIterator->second.linkState; - - // see if this time is indexed in the second state container - if ((*results2).find(time) == (*results2).end()) { - // nope. - out << "time " << time << " not found in second result set" << endl; - } - else { - // get the second result set's state - const networkNodeState_t networkNodeState2 = (*results2)[time].nodeState; - const networkLinkState_t networkLinkState2 = (*results2)[time].linkState; - double qualD=0; - - networkNodeState_t::const_iterator networkNodeIterator; - for (networkNodeIterator = nodeState1.begin(); networkNodeIterator != nodeState1.end(); ++networkNodeIterator) { - int nodeIndex = networkNodeIterator->first; - // trusting that all nodes are present... - const nodeState_t nodeState1 = networkNodeIterator->second; - const nodeState_t nodeState2 = networkNodeState2.at(nodeIndex); - - sumHeadDiff += fabs(nodeState1.head - nodeState2.head); - sumDemandDiff += fabs(nodeState1.demand - nodeState2.demand); - - qualD += fabs(nodeState1.quality - nodeState2.quality); - } - //out << "T: " << time << " dq: " << setprecision(20) << qualD << endl; - sumQualDiff += qualD; - - networkLinkState_t::const_iterator networkLinkIterator; - for (networkLinkIterator = linkState1.begin(); networkLinkIterator != linkState1.end(); ++networkLinkIterator) { - int linkIndex = networkLinkIterator->first; - // trusting that all nodes are present... - const linkState_t linkState1 = networkLinkIterator->second; - const linkState_t linkState2 = networkLinkState2.at(linkIndex); - - sumFlowDiff += fabs(linkState1.flow - linkState2.flow); - } - } - } - - int c1 = 18; - int p = 20; - out << setw(c1) << "Head Diff:" << setprecision(p) << sumHeadDiff << endl; - out << setw(c1) << "Demand Diff:" << setprecision(p) << sumDemandDiff << endl; - out << setw(c1) << "Quality Diff:" << setprecision(p) << sumQualDiff << endl; - out << setw(c1) << "Flow Diff:" << setprecision(p) << sumFlowDiff << endl; - - -} - - -void checkErr(int err, std::string function) { - if (err > 0) { - cerr << "Error in " << function << ": " << err << endl; - char errmsg[1024]; - ENgeterror(err, errmsg, 1024); - cerr << errmsg << endl; - throw err; - } -} diff --git a/src/testLemonTiger.h b/src/testLemonTiger.h deleted file mode 100755 index 5c1cc2f..0000000 --- a/src/testLemonTiger.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// testLemonTiger.h -// epanet -// -// Created by Sam Hatchett on 2/1/13. -// -// - -#ifndef __epanet__testLemonTiger__ -#define __epanet__testLemonTiger__ - -#include -#include - -#endif /* defined(__epanet__testLemonTiger__) */ diff --git a/src/toolkit.h b/src/toolkit.h deleted file mode 100755 index 6078898..0000000 --- a/src/toolkit.h +++ /dev/null @@ -1,255 +0,0 @@ -/* -******************************************************************* - -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 - -******************************************************************* -*/ - - -#ifndef DLLEXPORT - #ifdef DLL - #ifdef __cplusplus - #define DLLEXPORT extern "C" __declspec(dllexport) - #else - #define DLLEXPORT __declspec(dllexport) __stdcall - #endif - #elif defined(CYGWIN) - #define DLLEXPORT __stdcall - #else - #ifdef __cplusplus - #define DLLEXPORT - #else - #define DLLEXPORT - #endif - #endif -#endif - -// --- Define the EPANET toolkit constants - -#define EN_ELEVATION 0 /* Node parameters */ -#define EN_BASEDEMAND 1 -#define EN_PATTERN 2 -#define EN_EMITTER 3 -#define EN_INITQUAL 4 -#define EN_SOURCEQUAL 5 -#define EN_SOURCEPAT 6 -#define EN_SOURCETYPE 7 -#define EN_TANKLEVEL 8 -#define EN_DEMAND 9 -#define EN_HEAD 10 -#define EN_PRESSURE 11 -#define EN_QUALITY 12 -#define EN_SOURCEMASS 13 -#define EN_INITVOLUME 14 -#define EN_MIXMODEL 15 -#define EN_MIXZONEVOL 16 - -#define EN_TANKDIAM 17 -#define EN_MINVOLUME 18 -#define EN_VOLCURVE 19 -#define EN_MINLEVEL 20 -#define EN_MAXLEVEL 21 -#define EN_MIXFRACTION 22 -#define EN_TANK_KBULK 23 -#define EN_TANKVOLUME 24 -#define EN_MAXVOLUME 25 - -#define EN_DIAMETER 0 /* Link parameters */ -#define EN_LENGTH 1 -#define EN_ROUGHNESS 2 -#define EN_MINORLOSS 3 -#define EN_INITSTATUS 4 -#define EN_INITSETTING 5 -#define EN_KBULK 6 -#define EN_KWALL 7 -#define EN_FLOW 8 -#define EN_VELOCITY 9 -#define EN_HEADLOSS 10 -#define EN_STATUS 11 -#define EN_SETTING 12 -#define EN_ENERGY 13 -#define EN_LINKQUAL 14 /* TNT */ -#define EN_LINKPATTERN 15 - -#define EN_DURATION 0 /* Time parameters */ -#define EN_HYDSTEP 1 -#define EN_QUALSTEP 2 -#define EN_PATTERNSTEP 3 -#define EN_PATTERNSTART 4 -#define EN_REPORTSTEP 5 -#define EN_REPORTSTART 6 -#define EN_RULESTEP 7 -#define EN_STATISTIC 8 -#define EN_PERIODS 9 -#define EN_STARTTIME 10 /* Added TNT 10/2/2009 */ -#define EN_HTIME 11 -#define EN_HALTFLAG 12 -#define EN_NEXTEVENT 13 - -#define EN_ITERATIONS 0 -#define EN_RELATIVEERROR 1 - -#define EN_NODECOUNT 0 /* Component counts */ -#define EN_TANKCOUNT 1 -#define EN_LINKCOUNT 2 -#define EN_PATCOUNT 3 -#define EN_CURVECOUNT 4 -#define EN_CONTROLCOUNT 5 - -#define EN_JUNCTION 0 /* Node types */ -#define EN_RESERVOIR 1 -#define EN_TANK 2 - -#define EN_CVPIPE 0 /* Link types. */ -#define EN_PIPE 1 /* See LinkType in TYPES.H */ -#define EN_PUMP 2 -#define EN_PRV 3 -#define EN_PSV 4 -#define EN_PBV 5 -#define EN_FCV 6 -#define EN_TCV 7 -#define EN_GPV 8 - -#define EN_NONE 0 /* Quality analysis types. */ -#define EN_CHEM 1 /* See QualType in TYPES.H */ -#define EN_AGE 2 -#define EN_TRACE 3 - -#define EN_CONCEN 0 /* Source quality types. */ -#define EN_MASS 1 /* See SourceType in TYPES.H. */ -#define EN_SETPOINT 2 -#define EN_FLOWPACED 3 - -#define EN_CFS 0 /* Flow units types. */ -#define EN_GPM 1 /* See FlowUnitsType */ -#define EN_MGD 2 /* in TYPES.H. */ -#define EN_IMGD 3 -#define EN_AFD 4 -#define EN_LPS 5 -#define EN_LPM 6 -#define EN_MLD 7 -#define EN_CMH 8 -#define EN_CMD 9 - -#define EN_TRIALS 0 /* Misc. options */ -#define EN_ACCURACY 1 -#define EN_TOLERANCE 2 -#define EN_EMITEXPON 3 -#define EN_DEMANDMULT 4 - -#define EN_LOWLEVEL 0 /* Control types. */ -#define EN_HILEVEL 1 /* See ControlType */ -#define EN_TIMER 2 /* in TYPES.H. */ -#define EN_TIMEOFDAY 3 - -#define EN_AVERAGE 1 /* Time statistic types. */ -#define EN_MINIMUM 2 /* See TstatType in TYPES.H */ -#define EN_MAXIMUM 3 -#define EN_RANGE 4 - -#define EN_MIX1 0 /* Tank mixing models */ -#define EN_MIX2 1 -#define EN_FIFO 2 -#define EN_LIFO 3 - -#define EN_NOSAVE 0 /* Save-results-to-file flag */ -#define EN_SAVE 1 - -#define EN_INITFLOW 10 /* Re-initialize flows flag */ - -#define EN_CONST_HP 0 /* constant horsepower */ -#define EN_POWER_FUNC 1 /* power function */ -#define EN_CUSTOM 2 /* user-defined custom curve */ - -// --- Declare the EPANET toolkit functions -#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 *); - 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 ENgetheadcurve(int, char *); - int DLLEXPORT ENgetpumptype(int, int *); - - 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 *); - -#if defined(__cplusplus) -} -#endif From 16edcea410fb9a2e69a6e8deb623a1bdfdd64677 Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:35:02 -0400 Subject: [PATCH 06/33] fix duplicate symbols --- src/vars.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/vars.h b/src/vars.h index 77b7284..2a4f363 100755 --- a/src/vars.h +++ b/src/vars.h @@ -17,15 +17,15 @@ AUTHOR: L. Rossman #include #include "hash.h" - FILE *InFile, /* Input file pointer */ +EXTERN FILE *InFile, /* Input file pointer */ *OutFile, /* Output file pointer */ *RptFile, /* Report file pointer */ *HydFile, /* Hydraulics file pointer */ *TmpOutFile; /* Temporary file handle */ - long HydOffset, /* Hydraulics file byte offset */ +EXTERN long HydOffset, /* Hydraulics file byte offset */ OutOffset1, /* 1st output file byte offset */ OutOffset2; /* 2nd output file byte offset */ - char Msg[MAXMSG+1], /* Text of output message */ +EXTERN char Msg[MAXMSG+1], /* Text of output message */ InpFname[MAXFNAME+1], /* Input file name */ Rpt1Fname[MAXFNAME+1], /* Primary report file name */ Rpt2Fname[MAXFNAME+1], /* Secondary report file name */ @@ -65,7 +65,7 @@ AUTHOR: L. Rossman OpenQflag, /* Quality system opened flag */ SaveQflag, /* Quality results saved flag */ Saveflag; /* General purpose save flag */ - int MaxNodes, /* Node count from input file */ +EXTERN int MaxNodes, /* Node count from input file */ MaxLinks, /* Link count from input file */ MaxJuncs, /* Junction count */ MaxPipes, /* Pipe count */ @@ -99,7 +99,7 @@ AUTHOR: L. Rossman PageSize, /* Lines/page in output report */ CheckFreq, /* Hydraulics solver parameter */ MaxCheck; /* Hydraulics solver parameter */ - double Ucf[MAXVAR], /* Unit conversion factors */ +EXTERN double Ucf[MAXVAR], /* Unit conversion factors */ Ctol, /* Water quality tolerance */ Htol, /* Hydraulic head tolerance */ Qtol, /* Flow rate tolerance */ @@ -128,7 +128,7 @@ AUTHOR: L. Rossman Wwall, /* Avg. wall reaction rate */ Wtank, /* Avg. tank reaction rate */ Wsource; /* Avg. mass inflow */ - long Tstart, /* Starting time of day (sec) */ +EXTERN long Tstart, /* Starting time of day (sec) */ Hstep, /* Nominal hyd. time step (sec) */ Qstep, /* Quality time step (sec) */ Pstep, /* Time pattern time step (sec) */ @@ -141,12 +141,12 @@ AUTHOR: L. Rossman Hydstep, /* Actual hydraulic time step */ Rulestep, /* Rule evaluation time step */ Dur; /* Duration of simulation (sec) */ - SField Field[MAXVAR]; /* Output reporting fields */ +EXTERN SField Field[MAXVAR]; /* Output reporting fields */ /* Array pointers not allocated and freed in same routine */ - char *LinkStatus, /* Link status */ +EXTERN char *LinkStatus, /* Link status */ *OldStat; /* Previous link/tank status */ - double *NodeDemand, /* Node actual demand */ +EXTERN double *NodeDemand, /* Node actual demand */ *NodeQual, /* Node actual quality */ *E, /* Emitter flows */ *LinkSetting, /* Link settings */ @@ -194,19 +194,19 @@ EXTERN int _iterations; /* Info about hydraulic solution */ ** The following arrays are used to efficiently manage this sparsity: */ - double *Aii, /* Diagonal coeffs. of A */ +EXTERN double *Aii, /* Diagonal coeffs. of A */ *Aij, /* Non-zero, off-diagonal coeffs. of A */ *F; /* Right hand side coeffs. */ - double *P, /* Inverse headloss derivatives */ +EXTERN double *P, /* Inverse headloss derivatives */ *Y; /* Flow correction factors */ - int *Order, /* Node-to-row of A */ +EXTERN int *Order, /* Node-to-row of A */ *Row, /* Row-to-node of A */ *Ndx; /* Index of link's coeff. in Aij */ /* ** The following arrays store the positions of the non-zero coeffs. ** of the lower triangular portion of A whose values are stored in Aij: */ - int *XLNZ, /* Start position of each column in NZSUB */ +EXTERN int *XLNZ, /* Start position of each column in NZSUB */ *NZSUB, /* Row index of each coeff. in each column */ *LNZ; /* Position of each coeff. in Aij array */ From c9e1746a82bbc5143c481f83b5d8db90f9b7b6af Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:35:12 -0400 Subject: [PATCH 07/33] moves example networks --- {test => example-networks}/Net3.inp | 0 {test => example-networks}/sampletown.inp | 0 {test => example-networks}/simplenet.inp | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {test => example-networks}/Net3.inp (100%) rename {test => example-networks}/sampletown.inp (100%) rename {test => example-networks}/simplenet.inp (100%) diff --git a/test/Net3.inp b/example-networks/Net3.inp similarity index 100% rename from test/Net3.inp rename to example-networks/Net3.inp diff --git a/test/sampletown.inp b/example-networks/sampletown.inp similarity index 100% rename from test/sampletown.inp rename to example-networks/sampletown.inp diff --git a/test/simplenet.inp b/example-networks/simplenet.inp similarity index 100% rename from test/simplenet.inp rename to example-networks/simplenet.inp From 263e9eb3039fedea63caf0c04fcccb91a246c73d Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 10:35:57 -0400 Subject: [PATCH 08/33] fix compilation defs --- include/epanet2.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/epanet2.h b/include/epanet2.h index 6c3a7fa..38c8561 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -23,15 +23,15 @@ #endif #ifndef DLLEXPORT -#ifdef DLL +#ifdef WINDOWS #ifdef __cplusplus #define DLLEXPORT extern "C" __declspec(dllexport) #else -#define DLLEXPORT __declspec(dllexport) -#endif +#define DLLEXPORT __declspec(dllexport) __stdcall +#endif // __cplusplus #elif defined(CYGWIN) #define DLLEXPORT __stdcall -#else +#elif defined(__APPLE__) #ifdef __cplusplus #define DLLEXPORT #else @@ -83,7 +83,8 @@ #define EN_STATUS 11 #define EN_SETTING 12 #define EN_ENERGY 13 -#define EN_LINKQUAL 14 /* TNT */ +#define EN_LINKQUAL 14 +#define EN_LINKPATTERN 15 #define EN_DURATION 0 /* Time parameters */ #define EN_HYDSTEP 1 From 23865315aa24b5bc7b07b381f26bed059182357e Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Fri, 12 Jun 2015 11:22:04 -0400 Subject: [PATCH 09/33] removing utility code from library source main function should only be in standalone app. also removing inline defs for compile-time directives --- build/Xcode/epanet.xcodeproj/project.pbxproj | 4 +- src/epanet.c | 62 +------------------- 2 files changed, 4 insertions(+), 62 deletions(-) diff --git a/build/Xcode/epanet.xcodeproj/project.pbxproj b/build/Xcode/epanet.xcodeproj/project.pbxproj index 7d48c46..a2c8b20 100755 --- a/build/Xcode/epanet.xcodeproj/project.pbxproj +++ b/build/Xcode/epanet.xcodeproj/project.pbxproj @@ -428,7 +428,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = CLE; + GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_PREPROCESSOR_DEFINITIONS = ""; PRODUCT_NAME = runepanet; }; @@ -439,7 +439,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; GCC_MODEL_TUNING = G5; - GCC_PREPROCESSOR_DEFINITIONS = CLE; + GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_PREPROCESSOR_DEFINITIONS = ""; PRODUCT_NAME = runepanet; ZERO_LINK = NO; diff --git a/src/epanet.c b/src/epanet.c index a4aae2b..a2e6307 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -144,64 +144,6 @@ void (* viewprog) (char *); /* Pointer to progress viewing function */ ---------------------------------------------------------------- */ -/*** This code is no longer required ***** //(2.00.11 - LR) -#ifdef DLL -int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* reserved) -{ - viewprog = NULL; - return 1; -} -#endif -*****************************************/ - - -/* ----------------------------------------------------------------- - Entry point used to compile a stand-alone executable. ----------------------------------------------------------------- -*/ - -#ifdef CLE //(2.00.11 - LR) - -int main(int argc, char *argv[]) -/*-------------------------------------------------------------- -** Input: argc = number of command line arguments -** *argv[] = array of command line arguments -** Output: none -** Purpose: main program segment -** -** Command line for stand-alone operation is: -** progname f1 f2 f3 -** where progname = name of executable this code was compiled to, -** f1 = name of input file, f2 = name of report file, and -** f3 = name of binary output file (optional). -**-------------------------------------------------------------- -*/ -{ - char *f1,*f2,*f3; - char blank[] = ""; - int errcode; - -/* Check for proper number of command line arguments */ - if (argc < 3) writecon(FMT03); - else - { - - /* Call the main control function */ - f1 = argv[1]; - f2 = argv[2]; - if (argc > 3) f3 = argv[3]; - else f3 = blank; - writecon(FMT01); - errcode = ENepanet(f1,f2,f3,NULL); - if (errcode > 0) writecon(FMT11); - else if (Warnflag > 0) writecon(FMT10); - else writecon(FMT09); - } - return(0); -} /* End of main */ -#endif - /* ---------------------------------------------------------------- @@ -3295,10 +3237,10 @@ void writecon(char *s) **---------------------------------------------------------------- */ { -#ifdef CLE //(2.00.11 - LR) + //(2.00.11 - LR) fprintf(stdout,s); fflush(stdout); -#endif + } From dd286afe12b6ab175670d31ed84b0d10469a8e5f Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Fri, 12 Jun 2015 23:44:29 +0300 Subject: [PATCH 10/33] update include files --- .gitignore | 8 +++++++- include/epanet2.bas | 35 +++++++++++++++++++++-------------- include/epanet2.h | 38 ++++++++++++++++++++------------------ 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 9e6c1c7..afda7a6 100755 --- a/.gitignore +++ b/.gitignore @@ -2,9 +2,14 @@ *.slo *.lo *.o +*.map +*.exp +*.lib -# Compiled Dynamic libraries +# Compiled Dynamic libraries and executables *.so +*.dll +*.exe # Compiled Static libraries *.lai @@ -95,6 +100,7 @@ ipch/ *.psess *.vsp *.vspx +*.idb # Guidance Automation Toolkit *.gpState diff --git a/include/epanet2.bas b/include/epanet2.bas index 74d0b83..64e1b46 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -33,8 +33,8 @@ Global Const EN_MINLEVEL = 20 Global Const EN_MAXLEVEL = 21 Global Const EN_MIXFRACTION = 22 Global Const EN_TANK_KBULK = 23 - -Global Const EN_TANKVOLUME = 24 'ES +Global Const EN_TANKVOLUME = 24 +Global Const EN_MAXVOLUME = 25 Global Const EN_DIAMETER = 0 ' Link parameters Global Const EN_LENGTH = 1 @@ -62,7 +62,14 @@ Global Const EN_REPORTSTART = 6 Global Const EN_RULESTEP = 7 Global Const EN_STATISTIC = 8 Global Const EN_PERIODS = 9 -Global Const EN_STARTTIME = 10 'ES +Global Const EN_STARTTIME = 10 +Global Const EN_HTIME = 11 +Global Const EN_QTIME = 12 +Global Const EN_HALTFLAG = 13 +Global Const EN_NEXTEVENT = 14 + +Global Const EN_ITERATIONS = 0 +Global Const EN_RELATIVEERROR = 1 Global Const EN_NODECOUNT = 0 'Component counts Global Const EN_TANKCOUNT = 1 @@ -132,10 +139,6 @@ Global Const EN_SAVE = 1 Global Const EN_INITFLOW = 10 ' Re-initialize flow flag -Global Const EN_CONST_HP = 0 ' constant horsepower -Global Const EN_POWER_FUNC = 1 ' power function -Global Const EN_CUSTOM = 2 ' user-defined custom curve - 'These are the external functions that comprise the DLL Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As Any) As Long @@ -175,17 +178,20 @@ Global Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Long, L As Long) As Long Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Period As Long, Value As Single) As Long + Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal Index As Long, Value As Single) As Long Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) + Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal Code As Long, Value As Single) Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, Index As Long) As Long Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Long, Code As Long) As Long Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Code As Long, Value As Single) As Long + Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Long, X As Single, Y As Single) As Long - Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Long, numDemands As Long) As Long 'ES - Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, Value As Single) As Long 'ES - Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long 'ES + Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Long, numDemands As Long) As Long + Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, Value As Single) As Long + Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal ID As String, Index As Long) As Long Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long @@ -193,9 +199,9 @@ Global Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Long, Node1 As Long, Node2 As Long) As Long Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Code As Long, Value As Single) As Long - Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Long, nValues As Long, xValues As Any, yValues As Any) As Long 'ES - Declare Function ENgetheadcurve Lib "epanet2.dll" (ByVal Index As Long, ID As String) As Long 'ES - Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Long, PumpType As Long) As Long 'ES + Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Long, CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long + Declare Function ENgetheadcurve Lib "epanet2.dll" (ByVal Index As Long, ID As String) As Long + Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Long, PumpType As Long) As Long Declare Function ENgetversion Lib "epanet2.dll" (Value As Long) As Long @@ -209,4 +215,5 @@ Global Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Long, ByVal Value As Single) As Long Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Long) As Long Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long - + Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ChemName As String, ChemUnits As String, TraceNode As Long) As Long + Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal NodeIndex As Long, ByVal DemandIndex As Long, BaseDemand As Single) As Long diff --git a/include/epanet2.h b/include/epanet2.h index 38c8561..2a5b312 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -19,26 +19,27 @@ #define EPANET2_H #ifndef EN_API_FLOAT_TYPE -#define EN_API_FLOAT_TYPE float + #define EN_API_FLOAT_TYPE float #endif #ifndef DLLEXPORT -#ifdef WINDOWS -#ifdef __cplusplus -#define DLLEXPORT extern "C" __declspec(dllexport) -#else -#define DLLEXPORT __declspec(dllexport) __stdcall -#endif // __cplusplus -#elif defined(CYGWIN) -#define DLLEXPORT __stdcall -#elif defined(__APPLE__) -#ifdef __cplusplus -#define DLLEXPORT -#else -#define DLLEXPORT -#endif -#endif + #ifdef WINDOWS + #ifdef __cplusplus + #define DLLEXPORT extern "C" __declspec(dllexport) + #else + #define DLLEXPORT __declspec(dllexport) __stdcall + #endif // __cplusplus + #elif defined(CYGWIN) + #define DLLEXPORT __stdcall + #elif defined(__APPLE__) + #ifdef __cplusplus + #define DLLEXPORT + #else + #define DLLEXPORT + #endif + #endif #endif + // --- Define the EPANET toolkit constants #define EN_ELEVATION 0 /* Node parameters */ @@ -238,7 +239,8 @@ extern "C" { int DLLEXPORT ENgetlinkvalue(int index, int code, EN_API_FLOAT_TYPE *value); int DLLEXPORT ENgetcurve(int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues); - + int DLLEXPORT ENgetheadcurve(int, char *); + int DLLEXPORT ENgetpumptype(int, int *); int DLLEXPORT ENgetversion(int *version); @@ -259,4 +261,4 @@ extern "C" { } #endif -#endif //TOOLKIT_H \ No newline at end of file +#endif //EPANET2_H \ No newline at end of file From 79fb7ab9a4ed473093a5d2befe969bc5935ec8e6 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Fri, 12 Jun 2015 23:51:17 +0300 Subject: [PATCH 11/33] update def file --- src/epanet2.def | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/epanet2.def b/src/epanet2.def index a914dfc..fc84da2 100644 --- a/src/epanet2.def +++ b/src/epanet2.def @@ -59,6 +59,11 @@ EXPORTS ENgetnumdemands = _ENgetnumdemands@8 ENgetbasedemand = _ENgetbasedemand@12 ENgetdemandpattern = _ENgetdemandpattern@12 - ENgetcurve = _ENgetcurve@16 + ENgetcurve = _ENgetcurve@20 + ENgetstatistic = _ENgetstatistic@8 + ENgetcoord = _ENgetcoord@12 + ENgetqualinfo = _ENgetqualinfo@16 + ENsetbasedemand = _ENsetbasedemand@12 + ENgetaveragepatternvalue = _ENgetaveragepatternvalue@8 ENgetheadcurve = _ENgetheadcurve@8 ENgetpumptype = _ENgetpumptype@8 \ No newline at end of file From 82da5db7ec346a853520328b76ce60ae97f68bce Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sat, 13 Jun 2015 00:01:30 +0300 Subject: [PATCH 12/33] more c89 conformance variables should be declared at the beginning of functions --- src/epanet.c | 5 +++-- src/hash.c | 3 ++- src/quality.c | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index a2e6307..79a2fc7 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -3329,11 +3329,12 @@ int DLLEXPORT ENgetaveragepatternvalue(int index, EN_API_FLOAT_TYPE *value) ** and pattern **---------------------------------------------------------------- */ -{ *value = 0.0; +{ + int i; + *value = 0.0; if (!Openflag) return(102); if (index < 1 || index > Npats) return(205); //if (period < 1 || period > Pattern[index].Length) return(251); - int i; for (i=0; i Date: Sat, 13 Jun 2015 00:16:30 +0300 Subject: [PATCH 13/33] Check for open file in ENgetcurve and minor fixes --- src/epanet.c | 68 +++++++++++++++++++++++++++++----------------------- src/types.h | 2 +- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 79a2fc7..c89608d 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -12,8 +12,8 @@ DATE: 5/30/00 6/24/02 8/15/07 (2.00.11) 2/14/08 (2.00.12) -AUTHOR: L. Rossman - US EPA - NRMRL + AUTHORS: L. Rossman - US EPA - NRMRL + OpenWaterAnalytics members: see git stats for contributors EPANET performs extended period hydraulic and water quality analysis of looped, pressurized piping networks. The program consists of the @@ -37,7 +37,7 @@ The program can be compiled as either a stand-alone console application or as a dynamic link library (DLL) of function calls depending on whether the macro identifier 'DLL' is defined or not. -See TOOLKIT.H for function prototypes of exported DLL functions +See EPANET2.H for function prototypes of exported DLL functions See FUNCS.H for prototypes of all other functions See TYPES.H for declaration of global constants and data structures See VARS.H for declaration of global variables @@ -906,12 +906,11 @@ int DLLEXPORT ENgetversion(int *v) } -int DLLEXPORT ENgetcontrol(int cindex, int *ctype, int *lindex, - EN_API_FLOAT_TYPE *setting, int *nindex, EN_API_FLOAT_TYPE *level) +int DLLEXPORT ENgetcontrol(int cindex, int *ctype, int *lindex, 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) -** Output: *ctype = control type code (see TOOLKIT.H) +** Output: *ctype = control type code (see EPANET2.H) ** *lindex = index of controlled link ** *setting = control setting on link ** *nindex = index of controlling node (0 for TIMER @@ -962,7 +961,7 @@ int DLLEXPORT ENgetcontrol(int cindex, int *ctype, int *lindex, int DLLEXPORT ENgetcount(int code, int *count) /*---------------------------------------------------------------- -** Input: code = component code (see TOOLKIT.H) +** Input: code = component code (see EPANET2.H) ** Output: *count = number of components in network ** Returns: error code ** Purpose: retrieves the number of components of a @@ -988,7 +987,7 @@ int DLLEXPORT ENgetcount(int code, int *count) int DLLEXPORT ENgetoption(int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- -** Input: code = option code (see TOOLKIT.H) +** Input: code = option code (see EPANET2.H) ** Output: *value = option value ** Returns: error code ** Purpose: gets value for an analysis option @@ -1019,7 +1018,7 @@ int DLLEXPORT ENgetoption(int code, EN_API_FLOAT_TYPE *value) int DLLEXPORT ENgettimeparam(int code, long *value) /*---------------------------------------------------------------- -** Input: code = time parameter code (see TOOLKIT.H) +** Input: code = time parameter code (see EPANET2.H) ** Output: *value = value of time parameter ** Returns: error code ** Purpose: retrieves value of specific time parameter @@ -1056,7 +1055,7 @@ int DLLEXPORT ENgetflowunits(int *code) /*---------------------------------------------------------------- ** Input: none ** Output: *code = code of flow units in use -** (see TOOLKIT.H or TYPES.H) +** (see EPANET2.H or TYPES.H) ** Returns: error code ** Purpose: retrieves flow units code **---------------------------------------------------------------- @@ -1148,10 +1147,10 @@ int DLLEXPORT ENgetpatternvalue(int index, int period, EN_API_FLOAT_TYPE *value) } -int DLLEXPORT ENgetqualtype(int *qualcode, int *tracenode) +int DLLEXPORT ENgetqualtype(int *qualcode, int *tracenode) /*---------------------------------------------------------------- ** Input: none -** Output: *qualcode = WQ analysis code number (see TOOLKIT.H) +** Output: *qualcode = WQ analysis code number (see EPANET2.H) ** *tracenode = index of node being traced (if ** qualocode = WQ tracing) ** Returns: error code @@ -1272,7 +1271,7 @@ int DLLEXPORT ENgetnodeid(int index, char *id) int DLLEXPORT ENgetnodetype(int index, int *code) /*---------------------------------------------------------------- ** Input: index = node index -** Output: *code = node type code number (see TOOLKIT.H) +** Output: *code = node type code number (see EPANET2.H) ** Returns: error code ** Purpose: retrieves node type of specific node **---------------------------------------------------------------- @@ -1309,7 +1308,7 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y) int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: index = node index -** code = node parameter code (see TOOLKIT.H) +** code = node parameter code (see EPANET2.H) ** Output: *value = value of node's parameter ** Returns: error code ** Purpose: retrieves parameter value for a node @@ -1530,7 +1529,7 @@ int DLLEXPORT ENgetlinkid(int index, char *id) int DLLEXPORT ENgetlinktype(int index, int *code) /*------------------------------------------------------------------ ** Input: index = link index -** Output: *code = link type code number (see TOOLKIT.H) +** Output: *code = link type code number (see EPANET2.H) ** Returns: error code ** Purpose: retrieves link type of specific link **------------------------------------------------------------------ @@ -1567,7 +1566,7 @@ int DLLEXPORT ENgetlinknodes(int index, int *node1, int *node2) int DLLEXPORT ENgetlinkvalue(int index, int code, EN_API_FLOAT_TYPE *value) /*------------------------------------------------------------------ ** Input: index = link index -** code = link parameter code (see TOOLKIT.H) +** code = link parameter code (see EPANET2.H) ** Output: *value = value of link's parameter ** Returns: error code ** Purpose: retrieves parameter value for a link @@ -1720,21 +1719,29 @@ int DLLEXPORT ENgetcurve(int curveIndex, char* id, int *nValues, EN_API_FLOAT_T /*---------------------------------------------------------------- ** Input: curveIndex = curve index ** Output: *nValues = number of points on curve + ** id = curve ID ** *xValues = values for x ** *yValues = values for y ** Returns: error code - ** Purpose: retrieves end nodes of a specific link + ** Purpose: retrieves curve id, number of values and (x,y) values + ** + ** NOTE: 'id' must be able to hold MAXID characters **---------------------------------------------------------------- */ { - int err = 0; + int iPoint, nPoints; + Scurve curve; + EN_API_FLOAT_TYPE *pointX, *pointY; - Scurve curve = Curve[curveIndex]; - int nPoints = curve.Npts; +/* Check that input file opened */ + if (!Openflag) return(102); + + curve = Curve[curveIndex]; + nPoints = curve.Npts; + + pointX = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); + pointY = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); - EN_API_FLOAT_TYPE *pointX = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); - EN_API_FLOAT_TYPE *pointY = calloc(nPoints, sizeof(EN_API_FLOAT_TYPE)); - int iPoint; for (iPoint = 0; iPoint < nPoints; iPoint++) { double x = curve.X[iPoint] * Ucf[LENGTH]; double y = curve.Y[iPoint] * Ucf[VOLUME]; @@ -1742,12 +1749,13 @@ int DLLEXPORT ENgetcurve(int curveIndex, char* id, int *nValues, EN_API_FLOAT_T pointY[iPoint] = (EN_API_FLOAT_TYPE)y; } + strncpy(id,"", MAXID); strncpy(id, curve.ID, MAXID); *nValues = nPoints; *xValues = pointX; *yValues = pointY; - return err; + return(0); } @@ -1763,7 +1771,7 @@ int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, /*---------------------------------------------------------------- ** Input: cindex = control index (position of control statement ** in the input file, starting from 1) -** ctype = control type code (see TOOLKIT.H) +** ctype = control type code (see EPANET2.H) ** lindex = index of controlled link ** setting = control setting applied to link ** nindex = index of controlling node (0 for TIMER @@ -1850,7 +1858,7 @@ int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- ** Input: index = node index -** code = node parameter code (see TOOLKIT.H) +** code = node parameter code (see EPANET2.H) ** value = parameter value ** Output: none ** Returns: error code @@ -2063,7 +2071,7 @@ int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v) int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- ** Input: index = link index -** code = link parameter code (see TOOLKIT.H) +** code = link parameter code (see EPANET2.H) ** v = parameter value ** Output: none ** Returns: error code @@ -2297,7 +2305,7 @@ int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value int DLLEXPORT ENsettimeparam(int code, long value) /*---------------------------------------------------------------- -** Input: code = time parameter code (see TOOLKIT.H) +** Input: code = time parameter code (see EPANET2.H) ** value = time parameter value ** Output: none ** Returns: error code @@ -2389,7 +2397,7 @@ int DLLEXPORT ENsettimeparam(int code, long value) int DLLEXPORT ENsetoption(int code, EN_API_FLOAT_TYPE v) /*---------------------------------------------------------------- -** Input: code = option code (see TOOLKIT.H) +** Input: code = option code (see EPANET2.H) ** v = option value ** Output: none ** Returns: error code @@ -2450,7 +2458,7 @@ int DLLEXPORT ENsetstatusreport(int code) int DLLEXPORT ENsetqualtype(int qualcode, char *chemname, char *chemunits, char *tracenode) /*---------------------------------------------------------------- -** Input: qualcode = WQ parameter code (see TOOLKIT.H) +** Input: qualcode = WQ parameter code (see EPANET2.H) ** chemname = name of WQ constituent ** chemunits = concentration units of WQ constituent ** tracenode = ID of node being traced diff --git a/src/types.h b/src/types.h index 3119edd..f422a40 100755 --- a/src/types.h +++ b/src/types.h @@ -28,7 +28,7 @@ AUTHOR: L. Rossman Definition of 4-byte integers & reals ------------------------------------------- */ -typedef double REAL4; //(2.00.11 - LR) +typedef float REAL4; //(2.00.11 - LR) typedef int INT4; //(2.00.12 - LR) /* From 2c81796f7166bf56f12c9dd5fa7dede300f38754 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sat, 13 Jun 2015 00:32:26 +0300 Subject: [PATCH 14/33] One click compilation for Win DLL & EXE --- build/WinSDK/Readme.txt | 17 ----------------- build/WinSDK/dll_win_make.bat | 11 ----------- build/WinSDK/exe_win_make.bat | 11 ----------- build/WinSDK/win_make.bat | 22 ++++++++++++++++++++++ include/epanet2.h | 10 ++++++++++ 5 files changed, 32 insertions(+), 39 deletions(-) delete mode 100644 build/WinSDK/Readme.txt delete mode 100644 build/WinSDK/dll_win_make.bat delete mode 100644 build/WinSDK/exe_win_make.bat create mode 100644 build/WinSDK/win_make.bat diff --git a/build/WinSDK/Readme.txt b/build/WinSDK/Readme.txt deleted file mode 100644 index c7d5f1c..0000000 --- a/build/WinSDK/Readme.txt +++ /dev/null @@ -1,17 +0,0 @@ -For compiling EPANET2.DLL : - -Open the EPANET.C file and make sure that the line - #define DLL - is not commented out while the lines - #define CLE - #define SOL - are commented out. - -For compiling EPANET2.EXE : - -Open the EPANET.C file and make sure that the line - #define CLE - is not commented out while the lines - #define DLL - #define SOL - are commented out. diff --git a/build/WinSDK/dll_win_make.bat b/build/WinSDK/dll_win_make.bat deleted file mode 100644 index 611b64f..0000000 --- a/build/WinSDK/dll_win_make.bat +++ /dev/null @@ -1,11 +0,0 @@ -rem : set path to Windows SDK -SET SDK_PATH="C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\" - -rem : set path for source EPANET files -SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" - -CALL %SDK_PATH%SetEnv.cmd /x86 /release -CHDIR /D %SRC_PATH% - -rem : do the magic ... -cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:epanet2.def /MAP \ No newline at end of file diff --git a/build/WinSDK/exe_win_make.bat b/build/WinSDK/exe_win_make.bat deleted file mode 100644 index d068859..0000000 --- a/build/WinSDK/exe_win_make.bat +++ /dev/null @@ -1,11 +0,0 @@ -rem : set path to Windows SDK -SET SDK_PATH="C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\" - -rem : set path for source EPANET files -SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" - -CALL %SDK_PATH%SetEnv.cmd /x86 /release -CHDIR /D %SRC_PATH% - -rem : do the magic ... -cl -o epanet2.exe ..\run\main.c /I ..\include /I ..\run /I ..\src /link \ No newline at end of file diff --git a/build/WinSDK/win_make.bat b/build/WinSDK/win_make.bat new file mode 100644 index 0000000..321dd7f --- /dev/null +++ b/build/WinSDK/win_make.bat @@ -0,0 +1,22 @@ +rem : set path to Windows SDK +SET SDK_PATH="C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\" + +rem : set path for source EPANET files +SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" + +CALL %SDK_PATH%SetEnv.cmd /x86 /release +CHDIR /D %SRC_PATH% +del %SRC_PATH%\*.dll +del %SRC_PATH%\*.exe + +rem : do the magic ... + rem : creat EPANET2.DLL + cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:epanet2.def /MAP + rem : creat EPANET2.EXE + cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link + +rem : a bit of housekeeping and cleaning +del %SRC_PATH%\*.obj +del %SRC_PATH%\*.exp +del %SRC_PATH%\*.lib +del %SRC_PATH%\*.map diff --git a/include/epanet2.h b/include/epanet2.h index 2a5b312..8527d83 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -22,6 +22,16 @@ #define EN_API_FLOAT_TYPE float #endif +// --- define WINDOWS +#undef WINDOWS +#ifdef _WIN32 + #define WINDOWS +#endif +#ifdef __WIN32__ + #define WINDOWS +#endif + +// --- define DLLEXPORT #ifndef DLLEXPORT #ifdef WINDOWS #ifdef __cplusplus From 336c87cc910c6d1f5247285d8112b21a1110cd6e Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sat, 13 Jun 2015 00:52:38 +0300 Subject: [PATCH 15/33] fix for include file --- include/epanet2.bas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/epanet2.bas b/include/epanet2.bas index 64e1b46..08e22b8 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -199,8 +199,8 @@ Global Const EN_INITFLOW = 10 ' Re-initialize flow flag Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Long, Node1 As Long, Node2 As Long) As Long Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Code As Long, Value As Single) As Long - Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Long, CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long - Declare Function ENgetheadcurve Lib "epanet2.dll" (ByVal Index As Long, ID As String) As Long + Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Long, ByVal CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long + Declare Function ENgetheadcurve Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Long, PumpType As Long) As Long Declare Function ENgetversion Lib "epanet2.dll" (Value As Long) As Long From fb63b874f86a877963a6dc3f4d4570e5d51c7ad3 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sun, 14 Jun 2015 07:55:42 +0300 Subject: [PATCH 16/33] Moving def file into build --- {src => build/WinSDK}/epanet2.def | 0 build/WinSDK/win_make.bat | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename {src => build/WinSDK}/epanet2.def (100%) diff --git a/src/epanet2.def b/build/WinSDK/epanet2.def similarity index 100% rename from src/epanet2.def rename to build/WinSDK/epanet2.def diff --git a/build/WinSDK/win_make.bat b/build/WinSDK/win_make.bat index 321dd7f..cdfd45b 100644 --- a/build/WinSDK/win_make.bat +++ b/build/WinSDK/win_make.bat @@ -11,7 +11,7 @@ del %SRC_PATH%\*.exe rem : do the magic ... rem : creat EPANET2.DLL - cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:epanet2.def /MAP + cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:..\build\winsdk\epanet2.def /MAP rem : creat EPANET2.EXE cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link @@ -19,4 +19,4 @@ rem : a bit of housekeeping and cleaning del %SRC_PATH%\*.obj del %SRC_PATH%\*.exp del %SRC_PATH%\*.lib -del %SRC_PATH%\*.map +del %SRC_PATH%\*.map \ No newline at end of file From 82553cc422545fdf9afdb0e9ada8b61c41df7f16 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Mon, 15 Jun 2015 21:01:50 +0300 Subject: [PATCH 17/33] Add header documentation for new functions --- src/epanet.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index c89608d..5924c23 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -3270,7 +3270,16 @@ void writewin(char *s) } #endif } + + int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) +/*---------------------------------------------------------------- + ** Input: nodeIndex = index of node + ** Output: *numDemands = number of demand catagories + ** Returns: error code + ** Purpose: retrieves the number of a demand catagories for a node + **---------------------------------------------------------------- + */ { Pdemand d; int n=0; @@ -3281,7 +3290,17 @@ int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) *numDemands=n; return 0; } + + int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE *baseDemand) +/*---------------------------------------------------------------- + ** Input: nodeIndex = index of node + ** demandIdx = index of demand catagory + ** Output: *baseDemand = base demand for selected catagory + ** Returns: error code + ** Purpose: retrieves the node's base demand for a catagory + **---------------------------------------------------------------- + */ { Pdemand d; int n=1; @@ -3299,7 +3318,17 @@ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE * return 0; } + + int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand) +/*---------------------------------------------------------------- + ** Input: nodeIndex = index of node + ** demandIdx = index of demand catagory + ** baseDemand = base demand for selected catagory + ** Returns: error code + ** Purpose: sets the node's base demand for a catagory + **---------------------------------------------------------------- + */ { Pdemand d; int n=1; @@ -3314,7 +3343,17 @@ int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE b return 0; } + int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) +/*---------------------------------------------------------------- + ** Input: nodeIndex = index of node + ** demandIdx = index of demand catagory + ** Output: *pattIdx = demand pattern index + ** Returns: error code + ** Purpose: retrieves the index of a demand pattern for a specific + ** demand catagory of a node + **---------------------------------------------------------------- + */ { Pdemand d; int n=1; @@ -3327,14 +3366,13 @@ 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 + ** Output: *value = pattern average value ** Returns: error code - ** Purpose: retrieves multiplier for a specific time period - ** and pattern + ** Purpose: retrieves the average value of a pattern **---------------------------------------------------------------- */ { From 62730e6281ac45f0a86481a729e70ed7df7b33db Mon Sep 17 00:00:00 2001 From: Demetrios Eliades Date: Tue, 16 Jun 2015 09:42:07 +0300 Subject: [PATCH 18/33] Make files with relative paths Based on @eladsal's code. Location of Microsoft SDK is now retrieved from the registry. Also x86 and x64-bit architectures are included. --- build/WinSDK/makeWINx64.bat | 29 +++++++++++++++++++++++++++++ build/WinSDK/makeWINx86.bat | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 build/WinSDK/makeWINx64.bat create mode 100644 build/WinSDK/makeWINx86.bat diff --git a/build/WinSDK/makeWINx64.bat b/build/WinSDK/makeWINx64.bat new file mode 100644 index 0000000..96e8106 --- /dev/null +++ b/build/WinSDK/makeWINx64.bat @@ -0,0 +1,29 @@ +rem : set path to Windows SDK +Set Reg.Key=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows +Set Reg.Val=CurrentInstallFolder + +For /F "Tokens=2*" %%A In ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"' ) Do Call Set SDK_PATH=%%B +echo %SDK_PATH% + + +CALL "%SDK_PATH%bin\"SetEnv.cmd /x64 /release + +rem : set path for source EPANET files +SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" +cd ..\..\src +set SRC_PATH=%CD% + +del %SRC_PATH%\*.dll +del %SRC_PATH%\*.exe + +rem : do the magic ... + rem : create EPANET2.DLL + cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:..\build\winsdk\epanet2.def /MAP + rem : create EPANET2.EXE + cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link + +rem : a bit of housekeeping and cleaning +del %SRC_PATH%\*.obj +del %SRC_PATH%\*.exp +del %SRC_PATH%\*.lib +del %SRC_PATH%\*.map \ No newline at end of file diff --git a/build/WinSDK/makeWINx86.bat b/build/WinSDK/makeWINx86.bat new file mode 100644 index 0000000..9382c47 --- /dev/null +++ b/build/WinSDK/makeWINx86.bat @@ -0,0 +1,29 @@ +rem : set path to Windows SDK +Set Reg.Key=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows +Set Reg.Val=CurrentInstallFolder + +For /F "Tokens=2*" %%A In ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%Reg.Val%"' ) Do Call Set SDK_PATH=%%B +echo %SDK_PATH% + + +CALL "%SDK_PATH%bin\"SetEnv.cmd /x86 /release + +rem : set path for source EPANET files +SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" +cd ..\..\src +set SRC_PATH=%CD% + +del %SRC_PATH%\*.dll +del %SRC_PATH%\*.exe + +rem : do the magic ... + rem : create EPANET2.DLL + cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:..\build\winsdk\epanet2.def /MAP + rem : create EPANET2.EXE + cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link + +rem : a bit of housekeeping and cleaning +del %SRC_PATH%\*.obj +del %SRC_PATH%\*.exp +del %SRC_PATH%\*.lib +del %SRC_PATH%\*.map \ No newline at end of file From 91aa538adfeb0f786dba0c8b3f6927b8717460f7 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Thu, 25 Jun 2015 23:46:28 +0300 Subject: [PATCH 19/33] minor fix to VB header module --- include/epanet2.bas | 6 +++--- src/epanet.c | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/epanet2.bas b/include/epanet2.bas index 08e22b8..8df46c5 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -180,8 +180,8 @@ Global Const EN_INITFLOW = 10 ' Re-initialize flow flag Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Period As Long, Value As Single) As Long Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal Index As Long, Value As Single) As Long Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long - Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) - Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal Code As Long, Value As Single) + Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) As Long + Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal Code As Long, Value As Single) As Long Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, Index As Long) As Long Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Long, ByVal ID As String) As Long @@ -216,4 +216,4 @@ Global Const EN_INITFLOW = 10 ' Re-initialize flow flag Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Long) As Long Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ChemName As String, ChemUnits As String, TraceNode As Long) As Long - Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal NodeIndex As Long, ByVal DemandIndex As Long, BaseDemand As Single) As Long + Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal NodeIndex As Long, ByVal DemandIndex As Long, ByVal BaseDemand As Single) As Long diff --git a/src/epanet.c b/src/epanet.c index 5924c23..c98dd4d 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -3319,7 +3319,6 @@ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE * } - int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand) /*---------------------------------------------------------------- ** Input: nodeIndex = index of node From cdbd08acca1471611b27ce5bff28d2c9175b9862 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Tue, 30 Jun 2015 19:39:06 +0300 Subject: [PATCH 20/33] Added error code and description for wrong demand category index --- src/epanet.c | 23 ++++++++++++----------- src/text.h | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index c98dd4d..3d5e7f9 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -3198,7 +3198,8 @@ char *geterrmsg(int errcode) case 241: sprintf(Msg,ERR241,t_FUNCCALL,""); break; case 250: sprintf(Msg,ERR250); break; case 251: sprintf(Msg,ERR251); break; - + case 253: sprintf(Msg,ERR253); break; + /* File Errors */ case 301: strcpy(Msg,ERR301); break; case 302: strcpy(Msg,ERR302); break; @@ -3275,9 +3276,9 @@ void writewin(char *s) int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) /*---------------------------------------------------------------- ** Input: nodeIndex = index of node - ** Output: *numDemands = number of demand catagories + ** Output: *numDemands = number of demand categories ** Returns: error code - ** Purpose: retrieves the number of a demand catagories for a node + ** Purpose: retrieves the number of a demand categories for a node **---------------------------------------------------------------- */ { @@ -3295,10 +3296,10 @@ int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE *baseDemand) /*---------------------------------------------------------------- ** Input: nodeIndex = index of node - ** demandIdx = index of demand catagory - ** Output: *baseDemand = base demand for selected catagory + ** demandIdx = index of demand category + ** Output: *baseDemand = base demand for selected category ** Returns: error code - ** Purpose: retrieves the node's base demand for a catagory + ** Purpose: retrieves the node's base demand for a category **---------------------------------------------------------------- */ { @@ -3322,10 +3323,10 @@ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE * int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand) /*---------------------------------------------------------------- ** Input: nodeIndex = index of node - ** demandIdx = index of demand catagory - ** baseDemand = base demand for selected catagory + ** demandIdx = index of demand category + ** baseDemand = base demand for selected category ** Returns: error code - ** Purpose: sets the node's base demand for a catagory + ** Purpose: sets the node's base demand for a category **---------------------------------------------------------------- */ { @@ -3346,11 +3347,11 @@ int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE b int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIdx, int *pattIdx) /*---------------------------------------------------------------- ** Input: nodeIndex = index of node - ** demandIdx = index of demand catagory + ** demandIdx = index of demand category ** Output: *pattIdx = demand pattern index ** Returns: error code ** Purpose: retrieves the index of a demand pattern for a specific - ** demand catagory of a node + ** demand category of a node **---------------------------------------------------------------- */ { diff --git a/src/text.h b/src/text.h index 890e099..6d87cd8 100755 --- a/src/text.h +++ b/src/text.h @@ -493,6 +493,8 @@ AUTHOR: L. Rossman #define ERR250 "Input Error 250: function call contains invalid format." #define ERR251 "Input Error 251: function call contains invalid parameter code." +#define ERR253 "Input Error 253: Function call error - No such demand category index." + #define ERR301 "File Error 301: identical file names." #define ERR302 "File Error 302: cannot open input file." #define ERR303 "File Error 303: cannot open report file." From ce633b61bd14b3f8ec7fb72f6cdfa725af91fb10 Mon Sep 17 00:00:00 2001 From: Demetrios Eliades Date: Sat, 4 Jul 2015 15:18:55 +0300 Subject: [PATCH 21/33] Bug correction for Windows x64 compilation code. There seems to be an issue when creating the def file, so this was removed. Also an absolute path which was included by accident was removed. --- build/WinSDK/makeWINx64.bat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/WinSDK/makeWINx64.bat b/build/WinSDK/makeWINx64.bat index 96e8106..49acc49 100644 --- a/build/WinSDK/makeWINx64.bat +++ b/build/WinSDK/makeWINx64.bat @@ -9,7 +9,6 @@ echo %SDK_PATH% CALL "%SDK_PATH%bin\"SetEnv.cmd /x64 /release rem : set path for source EPANET files -SET SRC_PATH="D:\Projects\EPANET\Open Source\Code\owa\EPANET\src" cd ..\..\src set SRC_PATH=%CD% @@ -18,7 +17,7 @@ del %SRC_PATH%\*.exe rem : do the magic ... rem : create EPANET2.DLL - cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL /def:..\build\winsdk\epanet2.def /MAP + cl -o epanet2.dll epanet.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /link /DLL rem : create EPANET2.EXE cl -o epanet2.exe epanet.c ..\run\main.c hash.c hydraul.c inpfile.c input1.c input2.c input3.c mempool.c output.c quality.c report.c rules.c smatrix.c /I ..\include /I ..\run /I ..\src /link From fecac0a03f4a8aed24b4f907241aec5cd4b4c81c Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Tue, 21 Jul 2015 21:07:58 +0300 Subject: [PATCH 22/33] module file for VB.Net prepared by Lew Rossman --- include/epanet2.vb | 217 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 include/epanet2.vb diff --git a/include/epanet2.vb b/include/epanet2.vb new file mode 100644 index 0000000..4e8b9f0 --- /dev/null +++ b/include/epanet2.vb @@ -0,0 +1,217 @@ + +'EPANET2.VB +' +'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT +'(EPANET2.DLL) for use with VB.Net. + +'Last updated on 7/19/15 - LR + +Imports System.Runtime.InteropServices +Imports System.Text + +Module Epanet2 + +' These are codes used by the DLL functions +Public Const EN_ELEVATION = 0 ' Node parameters +Public Const EN_BASEDEMAND = 1 +Public Const EN_PATTERN = 2 +Public Const EN_EMITTER = 3 +Public Const EN_INITQUAL = 4 +Public Const EN_SOURCEQUAL = 5 +Public Const EN_SOURCEPAT = 6 +Public Const EN_SOURCETYPE = 7 +Public Const EN_TANKLEVEL = 8 +Public Const EN_DEMAND = 9 +Public Const EN_HEAD = 10 +Public Const EN_PRESSURE = 11 +Public Const EN_QUALITY = 12 +Public Const EN_SOURCEMASS = 13 +Public Const EN_INITVOLUME = 14 +Public Const EN_MIXMODEL = 15 +Public Const EN_MIXZONEVOL = 16 + +Public Const EN_TANKDIAM = 17 +Public Const EN_MINVOLUME = 18 +Public Const EN_VOLCURVE = 19 +Public Const EN_MINLEVEL = 20 +Public Const EN_MAXLEVEL = 21 +Public Const EN_MIXFRACTION = 22 +Public Const EN_TANK_KBULK = 23 + +Public Const EN_TANKVOLUME = 24 'ES + +Public Const EN_DIAMETER = 0 ' Link parameters +Public Const EN_LENGTH = 1 +Public Const EN_ROUGHNESS = 2 +Public Const EN_MINORLOSS = 3 +Public Const EN_INITSTATUS = 4 +Public Const EN_INITSETTING = 5 +Public Const EN_KBULK = 6 +Public Const EN_KWALL = 7 +Public Const EN_FLOW = 8 +Public Const EN_VELOCITY = 9 +Public Const EN_HEADLOSS = 10 +Public Const EN_STATUS = 11 +Public Const EN_SETTING = 12 +Public Const EN_ENERGY = 13 +Public Const EN_LINKQUAL = 14 'ES + +Public Const EN_DURATION = 0 ' Time parameters +Public Const EN_HYDSTEP = 1 +Public Const EN_QUALSTEP = 2 +Public Const EN_PATTERNSTEP = 3 +Public Const EN_PATTERNSTART = 4 +Public Const EN_REPORTSTEP = 5 +Public Const EN_REPORTSTART = 6 +Public Const EN_RULESTEP = 7 +Public Const EN_STATISTIC = 8 +Public Const EN_PERIODS = 9 +Public Const EN_STARTTIME = 10 'ES + +Public Const EN_NODECOUNT = 0 'Component counts +Public Const EN_TANKCOUNT = 1 +Public Const EN_LINKCOUNT = 2 +Public Const EN_PATCOUNT = 3 +Public Const EN_CURVECOUNT = 4 +Public Const EN_CONTROLCOUNT = 5 + +Public Const EN_JUNCTION = 0 ' Node types +Public Const EN_RESERVOIR = 1 +Public Const EN_TANK = 2 + +Public Const EN_CVPIPE = 0 ' Link types +Public Const EN_PIPE = 1 +Public Const EN_PUMP = 2 +Public Const EN_PRV = 3 +Public Const EN_PSV = 4 +Public Const EN_PBV = 5 +Public Const EN_FCV = 6 +Public Const EN_TCV = 7 +Public Const EN_GPV = 8 + +Public Const EN_NONE = 0 ' Quality analysis types +Public Const EN_CHEM = 1 +Public Const EN_AGE = 2 +Public Const EN_TRACE = 3 + +Public Const EN_CONCEN = 0 ' Source quality types +Public Const EN_MASS = 1 +Public Const EN_SETPOINT = 2 +Public Const EN_FLOWPACED = 3 + +Public Const EN_CFS = 0 ' Flow units types +Public Const EN_GPM = 1 +Public Const EN_MGD = 2 +Public Const EN_IMGD = 3 +Public Const EN_AFD = 4 +Public Const EN_LPS = 5 +Public Const EN_LPM = 6 +Public Const EN_MLD = 7 +Public Const EN_CMH = 8 +Public Const EN_CMD = 9 + +Public Const EN_TRIALS = 0 ' Misc. options +Public Const EN_ACCURACY = 1 +Public Const EN_TOLERANCE = 2 +Public Const EN_EMITEXPON = 3 +Public Const EN_DEMANDMULT = 4 + +Public Const EN_LOWLEVEL = 0 ' Control types +Public Const EN_HILEVEL = 1 +Public Const EN_TIMER = 2 +Public Const EN_TIMEOFDAY = 3 + +Public Const EN_AVERAGE = 1 'Time statistic types +Public Const EN_MINIMUM = 2 +Public Const EN_MAXIMUM = 3 +Public Const EN_RANGE = 4 + +Public Const EN_MIX1 = 0 'Tank mixing models +Public Const EN_MIX2 = 1 +Public Const EN_FIFO = 2 +Public Const EN_LIFO = 3 + +Public Const EN_NOSAVE = 0 ' Save-results-to-file flag +Public Const EN_SAVE = 1 +Public Const EN_INITFLOW = 10 ' Re-initialize flow flag + +Public Const EN_CONST_HP = 0 ' constant horsepower +Public Const EN_POWER_FUNC = 1 ' power function +Public Const EN_CUSTOM = 2 ' user-defined custom curve + +'These are the external functions that comprise the DLL + + Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As String) As Int32 + Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Int32 + Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Int32 + Declare Function ENclose Lib "epanet2.dll" () As Int32 + + Declare Function ENsolveH Lib "epanet2.dll" () As Int32 + Declare Function ENsaveH Lib "epanet2.dll" () As Int32 + Declare Function ENopenH Lib "epanet2.dll" () As Int32 + Declare Function ENinitH Lib "epanet2.dll" (ByVal SaveFlag As Int32) As Int32 + Declare Function ENrunH Lib "epanet2.dll" (ByRef T As Int32) As Int32 + Declare Function ENnextH Lib "epanet2.dll" (ByRef Tstep As Int32) As Int32 + Declare Function ENcloseH Lib "epanet2.dll" () As Int32 + Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Int32 + Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Int32 + + Declare Function ENsolveQ Lib "epanet2.dll" () As Int32 + Declare Function ENopenQ Lib "epanet2.dll" () As Int32 + Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Int32) As Int32 + Declare Function ENrunQ Lib "epanet2.dll" (ByRef T As Int32) As Int32 + Declare Function ENnextQ Lib "epanet2.dll" (ByRef Tstep As Int32) As Int32 + Declare Function ENstepQ Lib "epanet2.dll" (ByRef Tleft As Int32) As Int32 + Declare Function ENcloseQ Lib "epanet2.dll" () As Int32 + + Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Int32 + Declare Function ENreport Lib "epanet2.dll" () As Int32 + Declare Function ENresetreport Lib "epanet2.dll" () As Int32 + Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Int32 + + Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, Ctype As Int32, Lindex As Int32, Setting As Single, Nindex As Int32, Level As Single) As Int32 + Declare Function ENgetcount Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 + Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32 + Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 + Declare Function ENgetflowunits Lib "epanet2.dll" (ByRef Code As Int32) As Int32 + Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 + Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 + Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32 + Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByRef Value As Single) As Int32 + Declare Function ENgetqualtype Lib "epanet2.dll" (ByRef QualCode As Int32, ByRef TraceNode As Int32) As Int32 + Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Int32, ByVal ErrMsg As StringBuilder, ByVal N As Int32) + + Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 + Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 + Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32 + Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32 + + Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Int32, ByRef numDemands As Int32) As Int32 'ES + Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef Value As Single) As Int32 'ES + Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef PatIndex As Int32) As Int32 'ES + + Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32 + Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 + Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32 + Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Int32, ByRef Node1 As Int32, ByRef Node2 As Int32) As Int32 + Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32 + + Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Int32, ByRef nValues As Int32, ByRef xValues As Single, ByRef yValues As Single) As Int32 'ES + Declare Function ENgetheadcurve Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 'ES + Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Int32, ByRef PumpType As Int32) As Int32 'ES + + Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32 + + Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal Ctype As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32 + Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32 + Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32 + Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32 + Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByVal Value As Single) As Int32 + Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Int32) As Int32 + Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Single) As Int32 + Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Int32) As Int32 + Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Int32 + + Declare Function ENaddpattern Lib "epanet2.dll" (ByVal ID As String) As Int32 + +End Module From ef2763d1550b1d7f99ded1617cd18b614a738a77 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Wed, 22 Jul 2015 20:13:19 +0300 Subject: [PATCH 23/33] Fix to VB.Net include file By Lew Rossman --- include/epanet2.vb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/epanet2.vb b/include/epanet2.vb index 4e8b9f0..dbb3ed5 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -168,8 +168,8 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENreport Lib "epanet2.dll" () As Int32 Declare Function ENresetreport Lib "epanet2.dll" () As Int32 Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Int32 - - Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, Ctype As Int32, Lindex As Int32, Setting As Single, Nindex As Int32, Level As Single) As Int32 + + Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByRef CtlType As Int32, ByRef Lindex As Int32, ByRef Setting As Single, ByRef Nindex As Int32, ByRef Level As Single) As Int32 Declare Function ENgetcount Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32 Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32 @@ -202,7 +202,7 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32 - Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal Ctype As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32 + Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal CtlType As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32 Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32 Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32 Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32 From a3c7eaae15b65e2fed520ce8774907dc21387bb7 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Fri, 31 Jul 2015 14:41:18 +0300 Subject: [PATCH 24/33] Minor addition to vb header files --- include/epanet2.bas | 1 + include/epanet2.vb | 1 + 2 files changed, 2 insertions(+) diff --git a/include/epanet2.bas b/include/epanet2.bas index 8df46c5..2c3295c 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -51,6 +51,7 @@ Global Const EN_STATUS = 11 Global Const EN_SETTING = 12 Global Const EN_ENERGY = 13 Global Const EN_LINKQUAL = 14 'ES +Global Const EN_LINKPATTERN 15 Global Const EN_DURATION = 0 ' Time parameters Global Const EN_HYDSTEP = 1 diff --git a/include/epanet2.vb b/include/epanet2.vb index dbb3ed5..e74e1a5 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -55,6 +55,7 @@ Public Const EN_STATUS = 11 Public Const EN_SETTING = 12 Public Const EN_ENERGY = 13 Public Const EN_LINKQUAL = 14 'ES +Public Const EN_LINKPATTERN 15 Public Const EN_DURATION = 0 ' Time parameters Public Const EN_HYDSTEP = 1 From 0f65c830a37938bae4435a267bd098a0038b3737 Mon Sep 17 00:00:00 2001 From: Will Furnass Date: Fri, 31 Jul 2015 18:49:16 +0100 Subject: [PATCH 25/33] #define DLL_EXPORT as the empty string by default --- include/epanet2.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/epanet2.h b/include/epanet2.h index 8527d83..153fef4 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -47,6 +47,8 @@ #else #define DLLEXPORT #endif + #else + #define DLLEXPORT #endif #endif @@ -271,4 +273,4 @@ extern "C" { } #endif -#endif //EPANET2_H \ No newline at end of file +#endif //EPANET2_H From a35a61ef6dacd4146fe234c18fd607a3d3c4745c Mon Sep 17 00:00:00 2001 From: Will Furnass Date: Fri, 31 Jul 2015 18:50:26 +0100 Subject: [PATCH 26/33] Ensure that libm is linked to in cmake-driven builds --- build/CMake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/CMake/CMakeLists.txt b/build/CMake/CMakeLists.txt index 5aaa576..2edaf20 100644 --- a/build/CMake/CMakeLists.txt +++ b/build/CMake/CMakeLists.txt @@ -15,4 +15,4 @@ add_library(epanet STATIC ../../src/epanet.c ../../src/hydraul.c ../../src/hash # the standalone executable include_directories(../../src) add_executable(runepanet ../../run/main.c) -target_link_libraries (runepanet LINK_PUBLIC epanet) +target_link_libraries (runepanet LINK_PUBLIC epanet m) From d0c3f59f345d69c63c578de0fd7a0453c6c65c83 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Wed, 5 Aug 2015 14:15:27 +0300 Subject: [PATCH 27/33] Added missing parameters in the REPORT section The MESSAGES and FILE options were not saved --- src/inpfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/inpfile.c b/src/inpfile.c index e21fa98..3e7dcd6 100755 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -558,6 +558,9 @@ int saveinpfile(char *fname) fprintf(f, "\n STATUS %s", RptFlagTxt[Statflag]); fprintf(f, "\n SUMMARY %s", RptFlagTxt[Summaryflag]); fprintf(f, "\n ENERGY %s", RptFlagTxt[Energyflag]); + fprintf(f, "\n MESSAGES %s", RptFlagTxt[Messageflag]); + if (strlen(Rpt2Fname) > 0) + fprintf(f, "\n FILE %s", Rpt2Fname); switch (Nodeflag) { case 0: @@ -610,7 +613,7 @@ int saveinpfile(char *fname) } else fprintf(f, "\n %-20sNO", Field[i].Name); } - fprintf(f, "\n"); + fprintf(f, "\n\n"); /* Save auxilary data to new input file */ From 6878e046ed6dca4d602cd41ea23c962ced459c6c Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Fri, 7 Aug 2015 12:37:05 +0300 Subject: [PATCH 28/33] Removed old and unused code A bit of code cleaning --- src/epanet.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 3d5e7f9..3ec53e2 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -213,16 +213,6 @@ int DLLEXPORT ENopen(char *f1, char *f2, char *f3) /*** Updated 9/7/00 ***/ Messageflag = TRUE; - -/* If binary output file being used, then */ -/* do not write full results to Report file */ -/* (use it only for status reports). */ - Rptflag = 0; - if (strlen(f3) == 0) Rptflag = 1; - -/*** Updated 9/7/00 ***/ -/*** Previous code segment ignored. ***/ -/*** Rptflag now always set to 1. ***/ Rptflag = 1; /* Initialize global pointers to NULL. */ From f9ea14e57a293e4450afa8150ab8f755198f9432 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Thu, 20 Aug 2015 21:59:12 +0300 Subject: [PATCH 29/33] Fix HEAD and HEADLOSS results in report file --- src/input3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input3.c b/src/input3.c index d0922f6..96a9060 100755 --- a/src/input3.c +++ b/src/input3.c @@ -1370,7 +1370,7 @@ int reportdata() /* Check if input is a reporting criterion. */ /*** Special case needed to distinguish "HEAD" from "HEADLOSS" ***/ //(2.00.11 - LR) - if (strcomp(Tok[0], w_HEADLOSS)) i = HEADLOSS; //(2.00.11 - LR) + if (strcomp(Tok[0], t_HEADLOSS)) i = HEADLOSS; else i = findmatch(Tok[0],Fldname); //(2.00.11 - LR) if (i >= 0) //(2.00.11 - LR) /*****************************************************************/ //(2.00.11 - LR) From 186f21f9a7f39b8acd0bc4c017f5b009d152f798 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sat, 12 Sep 2015 11:54:57 +0300 Subject: [PATCH 30/33] update coord struct --- src/types.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/types.h b/src/types.h index f422a40..f4068fe 100755 --- a/src/types.h +++ b/src/types.h @@ -169,9 +169,10 @@ typedef struct /* CURVE OBJECT */ typedef struct /* Coord OBJECT */ { - char ID[MAXID+1]; /* Coord ID */ - double *X; /* X-values */ - double *Y; /* Y-values */ + char ID[MAXID+1]; /* Coord ID */ + double X; /* X-value */ + double Y; /* Y-value */ + char HaveCoords; /* Coordinates flag */ } Scoord; struct Sdemand /* DEMAND CATEGORY OBJECT */ From 4d6bcef623dfe4d4277e9599154fba6ebb9b8937 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sat, 12 Sep 2015 16:34:52 +0300 Subject: [PATCH 31/33] rewrite the coordinate getter currently controlled from input2.c lines 297-298. will need to add a flag to not load the coordinates. --- src/epanet.c | 26 +++++++------ src/funcs.h | 6 +-- src/input2.c | 105 +-------------------------------------------------- src/input3.c | 50 +++++++----------------- src/text.h | 1 + src/vars.h | 3 -- 6 files changed, 32 insertions(+), 159 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 3ec53e2..76b9070 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -239,7 +239,6 @@ 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()); @@ -1290,9 +1289,14 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y) **---------------------------------------------------------------- */ { - *x = Coord[index].X[0]; - *y = Coord[index].Y[0]; - return 0; + if (!Openflag) return(102); + if (index < 1 || index > Nnodes) return(203); + // check if node have coords + if (Coord[index].HaveCoords == 0) return(254); + + *x = Coord[index].X; + *y = Coord[index].Y; + return 0; } int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value) @@ -2770,12 +2774,11 @@ void initpointers() Pattern = NULL; Curve = NULL; Control = NULL; - Coord = NULL; + Coord = NULL; X = NULL; Patlist = NULL; Curvelist = NULL; - Coordlist = NULL; Adjlist = NULL; Aii = NULL; Aij = NULL; @@ -2885,12 +2888,10 @@ int allocdata() { // 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; + /* ini coord data */ + Coord[n].X = 0; + Coord[n].Y = 0; + Coord[n].HaveCoords = 0; } } @@ -3189,6 +3190,7 @@ char *geterrmsg(int errcode) case 250: sprintf(Msg,ERR250); break; case 251: sprintf(Msg,ERR251); break; case 253: sprintf(Msg,ERR253); break; + case 254: sprintf(Msg,ERR254); break; /* File Errors */ case 301: strcpy(Msg,ERR301); break; diff --git a/src/funcs.h b/src/funcs.h index 9847275..51ccc20 100755 --- a/src/funcs.h +++ b/src/funcs.h @@ -65,13 +65,11 @@ int addnodeID(int, char *); /* Adds node ID to data base */ int addlinkID(int, char *); /* Adds link ID to data base */ int addpattern(char *); /* Adds pattern to data base */ int addcurve(char *); /* Adds curve to data base */ -int addcoord(char *); /* Adds coord to data base */ STmplist *findID(char *, STmplist *); /* Locates ID on linked list */ int unlinked(void); /* Checks for unlinked nodes */ int getpumpparams(void); /* Computes pump curve coeffs.*/ int getpatterns(void); /* Gets pattern data from list*/ int getcurves(void); /* Gets curve data from list */ -int getcoords(void); /* Gets coordinate data from list */ int findmatch(char *,char *[]); /* Finds keyword in line */ int match(char *, char *); /* Checks for word match */ int gettokens(char *); /* Tokenizes input line */ @@ -88,7 +86,7 @@ int pumpdata(void); /* Processes pump data */ int valvedata(void); /* Processes valve data */ int patterndata(void); /* Processes pattern data */ int curvedata(void); /* Processes curve data */ -int coordata(void); /* Processes coordinate data */ +int coordata(void); /* Processes coordinate data */ int demanddata(void); /* Processes demand data */ int controldata(void); /* Processes simple controls */ int energydata(void); /* Processes energy data */ @@ -287,4 +285,4 @@ int saveepilog(void); /* Saves output file epilog */ /* ------------ INPFILE.C --------------*/ int saveinpfile(char *); /* Saves network to text file */ -#endif +#endif diff --git a/src/input2.c b/src/input2.c index b372867..4665076 100755 --- a/src/input2.c +++ b/src/input2.c @@ -48,7 +48,6 @@ char *Tok[MAXTOKS]; /* Array of token strings */ /* Used in INPUT3.C: */ STmplist *PrevPat; /* Pointer to pattern list element */ STmplist *PrevCurve; /* Pointer to curve list element */ -STmplist *PrevCoord; /* Pointer to coordinate list element */ /* Defined in enumstxt.h in EPANET.C */ extern char *SectTxt[]; /* Input section keywords */ @@ -79,7 +78,6 @@ int netsize() MaxRules = 0; MaxCurves = 0; sect = -1; - MaxCoords = 0; /* Add a default pattern 0 */ MaxPats = -1; @@ -121,8 +119,6 @@ int netsize() break; case _CURVES: errcode = addcurve(tok); break; -// case _COORDS: errcode = addcoord(tok); //06.02.2010-woohn -// break; } if (errcode) break; } @@ -176,7 +172,6 @@ int readdata() Npats = MaxPats; PrevPat = NULL; PrevCurve = NULL; - PrevCoord = NULL; sect = -1; errsum = 0; @@ -245,7 +240,6 @@ int readdata() /* Get pattern & curve data from temp. lists */ if (!errcode) errcode = getpatterns(); if (!errcode) errcode = getcurves(); - //if (!errcode) errcode = getcoords(); if (!errcode) errcode = getpumpparams(); /* Free input buffer */ @@ -300,7 +294,8 @@ int newline(int sect, char *line) case _OPTIONS: return(optiondata()); /* Data in these sections are not used for any computations */ - case _COORDS: return (0); //return(coordata()); + //case _COORDS: return (0); //uncomment to not load the coordinates + case _COORDS: return(coordata()); //comment out to load the coordinates case _LABELS: return(0); case _TAGS: return(0); case _VERTICES: return(0); @@ -520,43 +515,6 @@ int addcurve(char *id) return(0); } -int addcoord(char *id) -/* - **------------------------------------------------------------- - ** Input: id = curve ID label - ** Output: returns error code - ** Purpose: adds a new curve to the database - **-------------------------------------------------------------- - */ -{ - STmplist *c; - - /* Check if ID is same as last one processed */ - if (Coordlist != NULL && strcmp(id,Coordlist->ID) == 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) /* @@ -749,65 +707,6 @@ 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 96a9060..84a3a12 100755 --- a/src/input3.c +++ b/src/input3.c @@ -42,8 +42,6 @@ extern char *Fldname[]; extern char *Tok[MAXTOKS]; extern STmplist *PrevPat; extern STmplist *PrevCurve; - -extern STmplist *PrevCoord; extern int Ntokens; @@ -591,46 +589,24 @@ int coordata() **-------------------------------------------------------------- */ { - double x,y; - SFloatlist *fx, *fy; - STmplist *c; + double x, y; + int j; - /* Check for valid curve ID */ + /* Check for valid node 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 */ + /* Check for valid data */ + if ((j = findnode(Tok[0])) == 0) return(203); 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; - + + /* Save coord data */ + strncpy(Coord[j].ID, Node[j].ID, MAXID); + Coord[j].X = x; + Coord[j].Y = y; + Coord[j].HaveCoords = 1; + + return(0); } /* end of coordata */ int demanddata() diff --git a/src/text.h b/src/text.h index 6d87cd8..5c77428 100755 --- a/src/text.h +++ b/src/text.h @@ -494,6 +494,7 @@ AUTHOR: L. Rossman #define ERR251 "Input Error 251: function call contains invalid parameter code." #define ERR253 "Input Error 253: Function call error - No such demand category index." +#define ERR254 "Input Error 254: Function call error - Node have no coordinates." #define ERR301 "File Error 301: identical file names." #define ERR302 "File Error 302: cannot open input file." diff --git a/src/vars.h b/src/vars.h index 2a4f363..f4a2cbe 100755 --- a/src/vars.h +++ b/src/vars.h @@ -76,7 +76,6 @@ EXTERN int MaxNodes, /* Node count from input file */ 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 */ @@ -88,7 +87,6 @@ EXTERN int MaxNodes, /* Node count from input file */ 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 */ @@ -159,7 +157,6 @@ 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 */ From c12f901454cb72de0ade48d6db603f0acb07ea26 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sun, 13 Sep 2015 09:53:21 +0300 Subject: [PATCH 32/33] added ENsetcoord function also minor fix to include files --- build/WinSDK/epanet2.def | 1 + include/epanet2.bas | 3 ++- include/epanet2.h | 1 + include/epanet2.vb | 4 +++- src/epanet.c | 24 +++++++++++++++++++++++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/build/WinSDK/epanet2.def b/build/WinSDK/epanet2.def index fc84da2..ec3bee9 100644 --- a/build/WinSDK/epanet2.def +++ b/build/WinSDK/epanet2.def @@ -62,6 +62,7 @@ EXPORTS ENgetcurve = _ENgetcurve@20 ENgetstatistic = _ENgetstatistic@8 ENgetcoord = _ENgetcoord@12 + ENsetcoord = _ENsetcoord@12 ENgetqualinfo = _ENgetqualinfo@16 ENsetbasedemand = _ENsetbasedemand@12 ENgetaveragepatternvalue = _ENgetaveragepatternvalue@8 diff --git a/include/epanet2.bas b/include/epanet2.bas index 2c3295c..4260cfb 100644 --- a/include/epanet2.bas +++ b/include/epanet2.bas @@ -51,7 +51,7 @@ Global Const EN_STATUS = 11 Global Const EN_SETTING = 12 Global Const EN_ENERGY = 13 Global Const EN_LINKQUAL = 14 'ES -Global Const EN_LINKPATTERN 15 +Global Const EN_LINKPATTERN = 15 Global Const EN_DURATION = 0 ' Time parameters Global Const EN_HYDSTEP = 1 @@ -189,6 +189,7 @@ Global Const EN_INITFLOW = 10 ' Re-initialize flow flag Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Long, Code As Long) As Long Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Long, ByVal Code As Long, Value As Single) As Long Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Long, X As Single, Y As Single) As Long + Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Long, ByVal X As Single, ByVal Y As Single) As Long Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Long, numDemands As Long) As Long Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, Value As Single) As Long diff --git a/include/epanet2.h b/include/epanet2.h index 153fef4..b2d730c 100755 --- a/include/epanet2.h +++ b/include/epanet2.h @@ -239,6 +239,7 @@ extern "C" { int DLLEXPORT ENgetnodetype(int index, int *code); int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value); int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y); + int DLLEXPORT ENsetcoord(int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y); int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands); int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE *baseDemand); diff --git a/include/epanet2.vb b/include/epanet2.vb index e74e1a5..62da5fc 100644 --- a/include/epanet2.vb +++ b/include/epanet2.vb @@ -186,7 +186,9 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32 Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32 Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32 - + Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByRef X As Single, ByRef Y As Single) As Int32 + Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByVal X As Single, ByVal Y As Single) As Int32 + Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Int32, ByRef numDemands As Int32) As Int32 'ES Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef Value As Single) As Int32 'ES Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef PatIndex As Int32) As Int32 'ES diff --git a/src/epanet.c b/src/epanet.c index 76b9070..dbd9aca 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -1283,7 +1283,7 @@ 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 + ** *y = value of node's coordinate ** Returns: error code ** Purpose: retrieves coordinate x, y for a node **---------------------------------------------------------------- @@ -1299,6 +1299,28 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y) return 0; } + +int DLLEXPORT ENsetcoord(int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y) +/*---------------------------------------------------------------- + ** Input: index = node index + ** *x = value of node's coordinate + ** *y = value of node's coordinate + ** Output: None + ** Returns: error code + ** Purpose: sets coordinate x, y for a node + **---------------------------------------------------------------- + */ +{ + if (!Openflag) return(102); + if (index < 1 || index > Nnodes) return(203); + + Coord[index].X = x; + Coord[index].Y = y; + Coord[index].HaveCoords = 1; + return 0; +} + + int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value) /*---------------------------------------------------------------- ** Input: index = node index From 2c46a002ba44a66e79ea1f3151bdd764c4070106 Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Sun, 13 Sep 2015 12:56:28 +0300 Subject: [PATCH 33/33] Changed coordinates are saved to INP Added a flag which controls the loading of coordinates at epanet.c line 213. When set to TRUE coordinates are loaded and users can use the ENgetcoord and ENsetcoord functions. Changes are then saved when ENsaveinpfile is called. When set to FALSE coordinates are not loaded and can't be retrieved or changed. When saved, the COORD section is copied from the original INP file. --- src/epanet.c | 27 +++++++++++++++++++-------- src/inpfile.c | 27 +++++++++++++++++++++++++-- src/input2.c | 7 +++++-- src/input3.c | 2 +- src/text.h | 1 + src/vars.h | 3 ++- 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index dbd9aca..c27e231 100755 --- a/src/epanet.c +++ b/src/epanet.c @@ -210,7 +210,8 @@ int DLLEXPORT ENopen(char *f1, char *f2, char *f3) SaveHflag = FALSE; SaveQflag = FALSE; Warnflag = FALSE; - + Coordflag = TRUE; + /*** Updated 9/7/00 ***/ Messageflag = TRUE; Rptflag = 1; @@ -1291,8 +1292,10 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y) { if (!Openflag) return(102); if (index < 1 || index > Nnodes) return(203); + if (!Coordflag) return(255); + // check if node have coords - if (Coord[index].HaveCoords == 0) return(254); + if (Coord[index].HaveCoords == FALSE) return(254); *x = Coord[index].X; *y = Coord[index].Y; @@ -1313,10 +1316,11 @@ int DLLEXPORT ENsetcoord(int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y) { if (!Openflag) return(102); if (index < 1 || index > Nnodes) return(203); + if (!Coordflag) return(255); Coord[index].X = x; Coord[index].Y = y; - Coord[index].HaveCoords = 1; + Coord[index].HaveCoords = TRUE; return 0; } @@ -2880,14 +2884,17 @@ 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)); + if (Coordflag == TRUE) + { + 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)); + if (Coordflag == TRUE) ERRCODE(MEMCHECK(Coord)); } /* Initialize pointers used in patterns, curves, and demand category lists */ @@ -2911,9 +2918,12 @@ int allocdata() // node demand Node[n].D = NULL; /* ini coord data */ - Coord[n].X = 0; - Coord[n].Y = 0; - Coord[n].HaveCoords = 0; + if (Coordflag == TRUE) + { + Coord[n].X = 0; + Coord[n].Y = 0; + Coord[n].HaveCoords = FALSE; + } } } @@ -3213,6 +3223,7 @@ char *geterrmsg(int errcode) case 251: sprintf(Msg,ERR251); break; case 253: sprintf(Msg,ERR253); break; case 254: sprintf(Msg,ERR254); break; + case 255: sprintf(Msg,ERR255); break; /* File Errors */ case 301: strcpy(Msg,ERR301); break; diff --git a/src/inpfile.c b/src/inpfile.c index 3e7dcd6..5c06fc0 100755 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -77,7 +77,11 @@ void saveauxdata(FILE *f) / switch(sect) { case _RULES: - case _COORDS: + case _COORDS: if (Coordflag == FALSE) + { + fprintf(f, "%s", line); + } + break; case _VERTICES: case _LABELS: case _BACKDROP: @@ -92,7 +96,11 @@ void saveauxdata(FILE *f) / switch(sect) { case _RULES: - case _COORDS: + case _COORDS: if (Coordflag == FALSE) + { + fprintf(f, "%s", line); + } + break; case _VERTICES: case _LABELS: case _BACKDROP: @@ -615,6 +623,21 @@ int saveinpfile(char *fname) } fprintf(f, "\n\n"); +/* Write [COORDINATES] section */ + + if (Coordflag == TRUE) + { + fprintf(f, "\n\n[COORDINATES]"); + for (i=1; i<=Nnodes; i++) + { + if (Coord[i].HaveCoords == TRUE) + { + fprintf(f,"\n %-31s %14.6f %14.6f",Node[i].ID,Coord[i].X,Coord[i].Y); + } + } + fprintf(f, "\n\n"); + } + /* Save auxilary data to new input file */ saveauxdata(f); diff --git a/src/input2.c b/src/input2.c index 4665076..6ac3202 100755 --- a/src/input2.c +++ b/src/input2.c @@ -294,8 +294,11 @@ int newline(int sect, char *line) case _OPTIONS: return(optiondata()); /* Data in these sections are not used for any computations */ - //case _COORDS: return (0); //uncomment to not load the coordinates - case _COORDS: return(coordata()); //comment out to load the coordinates + case _COORDS: if (Coordflag == TRUE) + { + return(coordata()); + } + else return(0); case _LABELS: return(0); case _TAGS: return(0); case _VERTICES: return(0); diff --git a/src/input3.c b/src/input3.c index 84a3a12..4ab3487 100755 --- a/src/input3.c +++ b/src/input3.c @@ -604,7 +604,7 @@ int coordata() strncpy(Coord[j].ID, Node[j].ID, MAXID); Coord[j].X = x; Coord[j].Y = y; - Coord[j].HaveCoords = 1; + Coord[j].HaveCoords = TRUE; return(0); } /* end of coordata */ diff --git a/src/text.h b/src/text.h index 5c77428..abbd817 100755 --- a/src/text.h +++ b/src/text.h @@ -495,6 +495,7 @@ AUTHOR: L. Rossman #define ERR253 "Input Error 253: Function call error - No such demand category index." #define ERR254 "Input Error 254: Function call error - Node have no coordinates." +#define ERR255 "Input Error 255: Function call error - Coordinates were not loaded." #define ERR301 "File Error 301: identical file names." #define ERR302 "File Error 302: cannot open input file." diff --git a/src/vars.h b/src/vars.h index f4a2cbe..1b95d1a 100755 --- a/src/vars.h +++ b/src/vars.h @@ -64,7 +64,8 @@ EXTERN char Msg[MAXMSG+1], /* Text of output message */ SaveHflag, /* Hydraul. results saved flag */ OpenQflag, /* Quality system opened flag */ SaveQflag, /* Quality results saved flag */ - Saveflag; /* General purpose save flag */ + Saveflag, /* General purpose save flag */ + Coordflag; /* Load coordinates flag */ EXTERN int MaxNodes, /* Node count from input file */ MaxLinks, /* Link count from input file */ MaxJuncs, /* Junction count */