├── .gitignore ├── EPANET ├── Content.txt ├── ENMatlabCleanup.m ├── ENMatlabSetup.m ├── ENaddpattern.m ├── ENclose.m ├── ENcloseH.m ├── ENcloseQ.m ├── ENerror.m ├── ENgetalllinknodes.m ├── ENgetcontrol.m ├── ENgetcount.m ├── ENgeterror.m ├── ENgetflowunits.m ├── ENgetlinkid.m ├── ENgetlinkindex.m ├── ENgetlinknodes.m ├── ENgetlinktype.m ├── ENgetlinkvalue.m ├── ENgetnetsize.m ├── ENgetnodeid.m ├── ENgetnodeindex.m ├── ENgetnodetype.m ├── ENgetnodevalue.m ├── ENgetoption.m ├── ENgetpatternid.m ├── ENgetpatternindex.m ├── ENgetpatternlen.m ├── ENgetpatternvalue.m ├── ENgetqualtype.m ├── ENgettimeparam.m ├── ENgetversion.m ├── ENinitH.m ├── ENinitQ.m ├── ENnextH.m ├── ENnextQ.m ├── ENopen.m ├── ENopenH.m ├── ENopenQ.m ├── ENreport.m ├── ENresetreport.m ├── ENrunH.m ├── ENrunQ.m ├── ENsaveH.m ├── ENsavehydfile.m ├── ENsaveinpfile.m ├── ENsetcontrol.m ├── ENsetlinkvalue.m ├── ENsetnodevalue.m ├── ENsetoption.m ├── ENsetpattern.m ├── ENsetpatternvalue.m ├── ENsetqualtype.m ├── ENsetreport.m ├── ENsetstatusreport.m ├── ENsettimeparam.m ├── ENsolveH.m ├── ENsolveQ.m ├── ENstepQ.m ├── ENusehydfile.m └── ENwriteline.m ├── MSX ├── Content.txt ├── MSXMatlabCleanup.m ├── MSXMatlabSetup.m ├── MSXaddpattern.m ├── MSXclose.m ├── MSXerror.m ├── MSXgetID.m ├── MSXgetIDlen.m ├── MSXgetconstant.m ├── MSXgetcount.m ├── MSXgeterror.m ├── MSXgetindex.m ├── MSXgetinitqual.m ├── MSXgetparameter.m ├── MSXgetpatternlen.m ├── MSXgetpatternvalue.m ├── MSXgetqual.m ├── MSXgetsource.m ├── MSXgetspecies.m ├── MSXinit.m ├── MSXopen.m ├── MSXreport.m ├── MSXsavemsxfile.m ├── MSXsaveoutfile.m ├── MSXsetconstant.m ├── MSXsetinitqual.m ├── MSXsetparameter.m ├── MSXsetpattern.m ├── MSXsetpatternvalue.m ├── MSXsetsource.m ├── MSXsolveH.m ├── MSXsolveQ.m ├── MSXstep.m └── MSXusehydfile.m ├── README.md ├── Test ├── Content.txt ├── ENwraptest.m ├── MSXwraptest.m ├── example.m └── net2-cl2.msx └── Utils ├── NetworkFrame.m ├── NetworkMovie.m ├── Readme.txt ├── categorizeNodes.m ├── color.m ├── exampleMovie.m ├── getHydraulicData.m ├── getNodeXY.m ├── getQualityData.m └── html ├── NetworkMovie.html ├── exampleMovie.html ├── exampleMovie_01.eps └── exampleMovie_01.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | 9 | # Compiled Static libraries 10 | *.lai 11 | *.la 12 | *.a 13 | 14 | # Doxygen output 15 | doxygen_out/ 16 | 17 | # Mac Stuff 18 | .DS_Store 19 | *.swp 20 | *~.nib 21 | *.build/ 22 | DerivedData/ 23 | Debug/ 24 | 25 | *.xcodeproj/ 26 | !*.xcodeproj/project.pbxproj 27 | 28 | *.mode1v3 29 | *.mode2v3 30 | -------------------------------------------------------------------------------- /EPANET/Content.txt: -------------------------------------------------------------------------------- 1 | EPANET-Toolkit Functions by Task 2 | For reference see: EPANET programmer's toolkit Windows help file. 3 | Report bugs, inconsistencies, or errors to Feng Shang or Jim Uber 4 | 5 | Initialization 6 | ENMatlabSetup - Opens the EPANET DLL library and sets global variables required by the Matlab Epanet Toolkit 7 | ENMatlabCleanup - Closes the EPANET DLL library 8 | 9 | Opening and closing the EPANET Toolkit system 10 | ENopen - Opens the Toolkit to analyze a particular distribution system. 11 | ENclose - Closes down the Toolkit system (including all files being processed). 12 | 13 | 14 | Retrieving information about network nodes 15 | ENgetnodeindex - Retrieves the index of a node with a specified ID. 16 | ENgetnodeid - Retrieves the ID label of a node with a specified index. 17 | ENgetnodetype - Retrieves the node-type code for a specific node. 18 | ENgetnodevalue - Retrieves the value of a specific link parameter. 19 | 20 | 21 | Retrieving information about network links 22 | ENgetlinkindex - Retrieves the ID label of a link with a specified index. 23 | ENgetlinkid - Retrieves the ID label of a link with a specified index. 24 | ENgetlinktype - Retrieves the link-type code for a specific link. 25 | ENgetlinknodes - Retrieves the indexes of the end nodes of a specified link. 26 | ENgetlinkvalue - Retrieves the value of a specific link parameter. 27 | 28 | 29 | Retrieving information about time patterns 30 | ENgetpatternid - Retrieves the ID label of a particular time pattern. 31 | ENgetpatternindex - Retrieves the index of a particular time pattern. 32 | ENgetpatternlen - Retrieves the number of time periods in a specific time pattern. 33 | ENgetpatternvalue - Retrieves the multiplier factor for a specific time period in a time pattern. 34 | 35 | 36 | Retrieving other network information 37 | ENgetcontrol - Retrieves the parameters of a simple control statement. 38 | The index of the control is specified in cindex and the remaining arguments return the control's 39 | parameters. 40 | ENgetqualtype - Retrieves the type of water quality analysis called for. 41 | ENgetoption - Retrieves the value of a particular analysis option. 42 | 43 | 44 | 45 | Setting new values for network parameters 46 | ENsetcontrol - Sets the parameters of a simple control statement. 47 | ENsetnodevalue - Sets the value of a parameter for a specific node. 48 | ENsetlinkvalue - Sets the value of a parameter for a specific link. 49 | ENaddpattern - Adds a new time pattern to the network. 50 | ENsetpattern - Sets all of the multiplier factors for a specific time pattern. 51 | ENsetpatternvalue - Sets the multiplier factor for a specific period within a time pattern. 52 | ENsetqualtype - Sets the type of water quality analysis called for. 53 | ENsettimeparam - Sets the value of a time parameter. 54 | ENsetoption - Sets the value of a particular analysis option. 55 | 56 | 57 | Saving and using hydraulic analysis results files 58 | ENsavehydfile - Saves the current contents of the binary hydraulics file to a file. 59 | ENusehydfile - Uses the contents of the specified file as the current binary hydraulics file. 60 | 61 | 62 | 63 | Running a hydraulic analysis 64 | ENsolveH - Runs a complete hydraulic simulation with results 65 | for all time periods written to the binary Hydraulics file. 66 | ENopenH - Opens the hydraulics analysis system. 67 | ENinitH - Initializes storage tank levels, link status and settings, and 68 | the simulation clock time prior to running a hydraulic analysis. 69 | ENrunH - Runs a single period hydraulic analysis, retrieving the current simulation clock time t. 70 | ENnextH - Determines the length of time until the next hydraulic event 71 | occurs in an extended period simulation. 72 | ENcloseH - Closes the hydraulic analysis system, freeing all allocated memory. 73 | 74 | 75 | Running a water quality analysis 76 | ENsolveQ - Runs a complete water quality simulation with results at uniform 77 | reporting intervals written to EPANET's binary Output file. 78 | ENopenQ - Opens the water quality analysis system. 79 | ENinitQ - Initializes water quality and the simulation clock time prior to 80 | running a water quality analysis. 81 | ENrunQ - Makes available the hydraulic and water quality results that 82 | occur at the start of the next time period of a water quality analysis, where the start of the 83 | period is returned in t. 84 | ENnextQ - Advances the water quality simulation to the start of the next hydraulic time period. 85 | ENstepQ - Advances the water quality simulation one water quality time step. 86 | The time remaining in the overall simulation is returned in tleft. 87 | ENcloseQ - Closes the water quality analysis system, freeing all allocated memory. 88 | 89 | 90 | Generating an output report 91 | ENsaveH - Transfers results of a hydraulic simulation from the binary 92 | Hydraulics file to the binary Output file, where results are only reported at uniform reporting 93 | intervals. 94 | ENsaveinpfile - Writes all current network input data to a file using the format of an EPANET input file. 95 | ENreport - Writes a formatted text report on simulation results to the Report file. 96 | ENresetreport - Clears any report formatting commands that either appeared in the 97 | [REPORT] section of the EPANET Input file or were issued with the ENsetreport function. 98 | ENsetreport - Issues a report formatting command. Formatting commands are the 99 | same as used in the [REPORT] section of the EPANET Input file. 100 | ENsetstatusreport - Sets the level of hydraulic status reporting. 101 | ENgeterror - Retrieves the text of the message associated with a particular error or warning code. 102 | ENwriteline - Writes a line of text to the EPANET report file. 103 | 104 | 105 | General functions 106 | ENerror - Prints out the error message string associated with error number errcode 107 | ENgetflowunits - Retrieves a code number indicating the units used to express all flow rates. 108 | ENgetcount - Retrieves the number of network components of a specified type. 109 | 110 | 111 | Matlab specific functions 112 | ENgetalllinknodes - Gets the node indices associated with all network links 113 | ENgetnetsize - Retreive number of network components 114 | ENgetversion - Retrieves the EPANET code version 115 | -------------------------------------------------------------------------------- /EPANET/ENMatlabCleanup.m: -------------------------------------------------------------------------------- 1 | function ENMatlabCleanup(DLLname) 2 | % Declaration: 3 | % ENMatlabCleanup(DLLname) 4 | % 5 | % Description: 6 | % Unloads EPANET DLL library 7 | % 8 | % Arguments: 9 | % DLLname Name of the Epanet DLL file (w/o the *.dll extension) 10 | % 11 | % 12 | % Globals: 13 | % 14 | % Notes: 15 | % ENMatlabCleanup must be called at the end of a toolkit application. 16 | % must be called when all processing has been completed, 17 | % even if an error condition was encountered. 18 | 19 | 20 | global ENDLLNAME; 21 | %errcode = 0; 22 | if nargin == 1 23 | ENDLLNAME=DLLname; 24 | end; 25 | % Load library 26 | if libisloaded(ENDLLNAME) 27 | unloadlibrary(ENDLLNAME); 28 | else 29 | errstring =['Library ', ENDLLNAME, '.dll was not loaded']; 30 | disp(errstring); 31 | end; 32 | -------------------------------------------------------------------------------- /EPANET/ENMatlabSetup.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENMatlabSetup(DLLname,Hname) 2 | % Declaration: 3 | % [errcode] = ENMatlabSetup(DLLname,Hname) 4 | % 5 | % Description: 6 | % Opens the EPANET DLL library and sets global variables required by the 7 | % Matlab Epanet Toolkit 8 | % 9 | % EPANET Programmer's Toolkit Version: 10 | % This version is consistent with the API defined for EPANET v2.00.12. 11 | % If you are using another version of the EPANET programmer's toolkit DLL 12 | % and header file, an error will be issued. 13 | % 14 | % Arguments: 15 | % DLLname Name of the Epanet DLL file (w/o the *.dll extension) 16 | % Hname Name of the Epanet header file defining the exported symbols in 17 | % DLLname.dll (with the *.h extension). 18 | % 19 | % Returns: 20 | % Returns an error code (zero is normal termination). 21 | % 22 | % Globals: 23 | % EN_CONSTANT is a global structure containing all integer codes defined 24 | % for use of the Epanet programmer's toolkit (as defined in epanet2.h). 25 | % This structure can then be used for convenient access to these codes, 26 | % by declaring 'global EN_CONSTANT' in the code module. 27 | % 28 | % Notes: 29 | % ENMatlabSetup must be called before any of the other toolkit functions. 30 | 31 | global ENDLLNAME; 32 | global EN_CONSTANT; 33 | 34 | currentversion = 20012; 35 | %errcode = 0; 36 | 37 | % Load library 38 | ENDLLNAME=DLLname; 39 | ENHNAME=Hname; 40 | if ~libisloaded(ENDLLNAME) 41 | loadlibrary(ENDLLNAME,ENHNAME); 42 | end 43 | 44 | % Check version of EPANET DLL 45 | [errcode, version] = ENgetversion(); 46 | if version ~= currentversion 47 | errcode = 1; 48 | errstring = ['Current version ',num2str(version),' of EPANET is not supported. Update to version ',num2str(currentversion)]; 49 | disp(errstring); 50 | return 51 | end 52 | 53 | EN_CONSTANT = struct(... 54 | 'EN_ELEVATION', int32(0),... % Node parameters 55 | 'EN_BASEDEMAND', int32(1),... 56 | 'EN_PATTERN', int32(2),... 57 | 'EN_EMITTER', int32(3),... 58 | 'EN_INITQUAL', int32(4),... 59 | 'EN_SOURCEQUAL', int32(5),... 60 | 'EN_SOURCEPAT', int32(6),... 61 | 'EN_SOURCETYPE', int32(7),... 62 | 'EN_TANKLEVEL', int32(8),... 63 | 'EN_DEMAND', int32(9),... 64 | 'EN_HEAD', int32(10),... 65 | 'EN_PRESSURE', int32(11),... 66 | 'EN_QUALITY', int32(12),... 67 | 'EN_SOURCEMASS', int32(13),... 68 | 'EN_INITVOLUME', int32(14),... 69 | 'EN_MIXMODEL', int32(15),... 70 | 'EN_MIXZONEVOL', int32(16),... 71 | 'EN_TANKDIAM', int32(17),... 72 | 'EN_MINVOLUME', int32(18),... 73 | 'EN_VOLCURVE', int32(19),... 74 | 'EN_MINLEVEL', int32(20),... 75 | 'EN_MAXLEVEL', int32(21),... 76 | 'EN_MIXFRACTION', int32(22),... 77 | 'EN_TANK_KBULK', int32(23),... 78 | 'EN_DIAMETER', int32(0),... % Link parameters 79 | 'EN_LENGTH', int32(1),... 80 | 'EN_ROUGHNESS', int32(2),... 81 | 'EN_MINORLOSS', int32(3),... 82 | 'EN_INITSTATUS', int32(4),... 83 | 'EN_INITSETTING', int32(5),... 84 | 'EN_KBULK', int32(6),... 85 | 'EN_KWALL', int32(7),... 86 | 'EN_FLOW', int32(8),... 87 | 'EN_VELOCITY', int32(9),... 88 | 'EN_HEADLOSS', int32(10),... 89 | 'EN_STATUS', int32(11),... 90 | 'EN_SETTING', int32(12),... 91 | 'EN_ENERGY', int32(13),... 92 | 'EN_DURATION', int32(0),... % Time parameters 93 | 'EN_HYDSTEP', int32(1),... 94 | 'EN_QUALSTEP', int32(2),... 95 | 'EN_PATTERNSTEP', int32(3),... 96 | 'EN_PATTERNSTART', int32(4),... 97 | 'EN_REPORTSTEP', int32(5),... 98 | 'EN_REPORTSTART', int32(6),... 99 | 'EN_RULESTEP', int32(7),... 100 | 'EN_STATISTIC', int32(8),... 101 | 'EN_PERIODS', int32(9),... 102 | 'EN_NODECOUNT', int32(0),... % Component counts 103 | 'EN_TANKCOUNT', int32(1),... 104 | 'EN_LINKCOUNT', int32(2),... 105 | 'EN_PATCOUNT', int32(3),... 106 | 'EN_CURVECOUNT', int32(4),... 107 | 'EN_CONTROLCOUNT', int32(5),... 108 | 'EN_JUNCTION', int32(0),... % Node types 109 | 'EN_RESERVOIR', int32(1),... 110 | 'EN_TANK', int32(2),... 111 | 'EN_CVPIPE', int32(0),... % Link types 112 | 'EN_PIPE', int32(1),... 113 | 'EN_PUMP', int32(2),... 114 | 'EN_PRV', int32(3),... 115 | 'EN_PSV', int32(4),... 116 | 'EN_PBV', int32(5),... 117 | 'EN_FCV', int32(6),... 118 | 'EN_TCV', int32(7),... 119 | 'EN_GPV', int32(8),... 120 | 'EN_NONE', int32(0),... % Quality analysis types 121 | 'EN_CHEM', int32(1),... 122 | 'EN_AGE', int32(2),... 123 | 'EN_TRACE', int32(3),... 124 | 'EN_CONCEN', int32(0),... % Source quality types 125 | 'EN_MASS', int32(1),... 126 | 'EN_SETPOINT', int32(2),... 127 | 'EN_FLOWPACED', int32(3),... 128 | 'EN_CFS', int32(0),... % Flow units types 129 | 'EN_GPM', int32(1),... 130 | 'EN_MGD', int32(2),... 131 | 'EN_IMGD', int32(3),... 132 | 'EN_AFD', int32(4),... 133 | 'EN_LPS', int32(5),... 134 | 'EN_LPM', int32(6),... 135 | 'EN_MLD', int32(7),... 136 | 'EN_CMH', int32(8),... 137 | 'EN_CMD', int32(9),... 138 | 'EN_TRIALS', int32(0),... % Misc. options 139 | 'EN_ACCURACY', int32(1),... 140 | 'EN_TOLERANCE', int32(2),... 141 | 'EN_EMITEXPON', int32(3),... 142 | 'EN_DEMANDMULT', int32(4),... 143 | 'EN_LOWLEVEL', int32(0),... % Control types 144 | 'EN_HILEVEL', int32(1),... 145 | 'EN_TIMER', int32(2),... 146 | 'EN_TIMEOFDAY', int32(3),... 147 | 'EN_AVERAGE', int32(1),... % Time statistic types. 148 | 'EN_MINIMUM', int32(2),... 149 | 'EN_MAXIMUM', int32(3),... 150 | 'EN_RANGE', int32(4),... 151 | 'EN_MIX1', int32(0),... % Tank mixing models 152 | 'EN_MIX2', int32(1),... 153 | 'EN_FIFO', int32(2),... 154 | 'EN_LIFO', int32(3),... 155 | 'EN_NOSAVE', int32(0),... % Save-results-to-file flag 156 | 'EN_SAVE', int32(1),... 157 | 'EN_INITFLOW', int32(10)); % Re-initialize flow flag 158 | -------------------------------------------------------------------------------- /EPANET/ENaddpattern.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENaddpattern(patid) 2 | % Declaration: 3 | % int ENaddpattern( char* id ) 4 | % Description: 5 | % Adds a new time pattern to the network. 6 | % Arguments: 7 | % id: 8 | % ID label of pattern 9 | % Returns: 10 | % Returns an error code. 11 | % Notes: 12 | % The ID label should contain no more than 31 characters. 13 | % The new pattern will contain a single time period whose multiplier factor is 1. 14 | % Use the ENsetpattern function to populate the pattern with a specific set of multipliers after first retrieving its index with the ENgetpatternindex function. 15 | % Example: 16 | % char patId[] = "NewPattern"; 17 | % float patFactors[] = {0.8, 1.1, 1.4, 1.1, 0.8, 0.7}; 18 | % int patIndex; 19 | % ENaddpattern(patId); 20 | % ENgetpatternindex(patId, patIndex); 21 | % ENsetpattern(patIndex, patFactors, 6); 22 | 23 | global ENDLLNAME; 24 | 25 | errcode=calllib(ENDLLNAME,'ENaddpattern',patid); 26 | if errcode ENerror(errcode); end 27 | -------------------------------------------------------------------------------- /EPANET/ENclose.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENclose() 2 | % Declaration: 3 | % [errcode]=ENclose() 4 | % 5 | % Description: 6 | % Closes down the Toolkit system (including all files being processed). 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % Notes: 12 | % ENclose must be called when all processing has been completed, 13 | % even if an error condition was encountered. 14 | % 15 | % See Also: 16 | % ENopen 17 | % 18 | global ENDLLNAME; 19 | 20 | 21 | [errcode]=calllib(ENDLLNAME,'ENclose'); 22 | if errcode ENerror(errcode); end 23 | 24 | -------------------------------------------------------------------------------- /EPANET/ENcloseH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENcloseH() 2 | % Declaration: 3 | % [errcode] = ENcloseH() 4 | % 5 | % Description: 6 | % Closes the hydraulic analysis system, freeing all allocated memory. 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % Notes: 12 | % Call ENcloseH after all hydraulics analyses have been made using 13 | % ENinitH - ENrunH - ENnextH. Do not call this function if ENsolveH is being used. 14 | % 15 | % See Also: 16 | % ENopenH, ENinitH, ENrunH, ENnextH 17 | % 18 | global ENDLLNAME; 19 | 20 | [errcode]=calllib(ENDLLNAME,'ENcloseH'); 21 | if errcode ENerror(errcode); end 22 | -------------------------------------------------------------------------------- /EPANET/ENcloseQ.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENcloseQ() 2 | % Declaration: 3 | % [errcode] = ENcloseQ( ) 4 | % 5 | % Description: 6 | % Closes the water quality analysis system, freeing all allocated memory. 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % Notes: 12 | % Call ENcloseQ after all water quality analyses have been made using the ENinitQ - ENrunQ - ENnextQ (or ENstepQ) sequence of function calls. Do not call this function if ENsolveQ is being used. 13 | % 14 | % See Also: 15 | % ENopenQ, ENinitQ, ENrunQ, ENstepQ, ENnextQ 16 | % 17 | global ENDLLNAME; 18 | 19 | [errcode]=calllib(ENDLLNAME,'ENcloseQ'); 20 | if errcode ENerror(errcode); end 21 | -------------------------------------------------------------------------------- /EPANET/ENerror.m: -------------------------------------------------------------------------------- 1 | function [e] = ENerror(errcode) 2 | % Declaration: 3 | % [e]=ENerror(errcode) 4 | % 5 | % Description: 6 | % Prints out the error message string associated with error number errcode 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % See Also: 12 | % ENgeterror 13 | 14 | 15 | global ENDLLNAME; 16 | 17 | errstring=char(32*ones(1,80)); 18 | errcode=int32(errcode); 19 | len=int32(80); 20 | [e,errstring] = calllib(ENDLLNAME,'ENgeterror',errcode,errstring,len); 21 | %errstring=get(ps,'Value'); 22 | disp(errstring); 23 | %if errcode>=100 error('Fatal EPANET Error'); end 24 | -------------------------------------------------------------------------------- /EPANET/ENgetalllinknodes.m: -------------------------------------------------------------------------------- 1 | function [errcode,from,to] = ENgetalllinknodes() 2 | % Declaration: 3 | % [errcode,from,to]=ENgetalllinknodes() 4 | % 5 | % Description: 6 | % Gets the node indices associated with all network links 7 | % 8 | % Returns: 9 | % Returns integer lists (from,to) of node indices, in link index order. 10 | % Returns an error code. 11 | % 12 | % Notes: 13 | % Not toolkit function written for matlab. Uses ENgetlinknodes 14 | % 15 | % See Also: 16 | % ENgetlinknodes 17 | % 18 | global ENDLLNAME; 19 | %global EN_CONSTANT; 20 | global EN_SIZE; 21 | 22 | fval1=int32(0); 23 | fval2=int32(0); 24 | p1=libpointer('int32Ptr',fval1); 25 | p2=libpointer('int32Ptr',fval2); 26 | i=int32(1); 27 | from=int32(zeros(EN_SIZE.nlinks,1)); 28 | to=int32(zeros(EN_SIZE.nlinks,1)); 29 | for i=1:EN_SIZE.nlinks 30 | [errcode]=calllib(ENDLLNAME,'ENgetlinknodes',i,p1,p2); 31 | if errcode ENerror(errcode); end 32 | from(i)=get(p1,'Value'); 33 | to(i)=get(p2,'Value'); 34 | end 35 | -------------------------------------------------------------------------------- /EPANET/ENgetcontrol.m: -------------------------------------------------------------------------------- 1 | function [errcode, ctype,lindex,setting,nindex,level] = ENgetcontrol(cindex) 2 | % Declaration: 3 | % [errcode, ctype,lindex,setting,nindex,level] = ENgetcontrol(cindex) 4 | % 5 | % Description: 6 | % Retrieves the parameters of a simple control statement. The index of the 7 | % control is specified in cindex and the remaining arguments return the 8 | % control's parameters. 9 | % 10 | %Arguments: 11 | % cindex: control statement index 12 | % ctype: control type code 13 | % lindex: index of link being controlled 14 | % setting: value of the control setting 15 | % nindex: index of controlling node 16 | % level: value of controlling water level or pressure for 17 | % level controls or of time of control action 18 | % (in seconds) for time-based controls 19 | % 20 | % Returns: 21 | % Returns an error code. 22 | % 23 | %Notes: 24 | % Controls are indexed starting from 1 in the order in which they 25 | % were entered into the [CONTROLS] section of the EPANET input file. 26 | % 27 | % Control type codes consist of the following: 28 | % - 0 (Low Level Control) applies when tank level or node pressure drops below specified level 29 | % - 1 (High Level Control) applies when tank level or node pressure rises above specified level 30 | % - 2 (Timer Control) applies at specific time into simulation 31 | % - 3 (Time-of-Day Control) applies at specific time of day 32 | % 33 | % For pipes, a setting of 0 means the pipe is closed and 1 means it is open. 34 | % For a pump, the setting contains the pump's speed, with 0 meaning the pump 35 | % is closed and 1 meaning it is open at its normal speed. 36 | % For a valve, the setting refers to the valve's pressure, flow, or loss 37 | % coefficient value, depending on valve type. 38 | % 39 | % For Timer or Time-of-Day controls the nindex parameter equals 0. 40 | % 41 | % See ENsetcontrol for an example of using this function. 42 | % 43 | %See Also: 44 | % ENsetcontrol 45 | % 46 | % Version 2.00.07 (August 2008) 47 | 48 | 49 | global ENDLLNAME; 50 | 51 | ctype=int32(0); 52 | lindex=int32(0); 53 | setting=single(0); 54 | nindex=int32(0); 55 | level=single(0); 56 | 57 | cindex=int32(cindex); 58 | 59 | pctype=libpointer('int32Ptr',ctype); 60 | plindex=libpointer('int32Ptr',lindex); 61 | psetting=libpointer('singlePtr',setting); 62 | pnindex=libpointer('int32Ptr',nindex); 63 | plevel=libpointer('singlePtr',level); 64 | 65 | [errcode]=calllib(ENDLLNAME,'ENgetcontrol',cindex,pctype,plindex,psetting,pnindex,plevel); 66 | if errcode ENerror(errcode); end 67 | 68 | ctype=get(pctype,'Value'); 69 | lindex=get(plindex,'Value'); 70 | setting=get(psetting,'Value'); 71 | nindex=get(pnindex,'Value'); 72 | level=get(plevel,'Value'); 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /EPANET/ENgetcount.m: -------------------------------------------------------------------------------- 1 | function [errcode, count] = ENgetcount(countcode) 2 | % Declaration: 3 | % [errcode, count] = ENgetcount(countcode) 4 | % 5 | % Description: 6 | % Retrieves the number of network components of a specified type. 7 | % 8 | %Arguments: 9 | % countcode: component code (see below) 10 | % count: number of countcode components in the network 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Component codes consist of the following: 17 | % 18 | % EN_NODECOUNT 0 Nodes 19 | % EN_TANKCOUNT 1 Reservoirs and tank nodes 20 | % EN_LINKCOUNT 2 Links 21 | % EN_PATCOUNT 3 Time patterns 22 | % EN_CURVECOUNT 4 Curves 23 | % EN_CONTROLCOUNT 5 Simple controls 24 | % 25 | % The number of junctions in a network equals the number of nodes minus 26 | % the number of tanks and reservoirs. 27 | % 28 | % There is no facility within the Toolkit to add to or delete from the 29 | % components described in the Input file. 30 | % 31 | %See Also: 32 | % ENsetcontrol 33 | % 34 | % Version 2.00.07 (August 2008) 35 | 36 | 37 | global ENDLLNAME; 38 | global EN_CONSTANT; 39 | 40 | count=int32(0); 41 | pcount=libpointer('int32Ptr',count); 42 | countcode=int32(countcode); 43 | [errcode]=calllib(ENDLLNAME,'ENgetcount',countcode,pcount); 44 | if errcode ENerror(errcode); end 45 | 46 | count=get(pcount,'Value'); 47 | 48 | -------------------------------------------------------------------------------- /EPANET/ENgeterror.m: -------------------------------------------------------------------------------- 1 | function [e, errmsg] = ENgeterror(errcode) 2 | % Declaration: 3 | % [errcode, errmsg] = ENgeterror( int errcode) 4 | % 5 | % Description: 6 | % Retrieves the text of the message associated with a particular error or warning code. 7 | % 8 | % Arguments: 9 | % errcode: error or warning code 10 | % errmsg: text of the error or warning message for errcode 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Version 2.00.07 (January 2001) 16 | global ENDLLNAME; 17 | global EN_CONSTANT; 18 | errmsg = char(32*ones(1,80)); 19 | len=int32(80); 20 | errcode=int32(errcode); 21 | [e,errmsg] = calllib(ENDLLNAME,'ENgeterror',errcode,errmsg,len); 22 | if e ENerror(e); end 23 | -------------------------------------------------------------------------------- /EPANET/ENgetflowunits.m: -------------------------------------------------------------------------------- 1 | function [errcode,unitscode] = ENgetflowunits() 2 | % Declaration: 3 | % [unitscode,errcode] = ENgetflowunits() 4 | % 5 | % Description: 6 | % Retrieves a code number indicating the units used to express all flow rates. 7 | % 8 | % Arguments: 9 | % unitscode: value of a flow units code number (see below). 10 | % 11 | % Returns: 12 | % Returns an error code. 13 | % 14 | % Notes: 15 | % Flow units codes are as follows: 16 | % 17 | % 0 = EN_CFS cubic feet per second 18 | % 1 = EN_GPM gallons per minute 19 | % 2 = EN_MGD million gallons per day 20 | % 3 = EN_IMGD Imperial mgd 21 | % 4 = EN_AFD acre-feet per day 22 | % 5 = EN_LPS liters per second 23 | % 6 = EN_LPM liters per minute 24 | % 7 = EN_MLD million liters per day 25 | % 8 = EN_CMH cubic meters per hour 26 | % 9 = EN_CMD cubic meters per day 27 | % 28 | % Flow units are specified in the [OPTIONS] section of the EPANET Input file. 29 | % 30 | % Flow units in liters or cubic meters implies that metric units are used for 31 | % all other quantities in addition to flow. Otherwise US units are employed. (See Units of Measurement). 32 | % 33 | % Version 2.00.07 (January 2001) 34 | 35 | global ENDLLNAME; 36 | unitscode=int32(0); 37 | %pu=libpointer('int32Ptr',unitscode); 38 | [errcode, unitscode]=calllib(ENDLLNAME,'ENgetflowunits',unitscode); 39 | if errcode ENerror(errcode); end 40 | %unitscode=get(pu,'Value'); 41 | -------------------------------------------------------------------------------- /EPANET/ENgetlinkid.m: -------------------------------------------------------------------------------- 1 | function [errcode,id] = ENgetlinkid(index) 2 | % Declaration: 3 | % [errcode,id] = ENgetlinkid(index) 4 | % 5 | % Description: 6 | % Retrieves the ID label of a link with a specified index. 7 | % 8 | % Arguments: 9 | % index: link index 10 | % id: ID label of link 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % The ID label string should be sized to hold at least 15 characters. 17 | % Node indexes are consecutive integers starting from 1. 18 | % 19 | % See Also: 20 | % ENgetlinkindex 21 | % 22 | % Version 2.00.07 (January 2001) 23 | 24 | global ENDLLNAME; 25 | %global EN_CONSTANT; 26 | id=char(32*ones(1,17)); 27 | index=int32(index); 28 | [errcode,id]=calllib(ENDLLNAME,'ENgetlinkid',index,id); 29 | if errcode ENerror(errcode); end 30 | %id=get(pid,'Value'); 31 | -------------------------------------------------------------------------------- /EPANET/ENgetlinkindex.m: -------------------------------------------------------------------------------- 1 | function [errcode,index] = ENgetlinkindex(id) 2 | % Declaration: 3 | % [errcode,index] = ENgetlinkindex( id ) 4 | % 5 | % Description: 6 | % Retrieves the index of a link with a specified ID. 7 | % 8 | %Arguments: 9 | % id: link ID label 10 | % index: link index 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Link indexes are consecutive integers starting from 1. 17 | % 18 | %See Also: 19 | % ENgetlinkid 20 | % 21 | % Version 2.00.07 (August 2001) 22 | global ENDLLNAME; 23 | %global EN_CONSTANT; 24 | index=int32(0); 25 | %pidx=libpointer('int32Ptr',index); 26 | [errcode,id,index]=calllib(ENDLLNAME,'ENgetlinkindex',id,index); 27 | if errcode ENerror(errcode); end 28 | %index=get(pidx,'Value'); 29 | -------------------------------------------------------------------------------- /EPANET/ENgetlinknodes.m: -------------------------------------------------------------------------------- 1 | function [errcode,from,to] = ENgetlinknodes(index) 2 | % Declaration: 3 | % [from,to,errcode] = ENusehydfile(index) 4 | % 5 | % Description: 6 | % Retrieves the indexes of the end nodes of a specified link. 7 | % 8 | %Arguments: 9 | % index: link index 10 | % fromnode: index of node at start of link 11 | % tonode: index of node at end of link 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Node and link indexes are consecutive integers starting from 1. 18 | % 19 | % The From and To nodes are as defined for the link in the EPANET input file. 20 | % The actual direction of flow in the link is not considered. 21 | % 22 | %See Also: 23 | % ENgetlinkindex 24 | % 25 | % Version 2.00.07 (August 2008) 26 | 27 | global ENDLLNAME; 28 | %global EN_CONSTANT; 29 | %global EN_SIZE; 30 | 31 | from=int32(0); 32 | to=int32(0); 33 | index=int32(index); 34 | %p1=libpointer('int32Ptr',from); 35 | %p2=libpointer('int32Ptr',to); 36 | [errcode,from,to]=calllib(ENDLLNAME,'ENgetlinknodes',index,from,to); 37 | if errcode ENerror(errcode); end 38 | %from=get(p1,'Value'); 39 | %to=get(p2,'Value'); 40 | -------------------------------------------------------------------------------- /EPANET/ENgetlinktype.m: -------------------------------------------------------------------------------- 1 | function [errcode, type] = ENgetlinktype(index) 2 | % Declaration: 3 | % [errcode, type] = ENgetlinktype(index) 4 | % 5 | % Description: 6 | % Retrieves the link-type code for a specific link. 7 | % 8 | % Arguments: 9 | % index: link index 10 | % typecode: link-type code (see below) 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Link indexes are consecutive integers starting from 1. 17 | % Link type codes consist of the following constants: 18 | % EN_CVPIPE 0 Pipe with Check Valve 19 | % EN_PIPE 1 Pipe 20 | % EN_PUMP 2 Pump 21 | % EN_PRV 3 Pressure Reducing Valve 22 | % EN_PSV 4 Pressure Sustaining Valve 23 | % EN_PBV 5 Pressure Breaker Valve 24 | % EN_FCV 6 Flow Control Valve 25 | % EN_TCV 7 Throttle Control Valve 26 | % EN_GPV 8 General Purpose Valve 27 | % 28 | %See Also: 29 | % ENgetlinkindex 30 | % 31 | % Version 2.00.07 (January 2001) 32 | 33 | global ENDLLNAME; 34 | type=int32(0); 35 | %p=libpointer('int32Ptr',type); 36 | index=int32(index); 37 | [errcode,type]=calllib(ENDLLNAME,'ENgetlinktype',index,type); 38 | if errcode ENerror(errcode); end 39 | %type=get(p,'Value'); 40 | -------------------------------------------------------------------------------- /EPANET/ENgetlinkvalue.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = ENgetlinkvalue(index, paramcode) 2 | % Declaration: 3 | % [errcode,value] = ENgetlinkvalue(index, paramcode) 4 | % 5 | % Description: 6 | % Retrieves the value of a specific link parameter. 7 | % 8 | %Arguments: 9 | % index: link index 10 | % paramcode: parameter code (see below) 11 | % value: parameter value 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Link indexes are consecutive integers starting from 1. 18 | % 19 | % Link parameter codes consist of the following constants: 20 | % EN_DIAMETER 0 Diameter 21 | % EN_LENGTH 1 Length 22 | % EN_ROUGHNESS 2 Roughness coeff. 23 | % EN_MINORLOSS 3 Minor loss coeff. 24 | % EN_INITSTATUS 4 Initial link status (0 = closed, 1 = open) 25 | % EN_INITSETTING 5 Roughness for pipes,initial speed for pumps,initial setting for valves 26 | % EN_KBULK 6 Bulk reaction coeff. 27 | % EN_KWALL 7 Wall reaction coeff. 28 | % EN_FLOW 8 Flow rate 29 | % EN_VELOCITY 9 Flow velocity 30 | % EN_HEADLOSS 10 Head loss 31 | % EN_STATUS 11 Actual link status (0 = closed, 1 = open) 32 | % EN_SETTING 12 Roughness for pipes, actual speed for pumps, actual setting for valves 33 | % EN_ENERGY 13 Energy expended in kwatts 34 | % 35 | % Parameters 8 - 13 (EN_FLOW through EN_ENERGY) are computed values. The others are design parameters. 36 | % 37 | % Flow rate is positive if the direction of flow is from the designated 38 | % start node of the link to its designated end node, and negative otherwise. 39 | % 40 | % Values are returned in units which depend on the units used for flow rate 41 | % in the EPANET input file (see Units of Measurement). 42 | % 43 | %See Also: 44 | % ENgetlinkindex 45 | % 46 | % Version 2.00.07 (August 2008) 47 | 48 | global ENDLLNAME; 49 | %global EN_CONSTANT; 50 | value=single(0); 51 | %pv=libpointer('singlePtr',value); 52 | index=int32(index); 53 | paramcode=int32(paramcode); 54 | [errcode,value]=calllib(ENDLLNAME,'ENgetlinkvalue',index, paramcode, value); 55 | if errcode ENerror(errcode); end 56 | %value=get(pv,'Value'); -------------------------------------------------------------------------------- /EPANET/ENgetnetsize.m: -------------------------------------------------------------------------------- 1 | function [nnodes,ntanks,nlinks,npats,ncurves,ncontrols,errcode] = ENgetnetsize() 2 | % Declaration: 3 | % [nnodes,ntanks,nlinks,npats,ncurves,ncontrols,errcode] = ENgetnetsize() 4 | % 5 | % PURPOSE: 6 | % Retreive number of network components 7 | % 8 | % NOTES: 9 | % Called by ENopen() 10 | % 11 | % OUTPUT: 12 | % nnodes number of network nodes 13 | % ntanks number of network tanks/reservoirs 14 | % nlinks number of network links 15 | % npats number of time patterns 16 | % ncurves number of curves 17 | % ncontrols number of simple controls 18 | % errcode epanet error code 19 | 20 | global ENDLLNAME; 21 | global EN_CONSTANT; 22 | 23 | nnodes=int32(0); 24 | p=libpointer('int32Ptr',nnodes); 25 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_NODECOUNT,p); 26 | if errcode ENerror(errcode); end 27 | nnodes=get(p,'Value'); 28 | 29 | ntanks=int32(0); 30 | p=libpointer('int32Ptr',ntanks); 31 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_TANKCOUNT,p); 32 | if errcode ENerror(errcode); end 33 | ntanks=get(p,'Value'); 34 | 35 | nlinks=int32(0); 36 | p=libpointer('int32Ptr',nlinks); 37 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_LINKCOUNT,p); 38 | if errcode ENerror(errcode); end 39 | nlinks=get(p,'Value'); 40 | 41 | npats=int32(0); 42 | p=libpointer('int32Ptr',npats); 43 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_PATCOUNT,p); 44 | if errcode ENerror(errcode); end 45 | npats=get(p,'Value'); 46 | 47 | ncurves=int32(0); 48 | p=libpointer('int32Ptr',ncurves); 49 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_CURVECOUNT,p); 50 | if errcode ENerror(errcode); end 51 | ncurves=get(p,'Value'); 52 | 53 | ncontrols=int32(0); 54 | p=libpointer('int32Ptr',ncontrols); 55 | [errcode]=calllib(ENDLLNAME,'ENgetcount',EN_CONSTANT.EN_CONTROLCOUNT,p); 56 | if errcode ENerror(errcode); end 57 | ncontrols=get(p,'Value'); 58 | -------------------------------------------------------------------------------- /EPANET/ENgetnodeid.m: -------------------------------------------------------------------------------- 1 | function [errcode,id] = ENgetnodeid(index) 2 | % Declaration: 3 | % [errcode,id] = ENgetnodeid(index) 4 | % 5 | % Description: 6 | % Retrieves the ID label of a node with a specified index. 7 | % 8 | % Arguments: 9 | % index: node index 10 | % id: ID label of node 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % The ID label string should be sized to hold at least 15 characters. 17 | % Node indexes are consecutive integers starting from 1. 18 | % 19 | % See Also: 20 | % ENgetnodeindex 21 | % 22 | % Version 2.00.07 (January 2001) 23 | 24 | global ENDLLNAME; 25 | %global EN_CONSTANT; 26 | id=char(32*ones(1,17)); 27 | index=int32(index); 28 | [errcode,id]=calllib(ENDLLNAME,'ENgetnodeid',index,id); 29 | if errcode ENerror(errcode); end 30 | %id=get(pid,'Value'); 31 | -------------------------------------------------------------------------------- /EPANET/ENgetnodeindex.m: -------------------------------------------------------------------------------- 1 | function [errcode,index] = ENgetnodeindex(id) 2 | % Declaration: 3 | % [errcode, index] = ENgetnodeindex(id) 4 | % 5 | % Description: 6 | % Retrieves the index of a node with a specified ID. 7 | % 8 | % Arguments: 9 | % id: node ID label 10 | % index: node index 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Node indexes are consecutive integers starting from 1. 17 | % 18 | % See Also: 19 | % ENgetnodeid 20 | % 21 | % Version 2.00.07 (January 2001) 22 | 23 | global ENDLLNAME; 24 | %global EN_CONSTANT; 25 | index=int32(0); 26 | %pidx=libpointer('int32Ptr',index); 27 | [errcode, id, index]=calllib(ENDLLNAME,'ENgetnodeindex',id,index); 28 | if errcode ENerror(errcode); end 29 | %index=get(pidx,'Value'); 30 | -------------------------------------------------------------------------------- /EPANET/ENgetnodetype.m: -------------------------------------------------------------------------------- 1 | function [errcode, type] = ENgetnodetype(index) 2 | % Declaration: 3 | % [errcode type] = ENgetnodetype( int index ) 4 | % 5 | % Description: 6 | % Retrieves the node-type code for a specific node. 7 | % 8 | % Arguments: 9 | % index: node index 10 | % typecode: node-type code (see below) 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Node indexes are consecutive integers starting from 1. 17 | % Node type codes consist of the following constants: 18 | % 19 | % EN_JUNCTION 0 Junction node 20 | % EN_RESERVOIR 1 Reservoir node 21 | % EN_TANK 2 Tank node 22 | % 23 | % Version 2.00.07 (January 2001) 24 | 25 | global ENDLLNAME; 26 | type=int32(0); 27 | p=libpointer('int32Ptr',type); 28 | index=int32(index); 29 | [errcode]=calllib(ENDLLNAME,'ENgetnodetype',index,p); 30 | if errcode ENerror(errcode); end 31 | type=get(p,'Value'); 32 | -------------------------------------------------------------------------------- /EPANET/ENgetnodevalue.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = ENgetnodevalue(index, paramcode) 2 | % Declaration: 3 | % [errcode, value] = ENgetnodevalue( int index, int paramcode ) 4 | % 5 | % Description: 6 | % Retrieves the value of a specific link parameter. 7 | % 8 | % Arguments: 9 | % index: node index 10 | % paramcode: parameter code (see below) 11 | % value: parameter value 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | % Notes: 17 | % Node indexes are consecutive integers starting from 1. 18 | % Node parameter codes consist of the following constants: 19 | % 20 | % EN_ELEVATION 0 Elevation 21 | % EN_BASEDEMAND 1 Base demand 22 | % EN_PATTERN 2 Demand pattern index 23 | % EN_EMITTER 3 Emitter coeff. 24 | % EN_INITQUAL 4 Initial quality 25 | % EN_SOURCEQUAL 5 Source quality 26 | % EN_SOURCEPAT 6 Source pattern index 27 | % EN_SOURCETYPE 7 Source type(See note below) 28 | % EN_TANKLEVEL 8 Initial water level in tank 29 | % EN_DEMAND 9 Actual demand 30 | % EN_HEAD 10 Hydraulic head 31 | % EN_PRESSURE 11 Pressure 32 | % EN_QUALITY 12 Actual quality 33 | % EN_SOURCEMASS 13 Mass flow rate per minute of a chemical source 34 | % 35 | % The following parameter codes apply only to storage tank nodes: 36 | % EN_INITVOLUME 14 Initial water volume 37 | % EN_MIXMODEL 15 Mixing model code (see below) 38 | % EN_MIXZONEVOL 16 Inlet/Outlet zone volume in a 2-compartment tank 39 | % EN_TANKDIAM 17 Tank diameter 40 | % EN_MINVOLUME 18 Minimum water volume 41 | % EN_VOLCURVE 19 Index of volume versus depth curve (0 if none assigned) 42 | % EN_MINLEVEL 20 Minimum water level 43 | % EN_MAXLEVEL 21 Maximum water level 44 | % EN_MIXFRACTION 22 Fraction of total volume occupied by the inlet/outlet zone in a 2-compartment tank 45 | % EN_TANK_KBULK 23 Bulk reaction rate coefficient 46 | % 47 | % Parameters 9 - 13 (EN_DEMAND through EN_SOURCEMASS) are computed values. The others are input design parameters. 48 | % 49 | % Source types are identified with the following constants: 50 | % 51 | % EN_CONCEN 0 52 | % EN_MASS 1 53 | % EN_SETPOINT 2 54 | % EN_FLOWPACED 3 55 | % See [SOURCES] for a description of these source types. 56 | % 57 | % The codes for the various tank mixing model choices are as follows: 58 | % 59 | % EN_MIX1 0 Single compartment, complete mix model 60 | % EN_MIX2 1 Two-compartment, complete mix model 61 | % EN_FIFO 2 Plug flow, first in, first out model 62 | % EN_LIFO 3 Stacked plug flow, last in, first out model 63 | % 64 | % Values are returned in units which depend on the units used for flow rate in the EPANET input file (see Units of Measurement). 65 | % 66 | % Version 2.00.12 (March 2008) 67 | 68 | global ENDLLNAME; 69 | value=single(0); 70 | %p=libpointer('singlePtr',value); 71 | index=int32(index); 72 | paramcode=int32(paramcode); 73 | [errcode, value]=calllib(ENDLLNAME,'ENgetnodevalue',index, paramcode, value); 74 | if errcode ENerror(errcode); end 75 | %value=get(p,'Value'); 76 | -------------------------------------------------------------------------------- /EPANET/ENgetoption.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = ENgetoption(optioncode) 2 | % Declaration: 3 | % [errcode, value] = ENgetoption(optioncode) 4 | % 5 | % Description: 6 | % Retrieves the value of a particular analysis option. 7 | % 8 | %Arguments: 9 | % optioncode: an option code (see below) 10 | % value: an option value 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Option codes consist of the following constants: 17 | % 18 | % EN_TRIALS 0 19 | % EN_ACCURACY 1 20 | % EN_TOLERANCE 2 21 | % EN_EMITEXPON 3 22 | % EN_DEMANDMULT 4 23 | % 24 | %See Also: 25 | % ENsetoption 26 | % 27 | % Version 2.00.07 (August 2008) 28 | 29 | 30 | global ENDLLNAME; 31 | global EN_CONSTANT; 32 | 33 | value=single(0); 34 | pvalue=libpointer('singlePtr',value); 35 | optioncode=int32(optioncode); 36 | [errcode]=calllib(ENDLLNAME,'ENgetoption',optioncode,pvalue); 37 | if errcode ENerror(errcode); end 38 | 39 | value=get(pvalue,'Value'); 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /EPANET/ENgetpatternid.m: -------------------------------------------------------------------------------- 1 | function [errcode, id] = ENgetpatternid(index) 2 | % Declaration: 3 | % [errcode, id] = ENgetpatternid(index) 4 | % 5 | % Description: 6 | % Retrieves the ID label of a particular time pattern. 7 | % 8 | %Arguments: 9 | % index: pattern index 10 | % id: ID label of pattern 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % The ID label string should be sized to hold at least 32 characters. 17 | % 18 | % Pattern indexes are consecutive integers starting from 1. 19 | % 20 | % 21 | %See Also: 22 | % 23 | % Version 2.00.07 (August 2008) 24 | 25 | global ENDLLNAME; 26 | 27 | %length of id name can be maximum MAXID = 31 28 | id=char(32*ones(1,31)); 29 | index=int32(index); 30 | [errcode,id]=calllib(ENDLLNAME,'ENgetpatternid',index,id); 31 | if errcode ENerror(errcode); end 32 | -------------------------------------------------------------------------------- /EPANET/ENgetpatternindex.m: -------------------------------------------------------------------------------- 1 | function [errcode, index] = ENgetpatternindex(id) 2 | % Declaration: 3 | % [errcode,index] = ENusehydfile( id ) 4 | % 5 | % Description: 6 | % Retrieves the index of a particular time pattern. 7 | % 8 | %Arguments: 9 | % id: pattern ID label 10 | % index: pattern index 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Pattern indexes are consecutive integers starting from 1. 17 | % 18 | %See Also: 19 | % 20 | % Version 2.00.07 (August 2008) 21 | 22 | 23 | global ENDLLNAME; 24 | %global EN_CONSTANT; 25 | index=int32(0); 26 | %pidx=libpointer('int32Ptr',index); 27 | %id = cstring(id); 28 | [errcode,id, index]=calllib(ENDLLNAME,'ENgetpatternindex',id,index); 29 | if errcode ENerror(errcode); end 30 | %index=get(pidx,'Value'); -------------------------------------------------------------------------------- /EPANET/ENgetpatternlen.m: -------------------------------------------------------------------------------- 1 | function [errcode, len] = ENgetpatternlen(index) 2 | % Declaration: 3 | % [errcode, len] = ENgetpatternlen(index) 4 | % 5 | % Description: 6 | % Retrieves the number of time periods in a specific time pattern. 7 | % 8 | % Arguments: 9 | % index: pattern index 10 | % len: number of time periods in the pattern 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Pattern indexes are consecutive integers starting from 1. 17 | % 18 | % Version 2.00.07 (January 2001) 19 | 20 | global ENDLLNAME; 21 | index=int32(index); 22 | len=int32(0); 23 | %p=libpointer('int32Ptr',len); 24 | [errcode,len]=calllib(ENDLLNAME,'ENgetpatternlen',index,len); 25 | if errcode ENerror(errcode); end 26 | %len=get(p,'Value'); 27 | -------------------------------------------------------------------------------- /EPANET/ENgetpatternvalue.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = ENgetpatternvalue(index, period) 2 | % Declaration: 3 | % [errcode,value] = ENgetpatternvalue(index, period) 4 | % 5 | % Description: 6 | % Retrieves the multiplier factor for a specific time period in a time pattern. 7 | % 8 | %Arguments: 9 | % index: time pattern index 10 | % period: period within time pattern 11 | % value: multiplier factor for the period 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Pattern indexes and periods are consecutive integers starting from 1. 18 | % 19 | %See Also: 20 | % ENgetpatternindex, ENgetpatternlen, ENsetpatternvalue 21 | 22 | % 23 | % Version 2.00.07 (August 2001) 24 | global ENDLLNAME; 25 | 26 | value=single(0); 27 | p=libpointer('singlePtr',value); 28 | index=int32(index); 29 | period=int32(period); 30 | [errcode]=calllib(ENDLLNAME,'ENgetpatternvalue',index, period, p); 31 | if errcode ENerror(errcode); end 32 | value=get(p,'Value'); 33 | -------------------------------------------------------------------------------- /EPANET/ENgetqualtype.m: -------------------------------------------------------------------------------- 1 | function [errcode,qualcode,tracenode] = ENgetqualtype() 2 | % Declaration: 3 | % [errcode,qualcode,tracenode] = ENgetqualtype( ) 4 | % 5 | % Description: 6 | % Retrieves the type of water quality analysis called for. 7 | % 8 | % Arguments: 9 | % qualcode: water quality analysis code (see below) 10 | % tracenode: index of node traced in a source tracing analysis 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Water quality analysis codes are as follows: 17 | % 18 | % EN_NONE 0 No quality analysis 19 | % EN_CHEM 1 Chemical analysis 20 | % EN_AGE 2 Water age analysis 21 | % EN_TRACE 3 Source tracing 22 | % EN_MULTIS 4 Multiple Species 23 | % The tracenode value will be 0 when qualcode is not EN_TRACE. 24 | % 25 | % See Also: 26 | % ENsetqualtype 27 | % 28 | % Version 2.00.07 (January 2001) 29 | 30 | global ENDLLNAME; 31 | %global EN_CONSTANT; 32 | qualcode=int32(0); 33 | tracenode=int32(0); 34 | %pcode=libpointer('int32Ptr',qualcode); 35 | %pnode=libpointer('int32Ptr',tracenode); 36 | [errcode,qualcode,tracenode]=calllib(ENDLLNAME,'ENgetqualtype',qualcode,tracenode); 37 | if errcode ENerror(errcode); end 38 | %qualcode=get(pcode,'Value'); 39 | %tracenode=get(pnode,'Value'); 40 | -------------------------------------------------------------------------------- /EPANET/ENgettimeparam.m: -------------------------------------------------------------------------------- 1 | function [errcode, timevalue] = ENgettimeparam(paramcode) 2 | % Declaration: 3 | % [errcode,timevalue] = ENgettimeparam( paramcode ) 4 | % 5 | % Description: 6 | % Retrieves the value of a specific analysis time parameter. 7 | % 8 | % Arguments: 9 | % paramcode: time parameter code (see below) 10 | % timevalue: value of time parameter in seconds 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Time parameter codes consist of the following constants: 17 | % 18 | % EN_DURATION 0 Simulation duration 19 | % EN_HYDSTEP 1 Hydraulic time step 20 | % EN_QUALSTEP 2 Water quality time step 21 | % EN_PATTERNSTEP 3 Time pattern time step 22 | % EN_PATTERNSTART 4 Time pattern start time 23 | % EN_REPORTSTEP 5 Reporting time step 24 | % EN_REPORTSTART 6 Report starting time 25 | % EN_RULESTEP 7 Time step for evaluating rule-based controls 26 | % EN_STATISTIC 8 Type of time series post-processing used:0 = none1 = averaged2 = minimums3 = maximums4 = ranges 27 | % EN_PERIODS 9 Number of reporting periods saved to binary output file 28 | % 29 | % Version 2.00.07 (January 2001) 30 | 31 | global ENDLLNAME; 32 | %global EN_CONSTANT; 33 | timevalue=int32(0); 34 | %p=libpointer('int32Ptr',timevalue); 35 | paramcode=int32(paramcode); 36 | [errcode,timevalue]=calllib(ENDLLNAME,'ENgettimeparam',paramcode,timevalue); 37 | if errcode ENerror(errcode); end 38 | %timevalue=get(p,'Value'); 39 | -------------------------------------------------------------------------------- /EPANET/ENgetversion.m: -------------------------------------------------------------------------------- 1 | function [errcode, version] = ENgetversion() 2 | % Declaration: 3 | % [errcode version] = ENgetversion( ) 4 | % 5 | % Description: 6 | % Retrieves the EPANET code version 7 | % 8 | % Arguments: 9 | % version: The EPANET code version 10 | % 11 | % Returns: 12 | % Returns an error code. 13 | % 14 | 15 | global ENDLLNAME; 16 | version=int32(0); 17 | %p=libpointer('int32Ptr',version); 18 | [errcode,version]=calllib(ENDLLNAME,'ENgetversion',version); 19 | if errcode ENerror(errcode); end 20 | %version=get(p,'Value'); 21 | -------------------------------------------------------------------------------- /EPANET/ENinitH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENinitH(flag) 2 | % Declaration: 3 | % [errcode] = ENinitH( flag ) 4 | % 5 | % Description: 6 | % Initializes storage tank levels, link status and settings, 7 | % and the simulation clock time prior to running a hydraulic analysis. 8 | % 9 | %Arguments: 10 | % saveflag: 0-1 flag indicating if hydraulic results 11 | % will be saved to the hydraulics file. 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Call ENinitH prior to running a hydraulic analysis using ENrunH and ENnextH. 18 | % 19 | % ENopenH must have been called prior to calling ENinitH. 20 | % 21 | % Do not call ENinitH if a complete hydraulic analysis is being made with a call to ENsolveH. 22 | % 23 | % Set saveflag to 1 if you will be making a subsequent water quality run, 24 | % using ENreport to generate a report, or using ENsavehydfile to save the binary hydraulics file. 25 | % 26 | %See Also: 27 | % ENopenH, ENrunH, ENnextH, ENcloseH 28 | % 29 | % Version 2.00.07 (August 2008) 30 | 31 | global ENDLLNAME; 32 | flag=int32(flag); 33 | [errcode]=calllib(ENDLLNAME,'ENinitH',flag); 34 | if errcode ENerror(errcode); end 35 | -------------------------------------------------------------------------------- /EPANET/ENinitQ.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENinitQ(saveflag) 2 | % Declaration: 3 | % [errcode] = ENinitQ( saveflag ) 4 | % 5 | % Description: 6 | % Initializes water quality and the simulation clock time prior to running 7 | % a water quality analysis. 8 | % 9 | %Arguments: 10 | % saveflag: 0-1 flag indicating if analysis results should be saved to EPANET's binary 11 | % output file at uniform reporting periods. 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Call ENinitQ prior to running a water quality analysis using ENrunQ 18 | % in conjunction with either ENnextQ or ENstepQ. 19 | % 20 | % ENopenQ must have been called prior to calling ENinitQ. 21 | % 22 | % Do not call ENinitQ if a complete water quality analysis is being made with a call to ENsolveQ. 23 | % 24 | % Set saveflag to 1 if you intend to use ENreport to generate a report or wish to save computed results to the binary output file. 25 | % 26 | %See Also: 27 | % ENopenQ, ENrunQ, ENnextQ, ENstepQ, ENcloseQ 28 | % 29 | % Version 2.00.07 (August 2008) 30 | global ENDLLNAME; 31 | saveflag=int32(saveflag); 32 | [errcode]=calllib(ENDLLNAME,'ENinitQ',saveflag); 33 | if errcode ENerror(errcode); end 34 | -------------------------------------------------------------------------------- /EPANET/ENnextH.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/EPANET/ENnextH.m -------------------------------------------------------------------------------- /EPANET/ENnextQ.m: -------------------------------------------------------------------------------- 1 | function [errcode, tstep] = ENnextQ() 2 | % Declaration: 3 | % [errcode, tstep] = ENnextQ( ) 4 | % 5 | % Description: 6 | % Advances the water quality simulation to the start of the next hydraulic 7 | % time period. 8 | % 9 | % Arguments: 10 | % tstep: time (in seconds) until next hydraulic event occurs or 0 if at 11 | % the end of the simulation period. 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | % Notes: 17 | % This function is used in a do-while loop with ENrunQ to perform an 18 | % extended period water quality analysis. It allows you to access water 19 | % quality results at each hydraulic period of the simulation. The water 20 | % quality routing and reactions are carried out internally at a much 21 | % smaller time step. Use ENstepQ instead of this function if you need 22 | % to access results after each water quality time step. 23 | % The value of tstep is determined from information saved with the hydraulic 24 | % analysis that preceded the water quality analysis. Treat it as a 25 | % read-only variable. 26 | % 27 | % Example: 28 | % 29 | % long t, tstep; 30 | % ENsolveH(); /* Generate & save hydraulics */ 31 | % ENopenQ(); 32 | % ENinitQ(0); 33 | % do 34 | % { 35 | % ENrunQ(&t); 36 | % /* 37 | % Monitor results at time t, which 38 | % begins a new hydraulic time period 39 | % */ 40 | % ENnextQ(&tstep); 41 | % } while (tstep > 0) 42 | % ENcloseQ(); 43 | % 44 | % See Also: 45 | % ENopenQ, ENinitQ, ENrunQ, ENcloseQ 46 | % 47 | % Version 2.00.07 (January 2001) 48 | 49 | global ENDLLNAME; 50 | tstep=int32(0); 51 | %p=libpointer('int32Ptr',tstep); 52 | [errcode,tstep]=calllib(ENDLLNAME,'ENnextQ',tstep); 53 | if errcode ENerror(errcode); end 54 | %tstep=get(p,'Value'); 55 | tstep = double(tstep); 56 | 57 | -------------------------------------------------------------------------------- /EPANET/ENopen.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENopen(inpname,repname,binname) 2 | % Declaration: 3 | % [errcode] = ENopen( inpname, repname, binname ) 4 | % 5 | % Description: 6 | % Opens the Toolkit to analyze a particular distribution system. 7 | % Defines global structure EN_SIZE. 8 | % 9 | % Arguments: 10 | % inpname: name of an EPANET Input file 11 | % repname: name of an output Report file 12 | % binname: name of an optional binary Output file. 13 | % 14 | % Returns: 15 | % Returns an error code. 16 | % EN_SIZE is a global structure that contains the network size: nnodes, 17 | % ntanks, nlinks, npats, ncurves, ncontrols. This structure is defined for 18 | % convenience. 19 | % 20 | % Notes: 21 | % If there is no need to save EPANET's binary Output file then f3 can be an empty string (""). 22 | % If f2 is an empty string, then reporting will be made to the operating system's stdout device (which is usually the console). 23 | % ENopen must be called before any of the other toolkit functions (except ENepanet) are used. 24 | % 25 | % See Also: 26 | % ENclose 27 | % 28 | % Version 2.00.07 (January 2001) 29 | 30 | global ENDLLNAME; 31 | %global EN_CONSTANT; 32 | global EN_SIZE; 33 | 34 | errcode=calllib(ENDLLNAME,'ENopen',inpname,repname,binname); 35 | if errcode ENerror(errcode); end 36 | 37 | [nnodes,ntanks,nlinks,npats,ncurves,ncontrols,errcode] = ENgetnetsize(); 38 | if errcode ENerror(errcode); end 39 | 40 | EN_SIZE = struct(... 41 | 'nnodes', nnodes,... 42 | 'ntanks', ntanks,... 43 | 'nlinks', nlinks,... 44 | 'npats', npats,... 45 | 'ncurves',ncurves,... 46 | 'ncontrols',ncontrols); 47 | -------------------------------------------------------------------------------- /EPANET/ENopenH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENopenH() 2 | % Declaration: 3 | % [errcode] = ENopenH( void ) 4 | % 5 | % Description: 6 | % Opens the hydraulics analysis system. 7 | % 8 | %Arguments: 9 | % 10 | % Returns: 11 | % Returns an error code. 12 | % 13 | %Notes: 14 | % Call ENopenH prior to running the first hydraulic analysis using the 15 | % ENinitH - ENrunH - ENnextH sequence. Multiple analyses can be made before 16 | % calling ENcloseH to close the hydraulic analysis system. 17 | % 18 | % Do not call this function if ENsolveH is being used to run a complete hydraulic analysis. 19 | % 20 | %See Also: 21 | % ENinitH, ENrunH, ENnextH, ENcloseH 22 | % 23 | % Version 2.00.07 (August 2008) 24 | 25 | global ENDLLNAME; 26 | [errcode]=calllib(ENDLLNAME,'ENopenH'); 27 | if errcode ENerror(errcode); end 28 | -------------------------------------------------------------------------------- /EPANET/ENopenQ.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENopenQ() 2 | % Declaration: 3 | % [errcode] = ENopenQ( void ) 4 | % 5 | % Description: 6 | % Opens the water quality analysis system. 7 | % 8 | %Arguments: 9 | % 10 | % Returns: 11 | % Returns an error code. 12 | % 13 | %Notes: 14 | % Call ENopenQ prior to running the first water quality analysis using an 15 | % ENinitQ - ENrunQ - ENnextQ (or ENstepQ) sequence. Multiple water quality 16 | % analyses can be made before calling ENcloseQ to close the water quality analysis system. 17 | % 18 | % Do not call this function if a complete water quality analysis is being made using ENsolveQ. 19 | % 20 | %See Also: 21 | % ENintQ, ENrunQ, ENnextQ, ENstepQ, ENcloseQ 22 | % 23 | % Version 2.00.07 (August 2008) 24 | 25 | global ENDLLNAME; 26 | [errcode]=calllib(ENDLLNAME,'ENopenQ'); 27 | if errcode ENerror(errcode); end 28 | -------------------------------------------------------------------------------- /EPANET/ENreport.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENreport () 2 | % Declaration: 3 | % [errcode] = ENreport (void) 4 | % 5 | % Description: 6 | % Writes a formatted text report on simulation results to the Report file. 7 | % 8 | %Arguments: 9 | % 10 | % Returns: 11 | % Returns an error code. 12 | % 13 | %Notes: 14 | % Either a full hydraulic analysis or full hydraulic and water quality 15 | % analysis must have been run, with results saved to file, before ENreport 16 | % is called. In the former case, ENsaveH must also be called first to transfer 17 | % results from the Hydraulics file to the Output file. 18 | % 19 | % The format of the report is controlled by commands placed in 20 | % the [REPORT] section of the EPANET input file or by similar 21 | % commands issued with the ENsetreport function. 22 | % 23 | % 24 | %See Also: 25 | % 26 | % 27 | % Version 2.00.07 (August 2008) 28 | 29 | global ENDLLNAME; 30 | 31 | [errcode]=calllib(ENDLLNAME,'ENreport'); 32 | if errcode ENerror(errcode); end 33 | -------------------------------------------------------------------------------- /EPANET/ENresetreport.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENresetreport() 2 | % Declaration: 3 | % [errcode] = ENresetreport( void ) 4 | % 5 | % Description: 6 | % Clears any report formatting commands that either appeared 7 | % in the [REPORT] section of the EPANET Input file or were 8 | % issued with the ENsetreport function. 9 | % 10 | %Arguments: 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % After calling this function the default reporting options are in effect. These are: 17 | % -No status report 18 | % -No energy report 19 | % -No nodes reported on 20 | % -No links reported on 21 | % -Node variables reported to 2 decimal places 22 | % -Link variables reported to 2 decimal places (3 for friction factor) 23 | % -Node variables reported are elevation, head, pressure, and quality 24 | % -Link variables reported are flow, velocity, and head loss 25 | % 26 | %See Also: 27 | % ENreport, ENsetreport, ENsetstatusreport 28 | % 29 | % Version 2.00.07 (August 2008) 30 | 31 | global ENDLLNAME; 32 | 33 | [errcode]=calllib(ENDLLNAME,'ENresetreport'); 34 | if errcode ENerror(errcode); end 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /EPANET/ENrunH.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/EPANET/ENrunH.m -------------------------------------------------------------------------------- /EPANET/ENrunQ.m: -------------------------------------------------------------------------------- 1 | function [errcode, t] = ENrunQ() 2 | % Declaration: 3 | % [errcode,t] = ENrunQ( void ) 4 | % 5 | % Description: 6 | % Advances the water quality simulation to the start of the next hydraulic 7 | % time period. 8 | % 9 | %Arguments: 10 | % 11 | % Returns: 12 | % Returns an error code. 13 | % 14 | %Notes: 15 | % This function is used in a do-while loop with ENrunQ to perform an 16 | % extended period water quality analysis. It allows you to access water 17 | % quality results at each hydraulic period of the simulation. The water 18 | % quality routing and reactions are carried out internally at a much 19 | % smaller time step. Use ENstepQ instead of this function if you need 20 | % to access results after each water quality time step. 21 | % 22 | % The value of tstep is determined from information saved with the 23 | % hydraulic analysis that preceded the water quality analysis. 24 | % Treat it as a read-only variable. 25 | % 26 | %Example: 27 | % long t, tstep; 28 | % ENsolveH(); /* Generate & save hydraulics */ 29 | % ENopenQ(); 30 | % ENinitQ(0); 31 | % do { 32 | % ENrunQ(&t); 33 | % /* Monitor results at time t, which */ 34 | % /* begins a new hydraulic time period */ 35 | % ENnextQ(&tstep); 36 | % } while (tstep > 0); 37 | % ENcloseQ(); 38 | % 39 | %See Also: 40 | % ENopenQ, ENinitQ, ENrunQ, ENcloseQ 41 | % 42 | % Version 2.00.07 (August 2008) 43 | 44 | global ENDLLNAME; 45 | t=int32(0); 46 | %p=libpointer('int32Ptr',t); 47 | [errcode,t]=calllib(ENDLLNAME,'ENrunQ',t); 48 | if errcode ENerror(errcode); end 49 | %t=get(p,'Value'); 50 | t = double(t); 51 | -------------------------------------------------------------------------------- /EPANET/ENsaveH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsaveH() 2 | % Declaration: 3 | % [errcode] = ENsaveH( void ) 4 | % 5 | % Description: 6 | % Transfers results of a hydraulic simulation from the binary Hydraulics 7 | % file to the binary Output file, where results are only reported at 8 | % uniform reporting intervals. 9 | % 10 | % Returns: 11 | % Returns an error code. 12 | % 13 | % Notes: 14 | % ENsaveH is used when only a hydraulic analysis is run and results at 15 | % uniform reporting intervals need to be transferred to EPANET's binary 16 | % output file. Such would be the case when an output report to EPANET's 17 | % report file will be written using ENreport. 18 | % 19 | % The reporting times can be set either in the EPANET input file 20 | % (in its [TIMES] section) or by using the ENsettimeparam function. 21 | % 22 | % See Also: 23 | % ENreport, ENsettimeparam 24 | % 25 | % Version 2.00.07 (August 2008) 26 | 27 | global ENDLLNAME; 28 | 29 | [errcode]=calllib(ENDLLNAME,'ENsaveH'); 30 | if errcode ENerror(errcode); end -------------------------------------------------------------------------------- /EPANET/ENsavehydfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsavehydfile(fname) 2 | %Declaration: 3 | % [errcode] = ENsavehydfile(fname) 4 | % 5 | %Description: 6 | % Saves the current contents of the binary hydraulics file to a file. 7 | % 8 | %Arguments: 9 | % fname:name of the file where the hydraulics results should be saved. 10 | % 11 | %Returns: 12 | % Returns an error code. 13 | % 14 | %Notes: 15 | % Use this function to save the current set of hydraulics results to a file, 16 | % either for post-processing or to be used at a later time by calling the 17 | % ENusehydfile function. 18 | % The hydraulics file contains nodal demands and heads and link flows, 19 | % status, and settings for all hydraulic time steps, even intermediate ones. 20 | % Before calling this function hydraulic results must have been generated 21 | % and saved by having called ENsolveH or the ENinitH - ENrunH - ENnextH 22 | % sequence with the saveflag parameter of ENinitH set to 1. 23 | % 24 | %See Also: 25 | % ENusehydfile, ENsolveH, ENinitH 26 | % 27 | % Version 2.00.07 (August 2008) 28 | 29 | 30 | global ENDLLNAME; 31 | 32 | [errcode]=calllib(ENDLLNAME,'ENsavehydfile',fname); 33 | if errcode ENerror(errcode); end -------------------------------------------------------------------------------- /EPANET/ENsaveinpfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsaveinpfile(inpname) 2 | % Declaration: 3 | % [errcode] = ENsaveinpfile(inpname) 4 | % 5 | % Description: 6 | % 7 | % Writes all current network input data to a file using the format of an EPANET input file. 8 | % 9 | % Arguments: 10 | % 11 | % fname: name of the file where data is saved. 12 | % Returns: 13 | % 14 | % Returns an error code. 15 | % 16 | % Notes: 17 | % 18 | % The data saved reflect any changes made by calls to the ENsetxxx family of 19 | % functions since EPANET data was first loaded using ENopen. 20 | % 21 | global ENDLLNAME; 22 | %global EN_CONSTANT; 23 | errcode=calllib(ENDLLNAME,'ENsaveinpfile',inpname); 24 | if errcode ENerror(errcode); end 25 | -------------------------------------------------------------------------------- /EPANET/ENsetcontrol.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetcontrol(cindex,ctype,lindex,setting,nindex,level) 2 | % Declaration: 3 | % [errcode] = ENsetcontrol(cindex,ctype,lindex,setting,nindex,level) 4 | % 5 | % Description: 6 | % Sets the parameters of a simple control statement. 7 | % 8 | %Arguments: 9 | % cindex: control statement index 10 | % ctype: control type code 11 | % lindex: index of link being controlled 12 | % setting: value of the control setting 13 | % nindex: index of controlling node 14 | % level: value of controlling water level or pressure for 15 | % level controls or of time of control action 16 | % (in seconds) for time-based controls 17 | % 18 | % Returns: 19 | % Returns an error code. 20 | % 21 | %Notes: 22 | % Controls are indexed starting from 1 in the order in which they were 23 | % entered into the [CONTROLS] section of the EPANET input file. 24 | % 25 | % Control type codes consist of the following: 26 | % EN_LOWLEVEL 0 Control applied when tank level or node pressure drops below specified level 27 | % EN_HILEVEL 1 Control applied when tank level or node pressure rises above specified level 28 | % EN_TIMER 2 Control applied at specific time into simulation 29 | % EN_TIMEOFDAY 3 Control applied at specific time of day 30 | % 31 | % For pipes, a setting of 0 means the pipe is closed and 1 means it is open. 32 | % For a pump, the setting contains the pump's speed, with 0 meaning the pump 33 | % is closed and 1 meaning it is open at its normal speed. 34 | % For a valve, the setting refers to the valve's pressure, flow, or 35 | % loss coefficient, depending on valve type. 36 | % 37 | % For Timer or Time-of-Day controls set the nindex parameter to 0. 38 | % For level controls, if the controlling node nindex is a tank then 39 | % the level parameter should be a water level above the tank bottom 40 | % (not an elevation). Otherwise level should be a junction pressure. 41 | % 42 | % To remove a control on a particular link, set the lindex parameter to 0. 43 | % Values for the other parameters in the function will be ignored. 44 | % 45 | % Example: 46 | % This example uses ENgetcontrol and ENsetcontrol to change the low level 47 | % setting on the node that controls a link with index thelink to a new value newlevel. 48 | % 49 | % [errcode, numctrls] = ENgetcount(EN_CONTROLS) 50 | % for (i=1:1:numctrls) 51 | % [errcode, ctype,lindex,setting,nindex,level] = ENgetcontrol(i) 52 | % if (ctype == EN_LOWLEVEL && lindex == 1) 53 | % [errcode] = ENsetcontrol(i,ctype,lindex,setting,nindex,level) 54 | % end; 55 | % end; 56 | % 57 | %See Also: 58 | % ENgetcontrol 59 | % 60 | % Version 2.00.07 (August 2008) 61 | 62 | 63 | global ENDLLNAME; 64 | global EN_CONSTANT; 65 | 66 | ctype=int32(ctype); 67 | lindex=int32(lindex); 68 | setting=single(setting); 69 | nindex=int32(nindex); 70 | level=single(level); 71 | 72 | [errcode]=calllib(ENDLLNAME,'ENsetcontrol',cindex,ctype,lindex,setting,nindex,level); 73 | if errcode ENerror(errcode); end 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /EPANET/ENsetlinkvalue.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetlinkvalue(index, paramcode, value) 2 | % Declaration: 3 | % [errcode] = ENsetlinkvalue(index, paramcode, value) 4 | % 5 | % Description: 6 | % Sets the value of a parameter for a specific link. 7 | % 8 | %Arguments: 9 | % index: link index 10 | % paramcode: parameter code (see below) 11 | % value: parameter value 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Link indexes are consecutive integers starting from 1. 18 | % Link parameter codes consist of the following constants: 19 | % EN_DIAMETER 0 Diameter 20 | % EN_LENGTH 1 Length 21 | % EN_ROUGHNESS 2 Roughness coeff. 22 | % EN_MINORLOSS 3 Minor loss coeff. 23 | % EN_INITSTATUS 4 Initial link status (0 = closed, 1 = open) 24 | % EN_INITSETTING 5 Roughness for pipes, initial speed for pumps, initial setting for valves 25 | % EN_KBULK 6 Bulk reaction coeff. 26 | % EN_KWALL 7 Wall reaction coeff. 27 | % EN_STATUS 11 Current pump or valve status (0 = closed, 1 = open) 28 | % EN_SETTING 12 Roughness for pipes, current speed for pumps, current setting for valves 29 | % 30 | % Values are supplied in units which depend on the units used for flow rate 31 | % in the EPANET input file (see Units of Measurement). 32 | % 33 | % Use EN_INITSTATUS and EN_INITSETTING to set the design value for a 34 | % link's status or setting that exists prior to the start of a simulation. 35 | % Use EN_STATUS and EN_SETTING to change these values while a simulation is 36 | % being run (within the ENrunH - ENnextH loop). 37 | % 38 | % If a control valve has its status explicitly set to OPEN or CLOSED, 39 | % then to make it active again during a simulation you must provide a 40 | % new valve setting value using the EN_SETTING parameter. 41 | % 42 | % For pipes, either EN_ROUGHNESS or EN_INITSETTING can be used to change roughness. 43 | % 44 | %See Also: 45 | % 46 | 47 | % Version 2.00.07 (August 2008) 48 | 49 | global ENDLLNAME; 50 | %global EN_CONSTANT; 51 | index=int32(index); 52 | paramcode=int32(paramcode); 53 | value=single(value); 54 | [errcode]=calllib(ENDLLNAME,'ENsetlinkvalue',index, paramcode, value); 55 | if errcode ENerror(errcode); end 56 | -------------------------------------------------------------------------------- /EPANET/ENsetnodevalue.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetnodevalue(index, paramcode, value) 2 | % Declaration: 3 | % [errcode] = ENsetnodevalue(index, paramcode, value) 4 | % 5 | % Description: 6 | % Sets the value of a parameter for a specific node. 7 | % 8 | % Arguments: 9 | % index: node index 10 | % paramcode: parameter code (see below) 11 | % value: parameter value 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | % Notes: 17 | % Node indexes are consecutive integers starting from 1. 18 | % Node parameter codes consist of the following constants: 19 | % 20 | % EN_ELEVATION 0 Elevation 21 | % EN_BASEDEMAND 1 Baseline demand 22 | % EN_PATTERN 2 Time pattern index 23 | % EN_EMITTER 3 Emitter coefficient 24 | % EN_INITQUAL 4 Initial quality 25 | % EN_SOURCEQUAL 5 Source quality 26 | % EN_SOURCEPAT 6 Source pattern 27 | % EN_SOURCETYPE 7 Source type:(See note below) 28 | % EN_TANKLEVEL 8 Initial water level in tank 29 | % Source types are identified with the following constants: 30 | % 31 | % EN_CONCEN 0 32 | % EN_MASS 1 33 | % EN_SETPOINT 2 34 | % EN_FLOWPACED 3 35 | % See [SOURCES] for a description of these source types. 36 | % 37 | % Values are supplied in units which depend on the units used for flow rate in the EPANET input file (see Units of Measurement). 38 | % 39 | % Version 2.00.07 (January 2001) 40 | 41 | global ENDLLNAME; 42 | %global EN_CONSTANT; 43 | index=int32(index); 44 | paramcode=int32(paramcode); 45 | value=single(value); 46 | [errcode]=calllib(ENDLLNAME,'ENsetnodevalue',index, paramcode, value); 47 | if errcode ENerror(errcode); end 48 | -------------------------------------------------------------------------------- /EPANET/ENsetoption.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetoption(optioncode,value) 2 | % Declaration: 3 | % [errcode] = ENsetoption(optioncode,value) 4 | % 5 | % Description: 6 | % Sets the value of a particular analysis option. 7 | % 8 | %Arguments: 9 | % optioncode: an option code (see below) 10 | % value: an option value 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Option codes consist of the following constants: 17 | % 18 | % EN_TRIALS 0 19 | % EN_ACCURACY 1 20 | % EN_TOLERANCE 2 21 | % EN_EMITEXPON 3 22 | % EN_DEMANDMULT 4 23 | % 24 | %See Also: 25 | % ENgetoption 26 | % 27 | % Version 2.00.07 (August 2008) 28 | 29 | 30 | global ENDLLNAME; 31 | global EN_CONSTANT; 32 | 33 | optioncode=int32(optioncode); 34 | value=single(value); 35 | 36 | [errcode]=calllib(ENDLLNAME,'ENsetoption',optioncode,value); 37 | if errcode ENerror(errcode); end 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /EPANET/ENsetpattern.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetpattern(index, factors, nfactors) 2 | % Declaration: 3 | % [errcode] = ENsetpattern(index, factors, nfactors) 4 | % 5 | % Description: 6 | % Sets all of the multiplier factors for a specific time pattern. 7 | % 8 | %Arguments: 9 | % index: time pattern index 10 | % factors: multiplier factors for the entire pattern 11 | % nfactors: number of factors in the pattern 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Pattern indexes are consecutive integers starting from 1. 18 | % 19 | % factors points to a zero-based array that contains nfactors elements. 20 | % 21 | % Use this function to redefine (and resize) a time pattern all at once; 22 | % use ENsetpatternvalue to revise pattern factors in specific time periods of a pattern. 23 | % 24 | %See Also: 25 | % ENgetpatternindex, ENgetpatternlen, ENgetpatternvalue, 26 | % ENsetpatternvalue, ENaddpattern 27 | % 28 | % Version 2.00.07 (August 2008) 29 | 30 | global ENDLLNAME; 31 | index=int32(index); 32 | nfactors=int32(nfactors); 33 | p=libpointer('singlePtr',factors); 34 | [errcode]=calllib(ENDLLNAME,'ENsetpattern',index,p,nfactors); 35 | if errcode ENerror(errcode); end 36 | -------------------------------------------------------------------------------- /EPANET/ENsetpatternvalue.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetpatternvalue(index, period, value) 2 | % Declaration: 3 | % [errcode] = ENsetpatternvalue(index, period, value) 4 | % 5 | % Description: 6 | % Sets the multiplier factor for a specific period within a time pattern. 7 | % 8 | %Arguments: 9 | % index: time pattern index 10 | % period: period within time pattern 11 | % value: multiplier factor for the period 12 | % 13 | % Returns: 14 | % Returns an error code. 15 | % 16 | %Notes: 17 | % Pattern indexes are consecutive integers starting from 1. 18 | % 19 | % Use ENsetpattern to reset all of the factors in a time pattern. 20 | % 21 | %See Also: 22 | % ENgetpatternindex, ENgetpatternlen, ENgetpatternvalue, ENsetpattern 23 | % 24 | % Version 2.00.07 (August 2008) 25 | 26 | global ENDLLNAME; 27 | index=int32(index); 28 | period=int32(period); 29 | value=single(value); 30 | [errcode]=calllib(ENDLLNAME,'ENsetpatternvalue',index, period, value); 31 | if errcode ENerror(errcode); end 32 | -------------------------------------------------------------------------------- /EPANET/ENsetqualtype.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetqualtype(qualcode,chemname,chemunits,tracenode) 2 | % Declaration: 3 | % [errcode] = ENsetqualtype(qualcode,chemname,chemunits,tracenode) 4 | % 5 | % Description: 6 | % Sets the type of water quality analysis called for. 7 | % 8 | % Arguments: 9 | % qualcode: water quality analysis code (see below) 10 | % chemname: name of the chemical being analyzed 11 | % chemunits: units that the chemical is measured in 12 | % tracenode: ID of node traced in a source tracing analysis 13 | % 14 | % Returns: 15 | % Returns an error code. 16 | % 17 | % Notes: 18 | % Water quality analysis codes are as follows: 19 | % 20 | % EN_NONE 0 No quality analysis 21 | % EN_CHEM 1 Chemical analysis 22 | % EN_AGE 2 Water age analysis 23 | % EN_TRACE 3 Source tracing 24 | % Chemical name and units can be an empty string if the analysis is not for a chemical. The same holds for the trace node if the analysis is not for source tracing. 25 | % 26 | % Note that the trace node is specified by ID and not by index. 27 | % 28 | % See Also: 29 | % ENgetqualtype 30 | % 31 | % Version 2.00.07 (January 2001) 32 | 33 | global ENDLLNAME; 34 | %global EN_CONSTANT; 35 | 36 | qualcode=int32(qualcode); 37 | [errcode]=calllib(ENDLLNAME,'ENsetqualtype',qualcode,chemname,chemunits,tracenode); 38 | if errcode ENerror(errcode); end 39 | -------------------------------------------------------------------------------- /EPANET/ENsetreport.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetreport(command) 2 | % Declaration: 3 | % [errcode] = ENsetreport(command) 4 | % 5 | % Description: 6 | % Issues a report formatting command. Formatting commands 7 | % are the same as used in the [REPORT] section of the EPANET Input file. 8 | % 9 | %Arguments: 10 | % command: text of a report formatting command. 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Call ENresetreport to clear any previous report formatting commands 17 | % that either appeared in the Input file or were issued with calls 18 | % to ENsetreport or ENsetstatusreport. 19 | % 20 | % Formatted results of a simulation can be written to the Report 21 | % file using the ENreport function. 22 | % 23 | %See Also: 24 | % ENreport, ENresetreport, ENsetstatusreport 25 | % 26 | % Version 2.00.07 (August 2008) 27 | global ENDLLNAME; 28 | 29 | [errcode]=calllib(ENDLLNAME,'ENsetreport',command); 30 | if errcode ENerror(errcode); end -------------------------------------------------------------------------------- /EPANET/ENsetstatusreport.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsetstatusreport(statuslevel) 2 | % Declaration: 3 | % [errcode] = ENsetstatusreport(statuslevel) 4 | % 5 | % Description: 6 | % Sets the level of hydraulic status reporting. 7 | % 8 | %Arguments: 9 | % statuslevel: level of status reporting (see below). 10 | % 11 | % Returns: 12 | % Returns an error code. 13 | % 14 | %Notes: 15 | % Status reporting writes changes in the hydraulics status 16 | % of network elements to the Report file as a hydraulic 17 | % simulation unfolds. There are three levels of reporting: 18 | % 19 | % 0 - no status reporting 20 | % 1 - normal reporting 21 | % 2 - full status reporting 22 | % 23 | % The full status report contains information on the convergence 24 | % of each trial of the solution to the system hydraulic equations 25 | % at each time step of a simulation. It is useful mainly for debugging purposes. 26 | % 27 | % If many hydraulic analyses will be run in the application it is 28 | % recommended that status reporting be turned off (statuslevel = 0). 29 | % 30 | %See Also: 31 | % 32 | % Version 2.00.07 (August 2008) 33 | 34 | global ENDLLNAME; 35 | statuslevel=int32(statuslevel); 36 | [errcode]=calllib(ENDLLNAME,'ENsetstatusreport',statuslevel); 37 | if errcode ENerror(errcode); end 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /EPANET/ENsettimeparam.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsettimeparam(paramcode, timevalue) 2 | % Declaration: 3 | % [errcode] = ENsettimeparam(paramcode, timevalue) 4 | % 5 | % Description: 6 | % Sets the value of a time parameter. 7 | % 8 | % Arguments: 9 | % paramcode: time parameter code (see below) 10 | % timevalue: value of time parameter in seconds 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % Time parameter codes consist of the following constants: 17 | % 18 | % EN_DURATION 0 Simulation duration 19 | % EN_HYDSTEP 1 Hydraulic time step 20 | % EN_QUALSTEP 2 Water quality time step 21 | % EN_PATTERNSTEP 3 Time pattern time step 22 | % EN_PATTERNSTART 4 Time pattern start time 23 | % EN_REPORTSTEP 5 Reporting time step 24 | % EN_REPORTSTART 6 Report starting time 25 | % EN_RULESTEP 7 Time step for evaluating rule-based controls 26 | % EN_STATISTIC 8 Type of time series post-processing to use:EN_NONE (0) = noneEN_AVERAGE (1) = averagedEN_MINIMUM (2) = minimumsEN_MAXIMUM (3) = maximumsEN_RANGE (4) = ranges 27 | % Do not change time parameters after calling ENinitH in a hydraulic analysis or ENinitQ in a water quality analysis. 28 | % 29 | % Version 2.00.07 (January 2001) 30 | 31 | global ENDLLNAME; 32 | %global EN_CONSTANT; 33 | paramcode=int32(paramcode); 34 | timevalue=int32(timevalue); 35 | [errcode]=calllib(ENDLLNAME,'ENsettimeparam',paramcode,timevalue); 36 | if errcode ENerror(errcode); end 37 | -------------------------------------------------------------------------------- /EPANET/ENsolveH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsolveH() 2 | % Declaration: 3 | % [errcode] = ENsolveH( void ) 4 | % 5 | % Description: 6 | % Runs a complete hydraulic simulation with results for all time periods written to the binary Hydraulics file. 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % Notes: 12 | % Use ENsolveH to generate a complete hydraulic solution which can stand alone or be 13 | % used as input to a water quality analysis. It can also be followed by calls to 14 | % ENsaveH and ENreport to write a report on hydraulic results to the report file. 15 | % Do not use ENopenH, ENinitH, ENrunH, ENnextH, and ENcloseH in conjunction with ENsolveH. 16 | % 17 | % Example: 18 | % 19 | % ENopen("net1.inp", "net1.rpt", ""); 20 | % ENsolveH(); 21 | % ENsolveQ(); 22 | % ENreport(); 23 | % ENclose(); 24 | % 25 | % Version 2.00.07 (January 2001) 26 | 27 | global ENDLLNAME; 28 | [errcode]=calllib(ENDLLNAME,'ENsolveH'); 29 | if errcode ENerror(errcode); end 30 | -------------------------------------------------------------------------------- /EPANET/ENsolveQ.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENsolveQ() 2 | % Declaration: 3 | % [errcode] = ENsolveQ (void) 4 | % 5 | % Description: 6 | % Runs a complete water quality simulation with results at uniform 7 | % reporting intervals written to EPANET's binary Output file. 8 | % 9 | %Arguments: 10 | % fname: name of the file containing hydraulic analysis results for the current network. 11 | 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % A hydraulic analysis must have been run and saved to the binary 17 | % hydraulics file before calling ENsolveQ. It can be followed by 18 | % a call to ENreport to write a report on hydraulic and water quality 19 | % results to the report file. 20 | % 21 | % Do not use ENopenQ, ENinitQ, ENrunQ, ENnextQ, and ENcloseQ in conjunction with ENsolveQ. 22 | % 23 | %Example: 24 | % ENopen("net1.inp", "net1.rpt", ""); 25 | % ENsolveH(); 26 | % ENsolveQ(); 27 | % ENreport(); 28 | % ENclose(); 29 | % 30 | %See Also: 31 | % 32 | % 33 | % Version 2.00.07 (August 2008) 34 | global ENDLLNAME; 35 | 36 | [errcode]=calllib(ENDLLNAME,'ENsolveQ'); 37 | if errcode ENerror(errcode); end 38 | 39 | 40 | -------------------------------------------------------------------------------- /EPANET/ENstepQ.m: -------------------------------------------------------------------------------- 1 | function [errcode, tleft] = ENstepQ() 2 | % Declaration: 3 | % [errcode, tleft] = ENstepQ(void) 4 | % 5 | % Description: 6 | % Advances the water quality simulation one water quality time step. 7 | % The time remaining in the overall simulation is returned in tleft. 8 | % 9 | %Arguments: 10 | % tleft: seconds remaining in the overall simulation duration. 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % This function is used in a do-while loop with ENrunQ to perform 17 | % an extended period water quality simulation. It allows you to 18 | % access water quality results at each water quality time step of 19 | % the simulation, rather than at the start of each hydraulic period as with ENnextQ. 20 | % 21 | % Use the argument tleft to determine when no more calls to ENrunQ are 22 | % needed because the end of the simulation period has been reached (i.e., when tleft = 0). 23 | % 24 | % Treat tleft as a read-only variable (do not assign it a value). 25 | % 26 | %Example: 27 | %long t, tleft; 28 | % ENsolveH(); /* Generate & save hydraulics */ 29 | % ENopenQ(); 30 | % ENinitQ(0); 31 | % do { 32 | % ENrunQ(&t); 33 | % /* Monitor results at time t */ 34 | % ENstepQ(&tleft); 35 | % } while (tleft > 0); 36 | % ENcloseQ(); % 37 | % 38 | %See Also: 39 | % ENopenQ, ENinitQ, ENrunQ, ENcloseQ 40 | % 41 | % Version 2.00.07 (August 2008) 42 | global ENDLLNAME; 43 | tleft=int32(0); 44 | %p=libpointer('int32Ptr',tleft); 45 | [errcode,tleft]=calllib(ENDLLNAME,'ENstepQ',tleft); 46 | if errcode ENerror(errcode); end 47 | %tleft=get(p,'Value'); 48 | -------------------------------------------------------------------------------- /EPANET/ENusehydfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENusehydfile(hydfname) 2 | % Declaration: 3 | % [errcode] = ENusehydfile( hydfname ) 4 | % 5 | % Description: 6 | % Uses the contents of the specified file as the current binary hydraulics file. 7 | % 8 | %Arguments: 9 | % fname: name of the file containing hydraulic analysis results for the 10 | % current network. 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | %Notes: 16 | % Call this function to refuse a set of hydraulic analysis results saved 17 | % previously. These results are checked to see if they match the following 18 | % the parameters associated with the current network being analyzed: 19 | % number of nodes, number of tanks and reservoirs, number of links, 20 | % number of pumps, number of valves, and simulation duration. 21 | % 22 | % Do not call this function when the hydraulics analysis system is still 23 | % opened (i.e., ENopenH has been called but ENcloseH has not). 24 | % 25 | %See Also: 26 | % ENsavehydfile 27 | % 28 | % Version 2.00.07 (August 2008) 29 | 30 | global ENDLLNAME; 31 | 32 | [errcode]=calllib(ENDLLNAME,'ENusehydfile',hydfname); 33 | if errcode ENerror(errcode); end -------------------------------------------------------------------------------- /EPANET/ENwriteline.m: -------------------------------------------------------------------------------- 1 | function [errcode] = ENwriteline (line) 2 | % Declaration: 3 | % [errcode] = ENwriteline (line) 4 | % 5 | % Description: 6 | % Writes a line of text to the EPANET report file. 7 | % 8 | %Arguments: 9 | % line: text to be written to file. 10 | % 11 | % Returns: 12 | % Returns an error code. 13 | % 14 | %Notes: 15 | % 16 | %See Also: 17 | % 18 | % 19 | % Version 2.00.07 (August 2008) 20 | global ENDLLNAME; 21 | 22 | [errcode]=calllib(ENDLLNAME,'ENwriteline',line); 23 | if errcode ENerror(errcode); end 24 | -------------------------------------------------------------------------------- /MSX/Content.txt: -------------------------------------------------------------------------------- 1 | MSX Toolkit Functions 2 | For reference see: EPANET programmer's toolkit Windows help file, and EPANET/MSX User's Guide 3 | Report bugs, inconsistencies, or errors to Feng Shang or Jim Uber 4 | 5 | Initialization 6 | MSXMatlabSetup - Opens the MSX DLL library and sets global variables required by the Matlab MSX Toolkit 7 | MSXMatlabCleanup.m - Closes the MSX DLL library 8 | 9 | MSXopen - Opens the EPANET-MSX toolkit system. 10 | MSXclose - Closes the EPANET-MSX toolkit system. 11 | MSXsolveH - Solves for system hydraulics over the entire simulation period, 12 | saving results to an internal scratch file. 13 | MSXusehydfile - Uses a previously saved EPANET hydraulics file as the source of hydraulic information. 14 | MSXsolveQ - Solves for water quality over the entire simulation period and 15 | saves the results to an internal scratch file. 16 | MSXinit - Initializes the MSX system before solving for water quality results in a step-wise fashion. 17 | MSXstep - Advances the water quality solution through a single water quality time 18 | step when performing a step-wise simulation. 19 | MSXsaveoutfile - Saves water quality results computed for each node, 20 | link and reporting time period to a named binary file. 21 | MSXsavemsxfile - Saves the data associated with the current MSX project into a new MSX input file. 22 | MSXreport - Writes water quality simulations results as instructed by the MSX input file to a text file. 23 | MSXgetindex - Retrieves the internal index number of an MSX object given its ID name. 24 | MSXgetIDlen - Retrieves the number of characters in the ID name of an MSX object given its internal index number. 25 | MSXgetID - Retrieves the ID name of an MSX object given its internal index number. 26 | MSXgetcount - Retrieves the number of objects of a specific type. 27 | MSXgetspecies - Retrieves the attributes of a chemical species given its internal index number. 28 | MSXgetinitqual - Retrieves the initial concentration of a particular chemical species assigned 29 | to a specific node or link of the pipe network. 30 | MSXgetqual - Retrieves the concentration of a chemical species at a specific 31 | node or link of the network at the current simulation time step. 32 | MSXgetconstant - Retrieves the value of a particular reaction constant. 33 | MSXgetparameter - Retrieves the value of a particular reaction parameter for a 34 | given pipe or tank within the pipe network. 35 | MSXgetsource - Retrieves information on any external source of a particular 36 | chemical species assigned to a specific node of the pipe network. 37 | MSXgetpatternlen - Retrieves the number of time periods within a source time pattern. 38 | MSXgetpatternvalue - Retrieves the multiplier at a specific time period for a given source time pattern. 39 | MSXgeterror - Returns the text for an error message given its error code. 40 | MSXsetconstant - Assigns a new value to a specific reaction constant. 41 | MSXsetparameter - Assigns a value to a particular reaction parameter for a given pipe or tank within the pipe network. 42 | MSXsetinitqual - Assigns an initial concentration of a particular chemical species 43 | to a specific node or link of the pipe network. 44 | MSXsetsource - Sets the attributes of an external source of a particular chemical 45 | species to a specific node of the pipe network. 46 | MSXsetpattern - Assigns a new set of multipliers to a given MSX source time pattern. 47 | MSXsetpatternvalue - Assigns a new value to the multiplier for a specific time period 48 | in a given MSX source time pattern. 49 | MSXaddpattern - Adds a new, empty MSX source time pattern to the project. 50 | -------------------------------------------------------------------------------- /MSX/MSXMatlabCleanup.m: -------------------------------------------------------------------------------- 1 | function MSXMatlabCleanup(DLLname) 2 | % Declaration: 3 | % MSXMatlabCleanup(DLLname) 4 | % 5 | % Description: 6 | % Unloads MSX DLL library 7 | % 8 | % Arguments: 9 | % DLLname Name of the MSX DLL file (w/o the *.dll extension) 10 | % 11 | % Globals: 12 | % 13 | % Notes: 14 | % MSXMatlabCleanup must be called at the end of a toolkit application. 15 | % must be called when all processing has been completed, 16 | % even if an error condition was encountered. 17 | 18 | 19 | global MSXDLLNAME; 20 | %errcode = 0; 21 | if nargin == 1 22 | MSXDLLNAME=DLLname; 23 | end; 24 | % Load library 25 | if libisloaded(MSXDLLNAME) 26 | unloadlibrary(MSXDLLNAME); 27 | else 28 | errstring =['Library ', MSXDLLNAME, '.dll was not loaded']; 29 | disp(errstring); 30 | end; 31 | -------------------------------------------------------------------------------- /MSX/MSXMatlabSetup.m: -------------------------------------------------------------------------------- 1 | function [] = MSXMatlabSetup(DLLname,Hname) 2 | % Declaration: 3 | % [errcode] = MSXMatlabSetup(DLLname,Hname) 4 | % 5 | % Description: 6 | % Opens the DLL library and sets global variables required by the Matlab 7 | % Epanet-MSX Toolkit 8 | % 9 | % Arguments: 10 | % DLLname Name of the Epanet-MSX DLL file (w/o the *.dll extension) 11 | % Hname Name of the Epanet-MSX header file defining the exported symbols in 12 | % DLLname.dll (with the *.h extension). 13 | % 14 | % Returns: 15 | % Returns an error code. 16 | % 17 | % MSX_CONSTANT is a global structure containing all integer codes defined 18 | % for use of the Epanet-MSX programmer's toolkit (as defined in epanetmsx.h). 19 | % This structure can then be used for convenient access to these codes, 20 | % by declaring 'global ENMSX_CONSTANT' in the code module. 21 | % 22 | % Notes: 23 | % MSXMatlabSetup must be called before any of the other toolkit functions. 24 | % 25 | 26 | global MSXDLLNAME; 27 | global MSX_CONSTANT; 28 | 29 | MSXDLLNAME=DLLname; 30 | MSXHNAME=Hname; 31 | 32 | if ~libisloaded(MSXDLLNAME) 33 | loadlibrary(MSXDLLNAME,MSXHNAME); 34 | end 35 | 36 | MSX_CONSTANT = struct(... 37 | 'MSX_NODE', int32(0),... % Components 38 | 'MSX_LINK', int32(1),... 39 | 'MSX_TANK', int32(2),... 40 | 'MSX_SPECIES', int32(3),... % Component counts 41 | 'MSX_TERM', int32(4),... 42 | 'MSX_PARAMETER', int32(5),... 43 | 'MSX_CONSTANT', int32(6),... 44 | 'MSX_PATTERN', int32(7),... 45 | 'MSX_BULK', int32(0),... 46 | 'MSX_WALL', int32(1),... 47 | 'MSX_NOSOURCE', int32(-1),... 48 | 'MSX_CONCEN', int32(0),... % Source types 49 | 'MSX_MASS', int32(1),... 50 | 'MSX_SETPOINT', int32(2),... 51 | 'MSX_FLOWPACED', int32(3)); 52 | -------------------------------------------------------------------------------- /MSX/MSXaddpattern.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXaddpattern(id) 2 | % Declaration: 3 | % [errcode] = MSXaddpattern(id) 4 | % 5 | % Description: 6 | % Adds a new, empty MSX source time pattern to an MSX project 7 | % 8 | % Arguments: 9 | % id is a C-style character string containing the name of the new pattern. 10 | % 11 | % Returns: 12 | % Returns an error code or 0 for no error. 13 | % 14 | % Notes: 15 | % The new pattern has no time periods or multipliers assigned to it. The 16 | % MSXsetpattern function can be used to assign an array of multipliers to 17 | % the pattern. 18 | 19 | global MSXDLLNAME; 20 | [errcode]=calllib(MSXDLLNAME,'MSXaddpattern',id); 21 | if errcode MSXerror(errcode); end 22 | -------------------------------------------------------------------------------- /MSX/MSXclose.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXclose() 2 | % Declaration: 3 | % [errcode] = MSXclose(void); 4 | % 5 | % Description: 6 | % Closes the MSX Toolkit 7 | % 8 | % Returns: 9 | % Returns an error code. 10 | % 11 | % Notes: 12 | % The EPANET toolkit function ENclose should be called at some point after 13 | % calling MSXclose to down the EPANET toolkit system. 14 | 15 | global MSXDLLNAME; 16 | 17 | [errcode] = calllib(MSXDLLNAME,'MSXclose'); 18 | if errcode MSXerror(errcode); end 19 | -------------------------------------------------------------------------------- /MSX/MSXerror.m: -------------------------------------------------------------------------------- 1 | function [e] = MSXerror(errcode) 2 | % Declaration: 3 | % [e]=MSXerror(errcode); 4 | % 5 | % Description: 6 | % Prints out the error message string associated with error number errcode 7 | % 8 | % Arguments: 9 | % errcode: errorcode to which message will be displayed 10 | % 11 | % Returns: 12 | % Returns an error code or 0 for no error. 13 | % 14 | % See Also: 15 | % MSXgeterror 16 | % 17 | global MSXDLLNAME; 18 | 19 | e=int32(0); 20 | errcode=int32(errcode); 21 | len=int32(80); 22 | errstring=char(32*ones(1,len+1)); 23 | [e,errstring] = calllib(MSXDLLNAME,'MSXgeterror',errcode,errstring,len); 24 | disp(errstring); 25 | -------------------------------------------------------------------------------- /MSX/MSXgetID.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXgetID.m -------------------------------------------------------------------------------- /MSX/MSXgetIDlen.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXgetIDlen.m -------------------------------------------------------------------------------- /MSX/MSXgetconstant.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = MSXgetconstant(index) 2 | % Declaration: 3 | % [errcode, value] = MSXgetconstant(index) 4 | % 5 | % Description: 6 | % Retrieves the value of a particular reaction constant. 7 | % 8 | % Arguments: 9 | % index is the sequence number of the reaction constant 10 | % (starting from 1) as it appeared in the MSX input file; 11 | % 12 | % value is returned with the value assigned to the constant. 13 | % 14 | % Returns: 15 | % Returns an error code or 0 for no error. 16 | % 17 | 18 | global MSXDLLNAME; 19 | 20 | index=int32(index); 21 | value=0; 22 | [errcode,value]=calllib(MSXDLLNAME,'MSXgetconstant',index,value); 23 | if errcode MSXerror(errcode); end 24 | -------------------------------------------------------------------------------- /MSX/MSXgetcount.m: -------------------------------------------------------------------------------- 1 | function [errcode,count] = MSXgetcount(code) 2 | % Declaration: 3 | % [errcode,count] = MSXgetcount( code ) 4 | % 5 | % Description: 6 | % Retrieves the number of objects of a specific type. 7 | % 8 | % Arguments: 9 | % code: is the type of object being sought and must be one of the 10 | % following pre-defined constants: 11 | % MSX_SPECIES (for a chemical species), 12 | % MSX_CONSTANT (for a reaction constant), 13 | % MSX_PARAMETER (for a reaction parameter), 14 | % MSX_PATTERN (for a time pattern); 15 | % 16 | % count: is the number of objects of that type defined in the MSX input file. 17 | % 18 | % Returns: 19 | % Returns an error code or 0 for no error. 20 | 21 | global MSXDLLNAME; 22 | %global MSX_CONSTANT 23 | 24 | count=0; 25 | code=int32(code); 26 | [errcode,count] = calllib(MSXDLLNAME,'MSXgetcount',code,count); 27 | if errcode MSXerror(errcode); end -------------------------------------------------------------------------------- /MSX/MSXgeterror.m: -------------------------------------------------------------------------------- 1 | function [e,errmsg] = MSXgeterror(errcode,len) 2 | % Declaration: 3 | % [e,errmsg] = MSXgeterror(errcode,len); 4 | % 5 | % Description: 6 | % Returns the text for an error message given its error code. 7 | % 8 | % Arguments: 9 | % errcode: is the code number of an error condition generated by EPANET-MSX; 10 | % 11 | % msg: is a C-style character string that is returned containing the text of 12 | % the error message corresponding to the error code; 13 | % 14 | % len: is the maximum number of characters that msg can contain. 15 | % 16 | % Returns: 17 | % Returns an error code or 0 for no error. 18 | % 19 | % Notes: 20 | % msg should be sized to accept a minimum of 80 characters. 21 | % 22 | % This function only applies to error codes generated by the MSX toolkit. 23 | % There is a comparable EPANET toolkit function, ENgeterror, that applies 24 | % to EPANET errors. 25 | 26 | global MSXDLLNAME; 27 | 28 | errcode=int32(errcode); 29 | len=int32(len); 30 | errmsg=char(32*ones(1,len+1)); 31 | [e,errmsg] = calllib(MSXDLLNAME,'MSXgeterror',errcode,errmsg,len); 32 | if e MSXerror(e); end 33 | -------------------------------------------------------------------------------- /MSX/MSXgetindex.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXgetindex.m -------------------------------------------------------------------------------- /MSX/MSXgetinitqual.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = MSXgetinitqual(obj,index,species) 2 | % Declaration: 3 | % [errcode, value] = MSXgetinitqual(obj,index,species) 4 | % 5 | % Description: 6 | % Retrieves the initial concentration of a particular 7 | % chemical species assigned to a specific node or link of 8 | % the pipe network. 9 | % 10 | % Arguments: 11 | % obj: is type of object being queried and must be either: 12 | % MSX_NODE (defined as 0) for a node 13 | % MSX_LINK (defined as 1) for a link; 14 | % 15 | % index: is the internal sequence number (starting from 1) assigned to the 16 | % node or link; 17 | % 18 | % species: is the sequence number of the species (starting from 1); 19 | % 20 | % value: is returned with the initial concentration of the species at the 21 | % node or link of interest. 22 | % 23 | % Returns: 24 | % Returns an error code or 0 for no error. 25 | % 26 | % Notes: 27 | % The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can be 28 | % used to identify the index of a node or link from its ID name; 29 | % 30 | % Concentrations are expressed as mass units per liter for bulk species 31 | % and as mass per unit area for surface species. 32 | 33 | global MSXDLLNAME; 34 | 35 | obj=int32(obj); 36 | index=int32(index); 37 | species=int32(species); 38 | value=0; 39 | [errcode,value]=calllib(MSXDLLNAME,'MSXgetinitqual',obj,index,species,value); 40 | if errcode MSXerror(errcode); end 41 | -------------------------------------------------------------------------------- /MSX/MSXgetparameter.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = MSXgetparameter(obj,index,param) 2 | % Declaration: 3 | % [errcode, value] = MSXgetparameter(obj,index,param) 4 | % 5 | % Description: 6 | % Retrieves the value of a particular reaction parameter for 7 | % a given pipe or tank within the pipe network. 8 | % 9 | % Arguments: 10 | % obj: is type of object being queried and must be either: 11 | % MSX_NODE (defined as 0) for a node 12 | % MSX_LINK (defined as 1) for a link; 13 | % 14 | % index: is the internal sequence number (starting from 1) 15 | % assigned to the node or link; 16 | % 17 | % param: is the sequence number of the parameter (starting 18 | % from 1 as listed in the MSX input file); 19 | % 20 | % value: is returned with the value assigned to the parameter 21 | % for the node or link of interest. 22 | % 23 | % Returns: 24 | % Returns an error code or 0 for no error. 25 | % 26 | % Notes: 27 | % Reaction parameters are only defined for storage tank nodes and 28 | % pipe links. All other types of nodes and links have parameter values of 0. 29 | 30 | global MSXDLLNAME; 31 | 32 | obj=int32(obj); 33 | index=int32(index); 34 | param=int32(param); 35 | value=0; 36 | [errcode,value]=calllib(MSXDLLNAME,'MSXgetparameter',obj,index,param,value); 37 | if errcode MSXerror(errcode); end 38 | -------------------------------------------------------------------------------- /MSX/MSXgetpatternlen.m: -------------------------------------------------------------------------------- 1 | function [errcode, patlen] = MSXgetpatternlen(patindex) 2 | % Declaration: 3 | % [errcode, patlen] = MSXgetpatternlen(patindex); 4 | % 5 | % Description: 6 | % Retrieves the number of time periods within a source time pattern. 7 | % 8 | % Arguments: 9 | % (patindex) is the internal sequence number (starting from 1) of the pattern as 10 | % it appears in the MSX input file; 11 | % 12 | % patlen is returned with the number of time periods (and therefore number of 13 | % multipliers) that appear in the pattern. 14 | % 15 | % Returns: 16 | % Returns an error code or 0 for no error. 17 | % 18 | % Notes: 19 | % This function only applies to source time patterns that appear in the MSX 20 | % input file. There is a comparable EPANET toolkit function, 21 | % ENgetpatternlen, which can be used for the demand patterns defined in the 22 | % EPANET input file. 23 | % 24 | 25 | global MSXDLLNAME; 26 | 27 | patlen=int32(0); 28 | patindex=int32(patindex); 29 | [errcode,patlen]=calllib(MSXDLLNAME,'MSXgetpatternlen',patindex,patlen); 30 | if errcode MSXerror(errcode); end -------------------------------------------------------------------------------- /MSX/MSXgetpatternvalue.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXgetpatternvalue.m -------------------------------------------------------------------------------- /MSX/MSXgetqual.m: -------------------------------------------------------------------------------- 1 | function [errcode, value] = MSXgetqual(obj,index,species) 2 | % Declaration: 3 | % [errcode, value] = MSXgetqual(obj,index,species) 4 | % 5 | % Purpose: 6 | % Retrieves a chemical species concentration at a given node or 7 | % the average concentration along a link at the current simulation time 8 | % step. 9 | % 10 | % Arguments: 11 | % obj: is type of object being queried and must be either: 12 | % MSX_NODE (defined as 0) for a node 13 | % MSX_LINK (defined as 1) for a link; 14 | % 15 | % index: is the internal sequence number (starting from 1) assigned to the 16 | % node or link; 17 | % 18 | % species: is the sequence number of the species (starting from 1 as listed 19 | % in the MSX input file); 20 | % 21 | % value: is returned with the computed concentration of the species at the 22 | % current time period. 23 | % 24 | % Returns: 25 | % Returns an error code or 0 for no error. 26 | % 27 | % Notes: 28 | % The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can 29 | % be used to identify the index of a node or link from its ID name; 30 | % 31 | % Concentrations are expressed as mass units per liter for bulk species 32 | % and as mass per unit area for surface species. 33 | 34 | global MSXDLLNAME; 35 | %global MSX_CONSTANT; 36 | 37 | obj=int32(obj); 38 | index=int32(index); 39 | species=int32(species); 40 | value=0; 41 | [errcode,value]=calllib(MSXDLLNAME,'MSXgetqual',obj,index,species,value); 42 | if errcode MSXerror(errcode); end 43 | -------------------------------------------------------------------------------- /MSX/MSXgetsource.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXgetsource.m -------------------------------------------------------------------------------- /MSX/MSXgetspecies.m: -------------------------------------------------------------------------------- 1 | function [errcode, type, units, atol, rtol] = MSXgetspecies(index) 2 | % Declaration: 3 | % [errcode, type, units, atol, rtol] = MSXgetspecies(index) 4 | % 5 | % Description: 6 | % Retrieves the attributes of a chemical species given its 7 | % internal index number. 8 | % 9 | % Arguments: 10 | % index: is the sequence number of the species (starting from 11 | % 1 as listed in the MSX input file); 12 | % 13 | % type: is returned with one of the following pre-defined constants: 14 | % MSX_BULK (defined as 0) for a bulk water species, 15 | % MSX_WALL (defined as 1) for a pipe wall surface species; 16 | % 17 | % units: is a C-style character string array that is returned with the 18 | % mass units that were defined for the species in question. 19 | % It must be sized to hold a maximum of 15 characters plus the 20 | % terminating null character (for a total of 16). 21 | % 22 | % aTol: is returned with the absolute concentration tolerance defined 23 | % for the species (in concentration units); 24 | % 25 | % rTol: is returned with the relative concentration tolerance defined for the species. 26 | % 27 | % index = index (base 1) of the species in the list of all species. 28 | % 29 | % 30 | % Returns: 31 | % Returns an error code or 0 for no error. 32 | 33 | global MSXDLLNAME; 34 | %global MSX_CONSTANT; 35 | errcode = 0; 36 | 37 | 38 | index=int32(index); 39 | type=int32(0); 40 | units=char(32*ones(1,16)); 41 | rtol=double(0); 42 | atol=double(0); 43 | [errcode,type,units,atol,rtol]=calllib(MSXDLLNAME,'MSXgetspecies',index,type,units,atol,rtol); 44 | if errcode MSXerror(errcode); end 45 | -------------------------------------------------------------------------------- /MSX/MSXinit.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXinit(flag) 2 | %Declaration: 3 | % [errcode] = MSXinit(flag) 4 | % 5 | % Description: 6 | % Initializes the MSX system before solving for water quality results in 7 | % step-wise fashion. 8 | % 9 | % Arguments: 10 | % Set flag to 1 if water quality results should be saved to a 11 | % scratch binary file, or to 0 if results are not saved to file. 12 | % 13 | % Returns: 14 | % Returns an error code or 0 for no error. 15 | % 16 | % Notes: 17 | % This function must be called before a step-wise water quality simulation 18 | % is performed using MSXstep. Do not call this function if performing a 19 | % complete simulation using MSXsolveQ. 20 | 21 | 22 | global MSXDLLNAME; 23 | 24 | flag=int32(flag); 25 | [errcode]=calllib(MSXDLLNAME,'MSXinit',flag); 26 | if errcode MSXerror(errcode); end 27 | -------------------------------------------------------------------------------- /MSX/MSXopen.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXopen(msxname) 2 | % Declaration: 3 | % [errcode] = MSXopen( msxname ) 4 | % 5 | % Description: 6 | % Opens the MSX Toolkit to analyze a particular distribution system. 7 | % Defines global structure ENMSX_SIZE. 8 | % 9 | % Arguments: 10 | % msxname: name of an EPANET-MSX Input file 11 | % 12 | % Returns: 13 | % Returns an error code. 14 | % 15 | % Notes: 16 | % The standard EPANET toolkit function ENopen must have been called 17 | % first to open the EPANET toolkit along with an associated EPANET 18 | % input file for the network being analyzed as well as to identify 19 | % the name of a report file to which results are written. 20 | % 21 | % MSX_SIZE is a global structure that contains the msx size: nspecies, 22 | % nterms, nparams, nconstants, npats. 23 | % This structure is defined for user convenience. 24 | % 25 | % MSXopen must be called before any of the other msx toolkit functions 26 | % are used. 27 | % 28 | % See Also: 29 | % ENclose 30 | 31 | global MSXDLLNAME; 32 | global MSX_CONSTANT; 33 | global MSX_SIZE; 34 | 35 | %errcode = 0; 36 | 37 | [errcode] = calllib(MSXDLLNAME,'MSXopen',msxname); 38 | if errcode MSXerror(errcode); end 39 | if (errcode == 520) 40 | disp('current MSX project will be closed and the new project will be opened'); 41 | [errcode] = MSXclose(); 42 | if errcode MSXerror(errcode); 43 | else 44 | [errcode] = calllib(MSXDLLNAME,'MSXopen',msxname); 45 | if errcode MSXerror(errcode); end 46 | end 47 | end 48 | 49 | 50 | 51 | 52 | [errcode,nspecies] = MSXgetcount(MSX_CONSTANT.MSX_SPECIES); 53 | if errcode MSXerror(errcode); end 54 | 55 | [errcode,nparams] = MSXgetcount(MSX_CONSTANT.MSX_PARAMETER); 56 | if errcode MSXerror(errcode); end 57 | 58 | [errcode,nconstants] = MSXgetcount(MSX_CONSTANT.MSX_CONSTANT); 59 | if errcode MSXerror(errcode); end 60 | 61 | [errcode,npats] = MSXgetcount(MSX_CONSTANT.MSX_PATTERN); 62 | if errcode MSXerror(errcode); end 63 | 64 | MSX_SIZE = struct(... 65 | 'nspecies', nspecies,... 66 | 'nparams', nparams,... 67 | 'npats', npats,... 68 | 'nconstants',nconstants); 69 | -------------------------------------------------------------------------------- /MSX/MSXreport.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXreport() 2 | % Declaration: 3 | % [errcode] = MSXreport(void) 4 | % 5 | % Description: 6 | % Writes water quality simulations results as instructed by the MSX input file to a text file. 7 | % 8 | % Arguments: 9 | % 10 | % Notes: 11 | % Results are written to the EPANET report file unless a specific 12 | % water quality report file is named in the [REPORT] section of 13 | % the MSX input file. 14 | % 15 | 16 | global MSXDLLNAME; 17 | 18 | [errcode] = calllib(MSXDLLNAME,'MSXreport'); 19 | if errcode MSXerror(errcode); end 20 | -------------------------------------------------------------------------------- /MSX/MSXsavemsxfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsavemsxfile(outfname) 2 | % Declaration: 3 | % [errcode] = MSXsavemsxfile(outfname); 4 | % 5 | % Description: 6 | % Saves the data associated with the current MSX project into 7 | % a new MSX input file. 8 | % 9 | % Arguments: 10 | % outfname is a string containing the name of the 11 | % file to which data are saved. 12 | % 13 | % Returns: 14 | % Returns an error code or 0 for no error. 15 | % 16 | % Notes: 17 | % For a step-wise simulation using MSXstep, this function only 18 | % applies if MSXinit was called with its saveFlag parameter set to 1 (see 19 | % MSXinit). The format of the binary results file is described in Appendix 20 | % B of the MSX user's guide. 21 | 22 | global MSXDLLNAME; 23 | 24 | [errcode] = calllib(MSXDLLNAME,'MSXsavemsxfile',outfname); 25 | if errcode MSXerror(errcode); end 26 | -------------------------------------------------------------------------------- /MSX/MSXsaveoutfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsaveoutfile(outfname) 2 | %Declaration: 3 | % [errcode] = MSXsaveoutfile(outfname) 4 | % 5 | % Purpose: 6 | % Saves water quality results computed for each node, link and reporting time period to a named binary file. 7 | % 8 | % Input: 9 | % outfname = name of the binary results file. 10 | % 11 | % Returns: 12 | % an error code (or 0 for no error). 13 | % 14 | % Notes: 15 | % For a step-wise simulation using MSXstep, this function only 16 | % applies if MSXinit was called with its saveFlag parameter set to 1 (see MSXinit). 17 | % The format of the binary results file is described in Appendix B. 18 | 19 | 20 | global MSXDLLNAME; 21 | 22 | [errcode] = calllib(MSXDLLNAME,'MSXsaveoutfile',outfname); 23 | if errcode MSXerror(errcode); end 24 | -------------------------------------------------------------------------------- /MSX/MSXsetconstant.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsetconstant(index, value) 2 | % Declaration: 3 | % [errcode] = MSXsetconstant(index, value); 4 | % 5 | % Description: 6 | % Assigns a new value to a specific reaction constant. 7 | % 8 | % Arguments: 9 | % index is the sequence number of the reaction constant (starting from 1) 10 | % as it appeared in the MSX input file; 11 | % 12 | % value is the new value to be assigned to the constant. 13 | % 14 | % Returns: 15 | % Returns an error code or 0 for no error. 16 | 17 | global MSXDLLNAME; 18 | 19 | index=int32(index); 20 | value=double(value); 21 | [errcode]=calllib(MSXDLLNAME,'MSXsetconstant',index,value); 22 | if errcode MSXerror(errcode); end 23 | -------------------------------------------------------------------------------- /MSX/MSXsetinitqual.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsetinitqual(type,index,species,value) 2 | % Declaration: 3 | % [errcode] = MSXsetinitqual(type,index,species,value) 4 | % 5 | % Description: 6 | % Assigns an initial concentration of a particular chemical species to a 7 | % specific node or link of the pipe network. 8 | % 9 | % Arguments: 10 | % type: is type of object being queried and must be either: 11 | % MSX_NODE (defined as 0) for a node 12 | % MSX_LINK (defined as 1) for a link; 13 | % 14 | % index: is the internal sequence number (starting from 1) assigned to the 15 | % node or link; 16 | % 17 | % species: is the sequence number of the species (starting from 1 as listed 18 | % in the MSX input file); 19 | % 20 | % value: is the initial concentration of the species to be applied at the 21 | % node or link of interest. 22 | % 23 | % Returns: 24 | % Returns an error code or 0 for no error. 25 | % 26 | % Notes: 27 | % The EPANET toolkit functions ENgetnodeindex and ENgetlinkindex can be 28 | % used to identify the index of a node or link from its ID name; 29 | % 30 | % Concentrations are expressed as mass units per liter for bulk species and 31 | % as mass per unit area for surface species. 32 | 33 | global MSXDLLNAME; 34 | 35 | type=int32(type); 36 | index=int32(index); 37 | species=int32(species); 38 | value=double(value); 39 | [errcode]=calllib(MSXDLLNAME,'MSXsetinitqual',type,index,species,value); 40 | if errcode MSXerror(errcode); end 41 | -------------------------------------------------------------------------------- /MSX/MSXsetparameter.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsetparameter(type, index, param, value) 2 | % Declaration: 3 | % [errcode] = MSXsetparameter(type, index, param, value) 4 | % 5 | % Description: 6 | % Assigns a value to a particular reaction parameter for a given pipe or 7 | % tank within the pipe network. 8 | % 9 | % Arguments: 10 | % type: is type of object being queried and must be either: 11 | % MSX_NODE (defined as 0) for a node 12 | % MSX_LINK (defined as 1) for a link; 13 | % 14 | % index: is the internal sequence number (starting from 1) assigned to the 15 | % node or link; 16 | % 17 | % param: is the sequence number of the parameter (starting from 1 as listed 18 | % in the MSX input file); 19 | % 20 | % value: is the value to be assigned to the parameter for the node or link 21 | % of interest. 22 | % 23 | % Returns: 24 | % Returns an error code or 0 for no error. 25 | % 26 | % Notes: 27 | % Reaction parameters are only defined for storage tank nodes and 28 | % pipe links. Attempts to set parameter values for other types of nodes and 29 | % links will be ignored. 30 | 31 | global MSXDLLNAME; 32 | %global MSX_CONSTANT; 33 | 34 | type=int32(type); 35 | index=int32(index); 36 | param=int32(param); 37 | value=double(value); 38 | [errcode]=calllib(MSXDLLNAME,'MSXsetparameter',type,index,param,value); 39 | if errcode MSXerror(errcode); end 40 | -------------------------------------------------------------------------------- /MSX/MSXsetpattern.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsetpattern(pat, multi, len) 2 | % Declaration: 3 | % [errcode] = MSXsetpattern(pat, multi, len) 4 | % 5 | % Description: 6 | % Assigns a new set of multipliers to a given MSX source time pattern. 7 | % 8 | % Arguments: 9 | % pat is the internal sequence number (starting from 1) of the pattern as 10 | % it appears in the MSX input file; 11 | % 12 | % multi is an one-dimensional array of multiplier values to replace those previously used 13 | % by the pattern; 14 | % 15 | % len is the number of entries int the multiplier array mult. 16 | % 17 | % Returns: 18 | % Returns an error code or 0 for no error. 19 | % 20 | % Notes: 21 | % This function only applies to source time patterns that appear in the MSX 22 | % input file. There is a comparable EPANET toolkit function, ENsetpattern, 23 | % which can be used for the demand patterns defined in the EPANET input 24 | % file. 25 | 26 | global MSXDLLNAME; 27 | 28 | pat=int32(pat); 29 | len=int32(len); 30 | [errcode]=calllib(MSXDLLNAME,'MSXsetpattern',pat,multi,len); 31 | if errcode MSXerror(errcode); end 32 | -------------------------------------------------------------------------------- /MSX/MSXsetpatternvalue.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsetpatternvalue(pat, period, value) 2 | % Declaration: 3 | % [errcode] = MSXsetpatternvalue(pat, period, value); 4 | % 5 | % Description: 6 | % Assigns a new value to the multiplier for a specific time period in a 7 | % given MSX source time pattern. 8 | % 9 | % Arguments: 10 | % pat is the internal sequence number (starting from 1) of the pattern as 11 | % it appears in the MSX input file; 12 | % period is the time period (starting from 1) in the pattern to be 13 | % replaced; 14 | % value is the new multiplier value to use for that time period. 15 | % 16 | % Returns: 17 | % Returns an error code or 0 for no error. 18 | % 19 | % Notes: 20 | % This function only applies to source time patterns that appear in the MSX 21 | % input file. There is a comparable EPANET toolkit function, 22 | % ENsetpatternvalue, which can be used for the demand patterns defined in 23 | % the EPANET input file. 24 | 25 | 26 | global MSXDLLNAME; 27 | 28 | pat=int32(pat); 29 | period=int32(period); 30 | value=double(value); 31 | [errcode]=calllib(MSXDLLNAME,'MSXsetpatternvalue',pat,period,value); 32 | if errcode MSXerror(errcode); end 33 | -------------------------------------------------------------------------------- /MSX/MSXsetsource.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/MSX/MSXsetsource.m -------------------------------------------------------------------------------- /MSX/MSXsolveH.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsolveH() 2 | % Declaration: 3 | % [errcode] = MSXsolveH( void ) 4 | % 5 | % Description: 6 | % Runs a complete hydraulic simulation with results for all time periods 7 | % written to the binary Hydraulics file. 8 | % 9 | % Returns: 10 | % Returns an error code. 11 | % 12 | % Notes: 13 | % Either this function or MSXusehydfile (see below) must be called 14 | % before any water quality processing is performed. 15 | 16 | global MSXDLLNAME; 17 | 18 | [errcode]=calllib(MSXDLLNAME,'MSXsolveH'); 19 | if errcode MSXerror(errcode); end 20 | -------------------------------------------------------------------------------- /MSX/MSXsolveQ.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXsolveQ() 2 | % Declaration: 3 | % [errcode] = MSXsolveQ(void); 4 | % 5 | % Description: 6 | % Solves for water quality over the entire simulation period and saves the 7 | % results to an internal scratch file. 8 | % 9 | % Returns: 10 | % Returns an error code or 0 for no error. 11 | % 12 | % Notes: 13 | % This function does not allow access to computed water quality results as 14 | % the simulation unfolds. If such information is required use MSXinit in 15 | % conjunction with step-wise calls to MSXstep (see below). 16 | % 17 | 18 | global MSXDLLNAME; 19 | 20 | [errcode]=calllib(MSXDLLNAME,'MSXsolveQ'); 21 | if errcode MSXerror(errcode); end 22 | -------------------------------------------------------------------------------- /MSX/MSXstep.m: -------------------------------------------------------------------------------- 1 | function [errcode, t, tleft] = MSXstep() 2 | % Declaration: 3 | % [errcode, t, tleft] = MSXstep(void); 4 | % 5 | % Description: 6 | % Advances the water quality solution through a single water quality time 7 | % step when performing a step-wise simulation. 8 | % 9 | % Arguments: 10 | % Upon returning, t will contain the current simulation time at the end 11 | % of the step (in seconds) while tleft will contain the time left in the 12 | % simulation (also in seconds). 13 | % 14 | % Returns: 15 | % Returns an error code or 0 for no error. 16 | % 17 | % Notes: 18 | % This function should be placed in a loop that repeats until the value 19 | % of tleft becomes 0. MSXinit should be called before beginning the loop. 20 | % 21 | % The water quality time step used by this function is specified in the 22 | % [OPTIONS] section of the MSX input file. 23 | 24 | 25 | global MSXDLLNAME; 26 | 27 | t=int32(0); 28 | tleft=int32(0); 29 | [errcode,t,tleft]=calllib(MSXDLLNAME,'MSXstep',t,tleft); 30 | if errcode MSXerror(errcode); end 31 | t = double(t); 32 | tleft = double(tleft); 33 | 34 | -------------------------------------------------------------------------------- /MSX/MSXusehydfile.m: -------------------------------------------------------------------------------- 1 | function [errcode] = MSXusehydfile(hydfname) 2 | % Declaration: 3 | % [errcode] = ENMSXusehydfile( hydfname ) 4 | % 5 | % Description: 6 | % Specifies an existing hydraulics file to use when performing a 7 | % msx water quality analysis 8 | % 9 | % Returns: 10 | % Returns an error code. 11 | % 12 | % Notes: 13 | % Either this function or MSXsolveH must be called before any 14 | % water quality processing is performed. 15 | 16 | global MSXDLLNAME; 17 | 18 | [errcode]=calllib(MSXDLLNAME,'MSXusehydfile',hydfname); 19 | if errcode MSXerror(errcode); end 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | epanet-matlab 2 | ============= 3 | 4 | Description 5 | ----------- 6 | This product consists of a set of Matlab wrappers that allow use of the EPANET and EPANET-MSX programmer's toolkit APIs from within the Matlab environment. The Matlab functions share names with the C-language API functions. Usage of the Matlab functions is similar; the argument lists are identical, with the exception that Matlab separates input and output arguments. User's of the EPANET or EPANET-MSX APIs with Matlab programming experience should be able to make efficient use of this product. 7 | 8 | In addition to the Matlab API wrappers, this product includes a small number of utility routines that, for example, allow for plotting of the network using Matlab graphics. 9 | 10 | For reference see: EPANET programmer's toolkit Windows help file, and EPANET/MSX User's Guide. 11 | 12 | 13 | Requirements: 14 | ------------- 15 | Following files have to be in the search path: %(easiest is to copy them in the working directory) 16 | - epanet2.dll 17 | - epanet2.h 18 | - epanetmsx.dll 19 | - epanetmsx.h 20 | 21 | Also added to the path should be locations for the included directories: 22 | - EPANET toolkit matlab wrappers 23 | - MSX matlab wrappers 24 | - Test files 25 | - Utils files 26 | 27 | Use: 28 | ---- 29 | The frame of a toolkit application should always have the 30 | following form: 31 | 32 | global EN_CONSTANT 33 | global MSX_CONSTANT 34 | 35 | %load libraries 36 | %start EPANET toolkit 37 | ENMatlabSetup('epanet2','epanet2.h'); 38 | 39 | %start MSX toolkit 40 | MSXMatlabSetup('epanetmsx','epanetmsx.h'); 41 | 42 | %open hydraulic network 43 | [errcode] = ENopen(inpfn, rptfn, ''); 44 | 45 | % Open the MSX file 46 | [errcode] = MSXopen(msxfn); 47 | ... 48 | %close MSX file 49 | MSXclose(); 50 | 51 | %close hydraulic network 52 | ENclose(); 53 | 54 | %unload libraries 55 | ENMatlabCleanup(); 56 | MSXMatlabCleanup(); 57 | 58 | 59 | Examples for the use of the EPANET toolkit and the MSX toolkit 60 | can be found in the test folder. 61 | 62 | 63 | Notes: 64 | ------ 65 | 66 | - predefined objects are stored in the global structures 67 | `EN_CONSTANT` and `MSX_CONSTANT`. Thus functions that require the 68 | input of an object must be called as can be observed in the example below: 69 | 70 | [errcode,value]=ENgetlinkvalue(index,EN_CONSTANT.EN_LENGTH); 71 | 72 | The prefix of `EN_CONSTANT.` or `MSX_CONSTANT.` is required for all object inputs even though this is not indicated in the help files. The help file for the above example would only say: 73 | 74 | [errcode,value]=ENgetlinkvalue(index,EN_LENGTH); 75 | 76 | Alternatively, numeric codes can be used as indicated in the help files. 77 | 78 | - index numbers and id (names) of nodes, links, species etc. do not necessarily coincide. 79 | 80 | Authors & License: 81 | -------- 82 | Original Matlab wrappers and scripts by Jim Uber. 83 | 84 | This is free and unencumbered software released into the public domain. 85 | 86 | Anyone is free to copy, modify, publish, use, compile, sell, or 87 | distribute this software, either in source code form or as a compiled 88 | binary, for any purpose, commercial or non-commercial, and by any 89 | means. 90 | 91 | In jurisdictions that recognize copyright laws, the author or authors 92 | of this software dedicate any and all copyright interest in the 93 | software to the public domain. We make this dedication for the benefit 94 | of the public at large and to the detriment of our heirs and 95 | successors. We intend this dedication to be an overt act of 96 | relinquishment in perpetuity of all present and future rights to this 97 | software under copyright law. 98 | 99 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 100 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 101 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 102 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 103 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 104 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 105 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Test/Content.txt: -------------------------------------------------------------------------------- 1 | Content: 2 | 3 | exampe.m - This example uses the network file Net2.inp and the 4 | msx file net2-cl2.msx % (distributed with the MSX toolkit as 5 | example 2) % to plot the CL2 data of node 1, linke 1, node 17 6 | and link 17. 7 | 8 | The Toolkit example includes EPANET and MSX functionality and 9 | is based on example 2 of the MSX package: 10 | Net2.inp - Network 11 | input file used for EPANET and MSX toolkit test and example. 12 | net2-cl2.msx - MSX input file used for MSX toolkit test and 13 | example. 14 | 15 | Test functions for toolkit functions 16 | ENwraptest.m - Tests all the existing Matlab wrappers for the EPANET toolkit functions. 17 | MSXwraptest.m - Tests all the existing Matlab wrappers for the MSX toolkit functions. 18 | -------------------------------------------------------------------------------- /Test/ENwraptest.m: -------------------------------------------------------------------------------- 1 | 2 | global EN_CONSTANT 3 | 4 | %start epanet 5 | %exist('epanet2.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 6 | %exist('epanet2.h')%return 2 7 | [errcode]=ENMatlabSetup('epanet2','epanet2.h');% seems to work 8 | %check with 9 | %libisloaded('epanet2')% returns 1 =true 10 | %libfunctions('epanet2', '-full')%shows libaryfunction loaded 11 | 12 | %start MSX 13 | %exist('epanetmsx.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 14 | %exist('epanetmsx.h') 15 | %open MSX 16 | %MSXMatlabSetup('epanetmsx','epanetmsx.h'); 17 | 18 | %libisloaded('epanetmsx')% returns 1 =true 19 | %libfunctions('epanetmsx', '-full')%shows libaryfunction loaded 20 | 21 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 22 | exist('Net2.inp');% returns 2 23 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 24 | %exist('net3-bio.msx')% returns 2 25 | 26 | %call ENopen 27 | [errcode] = ENopen('Net2.inp', 'TEST.rpt', ''); 28 | % Open the MSX toolkit 29 | 30 | %[errcode] = MSXopen('net3-bio.msx') 31 | %[errcode,errmsg] = MSXgeterror(501,80); 32 | 33 | % Hydraulic analysis 34 | [errcode] = ENsolveH(); 35 | [errcode] = ENsaveH(); 36 | [errcode] = ENsavehydfile('Net2test.hyd'); 37 | 38 | %[errcode]= calllib('epanet2','ENsavehydfile','net3-bio.hyd'); 39 | %????????????does not save hydraulic results????? 40 | [errcode] = ENusehydfile('Net2test.hyd'); 41 | 42 | [errcode] = ENsolveQ(); 43 | 44 | [errcode] = ENwriteline('KKKKKKKKKKKKK'); 45 | 46 | [errcode] = ENresetreport(); 47 | str = 'STATUS YES'; 48 | [errcode] = ENsetreport(str); 49 | [errcode] = ENsetstatusreport(0); 50 | [errcode] = ENreport(); 51 | 52 | id = '1'; 53 | [errcode, index] = ENgetpatternindex(id); 54 | index = 2; 55 | [errcode, id] = ENgetpatternid(index); 56 | 57 | [errcode, value] = ENgetoption(EN_CONSTANT.EN_TOLERANCE); 58 | value = 0.0200; 59 | [errcode] = ENsetoption(EN_CONSTANT.EN_TOLERANCE,value); 60 | %[errcode, value] = ENgetoptionnolib(EN_CONSTANT.EN_TOLERANCE); 61 | [errcode, value] = ENgetoption(EN_CONSTANT.EN_TOLERANCE); 62 | [errcode, numctrls] = ENgetcount(EN_CONSTANT.EN_CONTROLCOUNT); 63 | for (i=1:1:numctrls) 64 | [errcode, ctype,lindex,setting,nindex,level] = ENgetcontrol(i); 65 | level = 101; 66 | lindex = 1; 67 | if (ctype == EN_CONSTANT.EN_LOWLEVEL && lindex == 1) 68 | [errcode] = ENsetcontrol(i,ctype,lindex,setting,nindex,level); 69 | [errcode, ctype,lindex,setting,nindex,level] = ENgetcontrol(i); 70 | end; 71 | end; 72 | 73 | 74 | [errcode,unitscode] = ENgetflowunits(); 75 | index = 1; 76 | [errcode,id] = ENgetlinkid(index); 77 | id = '20'; 78 | 79 | [errcode,index] = ENgetlinkindex(id); 80 | [errcode, type] = ENgetlinktype(index); 81 | [errcode, value] = ENgetlinkvalue(index,EN_CONSTANT.EN_LENGTH); 82 | value = value+100; 83 | [errcode] = ENsetlinkvalue(index, EN_CONSTANT.EN_LENGTH, value); 84 | [errcode, value] = ENgetlinkvalue(index,EN_CONSTANT.EN_LENGTH); 85 | 86 | [errcode,from,to] = ENgetlinknodes(30); 87 | [errcode,from1,to1] = ENgetalllinknodes(); 88 | 89 | [errcode, index] = ENgetnodeindex(id); 90 | [errcode,id] = ENgetnodeid(index); 91 | [errcode, type] = ENgetnodetype(index); 92 | [errcode, value] = ENgetnodevalue(index, EN_CONSTANT.EN_BASEDEMAND); 93 | value = value+4; 94 | [errcode] = ENsetnodevalue(index, EN_CONSTANT.EN_BASEDEMAND, value); 95 | [errcode, value] = ENgetnodevalue(index, EN_CONSTANT.EN_BASEDEMAND); 96 | 97 | [nnodes,ntanks,nlinks,npats,ncurves,ncontrols,errcode] = ENgetnetsize(); 98 | % close the toolkits 99 | 100 | id='2'; 101 | [errcode, index] = ENgetpatternindex(id); 102 | [errcode, len] = ENgetpatternlen(index); 103 | [errcode, value] = ENgetpatternvalue(index, 1); 104 | facts=[1,2,3,4,5]; 105 | [errcode] = ENsetpattern(index, facts, 5); 106 | [errcode, value] = ENgetpatternvalue(index, 1); 107 | [errcode] = ENsetpatternvalue(index, 1, 80); 108 | [errcode, value] = ENgetpatternvalue(index, 1); 109 | 110 | [e, errmsg] = ENgeterror(101); 111 | 112 | [errcode,timevalue] = ENgettimeparam(EN_CONSTANT.EN_HYDSTEP); 113 | timevalue = timevalue +4; 114 | [errcode] = ENsettimeparam(EN_CONSTANT.EN_HYDSTEP,timevalue); 115 | [errcode,timevalue] = ENgettimeparam(EN_CONSTANT.EN_HYDSTEP ); 116 | 117 | [errcode,qualcode,tracenode] = ENgetqualtype(); 118 | tracenode = '0'; 119 | [errcode] = ENsetqualtype(qualcode,'Pb','pfu',tracenode) 120 | [errcode,qualcode,tracenode] = ENgetqualtype(); 121 | 122 | [errcode] = ENsaveinpfile('ENtest.inp'); 123 | 124 | ENclose(); 125 | 126 | [errcode] = ENopen('Net2.inp', 'TESTst.rpt', ''); 127 | [errcode] = ENopenH(); 128 | [errcode] = ENinitH(1); 129 | 130 | [errcode,step] = ENnextH(); 131 | while(step > 0 && errcode == 0) 132 | [errcode,t] = ENrunH(); 133 | [errcode,step] = ENnextH(); 134 | end; 135 | [errcode] = ENsavehydfile('Net2test2.hyd'); 136 | [errcode] = ENcloseH(); 137 | 138 | ENclose(); 139 | 140 | [errcode] = ENopen('Net2.inp', 'TESTst.rpt', ''); 141 | 142 | [errcode] = ENusehydfile('Net2test2.hyd'); 143 | [errcode] = ENopenQ(); 144 | [errcode] = ENinitQ(1); 145 | [errcode,tstep] = ENnextQ(); 146 | %step 0 why 147 | while(tstep > 0 && errcode == 0) 148 | [errcode,t] = ENrunQ(); 149 | [errcode,tstep] = ENnextQ(); 150 | end; 151 | [errcode] = ENcloseQ(); 152 | 153 | ENclose(); 154 | ENMatlabCleanup(); 155 | 156 | -------------------------------------------------------------------------------- /Test/MSXwraptest.m: -------------------------------------------------------------------------------- 1 | % Tests all the existing Matlab wrappers for the MSX toolkit functions 2 | global MSX_CONSTANT 3 | global EN_CONSTANT 4 | 5 | %start epanet 6 | %exist('epanet2.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 7 | %exist('epanet2.h')%return 2 8 | ENMatlabSetup('epanet2','epanet2.h');% seems to work 9 | %check with 10 | %libisloaded('epanet2')% returns 1 =true 11 | %libfunctions('epanet2', '-full')%shows libaryfunction loaded 12 | 13 | %start MSX 14 | %exist('epanetmsx.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 15 | %exist('epanetmsx.h') 16 | %open MSX 17 | MSXMatlabSetup('epanetmsx','epanetmsx.h'); 18 | 19 | %libisloaded('epanetmsx')% returns 1 =true 20 | %libfunctions('epanetmsx', '-full')%shows libaryfunction loaded 21 | 22 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 23 | exist('onepipetest.inp')% returns 2 24 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 25 | exist('MSXtest.msx')% returns 2 26 | 27 | %call ENopen 28 | [errcode] = ENopen('Net2.inp', 'test.rpt', ''); 29 | % Open the MSX toolkit 30 | 31 | %[errcode] = MSXopen('MSXtest.msx'); 32 | [errcode] = MSXopen('net2-cl2.msx'); 33 | %[errcode,errmsg] = MSXgeterror(501,80); 34 | 35 | 36 | % Hydraulic analysis 37 | [errcode] = MSXsolveH(); 38 | [errcode]= ENsaveH(); 39 | [errcode] = ENsavehydfile('test.hyd'); 40 | 41 | [errcode] = MSXusehydfile('test.hyd'); 42 | 43 | [errcode] = MSXsolveQ(); 44 | [errcode] = MSXsaveoutfile('test.bin'); 45 | 46 | 47 | [errcode] = MSXaddpattern('testpat'); 48 | multi = [0.1 0.1 1 1 1]; 49 | len = 5; 50 | [errcode, index] = MSXgetindex(MSX_CONSTANT.MSX_PATTERN,'testpat'); 51 | [errcode] = MSXsetpattern(index, multi, len) 52 | [errcode, index] = MSXgetindex(MSX_CONSTANT.MSX_PATTERN,'testpat'); 53 | period = 1; 54 | [errcode, value] = MSXgetpatternvalue(index,period); 55 | 56 | node = 1; 57 | spec=1; 58 | [errcode,type, level, pat] = MSXgetsource(node,spec); 59 | type = 0; 60 | level=0.2; 61 | pat = 1; 62 | [errcode] = MSXsetsource(node,spec,type, level, pat); 63 | [errcode,type, level, pat] = MSXgetsource(node,spec); 64 | patindex =1; 65 | [errcode,patlen] = MSXgetpatternlen(pat); 66 | 67 | [errcode, value] = MSXgetpatternvalue(patindex,period); 68 | value = 0.3; 69 | [errcode] = MSXsetpatternvalue(patindex, period, value); 70 | [errcode, value] = MSXgetpatternvalue(patindex,period); 71 | 72 | [errcode, index] = MSXgetindex(MSX_CONSTANT.MSX_SPECIES,'CL2'); 73 | [errcode, len] = MSXgetIDlen(MSX_CONSTANT.MSX_SPECIES,index); 74 | [errcode, id] = MSXgetID(MSX_CONSTANT.MSX_SPECIES,index,len); 75 | 76 | index = 1; 77 | [errcode, value] = MSXgetconstant(index); 78 | value = value+10; 79 | [errcode] = MSXsetconstant(index, value); 80 | [errcode, value] = MSXgetconstant(index); 81 | 82 | 83 | type=MSX_CONSTANT.MSX_LINK; 84 | index =1; 85 | param = 1; 86 | [errcode, value] = MSXgetparameter(type,index,param); 87 | value = 3; 88 | [errcode] = MSXsetparameter(type, index, param, value); 89 | [errcode, value] = MSXgetparameter(type,index,param); 90 | 91 | species = 1; 92 | [errcode, value] = MSXgetqual(type,index,species); 93 | [errcode, value] = MSXgetinitqual(type,index,species); 94 | value = value+3; 95 | [errcode] = MSXsetinitqual(type,index,species,value); 96 | [errcode, value] = MSXgetinitqual(type,index,species); 97 | 98 | [errcode, type, units, atol, rtol] = MSXgetspecies(index); 99 | [errcode,count] = MSXgetcount(MSX_CONSTANT.MSX_SPECIES); 100 | 101 | [errcode,errmsg] = MSXgeterror(501,80); 102 | 103 | [errcode] = MSXsavemsxfile('msxsavedtest.msx'); 104 | [errcode] = MSXreport(); 105 | MSXclose(); 106 | 107 | [errcode] = MSXopen('net2-cl2.msx'); 108 | [errcode] = MSXusehydfile('test.hyd'); 109 | [errcode] = MSXinit(0); 110 | tleft=1; 111 | while (tleft > 0 && errcode == 0) 112 | [errcode, t, tleft] = MSXstep(); 113 | 114 | % Use MSXgetqual to retrieve results at time t 115 | [errcode, value] = MSXgetqual(MSX_CONSTANT.MSX_NODE,1,1); 116 | [errcode, value] = MSXgetqual(MSX_CONSTANT.MSX_LINK,1,1); 117 | 118 | end 119 | 120 | [errcode] = MSXreport(); 121 | 122 | 123 | % close the toolkits 124 | 125 | MSXclose(); 126 | ENclose(); 127 | 128 | ENMatlabCleanup(); 129 | MSXMatlabCleanup(); 130 | -------------------------------------------------------------------------------- /Test/example.m: -------------------------------------------------------------------------------- 1 | function example(msxfn,inpfn,rptfn) 2 | % Declaration: 3 | % MSXexample 4 | %Description: 5 | % This example uses the network file Net2.inp and the msx file net2-cl2.msx 6 | % (distributed with the MSX toolkit as example 2) 7 | % to plot the CL2 data of node 1, linke 1, node 17 and link 17. 8 | %=============================================================== 9 | global EN_CONSTANT 10 | global MSX_CONSTANT 11 | %global 12 | %global 13 | 14 | if nargin < 2 15 | msxfn ='net2-cl2.msx' 16 | end; 17 | if nargin < 1 18 | inpfn = 'Net2.inp' 19 | end; 20 | if nargin < 3 21 | [pathstr, name, ext, versn] = fileparts(msxfn); 22 | rptfn =[name,'.rpt']; 23 | end; 24 | [pathstr, name, ext, versn] = fileparts(msxfn); 25 | hydrfn = [name,'.hyd']; 26 | 27 | %start epanet 28 | %exist('epanet2.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 29 | %exist('epanet2.h')%return 2 30 | ENMatlabSetup('epanet2','epanet2.h');% seems to work 31 | %check with 32 | %libisloaded('epanet2')% returns 1 =true 33 | %libfunctions('epanet2', '-full')%shows libaryfunction loaded 34 | 35 | %start MSX 36 | %exist('epanetmsx.dll')%returns 3 MEX-file on MATLAB's search path seems to be right 37 | %exist('epanetmsx.h') 38 | %open MSX 39 | MSXMatlabSetup('epanetmsx','epanetmsx.h'); 40 | %libisloaded('epanetmsx')% returns 1 =true 41 | %libfunctions('epanetmsx', '-full')%shows libaryfunction loaded 42 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 43 | %exist('net3-bio.inp')% returns 2 44 | %export Epanet inp file (network) example network Net1.net in order to use ENopen: 45 | %exist('net3-bio.msx')% returns 2 46 | 47 | %open hydraulic network 48 | [errcode] = ENopen(inpfn, rptfn, ''); 49 | 50 | % Open the MSX toolkit 51 | [errcode] = MSXopen(msxfn); 52 | 53 | 54 | % Hydraulic analysis 55 | [errcode] = MSXsolveH(); 56 | [errcode]= ENsaveH(); 57 | [errcode]= ENsavehydfile(hydrfn); 58 | 59 | [errcode] = MSXusehydfile(hydrfn); 60 | 61 | % Solve WQ in stepwize fashion 62 | [errcode,speccnt] = MSXgetcount(MSX_CONSTANT.MSX_SPECIES); 63 | 64 | tleft = 1; 65 | i = 1; 66 | MSXinit(1); 67 | while (tleft > 0 && errcode == 0) 68 | [errcode, t, tleft] = MSXstep(); 69 | % Use MSXgetqual to retrieve results at time t 70 | %collect Pb data 71 | [errcode, bnvalue] = MSXgetqual(MSX_CONSTANT.MSX_NODE,1,1); 72 | CL2n1v(i)= bnvalue; 73 | [errcode, blvalue] = MSXgetqual(MSX_CONSTANT.MSX_LINK,1,1); 74 | CL2l1v(i)= blvalue; 75 | [errcode, bnvalue] = MSXgetqual(MSX_CONSTANT.MSX_NODE,17,1); 76 | CL2n17v(i)= bnvalue; 77 | [errcode, blvalue] = MSXgetqual(MSX_CONSTANT.MSX_LINK,17,1); 78 | CL2l17v(i)= blvalue; 79 | tspan(i) = t; 80 | i=i+1; 81 | end 82 | %plot results 83 | %tspan = [0 :stepsize: t-1]; 84 | figure 85 | %subplot of bulk concentration node 1 index 1??? 86 | subplot(2,1,1) 87 | plot(tspan,CL2n1v); 88 | title({'Node 1'}); 89 | ylabel('CL2 at Node 1'); 90 | xlabel('time'); 91 | %subplot of bulk concentration link 1 index1 ??? 92 | subplot(2,1,2) 93 | plot(tspan,CL2l1v); 94 | title('Link 1'); 95 | ylabel('CL2 in Link 1'); 96 | xlabel('time'); 97 | 98 | figure 99 | %subplot of bulk concentration node 1 index 1??? 100 | subplot(2,1,1) 101 | plot(tspan,CL2n17v); 102 | title({'Node 17'}); 103 | ylabel('CL2 in Node 17'); 104 | xlabel('time'); 105 | %subplot of bulk concentration link 1 index1 ??? 106 | subplot(2,1,2) 107 | plot(tspan,CL2l17v); 108 | title('Link 17'); 109 | ylabel('CL2 in Link 17'); 110 | xlabel('time'); 111 | [errcode] = MSXreport(); 112 | MSXclose(); 113 | ENclose(); 114 | 115 | ENMatlabCleanup(); 116 | MSXMatlabCleanup(); -------------------------------------------------------------------------------- /Test/net2-cl2.msx: -------------------------------------------------------------------------------- 1 | [TITLE] 2 | NET2 Chlorine Example 3 | 4 | 5 | [OPTIONS] 6 | AREA_UNITS FT2 7 | RATE_UNITS DAY 8 | SOLVER EUL 9 | TIMESTEP 3600 10 | RTOL 0.001 11 | ATOL 0.001 12 | 13 | 14 | [SPECIES] 15 | BULK CL2 MG 0.01 0.001 16 | 17 | 18 | [COEFFICIENTS] 19 | PARAMETER Kb 0.3 20 | PARAMETER Kw 1.0 21 | 22 | 23 | [TERMS] 24 | Kf 1.5826e-4 * RE^0.88 / D 25 | 26 | [PIPE] 27 | RATE CL2 -Kb*CL2 - (4/D)*Kw*Kf/(Kw+Kf)*CL2 28 | 29 | 30 | [TANK] 31 | RATE CL2 -Kb*CL2 32 | 33 | [SOURCES] 34 | ;CONC/MASS/FLOW/SETPOINT () 35 | CONC 1 CL2 0.8 36 | 37 | 38 | [QUALITY] 39 | GLOBAL CL2 0.5 40 | NODE 26 CL2 0.1 41 | 42 | [PARAMETERS] 43 | ;PIPE 44 | ;TANK 45 | 46 | [REPORT] 47 | NODES 2 20 23 26 48 | SPECIE CL2 YES 49 | -------------------------------------------------------------------------------- /Utils/NetworkFrame.m: -------------------------------------------------------------------------------- 1 | function [NData,fig] = NetworkFrame(fig,vdata,ldata,InpFname,... 2 | PData,SData,NData) 3 | % 4 | % NetworkFrame plots a static frame of a network graph described in Epanet 5 | % input format, with nodes and/or links colored using the values in vdata 6 | % and ldata. On first call for a given network, the line and node objects 7 | % are rendered, and the object handles stored so that subsequent calls are 8 | % more efficient (e.g., for generating movie frames recording simulation 9 | % results). 10 | % 11 | % Arguments 12 | % 13 | % fig 14 | % handle for existing figure, or [] for new figure. 15 | % vdata 16 | % vector of values used to color nodes, in Epanet node index 17 | % order. Length of vdata must be the number of nodes for the 18 | % network. If vdata = [] then nodes are not colored (black). 19 | % (note: the PData 'vsize' parameter can be set to zero, in which 20 | % case nodes will not be shown -- see below). 21 | % ldata 22 | % vector of values used to color links, in Epanet link index 23 | % order. Length of ldata must be the number of links for the 24 | % network. If ldata = [] then links are colored as the average 25 | % of their adjacent node values. 26 | % InpFname 27 | % String containing name of Epanet format input file describing 28 | % the network geometry. 29 | % PData 30 | % A structure containing information used for plotting, processed 31 | % during the first call for a given network (and ignored for 32 | % subsequent calls for the same network). May be set to [] to 33 | % accept all defaults (described below), or values may be 34 | % specified for one or more of the following members. 35 | % 36 | % c - colormap used to color nodes and links, as described for 37 | % function colormap(). Default is 'jet'. See 'doc colormap' for 38 | % more information about colormaps supplied with Matlab. 39 | % 40 | % logtransv - 'y' or 'n' to log10 transform the data in vdata 41 | % prior to plotting. Default is to leave data untransformed 42 | % ('n'). 43 | % 44 | % vmin,vmax - Minimum and maximum values of vdata that will be 45 | % colored - others are black. Default is vmin=min(vdata) and 46 | % vmax=max(vdata), for the node values vdata specified on first 47 | % call for a given network. 48 | % 49 | % logtransl - 'y' or 'n' to log10 transform the data in ldata 50 | % prior to plotting. Default is to leave data untransformed 51 | % ('n'). 52 | % 53 | % lmin,lmax - Minimum and maximum values of ldata that will be 54 | % colored - others are black. Default is lmin=min(ldata) and 55 | % lmax=max(ldata), for the link values ldata specified on first 56 | % call for a given network. 57 | % 58 | % lwidth - link line width, in points. Default is lwidth=3 pts. 59 | % 60 | % vsize - node size, in points. Set to zero to hide all junction 61 | % nodes and plot only links. Default is vsize=4 pts. 62 | % 63 | % tsize - tank node size, in points. Set to zero to hide tank 64 | % and reservoir nodes. Default is tsize=4 pts. 65 | % 66 | % legend - 'l', 'v', or 'n' to add a link colorbar legend on the 67 | % right side of the plot ('l'), a vertex node colorbar legend 68 | % ('v'), or no legend ('n'). Default is to exclude the legend 69 | % ('n'). 70 | % 71 | % DLLname - String containing name of Epanet DLL. Default is 72 | % 'epanet2'. 73 | % 74 | % Hname - String containing name of Epanet C header file. 75 | % Default is 'epanet2.h'. 76 | % SData 77 | % A structure array containing information used to annotate the 78 | % network nodes with symbols. Set to [] if the network is not 79 | % annotated. Valid members are as follows; all must be the same 80 | % length and corresponding entries describe the various 81 | % attributes describing the node symbols to be plotted: 82 | % 83 | % SData(i).ivs - 84 | % ith Node ID to annotate with symbols. 85 | % 86 | % SData(i).vsmarker - 87 | % Marker symbols corresponding to the node IDs defined in 88 | % SData(:).ivs. 89 | % 90 | % SData(i).vsmarkersize - 91 | % Marker symbol sizes corresponding to the node IDs defined in 92 | % SData(:).ivs. 93 | % 94 | % SData(i).vsmarkercolor - 95 | % Marker symbol colors corresponding to the node IDs defined in 96 | % SData(:).ivs. 97 | % Ndata 98 | % A structure containing various network data, set to [] on the 99 | % first use of NetworkFrame for a particular network, and 100 | % preserved across successive calls to NetworkFrame for the same 101 | % network (e.g., when using NetworkFrame to draw successive 102 | % frames in a movie using the same network but different node 103 | % values). NData should not be modified between successive 104 | % calls. 105 | % 106 | % 107 | % Jim Uber 108 | % 8/15/2005 109 | % modified 4/10/2009 110 | 111 | global EN_SIZE; 112 | 113 | if isempty(fig) 114 | fig=figure; 115 | axis equal; 116 | axis off; 117 | % set(fig,'Color',[0 0 0]); 118 | else 119 | figure(fig); 120 | end 121 | 122 | % Initial processing (first use only for a given network) 123 | if isempty(NData) 124 | % Default Plot Parameters 125 | NData.c = 'default'; 126 | NData.logtransv = 'n'; 127 | NData.logtransl = 'n'; 128 | NData.vmin = min(vdata); 129 | NData.vmax = max(vdata); 130 | NData.lmin = min(ldata); 131 | NData.lmax = max(ldata); 132 | NData.lwidth = 3; 133 | NData.vsize = 4; 134 | NData.tsize = 4; 135 | NData.legend = 'n'; 136 | NData.DLLname = 'epanet2'; 137 | NData.Hname = 'epanet2.h'; 138 | 139 | % User-specified Plot Parameters 140 | if isfield(PData,'c') NData.c = PData.c; end 141 | if isfield(PData,'logtransv') NData.logtransv = PData.logtransv; end 142 | if isfield(PData,'logtransl') NData.logtransl = PData.logtransl; end 143 | if isfield(PData,'vmin') NData.vmin = PData.vmin; end 144 | if isfield(PData,'vmax') NData.vmax = PData.vmax; end 145 | if isfield(PData,'lmin') NData.lmin = PData.lmin; end 146 | if isfield(PData,'lmax') NData.lmax = PData.lmax; end 147 | if isfield(PData,'lwidth') NData.lwidth = PData.lwidth; end 148 | if isfield(PData,'vsize') NData.vsize = PData.vsize; end 149 | if isfield(PData,'tsize') NData.tsize = PData.tsize; end 150 | if isfield(PData,'legend') NData.legend = PData.legend; end 151 | if isfield(PData,'DLLname') NData.DLLName = PData.DLLName; end 152 | if isfield(PData,'Hname') NData.Hname = PData.Hname; end 153 | 154 | % Colormaps 155 | colormap(NData.c); 156 | NData.cmap = colormap; 157 | 158 | % Open Epanet 159 | [errcode] = ENMatlabSetup(NData.DLLname,NData.Hname); 160 | if errcode ~=0 return; end 161 | [errcode] = ENopen(InpFname,'epanet.rpt',''); 162 | if errcode ~= 0 return; end 163 | 164 | % Network Size 165 | NData.nnodes = EN_SIZE.nnodes; 166 | NData.nlinks = EN_SIZE.nlinks; 167 | 168 | % Network topology 169 | [errcode,NData.from,NData.to] = ENgetalllinknodes(); 170 | if errcode ~= 0 return; end 171 | [errcode,Itank,Ijunc] = categorizeNodes(NData.nnodes); 172 | if errcode ~= 0 return; end 173 | 174 | % Node indices for extra node symbol IDs 175 | if ~isempty(SData) 176 | Sindex=zeros(length(SData),1); 177 | for i=1:length(SData) 178 | [errcode,Sindex(i)] = ENgetnodeindex(SData(i).ivs); 179 | if errcode ~= 0 return; end 180 | end 181 | end 182 | 183 | % Close Epanet 184 | [errcode] = ENclose(); 185 | if errcode ~= 0 return; end 186 | ENMatlabCleanup(); 187 | 188 | % Network Geometry (from processing text InpFname) 189 | [errcode,vx,vy,vertx,verty] = getNodeXY(InpFname,NData.DLLname,NData.Hname); 190 | if errcode ~= 0 return; end 191 | 192 | % Link handles 193 | x(1,:) = vx(NData.from); 194 | x(2,:) = vx(NData.to); 195 | y(1,:) = vy(NData.from); 196 | y(2,:) = vy(NData.to); 197 | for i=1:NData.nlinks 198 | NData.linkh(i) = ... 199 | line([x(1,i) vertx{i} x(2,i)],[y(1,i) verty{i} y(2,i)],'LineWidth',NData.lwidth); 200 | end 201 | 202 | % Node handles 203 | if NData.vsize > 0 204 | NData.nodeh=zeros(NData.nnodes,1); 205 | for i=1:NData.nnodes 206 | NData.nodeh(i)=line(vx(i),vy(i),'Marker','o','MarkerSize',NData.vsize); 207 | end 208 | NData.nodeh = NData.nodeh'; 209 | pval = cell(size(NData.nodeh(Itank)))'; 210 | pname(1)={'Marker'}; 211 | pname(2)={'MarkerSize'}; 212 | pval(:,1) = {'s'}; 213 | pval(:,2) = {NData.tsize}; 214 | set(NData.nodeh(Itank),pname,pval); 215 | end 216 | 217 | % Add colorbar legend 218 | if NData.legend~='n' 219 | logtrans='n'; 220 | if NData.legend=='l' 221 | minval=NData.lmin; 222 | maxval=NData.lmax; 223 | if NData.logtransl=='y' 224 | minval=log10(minval); 225 | maxval=log10(maxval); 226 | logtrans='y'; 227 | end 228 | else 229 | minval=NData.vmin; 230 | maxval=NData.vmax; 231 | if NData.logtransv=='y' 232 | minval=log10(minval); 233 | maxval=log10(maxval); 234 | logtrans='y'; 235 | end 236 | end 237 | % Right hand side legend 238 | NData.hvc = colorbar('EastOutside'); 239 | [mapsize,n] = size(NData.cmap); 240 | ytick = [1: floor(mapsize/4) : mapsize]; % ytick holds the colormap positions to label 241 | [m,ticksize] = size(ytick); 242 | if ytick(ticksize) ~= mapsize 243 | ticksize = ticksize + 1; 244 | ytick(ticksize) = mapsize; 245 | end 246 | dv = (maxval - minval)/mapsize; 247 | labelvalue = minval + (ytick - 1)*dv; 248 | labelstring = num2str( labelvalue', 3 ); 249 | ylab = {labelstring}; 250 | set(NData.hvc,'YTick',ytick); 251 | set(NData.hvc,'YTickLabel',ylab'); 252 | end 253 | 254 | % Extra node symbols 255 | NData.snodeh=[]; 256 | if ~isempty(SData) 257 | for i=1:length(Sindex) 258 | NData.snodeh(i)=line(vx(Sindex(i)),vy(Sindex(i)),'Marker',SData(i).vsmarker,... 259 | 'MarkerSize',SData(i).vsmarkersize,... 260 | 'MarkerFaceColor',SData(i).vsmarkercolor,... 261 | 'MarkerEdgeColor',SData(i).vsmarkercolor); 262 | end 263 | end 264 | 265 | end 266 | 267 | % Check node and link colors 268 | colornodes = false; 269 | if ~isempty(vdata) 270 | colornodes = true; 271 | [m,n]=size(vdata); 272 | if n==1 273 | vdata=vdata'; 274 | end 275 | if m*n ~= NData.nnodes 276 | disp 'vdata must be a vector of length equal to the number of nodes' 277 | return 278 | end 279 | end 280 | colorlinks = false; 281 | if ~isempty(ldata) 282 | colorlinks = true; 283 | [m,n]=size(ldata); 284 | if n==1 285 | ldata=ldata'; 286 | end 287 | if m*n ~= NData.nlinks 288 | disp 'ldata must be a vector of length equal to the number of links' 289 | return 290 | end 291 | end 292 | 293 | % Compute indices of nodes and links to color 294 | vmin = NData.vmin; 295 | vmax = NData.vmax; 296 | Ivmin = vdatavmax; 298 | Ivcolor = vdata>=vmin & vdata<=vmax; 299 | lmin = NData.lmin; 300 | lmax = NData.lmax; 301 | Ilmin = ldatalmax; 303 | Ilcolor = ldata>=lmin & ldata<=lmax; 304 | 305 | % Transformation 306 | if colornodes 307 | if NData.logtransv == 'y' 308 | vmin = log10(vmin); 309 | vmax = log10(vmax); 310 | vdata(Ivmin) = vmin; 311 | vdata(Ivmax) = vmax; 312 | vdata(Ivcolor) = log10(vdata(Ivcolor)); 313 | else 314 | vdata(Ivmin) = vmin; 315 | vdata(Ivmax) = vmax; 316 | end 317 | end 318 | if colorlinks 319 | if NData.logtransl == 'y' 320 | lmin = log10(lmin); 321 | lmax = log10(lmax); 322 | ldata(Ilmin) = lmin; 323 | ldata(Ilmax) = lmax; 324 | ldata(Ilcolor) = log10(ldata(Ilcolor)); 325 | else 326 | ldata(Ilmin) = lmin; 327 | ldata(Ilmax) = lmax; 328 | end 329 | end 330 | 331 | % COLOR LINKS 332 | if colorlinks % color by link data 333 | rgb = color(NData.cmap,ldata,lmin,lmax); % Return the color from the map 334 | rgb(~Ilcolor,:) = rgb(~Ilcolor,:)*0; % These links are black 335 | set(NData.linkh,{'Color'},num2cell(rgb,2)); 336 | elseif colornodes % color by adjacent node data 337 | vavg = (vdata(NData.from) + vdata(NData.to))/2; % Average value of adjacent nodes 338 | rgb = color(NData.cmap,vavg,vmin,vmax); % Return the color from the map 339 | Ilcolor = Ivcolor(NData.from)==1 & Ivcolor(NData.to)==1; 340 | rgb(~Ilcolor,:) = rgb(~Ilcolor,:)*0; % These links are black 341 | set(NData.linkh,{'Color'},num2cell(rgb,2)); 342 | end 343 | 344 | % COLOR JUNCTIONS 345 | if NData.vsize > 0 346 | if colornodes 347 | rgb = color(NData.cmap,vdata,vmin,vmax); % Return the color from the map 348 | rgb(~Ivcolor,:) = rgb(~Ivcolor,:)*0; % nodes are black if no color 349 | set(NData.nodeh,{'MarkerFaceColor'},num2cell(rgb,2),{'MarkerEdgeColor'},num2cell(rgb,2)); 350 | else 351 | rgb = zeros(NData.nnodes,3); % nodes are black if no color 352 | set(NData.nodeh,{'MarkerFaceColor'},num2cell(rgb,2),{'MarkerEdgeColor'},num2cell(rgb,2)); 353 | end 354 | end 355 | 356 | for i=1:length(NData.snodeh) 357 | set(NData.snodeh(i),'Marker',SData(i).vsmarker,... 358 | 'MarkerSize',SData(i).vsmarkersize,... 359 | 'MarkerFaceColor',SData(i).vsmarkercolor,... 360 | 'MarkerEdgeColor',SData(i).vsmarkercolor); 361 | end 362 | -------------------------------------------------------------------------------- /Utils/NetworkMovie.m: -------------------------------------------------------------------------------- 1 | function [] = NetworkMovie(V,L,fig,movfname,quality,fps,InpFname,... 2 | PData,SData) 3 | %% Synopsis 4 | % NetworkMovie uses NetworkFrame() to plot the network graph on figure 5 | % handle fig with nodes and links colored by V,L, and store the animation 6 | % as an *.avi movie. For detailed descriptions of the PData and SData 7 | % arguments, see NetworkFrame(). 8 | % 9 | % After the first frame is plotted (using NetworkFrame()), control is 10 | % passed to the standard input, and during this time you can use the 11 | % standard Matlab figure UI controls to modify the figure view as you 12 | % desire (e.g., zoom, pan). After the network view is how you want it, the 13 | % rest of the frames are generated consistent with that view. 14 | % 15 | %% Helpful Notes: 16 | % * Do not move or obscure the figure window after you position it 17 | % and the figure within, when the movie frames are 18 | % being rendered. Otherwise you will have whatever junk covers the figure 19 | % window in your movie. If you actually resize the figure window once the 20 | % movie frames are being rendered, you'll get an error message. 21 | % * To increase your resolution try increasing the physical size of the 22 | % figure window. Remember that what you see will be what you get. 23 | % * If a problem occurs when rendering the frames then Matlab seems to 24 | % stubbornly hang onto the *.avi movie file handle despite, for example, 25 | % issuing fclose('all'). The fix is 'clear all' and then you'll be able to 26 | % either delete or rewrite the same *.avi filename without shutting down 27 | % matlab first. 28 | % * The exampleMovie.m (or exampleMovie.html) code shows a complete example 29 | % of how to create a movie of Epanet or MSX simulation data, and for 30 | % standard use you should be able to modify some of those parameters for 31 | % your application. 32 | % 33 | %% Arguments 34 | % V (nnodes x nframes) matrix of node values to plot 35 | % L (nlinks x nframes) matrix of link values to plot 36 | % Either of V or L can be blank, in which case behavior is as 37 | % described in NetworkFrame(). 38 | % fig Existing figure handle to use. If [] then new figure is 39 | % created. 40 | % movfname AVI filename to store movie. If [] then no movie is made, 41 | % but the animation is displayed. 42 | % quality 0-100 quality of AVI movie 43 | % fps frames per second of AVI movie 44 | % InpFname Epanet input file name describing network geometry. 45 | % PData PData structure of plot options as described in 46 | % NetworkFrame(). 47 | % SData SData structure of plot symbols as described in 48 | % NetworkFrame(). 49 | % 50 | % Jim Uber 51 | % 8/15/2005 52 | % 4/10/2009 modified 53 | 54 | nframes = 0; 55 | if isempty(V) 56 | colorV=false; 57 | else 58 | colorV=true; 59 | nframes = length(V(1,:)); 60 | end 61 | if isempty(L) 62 | colorL=false; 63 | else 64 | colorL=true; 65 | nframes = length(L(1,:)); 66 | end 67 | 68 | if colorV && colorL 69 | if length(V(1,:)) ~= length(L(1,:)) 70 | disp 'Number of frames in V and L must agree.' 71 | return 72 | end 73 | end 74 | 75 | makeavi = ~isempty(movfname); 76 | 77 | % Figure props 78 | if isempty(fig) 79 | fig=figure; 80 | axis equal; 81 | axis off; 82 | % set(fig,'Color',[0 0 0]); 83 | else 84 | figure(fig); 85 | end 86 | if makeavi 87 | mov = avifile(movfname,'quality',quality,'fps',fps,'compression','Cinepak'); 88 | end 89 | 90 | % Draw the first frame and stop to allow user adjustment of figure window 91 | v = []; 92 | l = []; 93 | if colorV, v=V(:,1); end 94 | if colorL, l=L(:,1); end 95 | [NData,fig] = NetworkFrame(fig,v,l,InpFname,PData,SData,[]); 96 | disp 'Adjust figure window properties as desired, and press any key to continue' 97 | pause; 98 | if makeavi 99 | M=getframe(fig); 100 | mov = addframe(mov,M); 101 | else 102 | drawnow; 103 | end 104 | 105 | % Draw the rest 106 | for i=2:nframes 107 | if colorV, v=V(:,i); end 108 | if colorL, l=L(:,i); end 109 | [NData,fig] = NetworkFrame(fig,v,l,InpFname,PData,SData,NData); 110 | if makeavi 111 | M=getframe(fig); 112 | mov = addframe(mov,M); 113 | else 114 | drawnow; 115 | end 116 | end 117 | 118 | if makeavi 119 | mov = close(mov); 120 | end 121 | -------------------------------------------------------------------------------- /Utils/Readme.txt: -------------------------------------------------------------------------------- 1 | This directory contains various Matlab routines that add 2 | additional capabilities to the standard Epanet and Epanet-MSX 3 | toolkits. Documentation on usage of these routines are included 4 | in the code preambles. 5 | 6 | The utilities available include: 7 | 8 | NetworkFrame 9 | 10 | Plots a static frame of a network graph described in Epanet 11 | input format, with nodes and/or links colored using specified 12 | values. On first call for a given network, the line and node 13 | objects are rendered, and the object handles stored so that 14 | subsequent calls are more efficient (e.g., for generating movie 15 | frames recording simulation results). 16 | 17 | NetworkMovie 18 | 19 | Uses NetworkFrame() to plot frames of the network graph with 20 | nodes and links colored by the columns of matrices V and L. The 21 | resulting animation is stored as an *.avi movie. 22 | 23 | getQualityData 24 | Epanet or Epanet-MSX Matlab application to run a simulation and return 25 | quality results 26 | 27 | exampleMovie 28 | 29 | Example to illustrate the use of NetworkMovie and NetworkFrame 30 | to animate either a specified bulk or wall specie, or both, for 31 | an Epanet/MSX simulation, and store the result as an *.avi 32 | movie 33 | -------------------------------------------------------------------------------- /Utils/categorizeNodes.m: -------------------------------------------------------------------------------- 1 | function [errcode,Itank,Ijunc] = categorizeNodes(nnodes) 2 | % Constructs binary arrays Itank and Ijunc that record whether or not each 3 | % node is a tank node or a junction node. 4 | global EN_CONSTANT; 5 | 6 | Itank = false(nnodes,1); 7 | Ijunc = false(nnodes,1); 8 | for i=1:nnodes 9 | [errcode, type] = ENgetnodetype(i); 10 | if errcode return; end 11 | if type == EN_CONSTANT.EN_JUNCTION 12 | Ijunc(i) = true; 13 | else 14 | Itank(i) = true; 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /Utils/color.m: -------------------------------------------------------------------------------- 1 | function [rgb] = color(cmap,v,vmin,vmax) 2 | 3 | [m,n] = size(cmap); % m is the number of colors in map 4 | dv = (vmax-vmin)/m; % Divide interval into m bins 5 | if dv > 0 % Select the bin index where v falls 6 | i = max(ceil((v-vmin)/dv), 1); 7 | rgb = cmap(i,:); % Return the color from the map 8 | else 9 | rgb = cmap(ones(size(v)),:); 10 | end 11 | 12 | -------------------------------------------------------------------------------- /Utils/exampleMovie.m: -------------------------------------------------------------------------------- 1 | %% How to Make an AVI Movie of Your EPANET or EPANET-MSX Simulation 2 | %% Synopsis 3 | % This example illustrates the use of NetworkMovie and NetworkFrame to 4 | % animate either a bulk or wall specie, or both, for an Epanet/MSX 5 | % simulation, and store the result as an *.avi movie 6 | % 7 | % Note that the EPANET and MSX Matlab wrappers must be on your Matlab 8 | % search path. Matlab will also need to be able to find the epanet and 9 | % epanet-msx object libraries and header files. 10 | %% Get the Epanet-MSX Simulation Data 11 | % This example uses the Net2.inp and net2-cl2.msx data files located in 12 | % http://engcvs.uc.edu/repos/EPANET/MATLAB/trunk/src/Test. Note that an 13 | % ordinary Epanet simulation can also be used, in which case msxFname='' 14 | % (see getQualityData for details). 15 | msxFname = '../Test/net2-cl2.msx'; 16 | inpFname = '../Test/Net2.inp'; 17 | % Animate the bulk chlorine specie 18 | bulkSpecieID = 'CL2'; 19 | % There is no wall specie 20 | wallSpecieID = ''; 21 | % Get the simulation data using Epanet or Epanet-MSX 22 | [V,L,T,errcode] = getQualityData(bulkSpecieID,wallSpecieID,... 23 | msxFname,inpFname); 24 | if errcode > 100 25 | disp 'Error in network water quality computations' 26 | return 27 | end 28 | %% Specify Movie Parameters 29 | % These parameters are described in NetworkFrame()... 30 | fig = []; % Use a new figure window 31 | movFname = 'mymovie.avi'; % Movie file name 32 | quality = 100; % 0-100 movie quality (related to data compression) 33 | fps = 8; % Frame rate - # to display per second 34 | PData.c = 'jet'; % colormap - see 'help colormap' 35 | PData.logtransv = 'n'; % Do not log transform the data 36 | PData.vmin = 0; % min vertex value for plot color mapping 37 | PData.vmax = max(max(V)); % max vertex value 38 | % PData.logtransl = 'n'; % We're not plotting link data so these are ignored 39 | % PData.lmin = min(min(L)); 40 | % PData.lmax = max(max(L)); 41 | PData.lwidth = 3; % Width of links in points 42 | PData.vsize = 4; % Size of vertices in points (0 == omits verts) 43 | PData.tsize = 4; % Size of tank/reservoir nodes 44 | PData.legend = 'v'; % Show a colorbar legend for vertex data 45 | SData = []; % No special node symbols 46 | % SData(1...).ivs = []; % Node IDs to annotate with special symbols 47 | % SData(1...).vsmarker = []; % Marker symbols 48 | % SData(1...).vsmarkersize = []; % Marker symbol sizes 49 | % SData(1...).vsmarkercolor = []; % Marker symbol colors 50 | 51 | %% Write the Movie File 52 | % NetworkMovie will display the first frame in a figure window and allow 53 | % you to make adjustments to it (zoom, pan, etc.) before rendering the 54 | % frames into an AVI movie file. 55 | NetworkMovie(V,L,fig,movFname,quality,fps,inpFname,PData,SData); 56 | %% Show the Movie 57 | % You could display the movie in Matlab as follows, or just use 58 | % an external viewer... 59 | 60 | % mov = aviread(movFname); 61 | % h = figure; 62 | % axis equal; 63 | % movie(h,mov); 64 | -------------------------------------------------------------------------------- /Utils/getHydraulicData.m: -------------------------------------------------------------------------------- 1 | %% Function getHydraulicData 2 | function [V,L,T,errcode] = getHydraulicData(NodeType,LinkType,inpFname) 3 | %% Synopsis 4 | % [V,L,T,errcode] = getHydraulicData(NodeType,LinkType,inpFname) Returns 5 | % vertex (V) and link (L) data from running an Epanet hydraulic 6 | % simulation defined by the input file inpFname. The return value of V 7 | % contains the node data of type NodeType, while L contains the link data 8 | % of type LinkType. NodeType and LinkType are character strings as 9 | % defined in the Epanet toolkit documentation (i.e. 'EN_...'). The 10 | % ordering in V and/or L is node and/or link index order. The output 11 | % vector T contains the simulation times (in seconds) associated with 12 | % each frame. If either of NodeType or LinkType are undefined then V or 13 | % L will be empty. 14 | % 15 | % errcode = 0 if Epanet simulation completes normally; otherwise an error 16 | % message is printed and errcode > 0 corresponds to an Epanet error code. 17 | % 18 | % If defined, the output matrices V, L, and T are (nnodes x nframes), 19 | % (nlinks x nframes), and (nframes x 1) respectively. The value of 20 | % nframes is defined by the values of REPORT START and REPORT STEP in the 21 | % Epanet input file. Specifically, frames are stored only when Epanet 22 | % simulation time t satisfies: (t >= REPORT_START && mod(t,REPORT_STEP) 23 | % == 0). 24 | %% Global Declarations 25 | % defined for MATLAB versions of Epanet programmer's toolkits. See 26 | % ENMatlabSetup() 27 | global EN_CONSTANT 28 | global EN_SIZE 29 | %% Initialize MATLAB EPANET 30 | % Note that Matlab must be able to find the libraries epanet2.dll 31 | % or epanet2.so, and the header file epanet2.h 32 | 33 | % setup Epanet 34 | ENMatlabSetup('epanet2','epanet2.h'); 35 | 36 | % open Epanet 37 | [errcode] = ENopen(inpFname, 'epanet.rpt', ''); 38 | if errcode; return; end 39 | %% Hydraulic Analysis 40 | T = []; % The time data 41 | V = []; % The vertex data 42 | L = []; % The link data 43 | % Get the simulation time parameters 44 | [errcode, reportStart] = ENgettimeparam(EN_CONSTANT.EN_REPORTSTART); 45 | if errcode; return; end 46 | [errcode, reportStep] = ENgettimeparam(EN_CONSTANT.EN_REPORTSTEP); 47 | if errcode; return; end 48 | 49 | tleft = 1; % Time left in simulation 50 | iframe = 1; % frame index 51 | [errcode] = ENopenH(); 52 | if errcode; return; end 53 | [errcode] = ENinitH(0); 54 | if errcode; return; end 55 | while (tleft > 0 && errcode == 0) 56 | [errcode, t] = ENrunH(); 57 | 58 | if t >= reportStart && ~mod(t,reportStep) 59 | % Retrieve results at time t 60 | V = [V zeros(EN_SIZE.nnodes,1)]; 61 | for in=1:EN_SIZE.nnodes 62 | [errcode, V(in,iframe)] = ... 63 | ENgetnodevalue(in, EN_CONSTANT.(NodeType)); 64 | end 65 | L = [L zeros(EN_SIZE.nlinks,1)]; 66 | for in=1:EN_SIZE.nlinks 67 | [errcode, L(in,iframe)] = ... 68 | ENgetlinkvalue(in, EN_CONSTANT.(LinkType)); 69 | end 70 | T = [T; t]; 71 | 72 | iframe = iframe + 1; 73 | end 74 | 75 | [errcode, tleft] = ENnextH(); 76 | end 77 | [errcode] = ENcloseH(); 78 | if errcode; return; end 79 | %% Matlab Epanet cleanup 80 | ENclose(); 81 | ENMatlabCleanup(); 82 | -------------------------------------------------------------------------------- /Utils/getNodeXY.m: -------------------------------------------------------------------------------- 1 | function [errcode,vx,vy,vertx,verty] = getNodeXY(InpFname,DLLname,Hname) 2 | % Reads Epanet data file to get node coordinate info (no toolkit function 3 | % for this task). 4 | 5 | global EN_SIZE; 6 | 7 | % Copy epanet input file to temporary file 8 | tempInpFname = tempname; 9 | copyfile(InpFname,tempInpFname); 10 | 11 | % Open Epanet 12 | [errcode] = ENMatlabSetup(DLLname,Hname); 13 | if errcode ~=0 return; end 14 | [errcode] = ENopen(tempInpFname,'epanet.rpt',''); 15 | if errcode ~= 0 return; end 16 | 17 | % Initialize 18 | vx = NaN(EN_SIZE.nnodes,1); 19 | vy = NaN(EN_SIZE.nnodes,1); 20 | vertx = cell(EN_SIZE.nlinks,1); 21 | verty = cell(EN_SIZE.nlinks,1); 22 | nvert = zeros(EN_SIZE.nlinks,1); 23 | 24 | % Open epanet input file 25 | [EPANETIN,errmsg] = fopen( InpFname, 'rt' ); 26 | if EPANETIN < 0 27 | disp errmsg 28 | return 29 | end 30 | 31 | sect = 0; 32 | % Read each line from input file. 33 | while 1 34 | tline = fgetl(EPANETIN); 35 | if ~ischar(tline), break, end 36 | 37 | % Get first token in the line 38 | tok = strtok(tline); 39 | 40 | % Skip blank lines and comments 41 | if isempty(tok), continue, end 42 | if (tok(1) == ';'), continue, end 43 | 44 | % Check if at start of a new COOR or VERT section 45 | if (tok(1) == '[') 46 | % [COORDINATES] section 47 | if strcmpi(tok(1:5),'[COOR') 48 | sect = 1; 49 | continue; 50 | % [VERTICES] section 51 | elseif strcmpi(tok(1:5),'[VERT') 52 | sect = 2; 53 | continue; 54 | % [END] 55 | elseif strcmpi(tok(1:4),'[END') 56 | break; 57 | else 58 | sect = 0; 59 | continue; 60 | end 61 | end 62 | 63 | if sect == 0 64 | continue; 65 | 66 | % Coordinates 67 | elseif sect == 1 68 | A = textscan(tline,'%s %f %f'); 69 | % get the node index 70 | [errcode,index] = ENgetnodeindex(char(A{1})); 71 | if errcode ~=0 return; end 72 | vx(index) = A{2}; 73 | vy(index) = A{3}; 74 | 75 | % Vertices 76 | elseif sect == 2 77 | A = textscan(tline,'%s %f %f'); 78 | [errcode,index] = ENgetlinkindex(char(A{1})); 79 | if errcode ~=0 return; end 80 | nvert(index) = nvert(index) + 1; 81 | vertx{index}(nvert(index)) = A{2}; 82 | verty{index}(nvert(index)) = A{3}; 83 | end 84 | end 85 | 86 | % Close Epanet 87 | [errcode] = ENclose(); 88 | if errcode ~= 0 return; end 89 | ENMatlabCleanup(); 90 | 91 | % Close Epanet input file 92 | fclose(EPANETIN); 93 | -------------------------------------------------------------------------------- /Utils/getQualityData.m: -------------------------------------------------------------------------------- 1 | %% Function getQualityData 2 | function [V,L,T,errcode] = getQualityData(bulkSpecieID,wallSpecieID,... 3 | msxFname,inpFname) 4 | %% Synopsis 5 | % [V,L,T,errcode] = 6 | % getQualityData(bulkSpecieID,wallSpecieID,msxFname,inpFname) Returns 7 | % vertex (V) and link (L) data from running the Epanet or Epanet-MSX 8 | % simulation defined by the input files msxFname and inpFname. For MSX 9 | % simulations the data in V is data defined on all network vertices 10 | % (nodes) for the bulk specie ID bulkSpecieID, and L is data defined on 11 | % all network links (pipes) for the wall specie ID wallSpecieID. For an 12 | % ordinary Epanet simulation, msxFname would be a blank character string 13 | % (msxFname='') or an empty matrix (msxFname=[]). In this case both 14 | % bulkSpecieID and wallSpecieID are ignored, since Epanet does not know 15 | % about bulk or wall species; accordingly, for an ordinary Epanet 16 | % simulation, the return value of V contains the single-specie simulation 17 | % water quality data as defined in inpFname, while L=[]. For both MSX 18 | % and ordinary Epanet simulations, the ordering in V and/or L is node 19 | % and/or link index order. The output vector T contains the simulation 20 | % times (in seconds) associated with each frame. 21 | % 22 | % errcode = 0 if Epanet and Epanet-MSX simulations complete normally; 23 | % otherwise an error message is printed and errcode > 0 corresponds to an 24 | % Epanet or Epanet-MSX error code. 25 | % 26 | % If defined, the output matrices V, L, and T are (nnodex x nframes), 27 | % (nlinks x nframes), and (nframes x 1) respectively. The value of 28 | % nframes is determined differently for Epanet and Epanet-MSX 29 | % simulations: 30 | % 31 | % Epanet simulations: nframes is defined by the values of REPORT START 32 | % and REPORT STEP in the Epanet input file. Specifically, frames are 33 | % stored only when Epanet simulation time t satisfies: (t >= REPORT_START 34 | % && mod(t,REPORT_STEP) == 0). 35 | % 36 | % Epanet-MSX simulations: nframes is defined by the values of REPORT 37 | % START in the Epanet input file the value of TIMESTEP in the Epanet-MSX 38 | % input file. Specifically, frames are stored only when Epanet-MSX 39 | % simulation time t satisfies: (t >= REPORT_START && mod(t,TIMESTEP) == 40 | % 0). 41 | % 42 | %% Global Declarations 43 | % defined for MATLAB versions of Epanet and MSX programmer's toolkits. See 44 | % ENMatlabSetup() and MSXMatlabSetup() 45 | global MSX_CONSTANT 46 | global EN_CONSTANT 47 | global EN_SIZE 48 | %% Initialize MATLAB EPANET and MSX 49 | % Note that Matlab must be able to find the libraries epanet2.dll 50 | % or epanet2.so, epanetmsx.dll or epanetmsx.so, and the header files 51 | % epanet2.h and epanetmsx.h 52 | 53 | % setup Epanet 54 | ENMatlabSetup('epanet2','epanet2.h'); 55 | 56 | % open Epanet 57 | [errcode] = ENopen(inpFname, 'epanet.rpt', ''); 58 | if errcode; return; end 59 | 60 | if ~isempty(msxFname) 61 | % setup MSX 62 | MSXMatlabSetup('epanetmsx','epanetmsx.h'); 63 | 64 | % Open MSX 65 | [errcode] = MSXopen(msxFname); 66 | if errcode; return; end 67 | end 68 | 69 | %% Hydraulic and Water Quality Analyses 70 | T = []; % The output times 71 | V = []; % The vertex data 72 | L = []; % The link data 73 | if ~isempty(msxFname) 74 | % MSX simulation 75 | 76 | % Get the simulation time parameters 77 | [errcode, reportStart] = ENgettimeparam(EN_CONSTANT.EN_REPORTSTART); 78 | if errcode; return; end 79 | 80 | % Hydraulic analysis 81 | [errcode] = MSXsolveH(); 82 | if errcode; return; end 83 | 84 | % Specie information 85 | bulkSpecieIndex=0; 86 | wallSpecieIndex=0; 87 | if ~isempty(bulkSpecieID) 88 | [errcode,bulkSpecieIndex] = ... 89 | MSXgetindex(MSX_CONSTANT.MSX_SPECIES,bulkSpecieID); 90 | [errcode,bulkSpecieType,units,atol,rtol] = ... 91 | MSXgetspecies(bulkSpecieIndex); 92 | if bulkSpecieType ~= MSX_CONSTANT.MSX_BULK 93 | disp 'Specified bulk specie ID is incorrect type' 94 | return 95 | end 96 | if errcode; return; end 97 | end 98 | if ~isempty(wallSpecieID) 99 | [errcode,wallSpecieIndex] = ... 100 | MSXgetindex(MSX_CONSTANT.MSX_SPECIES,wallSpecieID); 101 | [errcode,wallSpecieType,units,atol,rtol] = ... 102 | MSXgetspecies(wallSpecieIndex); 103 | if wallSpecieType ~= MSX_CONSTANT.MSX_WALL 104 | disp 'Specified wall specie ID is incorrect type' 105 | return 106 | end 107 | if errcode return; end 108 | end 109 | 110 | tleft = 1; % Time left in simulation 111 | iframe = 1; % frame index 112 | MSXinit(1); 113 | while (tleft > 0 && errcode == 0) 114 | [errcode, t, tleft] = MSXstep(); 115 | 116 | if t >= reportStart 117 | % Retrieve results at time t 118 | if bulkSpecieIndex 119 | V = [V zeros(EN_SIZE.nnodes,1)]; 120 | for in=1:EN_SIZE.nnodes 121 | [errcode, V(in,iframe)] = ... 122 | MSXgetqual(MSX_CONSTANT.MSX_NODE,in,bulkSpecieIndex); 123 | end 124 | end 125 | if wallSpecieIndex 126 | L = [L zeros(EN_SIZE.nlinks,1)]; 127 | for in=1:EN_SIZE.nlinks 128 | [errcode, L(in,iframe)] = ... 129 | MSXgetqual(MSX_CONSTANT.MSX_LINK,in,wallSpecieIndex); 130 | end 131 | end 132 | T = [T; t]; 133 | 134 | iframe = iframe + 1; 135 | end 136 | end 137 | else 138 | % Ordinary Epanet simulation 139 | 140 | % Get the simulation time parameters 141 | [errcode, reportStart] = ENgettimeparam(EN_CONSTANT.EN_REPORTSTART); 142 | if errcode; return; end 143 | [errcode, reportStep] = ENgettimeparam(EN_CONSTANT.EN_REPORTSTEP); 144 | if errcode; return; end 145 | 146 | % Hydraulic analysis 147 | [errcode] = ENsolveH(); 148 | if errcode>100; return; end 149 | 150 | tleft = 1; % Time left in simulation 151 | iframe = 1; % frame index 152 | [errcode] = ENopenQ(); 153 | if errcode; return; end 154 | [errcode] = ENinitQ(0); 155 | if errcode; return; end 156 | while (tleft > 0 && errcode == 0) 157 | [errcode, t] = ENrunQ(); 158 | 159 | if t >= reportStart && ~mod(t,reportStep) 160 | % Retrieve results at time t 161 | V = [V zeros(EN_SIZE.nnodes,1)]; 162 | for in=1:EN_SIZE.nnodes 163 | [errcode, V(in,iframe)] = ... 164 | ENgetnodevalue(in, EN_CONSTANT.EN_QUALITY); 165 | end 166 | T = [T; t]; 167 | 168 | iframe = iframe + 1; 169 | end 170 | 171 | [errcode, tleft] = ENnextQ(); 172 | end 173 | [errcode] = ENcloseQ(); 174 | if errcode; return; end 175 | end 176 | %% Matlab Epanet cleanup 177 | ENclose(); 178 | ENMatlabCleanup(); 179 | if ~isempty(msxFname) 180 | MSXclose(); 181 | MSXMatlabCleanup(); 182 | end 183 | -------------------------------------------------------------------------------- /Utils/html/NetworkMovie.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | NetworkMovie 13 | 14 | 15 | 72 | 73 |
74 |

