|
| 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 |
0 commit comments