epanet-plus 0.0.1__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of epanet-plus might be problematic. Click here for more details.

Files changed (105) hide show
  1. docs/conf.py +67 -0
  2. epanet-msx-src/dispersion.h +27 -0
  3. epanet-msx-src/hash.c +107 -0
  4. epanet-msx-src/hash.h +28 -0
  5. epanet-msx-src/include/epanetmsx.h +104 -0
  6. epanet-msx-src/include/epanetmsx_export.h +42 -0
  7. epanet-msx-src/mathexpr.c +937 -0
  8. epanet-msx-src/mathexpr.h +39 -0
  9. epanet-msx-src/mempool.c +204 -0
  10. epanet-msx-src/mempool.h +24 -0
  11. epanet-msx-src/msxchem.c +1285 -0
  12. epanet-msx-src/msxcompiler.c +368 -0
  13. epanet-msx-src/msxdict.h +42 -0
  14. epanet-msx-src/msxdispersion.c +586 -0
  15. epanet-msx-src/msxerr.c +116 -0
  16. epanet-msx-src/msxfile.c +260 -0
  17. epanet-msx-src/msxfuncs.c +175 -0
  18. epanet-msx-src/msxfuncs.h +35 -0
  19. epanet-msx-src/msxinp.c +1504 -0
  20. epanet-msx-src/msxout.c +398 -0
  21. epanet-msx-src/msxproj.c +791 -0
  22. epanet-msx-src/msxqual.c +2011 -0
  23. epanet-msx-src/msxrpt.c +400 -0
  24. epanet-msx-src/msxtank.c +422 -0
  25. epanet-msx-src/msxtoolkit.c +1164 -0
  26. epanet-msx-src/msxtypes.h +551 -0
  27. epanet-msx-src/msxutils.c +524 -0
  28. epanet-msx-src/msxutils.h +56 -0
  29. epanet-msx-src/newton.c +158 -0
  30. epanet-msx-src/newton.h +34 -0
  31. epanet-msx-src/rk5.c +287 -0
  32. epanet-msx-src/rk5.h +39 -0
  33. epanet-msx-src/ros2.c +293 -0
  34. epanet-msx-src/ros2.h +35 -0
  35. epanet-msx-src/smatrix.c +816 -0
  36. epanet-msx-src/smatrix.h +29 -0
  37. epanet-src/AUTHORS +60 -0
  38. epanet-src/LICENSE +21 -0
  39. epanet-src/enumstxt.h +151 -0
  40. epanet-src/epanet.c +5937 -0
  41. epanet-src/epanet2.c +961 -0
  42. epanet-src/epanet2.def +131 -0
  43. epanet-src/errors.dat +79 -0
  44. epanet-src/flowbalance.c +186 -0
  45. epanet-src/funcs.h +219 -0
  46. epanet-src/genmmd.c +1000 -0
  47. epanet-src/hash.c +177 -0
  48. epanet-src/hash.h +28 -0
  49. epanet-src/hydcoeffs.c +1303 -0
  50. epanet-src/hydraul.c +1164 -0
  51. epanet-src/hydsolver.c +781 -0
  52. epanet-src/hydstatus.c +442 -0
  53. epanet-src/include/epanet2.h +466 -0
  54. epanet-src/include/epanet2_2.h +1962 -0
  55. epanet-src/include/epanet2_enums.h +518 -0
  56. epanet-src/inpfile.c +884 -0
  57. epanet-src/input1.c +672 -0
  58. epanet-src/input2.c +970 -0
  59. epanet-src/input3.c +2265 -0
  60. epanet-src/leakage.c +527 -0
  61. epanet-src/mempool.c +146 -0
  62. epanet-src/mempool.h +24 -0
  63. epanet-src/output.c +853 -0
  64. epanet-src/project.c +1691 -0
  65. epanet-src/quality.c +695 -0
  66. epanet-src/qualreact.c +800 -0
  67. epanet-src/qualroute.c +696 -0
  68. epanet-src/report.c +1559 -0
  69. epanet-src/rules.c +1500 -0
  70. epanet-src/smatrix.c +871 -0
  71. epanet-src/text.h +508 -0
  72. epanet-src/types.h +928 -0
  73. epanet-src/util/cstr_helper.c +59 -0
  74. epanet-src/util/cstr_helper.h +38 -0
  75. epanet-src/util/errormanager.c +92 -0
  76. epanet-src/util/errormanager.h +39 -0
  77. epanet-src/util/filemanager.c +212 -0
  78. epanet-src/util/filemanager.h +81 -0
  79. epanet-src/validate.c +408 -0
  80. epanet.cp313-win_amd64.pyd +0 -0
  81. epanet_plus/VERSION +1 -0
  82. epanet_plus/__init__.py +8 -0
  83. epanet_plus/epanet_plus.c +118 -0
  84. epanet_plus/epanet_toolkit.py +2730 -0
  85. epanet_plus/epanet_wrapper.py +2414 -0
  86. epanet_plus/include/epanet_plus.h +9 -0
  87. epanet_plus-0.0.1.dist-info/METADATA +152 -0
  88. epanet_plus-0.0.1.dist-info/RECORD +105 -0
  89. epanet_plus-0.0.1.dist-info/WHEEL +5 -0
  90. epanet_plus-0.0.1.dist-info/licenses/LICENSE +21 -0
  91. epanet_plus-0.0.1.dist-info/top_level.txt +11 -0
  92. examples/basic_usage.py +35 -0
  93. python-extension/ext.c +344 -0
  94. python-extension/pyepanet.c +2133 -0
  95. python-extension/pyepanet.h +143 -0
  96. python-extension/pyepanet2.c +1823 -0
  97. python-extension/pyepanet2.h +141 -0
  98. python-extension/pyepanet_plus.c +37 -0
  99. python-extension/pyepanet_plus.h +4 -0
  100. python-extension/pyepanetmsx.c +388 -0
  101. python-extension/pyepanetmsx.h +35 -0
  102. tests/test_epanet.py +16 -0
  103. tests/test_epanetmsx.py +36 -0
  104. tests/test_epyt.py +114 -0
  105. tests/test_load_inp_from_buffer.py +18 -0