Contents

75 |
76 | 81 |
function [] = NetworkMovie(V,L,fig,movfname,quality,fps,InpFname,...
 82 |     PData,SData)
 83 | 

Synopsis

84 |

NetworkMovie uses NetworkFrame() to plot the network graph on figure handle fig with nodes and links colored by V,L, and store 85 | the animation as an *.avi movie. For detailed descriptions of the PData and SData arguments, see NetworkFrame(). 86 |

87 |

After the first frame is plotted (using NetworkFrame()), control is passed to the standard input, and during this time you 88 | can use the standard Matlab figure UI controls to modify the figure view as you desire (e.g., zoom, pan). After the network 89 | view is how you want it, the rest of the frames are generated consistent with that view. 90 |

91 |

Helpful Notes:

92 |
93 |
    94 |
  • Do not move or obscure the figure window after you position it and the figure within, when the movie frames are being rendered. 95 | Otherwise you will have whatever junk covers the figure window in your movie. If you actually resize the figure window once 96 | the movie frames are being rendered, you'll get an error message. 97 |
  • 98 |
  • To increase your resolution try increasing the physical size of the figure window. Remember that what you see will be what 99 | you get. 100 |
  • 101 |
  • If a problem occurs when rendering the frames then Matlab seems to stubbornly hang onto the *.avi movie file handle despite, 102 | for example, issuing fclose('all'). The fix is 'clear all' and then you'll be able to either delete or rewrite the same *.avi 103 | filename without shutting down matlab first. 104 |
  • 105 |
  • The exampleMovie.m (or exampleMovie.html) code shows a complete example of how to create a movie of Epanet or MSX simulation 106 | data, and for standard use you should be able to modify some of those parameters for your application. 107 |
  • 108 |
