EPANET Programmer’s Toolkit

I have mentioned the EPANET toolkit several times before but didn’t post any information about it yet. The following info is from the toolkit readme file:

EPANET is a program that analyzes the hydraulic and water quality behavior of water distribution systems. The EPANET Programmer’s Toolkit is a dynamic link library (DLL) of functions that allows developers to customize EPANET’s computational engine for their own specific needs. The functions can be incorporated into 32-bit Windows applications written in C/C++, Delphi Pascal, Visual Basic, or any other language that can call functions within a Windows DLL. The Toolkit DLL file is named EPANET2.DLL and is distributed with EPANET. The Toolkit comes with several different header files, function definition files, and .lib files that simplify the task of interfacing it with C/C++, Delphi, and Visual Basic code.

The freeware FireFlow utility was written using the EPANET toolkit.

For more information and download see EPANET web page.

76 comments on “EPANET Programmer’s Toolkit
  1. lekshmibhavana says:

    sir

    i want to optimise the water distribution system of our campus using ant colony optimisation.
    i am with a set of equations associated with ant colony optimisation and, can you help me to develope a code to link with that of the epanet tool kit.

  2. lekshmibhavana says:

    can it be open the epanet tool kit with that of windows xp.

  3. Elad says:

    lekshmibhavana,

    1) The toolkit can be used in Windows XP.
    2) What exactly do you need regarding the Ant Colony optimization?

    Elad

  4. lekshmibhavana says:

    sir
    my project is the optimisation of water distribution system using Ant colony optimisation . Ants secreting a substance called pheromone during there way from nest to the food source. By means of these pheromone successive ants realise the shortest path and thus they can optimise their path . Like wise with the available diameters we can optimise water distribution system by keeping the minimum pressure head and other constraints.

    I came to know that we can develope a programme on Epanet tool kit and can be linked. Can i downloaded that epanet tool kit for that purpose and can you give me further advices about that
    yours sincerely

    LEKSHMI

  5. Elad says:

    lekshmibhavana,

    The EPANet Toolkit can be dwonloaded from here:
    http://www.epa.gov/ORD/NRMRL/wswrd/EN2toolkit.zip

    Elad

  6. lekshmibhavana says:

    Sir

    What should be the procedure adopted for writing a programme in c or c++ using toolkit.
    I DOWNLOADED THE EPANET TOOLKIT .
    Now i am with a water distribution network. From my learnings i came to know that first
    1. The network should be drawn in EPANET
    2. Enter the pipe lengths, water demands at all the nodes, elevations at all the nodes etc
    3. Write programme in Epanet.dll by calling required outputs from the Epanet
    4. Run the programme.

    Now i am with a possible 11 diameters and their associated costs. Where i input the cost?
    Can it be through the programme or anywhere else?

    i expect all the help from you

    I have a great expectation about my project

    THANKING YOU

    yOURS FAITHFULLY

    LEKSHMIBHAVANA

  7. Manuel says:

    I have a similar problem that LEKSHMIBHAVANA’s problem,
    I desire implementing heuristic algorithms with the EPANET’s input/output, but I don’t know how make this.

    Thanks and… sorry for my english

    Manuel

  8. Manuel,

    If you ask a specific question I can try and help 🙂

  9. tongirri says:

    i need example code because i writecode not work
    my file in c:\EN\
    in folder EN have file
    epanet2.dll
    epanet2vc.lib
    epanet2.h
    int1.inp
    test.c

    this is test.c code

    #include
    #include “epanet2.h”
    void main()
    {
    int errcode;

    errcode = ENopen(“int1.inp”,”int1.rpt”,””);
    if (errcode>0)
    {
    printf(“cann’t run ENopen”);
    ENclose();
    return;
    }

    ENsolveH();
    ENsolveQ();
    ENreport();
    ENclose();
    }

    please sent example code to my e-mail

    tongirri@hotmail.com

  10. tongirri,

    What error do you get?

    Please see this example:
    http://www.water-simulation.com/wsp/bb/viewtopic.php?id=238

  11. tongirri says:

    in my code
    i write code follow programmer’s toolkit in page “opening and closeing the toolkit” and “ENsolveH”

    after buid
    VC show

    ——————–Configuration: test – Win32 Debug——————–
    Compiling…
    test.c
    Linking…
    test.obj : error LNK2001: unresolved external symbol _ENreport@0
    test.obj : error LNK2001: unresolved external symbol _ENsolveQ@0
    test.obj : error LNK2001: unresolved external symbol _ENsolveH@0
    test.obj : error LNK2001: unresolved external symbol _ENclose@0
    test.obj : error LNK2001: unresolved external symbol _ENopen@12
    Debug/test.exe : fatal error LNK1120: 5 unresolved externals
    Error executing link.exe.

    test1.exe – 6 error(s), 0 warning(s)

    ————————————————-
    i see example2-c in programmer’s toolkit
    how i will call function “HydrantRating ()” in main program

    void main()
    {
    .
    .
    .
    HydrantRating (?,?,?,?);
    .
    .
    .
    }

    Thanks you

  12. Cynthia says:

    Hi!
    I have the same problem as tongirri, I keep on getting the error LINK for unresolved external symbol. I’m using VS.NET 2003 with C++ as a programming language, I’m including the epanet2.h, I read in another forum that I have to use the epanetvc.lib instead of the header file.

    Can someone please help me????

    Thanks

  13. Marco says:

    Hi Cynthia and Tongirri!
    I hope that these advices will help you, I met the same problem and spent a week to find the solution!!!
    These are the step I followed using Microsoft Visual C++:
    – include epanet2.h in your source file (.cpp);
    – compile the program;
    – link the library epanetvc.lib in this way:
    on the menu bar select
    project —> add to project —> files…
    To be sure that the library has been linked, control in the workspace, in “fileview” if there is the file epanetvc.lib.
    – Now you can build the program and then execute it!!

    If you’ll meet other problems write, I’m here!!

    Bye

  14. Moisֳ©s says:

    I am open and build the epanet2 source code in Delphi7, it’s work fine, however a save file in a project of my epanet don’t open in others versions of epanet (english and portuguese). Only when i use caracters “ֳ§ ֳ¡ ֳ© ֳ­ ֳ³ ֳ÷” in descrition of pump. I think that code page language or delphi are different of mine. I don’t know that do for fix this.

  15. Priya says:

    dear sir
    my project is determining the water quality of the distribution system. especially determining the concentration at each node. i have some set of equations to find the concentration. i have drawn the network and gave all the mandated inputs. i have run the analysis also. in my analysis i am getting concentration level at the initial node(reservoir and the first node) for the others i am getting 0Mg/l. i couldnt trouble shoot the problem. i dont know how to write c code also. whether to write in c editor or any editor inside the tool kit. when i import the network an input file is created. how to take input from this file and link with c code? plz sir help me for my futher work. i have great expectations for my project. expecting for your reply
    thanks and regards
    P.Priya

  16. Luke says:

    I’m designing a geothermal community ground loop system. It’s a closed loop where I am just supplying heat pumps with water for their heat exchangers to cycle. My question is should I represent a home with a “node” or a “pump”?

  17. Victor says:

    Hi
    I have a problem wiht MS Visual Studio 2005, I program using the Epanet Toolkit on a C files, but now i need program in C++ wiht Objects, but the MS Visual Studio sendme 55 error and 110 warnings, what hapen??

    please helpme !!
    Thanks

  18. shankar says:

    hi
    i m doing my m.tech thesis on optimal design of water distribution network using lingo software and rechecking the values in epanet. i am unable to write a code in lingo for head loss in a link around a loop,and i am not able to write for hl around the loop,

  19. Nehme says:

    Hi,
    I had the same problem that Victor is talking about and here is how I fixed the problem.
    If you’re using C++ on a windows machine:

    Open the epanet2.h file, modify all the functions in the file from:
    int DLLEXPORT function()
    to
    extern “C” __declspec(dllimport) int __stdcall function()

    example:
    int DLLEXPORT ENepanet(char *, char *, char *, void (*) (char *));
    became:
    extern “C” __declspec(dllimport) int __stdcall ENepanet(char *, char *, char *, void (*) (char *));

  20. Nick says:

    Hi there,

    I’m starting to setup the EPANet toolkit and link this into to an optimisation algorithm.

    I’m working in C and am having some problems calling the ENopen(“input.inp”,”input.rpt”,””) functions amongst others.

    I was wondering if anyone has had the same experience. I work on a Mac so I’m not sure if this would be a problem.

    Can someone in lamens terms maybe tell me where the toolkit header files etc need to be copied and other instructions?

    cheers,

    n

  21. Victor says:

    Hi

    i have a big problem, a work with Epanet tool in a Genetic Algorithm in C++ with the MS visual studio 2005, when i call 32767 times to toolkit ocurrs the problem, error 305!!

    some one help me!!

    Thanks
    victor

    • bcoelho says:

      error 305 corresponds to a problem opening hydraulics file. Maybe you are using ENsolveH() in your program – you should not use it in optimisation procedures. Instead you should use ENopenH, ENinitH, ENrunH, ENnextH and ENclose. Notice that you should use ENinitH(00) or ENinitH(10) in order to do not save hydraulic results. Results should be used directly as they are generated in the cycle ENrunH-ENnextH. Using ENinitH(01) or ENinitH(11) (options to save results) will generate the same error 305 after 32767 iterations.

  22. Prasad says:

    Hi Nehme,
    I could not still figure this out. Could you please elaborate if there are any int to be declared or “;” missing.

    Thanks,
    Prasad

  23. Prasad says:

    Hi Nehme,
    My errors doubled from 55 to 110 and got 2 warnings instead of 110. Errors are as follows:
    VICTOR, WERE YOU ABLE TO FIGURE OUT THE ERRORS?

    x error : ‘int’ should be preceded by ‘;’
    1>c:\program files\microsoft visual studio 9.0\vc\include\epanet2.h(164) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft visual studio 9.0\vc\include\epanet2.h(164) : warning C4091: ‘__declspec(dllimport)’ : ignored on left of ‘int’ when no variable is declared

  24. AAS says:

    Victor, post or email me your code

  25. Prasad says:

    Hi Macro,
    I am using VC++ express edition 2008. I was trying to follow your directions but could not get the workspace or it did not show the appropriate links. Please help!

  26. Prasad says:

    I have to change the header file. Please let me know if anyone is interested in knowing the solution.

  27. Hailiang says:

    Usually one can call epanet source code in two ways: all explanation apply to vc++ 2008 express,
    1 use the source code. You need to go to tools-> options->projects and solutions-> vc++ directories, then add the epanet source code to the include path. Or you can copy the source code to your project file, so you do not need to include the file folder,

    2 use the .dll and .lib. add the following command in front of the main function, #pragma commend(lib, “epanet.lib”) #include “epanet2.h”. In the epanet2.h, you need to add #extern “C” to extern functions to resolve the external symbols, e.g. ENopen. You do not need the DLLExport now, delete all of them, and the ones in epanet.c file.

  28. Prasad says:

    Thanks a lot Hailiang! This solves the problem. Quick question – If you can quote an example of making use of ENsameinpfile shall be great help.

  29. Prasad says:

    Also, it would be a big help if you could provide an example of creating a report for age at nodes using toolkit

  30. RePrasad says:

    What is the best way to report the age in the rpt file using toolkit? Can someone help me with an example?

  31. hayrat says:

    Sulfate and total hardnes are overproof, others no overproof of the standards.However, i do not know how to applying epanet to evaluate it?

  32. Javad says:

    Dear Elad,

    I want to develop an application in order to energy optimization in pump stations maybe with Python, am I could connect to Epanet toolkit? Please help me

    Thanks.

  33. Alec says:

    Dear Elad,

    I want to develop an application in order to calibrate water network model (just simple cycle). I would like to use The EPANET Programmer’s Toolkit. Which c++ compiler is the most suitable to do that into it?

    Best regard,
    Alec

  34. azamnakhaee says:

    Hello. My name is Nakhaee. Graduate student I am a civil engineering degree. For a thesis on the application must I link epanet into Matlab and roughness of the pipe in software Matlab and I epanet about the pressure and velocity of the epanet and I use the program Matlab. I’m grateful if you can help me

  35. Asaph Mercy says:

    Hello,
    I have been trying to build an EPANET2.DLL file using Microsoft Visual Studio.
    After loading all the source and header files into the Microsoft Visual Studio project, building of the dll file is done perfectly. Now the problem is that when I replace the generated dll file with the original dll file that is included in the EPANET2 installation package, and open epanet GUI, I get this Error Message: “The procedure entry point ENCLOSEQ could not be located in the dynamic link library EPANET2.DLL”.
    If any one has ever encountered this problem please advise on how I can solve it.

  36. maha says:

    i want to optimise the water distribution system using particle swarm optimisation.
    can you help me to develope a code to link matlab to epanet kit.

  37. Juan Luis Mejido says:

    Hi guys:

    I used Epanet Toolkit in a VB6 project a few years ago. Right now i’m trying to modify and convert my program to Visual Basic .NET code but i’m having unexpected errors like “Access Violation Exception” while trying to execute functions as ENGetNodeIndex and others. Anyone has the experience of declaring epanes2.dll functions in VB.NET?

    Thanks a lot

    Juan

  38. Masud Rana says:

    Hello All,

    I am trying build programs to run simulation using EPANET toolkit using visual c++ 2008. For starter I am trying to write a simple program that only calls ENopen() function. I have a properly formatted input file named “input.txt”. But there is no way I can run my program. I have tried so many different methods and I desperately need help. I think my problem is that I am not linking the library file properly. I am pasting my code here for your reference and also the error message:

    #include
    #include”epanet2.h”

    using namespace std;
    void main()
    {
    //FILE *fp;
    //f1 = fopen(“C:\\Users\\Masud Rana\\Documents\\C++ CPP Files\\ENtest01\\ENtest01\\input.txt”,”r”);
    //f2 = fopen(“C:\\Users\\Masud Rana\\Documents\\C++ CPP Files\\ENtest01\\ENtest01\\output.txt”,”w”);

    char *f1,*f2,*f3;
    int errcode=ENopen(f1,f2,f3);
    if (errcode>0)
    {
    cout<<"\n Error in executing the function Enopen \n";
    return;
    //int ENclose();
    } else cout<ENtest01.obj : error LNK2019: unresolved external symbol _ENopen@12 referenced in function _main

    1>C:\Users\Masud Rana\Documents\C++ CPP Files\ENtest01\Debug\ENtest01.exe : fatal error LNK1120: 1 unresolved externals

    • bcoelho says:

      you need to open f3 file or use ENopen(f1, f2, “”) if you dont want to save a binary output file…

  39. Masud Rana says:

    All help is greatly appreciated.
    Thanks.
    Masud

  40. Masud Rana says:

    I have finally managed to link the library file. So you can disregard my previous questions. But now the problem is how do I provide the function ENopen(char*,char*,char*) with pointer to type char when I am actually trying to provide it with a input.inp file.

    I have tried ENopen(“input.inp”,”output.rpt”,””); but it is not working. Do I have to keep the input.inp file in a specific directory? Now it is in the project folder but the ENopen function won’t run.

    Thanks,
    Masud

  41. Adina says:

    Hello! I am new to the epanet toolkit. I loaded the library in matlab, and i have tried several simple exemples which worked for the complete extended period analysis. Now i have problems when i try to run the sequence ENopenH – ENinitH – ENrunH- ENnextH – ENcloseH to step through the simulation one hydraulic time step at a time. I have tried to make a code that at each time step increments every diameter by 10 mm, and to see the efect over the velocity at each time step. Here is the code:

    wdsfile=’Incercare_toolkit2.inp’;
    epanetloadfile(wdsfile);

    calllib(‘epanet2’, ‘ENopenH’);
    calllib(‘epanet2’, ‘ENinitH’, 00);

    % Initialise some variables:
    t = 0; tstep = 0; value = 0.0;
    Nr_cond=getdata(‘EN_LINKCOUNT’);
    [D]=getdata(‘EN_DIAMETER’);

    while tstep<10000
    [t]=calllib('epanet2','ENrunH',t);
    for i=1:Nr_cond
    D(i)=D(i)+10;
    end
    setdata('EN_DIAMETER',[D]);
    [valoare]=getdata('EN_VELOCITY');
    t
    valoare

    tstep=tstep+3600
    calllib('epanet2', 'ENnextH', tstep);
    end
    % Close the solver
    calllib('epanet2', 'ENcloseH');

    %close everything
    epanetclose();

    The result is an error of matlab which tells me that i should close the program, the diameters increase with 10 mm on each time step, but the matrix "valoare" contains all the modified velocities for all the time steps, as i would have ran the code for an complete extended period analysis (for 12 hours).

    Could you please tell me what am i doing wrong, or could you please give me an exemple of matlab code to run this kind of simulation?

  42. Nuno Dias says:

    Hello,

    In VBA for Excel, I need to indicate the full path of the input and output files, so I think it should be the same…

    Good luck,
    Nuno Dias

  43. Masud Rana says:

    I Actually figured out the problem. The parameters of ENopen – ENopen(char*,char*,char*) – are just pointers whose value is the name of the file you want as input. So if your input file name is input.inp, you can simply declare:

    char *f1 = “input.inp”;
    char *f2 = “output.rpt”;

    and then call the function by.. ENopen(f1, f2, “”);

    and keep the input.inp in the same directory as your cpp file. And the ENopen function should run fine.

    If it still doesn’t run, then it is very handy to check the error code that ENopen function returns (check my code above). You look up the error code in the EPAnet toolkit manual and you will know exactly why is your program not running.

    Thanks,
    Masud

  44. James Ryan Monterola says:

    My EPANET2.0 won’t run , i reformatted my pc then installed a new windows xp . it wont run anymore, but before i reformatted my pc, the EPANET2.0 perfectly runs on windows xp.

  45. Nil says:

    I am using EPANET toolkit. But, getting errors while compiling the code, though I am using the same code given in user manual….please help me how can I resolve it.

    the errors are:

    Linking…
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXclose@0
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXsaveoutfile@4
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXreport@0
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXstep@8
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXinit@4
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXsolveH@0
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _MSXopen@4
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _ENclose@0
    EPANETMSX.OBJ : error LNK2001: unresolved external symbol _ENopen@12
    Debug/EPANETMSX.exe : fatal error LNK1120: 9 unresolved externals
    Error executing link.exe.

    EPANETMSX.exe – 10 error(s), 0 warning(s)

  46. Nil says:

    The previous problem is solved by adding two headers…however, when i am executing the file it is giving following message: The application failed to initialize properly (0xc000007b) Click on OK to terminate the application..is there any solve…??? plz help me…

  47. Hamed says:

    Hi dear friends
    I want to connect my visual basic 6 project to epanet with toolkit.
    I read it’s manual many times but when i use as following code the program return error 203!
    “ENgetnodeindex(MyNode, nodeindex)”

    can you help and send an example project with visual basic to me
    best regard

  48. Mengning Qiu says:

    Hello everyone!
    Just wondering are there any requirement to use ENGETNODEVALUE(NODE ID,EN_SOURCEMASS,&f)
    I’ve tried to get the chlorine mass flowrate at the dosage point to calculate the cost. But the value it stores in f is always 0.

  49. Ricardo says:

    How I can start modifying the source code of EPANET?

  50. Lucas Vasconcelos says:

    @Ricardo

    The source code is available in EPA’s website
    http://www.epa.gov/nrmrl/wswrd/dw/epanet.html

    There is no need for it, though. The toolkit is meant to save you the trouble of understanding the source code. You can call the program’s functions without even recompiling the original DLL.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.