epanet-src/epanet2.c ADDED
@@ -0,0 +1,961 @@
1
+ /*
2
+ ******************************************************************************
3
+ Project: OWA EPANET
4
+ Version: 2.3
5
+ Module: epanet2.c
6
+ Description: implementation of the legacy EPANET API functions
7
+ Authors: see AUTHORS
8
+ Copyright: see AUTHORS
9
+ License: see LICENSE
10
+ Last Updated: 02/14/2025
11
+ ******************************************************************************
12
+ */
13
+
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+
17
+ #include "types.h"
18
+ #include "funcs.h"
19
+
20
+ #include "epanet2.h"
21
+ #include "epanet2_2.h"
22
+
23
+
24
+ // This single global variable is used only when the library is called
25
+ // in "legacy mode" with the 2.1-style API.
26
+ Project __defaultProject;
27
+ Project *_defaultProject = &__defaultProject;
28
+
29
+ // Functions for creating and removing default temporary files
30
+ void createtmpfiles()
31
+ {
32
+ getTmpName(_defaultProject->TmpHydFname);
33
+ getTmpName(_defaultProject->TmpOutFname);
34
+ getTmpName(_defaultProject->TmpStatFname);
35
+ }
36
+
37
+ void removetmpfiles()
38
+ {
39
+ remove(_defaultProject->TmpHydFname);
40
+ remove(_defaultProject->TmpOutFname);
41
+ remove(_defaultProject->TmpStatFname);
42
+ }
43
+
44
+
45
+ /********************************************************************
46
+
47
+ Project Functions
48
+
49
+ ********************************************************************/
50
+
51
+ int DLLEXPORT ENepanet(const char *inpFile, const char *rptFile,
52
+ const char *outFile, void (*pviewprog)(char *))
53
+ {
54
+ /*------------------------------------------------------------------------
55
+ ** Input: inpFile = name of EPANET formatted input file
56
+ ** rptFile = name of report file
57
+ ** outFile = name of binary output file
58
+ ** pviewprog = see note below
59
+ ** Output: none
60
+ ** Returns: error code
61
+ ** Purpose: runs a complete EPANET simulation
62
+ **
63
+ ** The pviewprog() argument is a pointer to a callback function
64
+ ** that takes a character string (char *) as its only parameter.
65
+ ** The function would reside in and be used by the calling
66
+ ** program to display the progress messages that EPANET generates
67
+ ** as it carries out its computations. If this feature is not
68
+ ** needed then the argument should be NULL.
69
+ **-------------------------------------------------------------------------
70
+ */
71
+ int errcode = 0;
72
+ int warncode = 0;
73
+
74
+ // Run the project and record any warning
75
+ createtmpfiles();
76
+ errcode = EN_runproject(_defaultProject, inpFile, rptFile, outFile, pviewprog);
77
+ if (errcode < 100) warncode = errcode;
78
+ removetmpfiles();
79
+
80
+ // Return the warning code if the run had no errors
81
+ if (warncode) errcode = MAX(errcode, warncode);
82
+ return errcode;
83
+ }
84
+
85
+ int DLLEXPORT ENinit(const char *rptFile, const char *outFile, int unitsType,
86
+ int headlossType)
87
+ {
88
+ int errcode = 0;
89
+ createtmpfiles();
90
+ errcode = EN_init(_defaultProject, rptFile, outFile, unitsType, headlossType);
91
+ return errcode;
92
+ }
93
+
94
+ int DLLEXPORT ENopen(const char *inpFile, const char *rptFile, const char *outFile)
95
+ {
96
+ int errcode = 0;
97
+ createtmpfiles();
98
+ errcode = EN_open(_defaultProject, inpFile, rptFile, outFile);
99
+ return errcode;
100
+ }
101
+
102
+ int DLLEXPORT ENopenX(const char *inpFile, const char *rptFile, const char *outFile)
103
+ {
104
+ int errcode = 0;
105
+ createtmpfiles();
106
+ errcode = EN_openX(_defaultProject, inpFile, rptFile, outFile);
107
+ return errcode;
108
+ }
109
+
110
+ int DLLEXPORT ENgettitle(char *line1, char *line2, char *line3)
111
+ {
112
+ return EN_gettitle(_defaultProject, line1, line2, line3) ;
113
+ }
114
+
115
+ int DLLEXPORT ENsettitle(const char *line1, const char *line2, const char *line3)
116
+ {
117
+ return EN_settitle(_defaultProject, line1, line2, line3) ;
118
+ }
119
+
120
+ int DLLEXPORT ENgetcomment(int object, int index, char *comment)
121
+ {
122
+ return EN_getcomment(_defaultProject, object, index, comment);
123
+ }
124
+
125
+ int DLLEXPORT ENsetcomment(int object, int index, const char *comment)
126
+ {
127
+ return EN_setcomment(_defaultProject, object, index, comment);
128
+ }
129
+
130
+ int DLLEXPORT ENgettag(int object, int index, char *tag)
131
+ {
132
+ return EN_gettag(_defaultProject, object, index, tag);
133
+ }
134
+
135
+ int DLLEXPORT ENsettag(int object, int index, const char *tag)
136
+ {
137
+ return EN_settag(_defaultProject, object, index, tag);
138
+ }
139
+ int DLLEXPORT ENgetcount(int object, int *count)
140
+ {
141
+ return EN_getcount(_defaultProject, object, count);
142
+ }
143
+
144
+ int DLLEXPORT ENsaveinpfile(const char *filename)
145
+ {
146
+ return EN_saveinpfile(_defaultProject, filename);
147
+ }
148
+
149
+ int DLLEXPORT ENclose()
150
+ {
151
+ EN_close(_defaultProject);
152
+ removetmpfiles();
153
+ return 0;
154
+ }
155
+
156
+ /********************************************************************
157
+
158
+ Hydraulic Analysis Functions
159
+
160
+ ********************************************************************/
161
+
162
+ int DLLEXPORT ENsolveH() { return EN_solveH(_defaultProject); }
163
+
164
+ int DLLEXPORT ENsaveH() { return EN_saveH(_defaultProject); }
165
+
166
+ int DLLEXPORT ENopenH() { return EN_openH(_defaultProject); }
167
+
168
+ int DLLEXPORT ENinitH(int initFlag) { return EN_initH(_defaultProject, initFlag); }
169
+
170
+ int DLLEXPORT ENrunH(long *currentTime) { return EN_runH(_defaultProject, currentTime); }
171
+
172
+ int DLLEXPORT ENnextH(long *tStep) { return EN_nextH(_defaultProject, tStep); }
173
+
174
+ int DLLEXPORT ENcloseH() { return EN_closeH(_defaultProject); }
175
+
176
+ int DLLEXPORT ENsavehydfile(const char *filename)
177
+ {
178
+ return EN_savehydfile(_defaultProject, filename);
179
+ }
180
+
181
+ int DLLEXPORT ENusehydfile(const char *filename)
182
+ {
183
+ return EN_usehydfile(_defaultProject, filename);
184
+ }
185
+
186
+ /********************************************************************
187
+
188
+ Water Quality Analysis Functions
189
+
190
+ ********************************************************************/
191
+
192
+ int DLLEXPORT ENsolveQ() { return EN_solveQ(_defaultProject); }
193
+
194
+ int DLLEXPORT ENopenQ() { return EN_openQ(_defaultProject); }
195
+
196
+ int DLLEXPORT ENinitQ(int saveFlag) { return EN_initQ(_defaultProject, saveFlag); }
197
+
198
+ int DLLEXPORT ENrunQ(long *currentTime) { return EN_runQ(_defaultProject, currentTime); }
199
+
200
+ int DLLEXPORT ENnextQ(long *tStep) { return EN_nextQ(_defaultProject, tStep); }
201
+
202
+ int DLLEXPORT ENstepQ(long *timeLeft) { return EN_stepQ(_defaultProject, timeLeft); }
203
+
204
+ int DLLEXPORT ENcloseQ() { return EN_closeQ(_defaultProject); }
205
+
206
+ /********************************************************************
207
+
208
+ Reporting Functions
209
+
210
+ ********************************************************************/
211
+
212
+ int DLLEXPORT ENwriteline(const char *line) { return EN_writeline(_defaultProject, line); }
213
+
214
+ int DLLEXPORT ENreport() { return EN_report(_defaultProject); }
215
+
216
+ int DLLEXPORT ENcopyreport(const char *filename)
217
+ {
218
+ return EN_copyreport(_defaultProject, filename);
219
+ }
220
+
221
+ int DLLEXPORT ENclearreport() { return EN_clearreport(_defaultProject); }
222
+
223
+ int DLLEXPORT ENresetreport() { return EN_resetreport(_defaultProject); }
224
+
225
+ int DLLEXPORT ENsetreport(const char *format) { return EN_setreport(_defaultProject, format); }
226
+
227
+ int DLLEXPORT ENsetstatusreport(int level)
228
+ {
229
+ return EN_setstatusreport(_defaultProject, level);
230
+ }
231
+
232
+ int DLLEXPORT ENsetreportcallback(void (*callback)(void *userData, void *EN_projectHandle, const char*))
233
+ {
234
+ return EN_setreportcallback(_defaultProject, callback);
235
+ }
236
+
237
+ int DLLEXPORT ENsetreportcallbackuserdata(void *userData)
238
+ {
239
+ return EN_setreportcallbackuserdata(_defaultProject, userData);
240
+ }
241
+
242
+ int DLLEXPORT ENgetversion(int *version) { return EN_getversion(version); }
243
+
244
+ int DLLEXPORT ENgeterror(int errcode, char *errmsg, int maxLen)
245
+ {
246
+ return EN_geterror(errcode, errmsg, maxLen);
247
+ }
248
+
249
+ int DLLEXPORT ENgetstatistic(int type, EN_API_FLOAT_TYPE *value)
250
+ {
251
+ double v = 0.0;
252
+ int errcode = EN_getstatistic(_defaultProject, type, &v);
253
+ *value = (EN_API_FLOAT_TYPE)v;
254
+ return errcode;
255
+ }
256
+
257
+ int DLLEXPORT ENgetresultindex(int type, int index, int *value)
258
+ {
259
+ return EN_getresultindex(_defaultProject, type, index, value);
260
+ }
261
+
262
+ int DLLEXPORT ENtimetonextevent(int *eventType, long *duration, int *elementIndex)
263
+ {
264
+ return EN_timetonextevent(_defaultProject, eventType, duration, elementIndex);
265
+ }
266
+
267
+ /********************************************************************
268
+
269
+ Analysis Options Functions
270
+
271
+ ********************************************************************/
272
+
273
+ int DLLEXPORT ENgetoption(int option, EN_API_FLOAT_TYPE *value)
274
+ {
275
+ double v = 0.0;
276
+ int errcode = EN_getoption(_defaultProject, option, &v);
277
+ *value = (EN_API_FLOAT_TYPE)v;
278
+ return errcode;
279
+ }
280
+
281
+ int DLLEXPORT ENsetoption(int option, EN_API_FLOAT_TYPE value)
282
+ {
283
+ return EN_setoption(_defaultProject, option, value);
284
+ }
285
+
286
+ int DLLEXPORT ENgetflowunits(int *units)
287
+ {
288
+ return EN_getflowunits(_defaultProject, units);
289
+ }
290
+
291
+ int DLLEXPORT ENsetflowunits(int units)
292
+ {
293
+ return EN_setflowunits(_defaultProject, units);
294
+ }
295
+
296
+ int DLLEXPORT ENgettimeparam(int param, long *value)
297
+ {
298
+ return EN_gettimeparam(_defaultProject, param, value);
299
+ }
300
+
301
+ int DLLEXPORT ENsettimeparam(int param, long value)
302
+ {
303
+ return EN_settimeparam(_defaultProject, param, value);
304
+ }
305
+
306
+ int DLLEXPORT ENgetqualinfo(int *qualType, char *chemName, char *chemUnits,
307
+ int *traceNode)
308
+ {
309
+ return EN_getqualinfo(_defaultProject, qualType, chemName, chemUnits, traceNode);
310
+ }
311
+
312
+ int DLLEXPORT ENgetqualtype(int *qualType, int *traceNode)
313
+ {
314
+ return EN_getqualtype(_defaultProject, qualType, traceNode);
315
+ }
316
+
317
+ int DLLEXPORT ENsetqualtype(int qualType, const char *chemName,
318
+ const char *chemUnits, const char *traceNode)
319
+ {
320
+ return EN_setqualtype(_defaultProject, qualType, chemName, chemUnits, traceNode);
321
+ }
322
+
323
+ /********************************************************************
324
+
325
+ Node Functions
326
+
327
+ ********************************************************************/
328
+
329
+ int DLLEXPORT ENaddnode(const char *id, int nodeType, int *index)
330
+ {
331
+ return EN_addnode(_defaultProject, id, nodeType, index);
332
+ }
333
+
334
+ int DLLEXPORT ENdeletenode(int index, int actionCode)
335
+ {
336
+ return EN_deletenode(_defaultProject, index, actionCode);
337
+ }
338
+
339
+ int DLLEXPORT ENgetnodeindex(const char *id, int *index)
340
+ {
341
+ return EN_getnodeindex(_defaultProject, id, index);
342
+ }
343
+
344
+ int DLLEXPORT ENgetnodeid(int index, char *id)
345
+ {
346
+ return EN_getnodeid(_defaultProject, index, id);
347
+ }
348
+
349
+ int DLLEXPORT ENsetnodeid(int index, const char *newid)
350
+ {
351
+ return EN_setnodeid(_defaultProject, index, newid);
352
+ }
353
+
354
+ int DLLEXPORT ENgetnodetype(int index, int *nodeType)
355
+ {
356
+ return EN_getnodetype(_defaultProject, index, nodeType);
357
+ }
358
+
359
+ int DLLEXPORT ENgetnodevalue(int index, int property, EN_API_FLOAT_TYPE *value)
360
+ {
361
+ double v = 0.0;
362
+ int errcode = EN_getnodevalue(_defaultProject, index, property, &v);
363
+ *value = (EN_API_FLOAT_TYPE)v;
364
+ return errcode;
365
+ }
366
+
367
+ int DLLEXPORT ENgetnodevalues(int property, EN_API_FLOAT_TYPE *values)
368
+ {
369
+ int i, errcode = 0;
370
+ EN_API_FLOAT_TYPE value;
371
+
372
+ for (i = 1; i <= _defaultProject->network.Nnodes; i++)
373
+ {
374
+ errcode = ENgetnodevalue(i, property, &value);
375
+ values[i-1] = value;
376
+ if (errcode != 0) return errcode;
377
+ }
378
+ return 0;
379
+ }
380
+
381
+ int DLLEXPORT ENsetnodevalue(int index, int property, EN_API_FLOAT_TYPE value)
382
+ {
383
+ return EN_setnodevalue(_defaultProject, index, property, value);
384
+ }
385
+
386
+ int DLLEXPORT ENsetjuncdata(int index, EN_API_FLOAT_TYPE elev, EN_API_FLOAT_TYPE dmnd,
387
+ const char *dmndpat)
388
+ {
389
+ return EN_setjuncdata(_defaultProject, index, elev, dmnd, dmndpat);
390
+ }
391
+
392
+ int DLLEXPORT ENsettankdata(int index, EN_API_FLOAT_TYPE elev,
393
+ EN_API_FLOAT_TYPE initlvl, EN_API_FLOAT_TYPE minlvl,
394
+ EN_API_FLOAT_TYPE maxlvl, EN_API_FLOAT_TYPE diam,
395
+ EN_API_FLOAT_TYPE minvol, const char *volcurve)
396
+ {
397
+ return EN_settankdata(_defaultProject, index, elev, initlvl, minlvl, maxlvl,
398
+ diam, minvol, volcurve);
399
+ }
400
+
401
+ int DLLEXPORT ENgetcoord(int index, double *x, double *y)
402
+ {
403
+ return EN_getcoord(_defaultProject, index, x, y);
404
+ }
405
+
406
+ int DLLEXPORT ENsetcoord(int index, double x, double y)
407
+ {
408
+ return EN_setcoord(_defaultProject, index, x, y);
409
+ }
410
+
411
+ /********************************************************************
412
+
413
+ Nodal Demand Functions
414
+
415
+ ********************************************************************/
416
+
417
+ int DLLEXPORT ENgetdemandmodel(int *model, EN_API_FLOAT_TYPE *pmin,
418
+ EN_API_FLOAT_TYPE *preq, EN_API_FLOAT_TYPE *pexp)
419
+ {
420
+ double pmin2 = 0.0, preq2 = 0.0, pexp2 = 0.0;
421
+ int errcode = EN_getdemandmodel(_defaultProject, model, &pmin2, &preq2, &pexp2);
422
+ *pmin = (EN_API_FLOAT_TYPE)pmin2;
423
+ *preq = (EN_API_FLOAT_TYPE)preq2;
424
+ *pexp = (EN_API_FLOAT_TYPE)pexp2;
425
+ return errcode;
426
+ }
427
+
428
+ int DLLEXPORT ENsetdemandmodel(int model, EN_API_FLOAT_TYPE pmin,
429
+ EN_API_FLOAT_TYPE preq, EN_API_FLOAT_TYPE pexp)
430
+ {
431
+ return EN_setdemandmodel(_defaultProject, model, pmin, preq, pexp);
432
+ }
433
+
434
+ int DLLEXPORT ENadddemand(int nodeIndex, EN_API_FLOAT_TYPE baseDemand,
435
+ const char *demandPattern, const char *demandName)
436
+ {
437
+ return EN_adddemand(_defaultProject, nodeIndex, baseDemand, demandPattern, demandName);
438
+ }
439
+
440
+ int DLLEXPORT ENdeletedemand(int nodeIndex, int demandIndex)
441
+ {
442
+ return EN_deletedemand(_defaultProject, nodeIndex, demandIndex);
443
+ }
444
+
445
+ int DLLEXPORT ENgetdemandindex(int nodeIndex, const char *demandName, int *demandIndex)
446
+ {
447
+ return EN_getdemandindex(_defaultProject, nodeIndex, demandName, demandIndex);
448
+ }
449
+
450
+ int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands)
451
+ {
452
+ return EN_getnumdemands(_defaultProject, nodeIndex, numDemands);
453
+ }
454
+
455
+ int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIndex,
456
+ EN_API_FLOAT_TYPE *baseDemand)
457
+ {
458
+ double bd2 = 0.0;
459
+ int errcode = EN_getbasedemand(_defaultProject, nodeIndex, demandIndex, &bd2);
460
+ *baseDemand = (EN_API_FLOAT_TYPE)bd2;
461
+ return errcode;
462
+ }
463
+
464
+ int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIndex,
465
+ EN_API_FLOAT_TYPE baseDemand)
466
+ {
467
+ return EN_setbasedemand(_defaultProject, nodeIndex, demandIndex, baseDemand);
468
+ }
469
+
470
+ int DLLEXPORT ENsetdemandpattern(int nodeIndex, int demandIndex, int patIndex)
471
+ {
472
+ return EN_setdemandpattern(_defaultProject, nodeIndex, demandIndex, patIndex);
473
+ }
474
+
475
+ int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIndex, int *pattIdx)
476
+ {
477
+ return EN_getdemandpattern(_defaultProject, nodeIndex, demandIndex, pattIdx);
478
+ }
479
+
480
+ int DLLEXPORT ENgetdemandname(int nodeIndex, int demandIndex, char *demandName)
481
+ {
482
+ return EN_getdemandname(_defaultProject, nodeIndex, demandIndex, demandName);
483
+ }
484
+
485
+ int DLLEXPORT ENsetdemandname(int nodeIndex, int demandIndex, const char *demandName)
486
+ {
487
+ return EN_setdemandname(_defaultProject, nodeIndex, demandIndex, demandName);
488
+ }
489
+
490
+ /********************************************************************
491
+
492
+ Link Functions
493
+
494
+ ********************************************************************/
495
+
496
+ int DLLEXPORT ENaddlink(const char *id, int linkType, const char *fromNode,
497
+ const char *toNode, int *index)
498
+ {
499
+ return EN_addlink(_defaultProject, id, linkType, fromNode, toNode, index);
500
+ }
501
+
502
+ int DLLEXPORT ENdeletelink(int index, int actionCode)
503
+ {
504
+ return EN_deletelink(_defaultProject, index, actionCode);
505
+ }
506
+
507
+ int DLLEXPORT ENgetlinkindex(const char *id, int *index)
508
+ {
509
+ return EN_getlinkindex(_defaultProject, id, index);
510
+ }
511
+
512
+ int DLLEXPORT ENgetlinkid(int index, char *id)
513
+ {
514
+ return EN_getlinkid(_defaultProject, index, id);
515
+ }
516
+
517
+ int DLLEXPORT ENsetlinkid(int index, const char *newid)
518
+ {
519
+ return EN_setlinkid(_defaultProject, index, newid);
520
+ }
521
+
522
+ int DLLEXPORT ENgetlinktype(int index, int *linkType)
523
+ {
524
+ return EN_getlinktype(_defaultProject, index, linkType);
525
+ }
526
+
527
+ int DLLEXPORT ENsetlinktype(int *index, int linkType, int actionCode)
528
+ {
529
+ return EN_setlinktype(_defaultProject, index, linkType, actionCode);
530
+ }
531
+
532
+ int DLLEXPORT ENgetlinknodes(int index, int *node1, int *node2)
533
+ {
534
+ return EN_getlinknodes(_defaultProject, index, node1, node2);
535
+ }
536
+
537
+ int DLLEXPORT ENsetlinknodes(int index, int node1, int node2)
538
+ {
539
+ return EN_setlinknodes(_defaultProject, index, node1, node2);
540
+ }
541
+
542
+ int DLLEXPORT ENgetlinkvalue(int index, int property, EN_API_FLOAT_TYPE *value)
543
+ {
544
+ double v = 0.0;
545
+ int errcode = EN_getlinkvalue(_defaultProject, index, property, &v);
546
+ *value = (EN_API_FLOAT_TYPE)v;
547
+ return errcode;
548
+ }
549
+ int DLLEXPORT ENgetlinkvalues(int property, EN_API_FLOAT_TYPE *values)
550
+ {
551
+ int i, errcode = 0;
552
+ EN_API_FLOAT_TYPE value;
553
+
554
+ for (i = 1; i <= _defaultProject->network.Nlinks; i++)
555
+ {
556
+ errcode = ENgetlinkvalue(i, property, &value);
557
+ values[i-1] = value;
558
+ if (errcode != 0) return errcode;
559
+ }
560
+ return 0;
561
+ }
562
+
563
+ int DLLEXPORT ENsetlinkvalue(int index, int property, EN_API_FLOAT_TYPE value)
564
+ {
565
+ return EN_setlinkvalue(_defaultProject, index, property, value);
566
+ }
567
+
568
+ int DLLEXPORT ENsetpipedata(int index, EN_API_FLOAT_TYPE length,
569
+ EN_API_FLOAT_TYPE diam, EN_API_FLOAT_TYPE rough, EN_API_FLOAT_TYPE mloss)
570
+ {
571
+ return EN_setpipedata(_defaultProject, index, length, diam, rough, mloss);
572
+ }
573
+
574
+ int DLLEXPORT ENgetvertexcount(int index, int *count)
575
+ {
576
+ return EN_getvertexcount(_defaultProject, index, count);
577
+ }
578
+
579
+ int DLLEXPORT ENgetvertex(int index, int vertex, double *x, double *y)
580
+ {
581
+ return EN_getvertex(_defaultProject, index, vertex, x, y);
582
+ }
583
+
584
+ int DLLEXPORT ENsetvertex(int index, int vertex, double x, double y)
585
+ {
586
+ return EN_setvertex(_defaultProject, index, vertex, x, y);
587
+ }
588
+
589
+ int DLLEXPORT ENsetvertices(int index, double *x, double *y, int count)
590
+ {
591
+ return EN_setvertices(_defaultProject, index, x, y, count);
592
+ }
593
+
594
+ /********************************************************************
595
+
596
+ Pump Functions
597
+
598
+ ********************************************************************/
599
+
600
+ int DLLEXPORT ENgetpumptype(int linkIndex, int *pumpType)
601
+ {
602
+ return EN_getpumptype(_defaultProject, linkIndex, pumpType);
603
+ }
604
+
605
+ int DLLEXPORT ENgetheadcurveindex(int linkIndex, int *curveIndex)
606
+ {
607
+ return EN_getheadcurveindex(_defaultProject, linkIndex, curveIndex);
608
+ }
609
+
610
+ int DLLEXPORT ENsetheadcurveindex(int linkIndex, int curveIndex)
611
+ {
612
+ return EN_setheadcurveindex(_defaultProject, linkIndex, curveIndex);
613
+ }
614
+
615
+ /********************************************************************
616
+
617
+ Time Pattern Functions
618
+
619
+ ********************************************************************/
620
+
621
+ int DLLEXPORT ENaddpattern(const char *id)
622
+ {
623
+ return EN_addpattern(_defaultProject, id);
624
+ }
625
+
626
+ int DLLEXPORT ENdeletepattern(int index)
627
+ {
628
+ return EN_deletepattern(_defaultProject, index);
629
+ }
630
+
631
+ int DLLEXPORT ENgetpatternindex(const char *id, int *index)
632
+ {
633
+ return EN_getpatternindex(_defaultProject, id, index);
634
+ }
635
+
636
+ int DLLEXPORT ENgetpatternid(int index, char *id)
637
+ {
638
+ return EN_getpatternid(_defaultProject, index, id);
639
+ }
640
+
641
+ int DLLEXPORT ENsetpatternid(int index, const char *id)
642
+ {
643
+ return EN_setpatternid(_defaultProject, index, id);
644
+ }
645
+
646
+ int DLLEXPORT ENgetpatternlen(int index, int *len)
647
+ {
648
+ return EN_getpatternlen(_defaultProject, index, len);
649
+ }
650
+
651
+ int DLLEXPORT ENgetpatternvalue(int index, int period, EN_API_FLOAT_TYPE *value)
652
+ {
653
+ double v = 0.0;
654
+ int errcode = EN_getpatternvalue(_defaultProject, index, period, &v);
655
+ *value = (EN_API_FLOAT_TYPE)v;
656
+ return errcode;
657
+ }
658
+
659
+ int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value)
660
+ {
661
+ return EN_setpatternvalue(_defaultProject, index, period, value);
662
+ }
663
+
664
+ int DLLEXPORT ENgetaveragepatternvalue(int index, EN_API_FLOAT_TYPE *value)
665
+ {
666
+ double v;
667
+ int errcode = EN_getaveragepatternvalue(_defaultProject, index, &v);
668
+ *value = (EN_API_FLOAT_TYPE)v;
669
+ return errcode;
670
+ }
671
+
672
+ int DLLEXPORT ENsetpattern(int index, EN_API_FLOAT_TYPE *values, int len)
673
+ {
674
+ double *v = NULL;
675
+ int i, errcode;
676
+ if (values == NULL) return 206;
677
+ v = (double *)calloc(len, sizeof(double));
678
+ if (v)
679
+ {
680
+ for (i = 0; i < len; i++) v[i] = values[i];
681
+ errcode = EN_setpattern(_defaultProject, index, v, len);
682
+ }
683
+ else errcode = 101;
684
+ free(v);
685
+ return errcode;
686
+ }
687
+
688
+ int DLLEXPORT ENloadpatternfile(const char *filename, const char *id)
689
+ {
690
+ return EN_loadpatternfile(_defaultProject, filename, id);
691
+ }
692
+
693
+ /********************************************************************
694
+
695
+ Data Curve Functions
696
+
697
+ ********************************************************************/
698
+
699
+ int DLLEXPORT ENaddcurve(const char *id)
700
+ {
701
+ return EN_addcurve(_defaultProject, id);
702
+ }
703
+
704
+ int DLLEXPORT ENdeletecurve(int index)
705
+ {
706
+ return EN_deletecurve(_defaultProject, index);
707
+ }
708
+
709
+ int DLLEXPORT ENgetcurveindex(const char *id, int *index)
710
+ {
711
+ return EN_getcurveindex(_defaultProject, id, index);
712
+ }
713
+
714
+ int DLLEXPORT ENgetcurveid(int index, char *id)
715
+ {
716
+ return EN_getcurveid(_defaultProject, index, id);
717
+ }
718
+
719
+ int DLLEXPORT ENsetcurveid(int index, const char *id)
720
+ {
721
+ return EN_setcurveid(_defaultProject, index, id);
722
+ }
723
+
724
+ int DLLEXPORT ENgetcurvelen(int index, int *len)
725
+ {
726
+ return EN_getcurvelen(_defaultProject, index, len);
727
+ }
728
+
729
+ int DLLEXPORT ENgetcurvetype(int index, int *type)
730
+ {
731
+ return EN_getcurvetype(_defaultProject, index, type);
732
+ }
733
+
734
+ int DLLEXPORT ENsetcurvetype(int index, int type)
735
+ {
736
+ return EN_setcurvetype(_defaultProject, index, type);
737
+ }
738
+
739
+ int DLLEXPORT ENgetcurvevalue(int curveIndex, int pointIndex, EN_API_FLOAT_TYPE *x,
740
+ EN_API_FLOAT_TYPE *y)
741
+ {
742
+ double xx = 0.0, yy = 0.0;
743
+ int errcode = EN_getcurvevalue(_defaultProject, curveIndex, pointIndex, &xx, &yy);
744
+ *x = (EN_API_FLOAT_TYPE)xx;
745
+ *y = (EN_API_FLOAT_TYPE)yy;
746
+ return errcode;
747
+ }
748
+
749
+ int DLLEXPORT ENsetcurvevalue(int curveIndex, int pointIndex, EN_API_FLOAT_TYPE x,
750
+ EN_API_FLOAT_TYPE y)
751
+ {
752
+ return EN_setcurvevalue(_defaultProject, curveIndex, pointIndex, x, y);
753
+ }
754
+
755
+ int DLLEXPORT ENgetcurve(int index, char *id, int *nPoints,
756
+ EN_API_FLOAT_TYPE *xValues, EN_API_FLOAT_TYPE *yValues)
757
+ {
758
+ int i;
759
+ Network *net = &_defaultProject->network;
760
+ Scurve *curve;
761
+
762
+ if (index <= 0 || index > net->Ncurves) return 206;
763
+ if (xValues == NULL || yValues == NULL) return 206;
764
+ curve = &net->Curve[index];
765
+ strncpy(id, curve->ID, MAXID);
766
+ *nPoints = curve->Npts;
767
+ for (i = 0; i < curve->Npts; i++)
768
+ {
769
+ xValues[i] = (EN_API_FLOAT_TYPE)curve->X[i];
770
+ yValues[i] = (EN_API_FLOAT_TYPE)curve->Y[i];
771
+ }
772
+ return 0;
773
+ }
774
+
775
+ int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *xValues,
776
+ EN_API_FLOAT_TYPE *yValues, int nPoints)
777
+ {
778
+ double *xx = NULL;
779
+ double *yy = NULL;
780
+ int i, errcode = 0;
781
+
782
+ if (xValues == NULL || yValues == NULL) return 206;
783
+ if (nPoints < 1) return 202;
784
+
785
+ xx = (double *)calloc(nPoints, sizeof(double));
786
+ yy = (double *)calloc(nPoints, sizeof(double));
787
+ if (xx && yy)
788
+ {
789
+ for (i = 0; i < nPoints; i++)
790
+ {
791
+ xx[i] = xValues[i];
792
+ yy[i] = yValues[i];
793
+ }
794
+ errcode = EN_setcurve(_defaultProject, index, xx, yy, nPoints);
795
+ }
796
+ else errcode = 101;
797
+ free(xx);
798
+ free(yy);
799
+ return errcode;
800
+ }
801
+
802
+ /********************************************************************
803
+
804
+ Simple Controls Functions
805
+
806
+ ********************************************************************/
807
+
808
+ int DLLEXPORT ENaddcontrol(int type, int linkIndex, EN_API_FLOAT_TYPE setting,
809
+ int nodeIndex, EN_API_FLOAT_TYPE level, int *index)
810
+ {
811
+ return EN_addcontrol(_defaultProject, type, linkIndex, setting, nodeIndex,
812
+ level, index);
813
+ }
814
+
815
+ int DLLEXPORT ENdeletecontrol(int index)
816
+ {
817
+ return EN_deletecontrol(_defaultProject, index);
818
+ }
819
+
820
+ int DLLEXPORT ENgetcontrol(int index, int *type, int *linkIndex,
821
+ EN_API_FLOAT_TYPE *setting, int *nodeIndex, EN_API_FLOAT_TYPE *level)
822
+ {
823
+ double setting2 = 0.0, level2 = 0.0;
824
+ int errcode = EN_getcontrol(_defaultProject, index, type, linkIndex, &setting2,
825
+ nodeIndex, &level2);
826
+ *setting = (EN_API_FLOAT_TYPE)setting2;
827
+ *level = (EN_API_FLOAT_TYPE)level2;
828
+ return errcode;
829
+ }
830
+
831
+ int DLLEXPORT ENsetcontrol(int index, int type, int linkIndex,
832
+ EN_API_FLOAT_TYPE setting, int nodeIndex, EN_API_FLOAT_TYPE level)
833
+ {
834
+ return EN_setcontrol(_defaultProject, index, type, linkIndex, setting,
835
+ nodeIndex, level);
836
+ }
837
+
838
+
839
+ int DLLEXPORT ENgetcontrolenabled(int index, int *out_enabled)
840
+ {
841
+ return EN_getcontrolenabled(_defaultProject, index, out_enabled);
842
+ }
843
+
844
+ int DLLEXPORT ENsetcontrolenabled(int index, int enabled)
845
+ {
846
+ return EN_setcontrolenabled(_defaultProject, index, enabled);
847
+ }
848
+
849
+ /********************************************************************
850
+
851
+ Rule-Based Controls Functions
852
+
853
+ ********************************************************************/
854
+
855
+ int DLLEXPORT ENaddrule(char *rule)
856
+ {
857
+ return EN_addrule(_defaultProject, rule);
858
+ }
859
+
860
+ int DLLEXPORT ENdeleterule(int index)
861
+ {
862
+ return EN_deleterule(_defaultProject, index);
863
+ }
864
+
865
+ int DLLEXPORT ENgetrule(int index, int *nPremises, int *nThenActions,
866
+ int *nElseActions, EN_API_FLOAT_TYPE *priority)
867
+ {
868
+ double priority2 = 0.0;
869
+ int errcode = EN_getrule(_defaultProject, index, nPremises, nThenActions,
870
+ nElseActions, &priority2);
871
+ *priority = (EN_API_FLOAT_TYPE)priority2;
872
+ return errcode;
873
+ }
874
+
875
+ int DLLEXPORT ENgetruleID(int index, char* id)
876
+ {
877
+ return EN_getruleID(_defaultProject, index, id);
878
+ }
879
+
880
+ int DLLEXPORT ENgetpremise(int ruleIndex, int premiseIndex, int *logop, int *object,
881
+ int *objIndex, int *variable, int *relop, int *status,
882
+ EN_API_FLOAT_TYPE *value)
883
+ {
884
+ double v = 0.0;
885
+ int errcode = EN_getpremise(_defaultProject, ruleIndex, premiseIndex, logop,
886
+ object, objIndex, variable, relop, status, &v);
887
+ *value = (EN_API_FLOAT_TYPE)v;
888
+ return errcode;
889
+ }
890
+
891
+ int DLLEXPORT ENsetpremise(int ruleIndex, int premiseIndex, int logop, int object,
892
+ int objIndex, int variable, int relop, int status, EN_API_FLOAT_TYPE value)
893
+ {
894
+ return EN_setpremise(_defaultProject, ruleIndex, premiseIndex, logop, object,
895
+ objIndex, variable, relop, status, value);
896
+ }
897
+
898
+ int DLLEXPORT ENsetpremiseindex(int ruleIndex, int premiseIndex, int objIndex)
899
+ {
900
+ return EN_setpremiseindex(_defaultProject, ruleIndex, premiseIndex, objIndex);
901
+ }
902
+
903
+ int DLLEXPORT ENsetpremisestatus(int ruleIndex, int premiseIndex, int status)
904
+ {
905
+ return EN_setpremisestatus(_defaultProject, ruleIndex, premiseIndex, status);
906
+ }
907
+
908
+ int DLLEXPORT ENsetpremisevalue(int ruleIndex, int premiseIndex, EN_API_FLOAT_TYPE value)
909
+ {
910
+ return EN_setpremisevalue(_defaultProject, ruleIndex, premiseIndex, value);
911
+ }
912
+
913
+ int DLLEXPORT ENgetthenaction(int ruleIndex, int actionIndex, int *linkIndex,
914
+ int *status, EN_API_FLOAT_TYPE *setting)
915
+ {
916
+ double setting2 = 0.0;
917
+ int errcode = EN_getthenaction(_defaultProject, ruleIndex, actionIndex, linkIndex,
918
+ status, &setting2);
919
+ *setting = (EN_API_FLOAT_TYPE)setting2;
920
+ return errcode;
921
+ }
922
+
923
+ int DLLEXPORT ENsetthenaction(int ruleIndex, int actionIndex, int linkIndex,
924
+ int status, EN_API_FLOAT_TYPE setting)
925
+ {
926
+ return EN_setthenaction(_defaultProject, ruleIndex, actionIndex, linkIndex,
927
+ status, setting);
928
+ }
929
+
930
+ int DLLEXPORT ENgetelseaction(int ruleIndex, int actionIndex, int *linkIndex,
931
+ int *status, EN_API_FLOAT_TYPE *setting)
932
+ {
933
+ double setting2 = 0.0;
934
+ int errcode = EN_getelseaction(_defaultProject, ruleIndex, actionIndex, linkIndex,
935
+ status, &setting2);
936
+ *setting = (EN_API_FLOAT_TYPE)setting2;
937
+ return errcode;
938
+ }
939
+
940
+ int DLLEXPORT ENsetelseaction(int ruleIndex, int actionIndex, int linkIndex,
941
+ int status, EN_API_FLOAT_TYPE setting)
942
+ {
943
+ return EN_setelseaction(_defaultProject, ruleIndex, actionIndex, linkIndex,
944
+ status, setting);
945
+ }
946
+
947
+ int DLLEXPORT ENsetrulepriority(int index, EN_API_FLOAT_TYPE priority)
948
+ {
949
+ return EN_setrulepriority(_defaultProject, index, priority);
950
+ }
951
+
952
+
953
+ int DLLEXPORT ENgetruleenabled(int index, int *out_enabled)
954
+ {
955
+ return EN_getruleenabled(_defaultProject, index, out_enabled);
956
+ }
957
+
958
+ int DLLEXPORT ENsetruleenabled(int index, int enabled)
959
+ {
960
+ return EN_setruleenabled(_defaultProject, index, enabled);
961
+ }