109 |
110 |

Arguments

V           (nnodes x nframes) matrix of node values to plot
111 | L           (nlinks x nframes) matrix of link values to plot
112 |             Either of V or L can be blank, in which case behavior is as
113 |             described in NetworkFrame().
114 | fig         Existing figure handle to use.  If [] then new figure is
115 |             created.
116 | movfname    AVI filename to store movie.  If [] then no movie is made,
117 |             but the animation is displayed.
118 | quality     0-100 quality of AVI movie
119 | fps         frames per second of AVI movie
120 | InpFname    Epanet input file name describing network geometry.
121 | PData       PData structure of plot options as described in
122 |             NetworkFrame().
123 | SData       SData structure of plot symbols as described in
124 |             NetworkFrame().
125 | 126 |
nframes = 0;
127 | if isempty(V)
128 |     colorV=false;
129 | else
130 |     colorV=true;
131 |     nframes = length(V(1,:));
132 | end
133 | if isempty(L)
134 |     colorL=false;
135 | else
136 |     colorL=true;
137 |     nframes = length(L(1,:));
138 | end
139 | 
140 | if colorV && colorL
141 |     if length(V(1,:)) ~= length(L(1,:))
142 |         disp 'Number of frames in V and L must agree.'
143 |         return
144 |     end
145 | end
146 | 
147 | makeavi = ~isempty(movfname);
148 | 
149 | % Figure props
150 | if isempty(fig)
151 |     fig=figure;
152 |     axis equal;
153 |     axis off;
154 | %    set(fig,'Color',[0 0 0]);
155 | else
156 |     figure(fig);
157 | end
158 | if makeavi
159 |     mov = avifile(movfname,'quality',quality,'fps',fps,'compression','Cinepak');
160 | end
161 | 
162 | % Draw the first frame and stop to allow user adjustment of figure window
163 | v = [];
164 | l = [];
165 | if colorV, v=V(:,1); end
166 | if colorL, l=L(:,1); end
167 | [NData,fig] = NetworkFrame(fig,v,l,InpFname,PData,SData,[]);
168 | disp 'Adjust figure window properties as desired, and press any key to continue'
169 | pause;
170 | if makeavi
171 |     M=getframe(fig);
172 |     mov = addframe(mov,M);
173 | else
174 |     drawnow;
175 | end
176 | 
177 | % Draw the rest
178 | for i=2:nframes
179 |     if colorV, v=V(:,i); end
180 |     if colorL, l=L(:,i); end
181 |     [NData,fig] = NetworkFrame(fig,v,l,InpFname,PData,SData,NData);
182 |     if makeavi
183 |         M=getframe(fig);
184 |         mov = addframe(mov,M);
185 |     else
186 |         drawnow;
187 |     end
188 | end
189 | 
190 | if makeavi
191 |     mov = close(mov);
192 | end
193 | 
195 |
196 | 197 | -------------------------------------------------------------------------------- /Utils/html/exampleMovie.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 12 | How to Make an AVI Movie of Your EPANET or EPANET-MSX Simulation 13 | 14 | 15 | 72 | 73 |
74 |

How to Make an AVI Movie of Your EPANET or EPANET-MSX Simulation

75 | 76 |

Contents

77 | 86 |

Synopsis

87 |

This example illustrates the use of NetworkMovie and NetworkFrame to animate either a bulk or wall specie, or both, for an 88 | Epanet/MSX simulation, and store the result as an *.avi movie 89 |

90 |

Note that the EPANET and MSX Matlab wrappers must be on your Matlab search path. Matlab will also need to be able to find 91 | the epanet and epanet-msx object libraries and header files. 92 |

93 |

Get the Epanet-MSX Simulation Data

94 |

This example uses the Net2.inp and net2-cl2.msx data files from the official MSX repository. Note that an ordinary Epanet simulation can also be used, in which case msxFname='' (see getQualityData for details). 95 |

msxFname = '../Test/net2-cl2.msx';
 96 | inpFname = '../Test/Net2.inp';
 97 | %   Animate the bulk chlorine specie
 98 | bulkSpecieID = 'CL2';
 99 | %   There is no wall specie
100 | wallSpecieID = '';
101 | %   Get the simulation data using Epanet or Epanet-MSX
102 | [V,L,T,errcode] = getQualityData(bulkSpecieID,wallSpecieID,...
103 |     msxFname,inpFname);
104 | if errcode > 100
105 |     disp 'Error in network water quality computations'
106 |     return
107 | end
108 | 

Specify Movie Parameters

109 |

These parameters are described in NetworkFrame()...

fig = [];                   % Use a new figure window
110 | movFname = 'mymovie.avi';   % Movie file name
111 | quality = 100;              % 0-100 movie quality (related to data compression)
112 | fps = 8;                    % Frame rate - # to display per second
113 | PData.c = 'jet';            % colormap - see 'help colormap'
114 | PData.logtransv = 'n';      % Do not log transform the data
115 | PData.vmin = 0;             % min vertex value for plot color mapping
116 | PData.vmax = max(max(V));   % max vertex value
117 | % PData.logtransl = 'n';    % We're not plotting link data so these are ignored
118 | % PData.lmin = min(min(L));
119 | % PData.lmax = max(max(L));
120 | PData.lwidth = 3;           % Width of links in points
121 | PData.vsize = 4;            % Size of vertices in points (0 == omits verts)
122 | PData.tsize = 4;            % Size of tank/reservoir nodes
123 | PData.legend = 'v';         % Show a colorbar legend for vertex data
124 | SData = [];                 % No special node symbols
125 | % SData(1...).ivs = [];             % Node IDs to annotate with special symbols
126 | % SData(1...).vsmarker = [];        % Marker symbols
127 | % SData(1...).vsmarkersize = [];    % Marker symbol sizes
128 | % SData(1...).vsmarkercolor = [];   % Marker symbol colors
129 | 

Write the Movie File

130 |

NetworkMovie will display the first frame in a figure window and allow you to make adjustments to it (zoom, pan, etc.) before 131 | rendering the frames into an AVI movie file. 132 |

NetworkMovie(V,L,fig,movFname,quality,fps,inpFname,PData,SData);
133 | 

Show the Movie

134 |

You could display the movie in Matlab as follows, or just use an external viewer...

% mov = aviread(movFname);
135 | % h = figure;
136 | % axis equal;
137 | % movie(h,mov);
138 | 
140 |
141 | 142 | 143 | -------------------------------------------------------------------------------- /Utils/html/exampleMovie_01.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: MATLAB, The Mathworks, Inc. Version 7.4.0.287 (R2007a). Operating System: Microsoft Windows XP. 3 | %%Title: C:\Documents and Settings\Jim\My Documents\ENGCVS\EPANET\MATLAB\trunk\src\Utils\html\exampleMovie_01.eps 4 | %%CreationDate: 05/05/2009 19:15:27 5 | %%DocumentNeededFonts: Helvetica 6 | %%DocumentProcessColors: Cyan Magenta Yellow Black 7 | %%LanguageLevel: 2 8 | %%Pages: 1 9 | %%BoundingBox: 147 286 491 520 10 | %%EndComments 11 | 12 | %%BeginProlog 13 | % MathWorks dictionary 14 | /MathWorks 160 dict begin 15 | % definition operators 16 | /bdef {bind def} bind def 17 | /ldef {load def} bind def 18 | /xdef {exch def} bdef 19 | /xstore {exch store} bdef 20 | % operator abbreviations 21 | /c /clip ldef 22 | /cc /concat ldef 23 | /cp /closepath ldef 24 | /gr /grestore ldef 25 | /gs /gsave ldef 26 | /mt /moveto ldef 27 | /np /newpath ldef 28 | /cm /currentmatrix ldef 29 | /sm /setmatrix ldef 30 | /rm /rmoveto ldef 31 | /rl /rlineto ldef 32 | /s {show newpath} bdef 33 | /sc {setcmykcolor} bdef 34 | /sr /setrgbcolor ldef 35 | /sg /setgray ldef 36 | /w /setlinewidth ldef 37 | /j /setlinejoin ldef 38 | /cap /setlinecap ldef 39 | /rc {rectclip} bdef 40 | /rf {rectfill} bdef 41 | % page state control 42 | /pgsv () def 43 | /bpage {/pgsv save def} bdef 44 | /epage {pgsv restore} bdef 45 | /bplot /gsave ldef 46 | /eplot {stroke grestore} bdef 47 | % orientation switch 48 | /portraitMode 0 def /landscapeMode 1 def /rotateMode 2 def 49 | % coordinate system mappings 50 | /dpi2point 0 def 51 | % font control 52 | /FontSize 0 def 53 | /FMS {/FontSize xstore findfont [FontSize 0 0 FontSize neg 0 0] 54 | makefont setfont} bdef 55 | /ISOLatin1Encoding where {pop /WindowsLatin1Encoding 256 array bdef 56 | ISOLatin1Encoding WindowsLatin1Encoding copy pop 57 | /.notdef/.notdef/quotesinglbase/florin/quotedblbase/ellipsis/dagger 58 | /daggerdbl/circumflex/perthousand/Scaron/guilsinglleft/OE/.notdef/.notdef 59 | /.notdef/.notdef/quoteleft/quoteright/quotedblleft/quotedblright/bullet 60 | /endash/emdash/tilde/trademark/scaron/guilsinglright/oe/.notdef/.notdef 61 | /Ydieresis WindowsLatin1Encoding 128 32 getinterval astore pop} 62 | {/WindowsLatin1Encoding StandardEncoding bdef} ifelse 63 | /reencode {exch dup where {pop load} {pop StandardEncoding} ifelse 64 | exch dup 3 1 roll findfont dup length dict begin 65 | { 1 index /FID ne {def}{pop pop} ifelse } forall 66 | /Encoding exch def currentdict end definefont pop} bdef 67 | /isroman {findfont /CharStrings get /Agrave known} bdef 68 | /FMSR {3 1 roll 1 index dup isroman {reencode} {pop pop} ifelse 69 | exch FMS} bdef 70 | /csm {1 dpi2point div -1 dpi2point div scale neg translate 71 | dup landscapeMode eq {pop -90 rotate} 72 | {rotateMode eq {90 rotate} if} ifelse} bdef 73 | % line types: solid, dotted, dashed, dotdash 74 | /SO { [] 0 setdash } bdef 75 | /DO { [.5 dpi2point mul 4 dpi2point mul] 0 setdash } bdef 76 | /DA { [6 dpi2point mul] 0 setdash } bdef 77 | /DD { [.5 dpi2point mul 4 dpi2point mul 6 dpi2point mul 4 78 | dpi2point mul] 0 setdash } bdef 79 | % macros for lines and objects 80 | /L {lineto stroke} bdef 81 | /MP {3 1 roll moveto 1 sub {rlineto} repeat} bdef 82 | /AP {{rlineto} repeat} bdef 83 | /PDlw -1 def 84 | /W {/PDlw currentlinewidth def setlinewidth} def 85 | /PP {closepath eofill} bdef 86 | /DP {closepath stroke} bdef 87 | /MR {4 -2 roll moveto dup 0 exch rlineto exch 0 rlineto 88 | neg 0 exch rlineto closepath} bdef 89 | /FR {MR stroke} bdef 90 | /PR {MR fill} bdef 91 | /L1i {{currentfile picstr readhexstring pop} image} bdef 92 | /tMatrix matrix def 93 | /MakeOval {newpath tMatrix currentmatrix pop translate scale 94 | 0 0 1 0 360 arc tMatrix setmatrix} bdef 95 | /FO {MakeOval stroke} bdef 96 | /PO {MakeOval fill} bdef 97 | /PD {currentlinewidth 2 div 0 360 arc fill 98 | PDlw -1 eq not {PDlw w /PDlw -1 def} if} def 99 | /FA {newpath tMatrix currentmatrix pop translate scale 100 | 0 0 1 5 -2 roll arc tMatrix setmatrix stroke} bdef 101 | /PA {newpath tMatrix currentmatrix pop translate 0 0 moveto scale 102 | 0 0 1 5 -2 roll arc closepath tMatrix setmatrix fill} bdef 103 | /FAn {newpath tMatrix currentmatrix pop translate scale 104 | 0 0 1 5 -2 roll arcn tMatrix setmatrix stroke} bdef 105 | /PAn {newpath tMatrix currentmatrix pop translate 0 0 moveto scale 106 | 0 0 1 5 -2 roll arcn closepath tMatrix setmatrix fill} bdef 107 | /vradius 0 def /hradius 0 def /lry 0 def 108 | /lrx 0 def /uly 0 def /ulx 0 def /rad 0 def 109 | /MRR {/vradius xdef /hradius xdef /lry xdef /lrx xdef /uly xdef 110 | /ulx xdef newpath tMatrix currentmatrix pop ulx hradius add uly 111 | vradius add translate hradius vradius scale 0 0 1 180 270 arc 112 | tMatrix setmatrix lrx hradius sub uly vradius add translate 113 | hradius vradius scale 0 0 1 270 360 arc tMatrix setmatrix 114 | lrx hradius sub lry vradius sub translate hradius vradius scale 115 | 0 0 1 0 90 arc tMatrix setmatrix ulx hradius add lry vradius sub 116 | translate hradius vradius scale 0 0 1 90 180 arc tMatrix setmatrix 117 | closepath} bdef 118 | /FRR {MRR stroke } bdef 119 | /PRR {MRR fill } bdef 120 | /MlrRR {/lry xdef /lrx xdef /uly xdef /ulx xdef /rad lry uly sub 2 div def 121 | newpath tMatrix currentmatrix pop ulx rad add uly rad add translate 122 | rad rad scale 0 0 1 90 270 arc tMatrix setmatrix lrx rad sub lry rad 123 | sub translate rad rad scale 0 0 1 270 90 arc tMatrix setmatrix 124 | closepath} bdef 125 | /FlrRR {MlrRR stroke } bdef 126 | /PlrRR {MlrRR fill } bdef 127 | /MtbRR {/lry xdef /lrx xdef /uly xdef /ulx xdef /rad lrx ulx sub 2 div def 128 | newpath tMatrix currentmatrix pop ulx rad add uly rad add translate 129 | rad rad scale 0 0 1 180 360 arc tMatrix setmatrix lrx rad sub lry rad 130 | sub translate rad rad scale 0 0 1 0 180 arc tMatrix setmatrix 131 | closepath} bdef 132 | /FtbRR {MtbRR stroke } bdef 133 | /PtbRR {MtbRR fill } bdef 134 | /stri 6 array def /dtri 6 array def 135 | /smat 6 array def /dmat 6 array def 136 | /tmat1 6 array def /tmat2 6 array def /dif 3 array def 137 | /asub {/ind2 exch def /ind1 exch def dup dup 138 | ind1 get exch ind2 get sub exch } bdef 139 | /tri_to_matrix { 140 | 2 0 asub 3 1 asub 4 0 asub 5 1 asub 141 | dup 0 get exch 1 get 7 -1 roll astore } bdef 142 | /compute_transform { 143 | dmat dtri tri_to_matrix tmat1 invertmatrix 144 | smat stri tri_to_matrix tmat2 concatmatrix } bdef 145 | /ds {stri astore pop} bdef 146 | /dt {dtri astore pop} bdef 147 | /db {2 copy /cols xdef /rows xdef mul dup 3 mul string 148 | currentfile 149 | 3 index 0 eq {/ASCIIHexDecode filter} 150 | {/ASCII85Decode filter 3 index 2 eq {/RunLengthDecode filter} if } 151 | ifelse exch readstring pop 152 | dup 0 3 index getinterval /rbmap xdef 153 | dup 2 index dup getinterval /gbmap xdef 154 | 1 index dup 2 mul exch getinterval /bbmap xdef pop pop}bdef 155 | /it {gs np dtri aload pop moveto lineto lineto cp c 156 | cols rows 8 compute_transform 157 | rbmap gbmap bbmap true 3 colorimage gr}bdef 158 | /il {newpath moveto lineto stroke}bdef 159 | currentdict end def 160 | %%EndProlog 161 | 162 | %%BeginSetup 163 | MathWorks begin 164 | 165 | 0 cap 166 | 167 | end 168 | %%EndSetup 169 | 170 | %%Page: 1 1 171 | %%BeginPageSetup 172 | %%PageBoundingBox: 147 286 491 520 173 | MathWorks begin 174 | bpage 175 | %%EndPageSetup 176 | 177 | %%BeginObject: obj1 178 | bplot 179 | 180 | /dpi2point 12 def 181 | portraitMode 1164 6624 csm 182 | 183 | 609 384 4124 2805 rc 184 | 110 dict begin %Colortable dictionary 185 | /c0 { 0.000000 0.000000 0.000000 sr} bdef 186 | /c1 { 1.000000 1.000000 1.000000 sr} bdef 187 | /c2 { 0.900000 0.000000 0.000000 sr} bdef 188 | /c3 { 0.000000 0.820000 0.000000 sr} bdef 189 | /c4 { 0.000000 0.000000 0.800000 sr} bdef 190 | /c5 { 0.910000 0.820000 0.320000 sr} bdef 191 | /c6 { 1.000000 0.260000 0.820000 sr} bdef 192 | /c7 { 0.000000 0.820000 0.820000 sr} bdef 193 | c0 194 | 1 j 195 | 0.8 sg 196 | 0 0 5006 3754 rf 197 | 1 sg 198 | 6 w 199 | gs 651 526 3256 2569 rc 200 | 36 w 201 | /c8 { 0.750000 0.000000 0.000000 sr} bdef 202 | c8 203 | -61 -495 1891 3094 2 MP stroke 204 | /c9 { 1.000000 0.437500 0.000000 sr} bdef 205 | c9 206 | 0 -155 1830 2599 2 MP stroke 207 | -248 -31 1830 2599 2 MP stroke 208 | /c10 { 1.000000 1.000000 0.000000 sr} bdef 209 | c10 210 | 93 -217 1582 2568 2 MP stroke 211 | 155 93 1675 2351 2 MP stroke 212 | /c11 { 1.000000 0.937500 0.000000 sr} bdef 213 | c11 214 | 278 62 1830 2444 2 MP stroke 215 | /c12 { 0.625000 1.000000 0.375000 sr} bdef 216 | c12 217 | 247 -495 2108 2506 2 MP stroke 218 | /c13 { 0.000000 0.812500 1.000000 sr} bdef 219 | c13 220 | 62 278 2355 2011 2 MP stroke 221 | /c14 { 0.250000 1.000000 0.750000 sr} bdef 222 | c14 223 | 0 -93 2355 2011 2 MP stroke 224 | /c15 { 0.000000 0.000000 1.000000 sr} bdef 225 | c15 226 | -31 217 2417 2289 2 MP stroke 227 | c13 228 | 31 -216 2355 1918 2 MP stroke 229 | /c16 { 0.000000 0.250000 1.000000 sr} bdef 230 | c16 231 | 62 -340 2386 1702 2 MP stroke 232 | c15 233 | -31 -124 2448 1362 2 MP stroke 234 | /c17 { 0.000000 0.000000 0.875000 sr} bdef 235 | c17 236 | 0 -62 2417 1238 2 MP stroke 237 | /c18 { 0.000000 0.000000 0.687500 sr} bdef 238 | c18 239 | -31 -93 2417 1176 2 MP stroke 240 | /c19 { 0.000000 0.000000 0.812500 sr} bdef 241 | c19 242 | -340 -31 2417 1238 2 MP stroke 243 | c18 244 | -309 0 2386 1083 2 MP stroke 245 | 0 -124 2077 1207 2 MP stroke 246 | -124 31 2077 1083 2 MP stroke 247 | /c20 { 0.000000 0.000000 0.625000 sr} bdef 248 | c20 249 | 0 124 1953 1114 2 MP stroke 250 | c18 251 | -186 185 2077 1207 2 MP stroke 252 | c20 253 | 217 -62 2417 1176 2 MP stroke 254 | /c21 { 0.000000 0.000000 0.562500 sr} bdef 255 | c21 256 | 185 186 2634 1114 2 MP stroke 257 | 93 -217 2819 1300 2 MP stroke 258 | 278 -31 2634 1114 2 MP stroke 259 | c20 260 | -62 -93 2386 1021 2 MP stroke 261 | c18 262 | 0 -62 2386 1083 2 MP stroke 263 | c21 264 | 0 -61 2324 928 2 MP stroke 265 | c18 266 | -61 0 2324 867 2 MP stroke 267 | c20 268 | 62 -124 2324 867 2 MP stroke 269 | 62 -217 2386 743 2 MP stroke 270 | 93 31 2448 526 2 MP stroke 271 | 216 31 2541 557 2 MP stroke 272 | c21 273 | 62 -124 2912 1083 2 MP stroke 274 | 0 -123 2974 959 2 MP stroke 275 | c20 276 | -62 154 1953 1238 2 MP stroke 277 | c18 278 | 31 155 2541 557 2 MP stroke 279 | /c22 { 0.000000 0.000000 0.750000 sr} bdef 280 | c22 281 | 124 31 2572 712 2 MP stroke 282 | c18 283 | -185 124 2757 588 2 MP stroke 284 | c21 285 | 124 -62 2757 588 2 MP stroke 286 | 6 w 287 | c15 288 | 1891 3094 PD 289 | gr 290 | 291 | c15 292 | gs 1842 3045 99 99 rc 293 | /c23 { 0.500000 0.000000 0.000000 sr} bdef 294 | c23 295 | 24 24 1891 3094 PO 296 | 24 24 1891 3094 FO 297 | gr 298 | 299 | c23 300 | gs 651 526 3256 2569 rc 301 | c15 302 | 1830 2599 PD 303 | gs 1781 2550 99 99 rc 304 | /c24 { 1.000000 0.062500 0.000000 sr} bdef 305 | c24 306 | 24 24 1830 2599 PO 307 | 24 24 1830 2599 FO 308 | gr 309 | 310 | c24 311 | c15 312 | 1582 2568 PD 313 | gs 1533 2519 99 99 rc 314 | /c25 { 1.000000 0.750000 0.000000 sr} bdef 315 | c25 316 | 24 24 1582 2568 PO 317 | 24 24 1582 2568 FO 318 | gr 319 | 320 | c25 321 | c15 322 | 1675 2351 PD 323 | gs 1626 2302 99 99 rc 324 | /c26 { 0.750000 1.000000 0.250000 sr} bdef 325 | c26 326 | 24 24 1675 2351 PO 327 | 24 24 1675 2351 FO 328 | gr 329 | 330 | c26 331 | c15 332 | 1830 2444 PD 333 | gs 1781 2395 99 99 rc 334 | c25 335 | 24 24 1830 2444 PO 336 | 24 24 1830 2444 FO 337 | gr 338 | 339 | c25 340 | c15 341 | 2108 2506 PD 342 | gs 2059 2457 99 99 rc 343 | /c27 { 0.812500 1.000000 0.187500 sr} bdef 344 | c27 345 | 24 24 2108 2506 PO 346 | 24 24 2108 2506 FO 347 | gr 348 | 349 | c27 350 | c15 351 | 2355 2011 PD 352 | gs 2306 1962 99 99 rc 353 | /c28 { 0.437500 1.000000 0.562500 sr} bdef 354 | c28 355 | 24 24 2355 2011 PO 356 | 24 24 2355 2011 FO 357 | gr 358 | 359 | c28 360 | c15 361 | 2417 2289 PD 362 | gs 2368 2240 99 99 rc 363 | /c29 { 0.000000 0.187500 1.000000 sr} bdef 364 | c29 365 | 24 24 2417 2289 PO 366 | 24 24 2417 2289 FO 367 | gr 368 | 369 | c29 370 | c15 371 | 2355 1918 PD 372 | gs 2306 1869 99 99 rc 373 | /c30 { 0.125000 1.000000 0.875000 sr} bdef 374 | c30 375 | 24 24 2355 1918 PO 376 | 24 24 2355 1918 FO 377 | gr 378 | 379 | c30 380 | c15 381 | 2386 2506 PD 382 | gs 2337 2457 99 99 rc 383 | c17 384 | 24 24 2386 2506 PO 385 | 24 24 2386 2506 FO 386 | gr 387 | 388 | c17 389 | c15 390 | 2386 1702 PD 391 | gs 2337 1653 99 99 rc 392 | /c31 { 0.000000 0.500000 1.000000 sr} bdef 393 | c31 394 | 24 24 2386 1702 PO 395 | 24 24 2386 1702 FO 396 | gr 397 | 398 | c31 399 | c15 400 | 2448 1362 PD 401 | gs 2399 1313 99 99 rc 402 | /c32 { 0.000000 0.062500 1.000000 sr} bdef 403 | c32 404 | 24 24 2448 1362 PO 405 | 24 24 2448 1362 FO 406 | gr 407 | 408 | c32 409 | c15 410 | 2417 1238 PD 411 | gs 2368 1189 99 99 rc 412 | 24 24 2417 1238 PO 413 | 24 24 2417 1238 FO 414 | gr 415 | 416 | 2417 1176 PD 417 | gs 2368 1127 99 99 rc 418 | c18 419 | 24 24 2417 1176 PO 420 | 24 24 2417 1176 FO 421 | gr 422 | 423 | c18 424 | c15 425 | 2386 1083 PD 426 | gs 2337 1034 99 99 rc 427 | c18 428 | 24 24 2386 1083 PO 429 | 24 24 2386 1083 FO 430 | gr 431 | 432 | c18 433 | c15 434 | 2077 1207 PD 435 | gs 2028 1158 99 99 rc 436 | c18 437 | 24 24 2077 1207 PO 438 | 24 24 2077 1207 FO 439 | gr 440 | 441 | c18 442 | c15 443 | 2077 1083 PD 444 | gs 2028 1034 99 99 rc 445 | c18 446 | 24 24 2077 1083 PO 447 | 24 24 2077 1083 FO 448 | gr 449 | 450 | c18 451 | c15 452 | 1953 1114 PD 453 | gs 1904 1065 99 99 rc 454 | c20 455 | 24 24 1953 1114 PO 456 | 24 24 1953 1114 FO 457 | gr 458 | 459 | c20 460 | c15 461 | 1891 1392 PD 462 | gs 1842 1343 99 99 rc 463 | c20 464 | 24 24 1891 1392 PO 465 | 24 24 1891 1392 FO 466 | gr 467 | 468 | c20 469 | c15 470 | 2634 1114 PD 471 | gs 2585 1065 99 99 rc 472 | c21 473 | 24 24 2634 1114 PO 474 | 24 24 2634 1114 FO 475 | gr 476 | 477 | c21 478 | c15 479 | 2819 1300 PD 480 | gs 2770 1251 99 99 rc 481 | c21 482 | 24 24 2819 1300 PO 483 | 24 24 2819 1300 FO 484 | gr 485 | 486 | c21 487 | c15 488 | 2912 1083 PD 489 | gs 2863 1034 99 99 rc 490 | c21 491 | 24 24 2912 1083 PO 492 | 24 24 2912 1083 FO 493 | gr 494 | 495 | c21 496 | c15 497 | 2324 928 PD 498 | gs 2275 879 99 99 rc 499 | c21 500 | 24 24 2324 928 PO 501 | 24 24 2324 928 FO 502 | gr 503 | 504 | c21 505 | c15 506 | 2386 1021 PD 507 | gs 2337 972 99 99 rc 508 | c18 509 | 24 24 2386 1021 PO 510 | 24 24 2386 1021 FO 511 | gr 512 | 513 | c18 514 | c15 515 | 2324 867 PD 516 | gs 2275 818 99 99 rc 517 | c21 518 | 24 24 2324 867 PO 519 | 24 24 2324 867 FO 520 | gr 521 | 522 | c21 523 | c15 524 | 2448 526 PD 525 | gr 526 | 527 | c15 528 | gs 2399 477 99 99 rc 529 | c18 530 | 24 24 2448 526 PO 531 | 24 24 2448 526 FO 532 | gr 533 | 534 | c18 535 | gs 651 526 3256 2569 rc 536 | c15 537 | 2757 588 PD 538 | gs 2708 539 99 99 rc 539 | c21 540 | 24 24 2757 588 PO 541 | 24 24 2757 588 FO 542 | gr 543 | 544 | c21 545 | c15 546 | 2541 557 PD 547 | gr 548 | 549 | c15 550 | gs 2492 508 99 99 rc 551 | c20 552 | 24 24 2541 557 PO 553 | 24 24 2541 557 FO 554 | gr 555 | 556 | c20 557 | gs 651 526 3256 2569 rc 558 | c15 559 | 2696 743 PD 560 | gs 2647 694 99 99 rc 561 | c22 562 | 24 24 2696 743 PO 563 | 24 24 2696 743 FO 564 | gr 565 | 566 | c22 567 | c15 568 | 2386 743 PD 569 | gs 2337 694 99 99 rc 570 | c20 571 | 24 24 2386 743 PO 572 | 24 24 2386 743 FO 573 | gr 574 | 575 | c20 576 | c15 577 | 1953 1238 PD 578 | gs 1904 1189 99 99 rc 579 | c21 580 | 24 24 1953 1238 PO 581 | 24 24 1953 1238 FO 582 | gr 583 | 584 | c21 585 | c15 586 | 2974 959 PD 587 | gs 2925 910 99 99 rc 588 | c21 589 | 24 24 2974 959 PO 590 | 24 24 2974 959 FO 591 | gr 592 | 593 | c21 594 | c15 595 | 2974 836 PD 596 | gs 2925 787 99 99 rc 597 | c21 598 | 24 24 2974 836 PO 599 | 24 24 2974 836 FO 600 | gr 601 | 602 | c21 603 | c15 604 | 2572 712 PD 605 | gs 2523 663 99 99 rc 606 | c19 607 | 24 24 2572 712 PO 608 | 24 24 2572 712 FO 609 | gr 610 | 611 | c19 612 | c15 613 | 2881 526 PD 614 | gr 615 | 616 | c15 617 | gs 2832 477 99 99 rc 618 | c20 619 | 24 24 2881 526 PO 620 | 24 24 2881 526 FO 621 | gr 622 | 623 | c20 624 | gs 651 526 3256 2569 rc 625 | c15 626 | 2263 867 PD 627 | gs 2214 818 99 99 rc 628 | 0 j 629 | 0 -38 -38 0 0 38 38 0 2244 848 5 MP 630 | c22 631 | gs 632 | PP 633 | gr 634 | DP 635 | gr 636 | 637 | c22 638 | gr 639 | 640 | c22 641 | 0 sg 642 | %%IncludeResource: font Helvetica 643 | /Helvetica /WindowsLatin1Encoding 120 FMSR 644 | 645 | 634 3137 mt 646 | ( ) s 647 | 3890 568 mt 648 | ( ) s 649 | 1 sg 650 | 0 2569 240 0 0 -2569 4110 3095 4 MP 651 | PP 652 | -240 0 0 2569 240 0 0 -2569 4110 3095 5 MP stroke 653 | gs 4110 526 241 2570 rc 654 | /mwscm { [/Indexed /DeviceRGB 63 655 | < 656 | 00008f 00009f 0000af 0000bf 0000cf 0000df 0000ef 0000ff 000fff 001fff 657 | 002fff 003fff 004fff 005fff 006fff 007fff 008fff 009fff 00afff 00bfff 658 | 00cfff 00dfff 00efff 00ffff 0fffef 1fffdf 2fffcf 3fffbf 4fffaf 5fff9f 659 | 6fff8f 7fff7f 8fff6f 9fff5f afff4f bfff3f cfff2f dfff1f efff0f ffff00 660 | ffef00 ffdf00 ffcf00 ffbf00 ffaf00 ff9f00 ff8f00 ff7f00 ff6f00 ff5f00 661 | ff4f00 ff3f00 ff2f00 ff1f00 ff0f00 ff0000 ef0000 df0000 cf0000 bf0000 662 | af0000 9f0000 8f0000 7f0000 663 | > 664 | ] setcolorspace } bdef mwscm 665 | gs np 4110 526 mt 0 2569 rl 240 0 rl 0 -2569 rl cp c np 666 | [240 0 0 2569 4110 526] cc 667 | << % Image dictionary 668 | /ImageType 1 669 | /Width 1 /Height 64 670 | /BitsPerComponent 8 671 | /Decode [0 255] 672 | /ImageMatrix [1.000000 0 0 64.000000 0 0] 673 | /DataSource currentfile 674 | /ASCII85Decode filter 675 | /RunLengthDecode filter 676 | >> 677 | image 678 | 5%1/1W2!-mp>f,U4KV+ 681 | gr 682 | gr 683 | 684 | 4 w 685 | DO 686 | SO 687 | 6 w 688 | 0 sg 689 | 4110 526 mt 4350 526 L 690 | 4110 3095 mt 4350 3095 L 691 | 4350 3095 mt 4350 526 L 692 | 4110 3095 mt 4110 526 L 693 | 4110 3095 mt 4350 3095 L 694 | 4350 3095 mt 4350 526 L 695 | 4350 3095 mt 4324 3095 L 696 | 4110 3095 mt 4135 3095 L 697 | 4384 3139 mt 698 | ( 0) s 699 | 4350 2452 mt 4324 2452 L 700 | 4110 2452 mt 4135 2452 L 701 | 4384 2496 mt 702 | ( 0.2) s 703 | 4350 1810 mt 4324 1810 L 704 | 4110 1810 mt 4135 1810 L 705 | 4384 1854 mt 706 | ( 0.4) s 707 | 4350 1168 mt 4324 1168 L 708 | 4110 1168 mt 4135 1168 L 709 | 4384 1212 mt 710 | ( 0.6) s 711 | 4350 566 mt 4324 566 L 712 | 4110 566 mt 4135 566 L 713 | 4384 610 mt 714 | (0.788) s 715 | 4110 526 mt 4350 526 L 716 | 4110 3095 mt 4350 3095 L 717 | 4350 3095 mt 4350 526 L 718 | 4110 3095 mt 4110 526 L 719 | 720 | end %%Color Dict 721 | 722 | eplot 723 | %%EndObject 724 | 725 | epage 726 | end 727 | 728 | showpage 729 | 730 | %%Trailer 731 | %%EOF 732 | -------------------------------------------------------------------------------- /Utils/html/exampleMovie_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenWaterAnalytics/epanet-matlab/c998b8c7bd3c46519d4250e9742b25aee0f31deb/Utils/html/exampleMovie_01.png --------------------------------------------------------------------------------