This example shows how a network can be built just through toolkit function calls, eliminating the need to always use an EPANET formatted input file. This creates opportunities to use other sources of network data in one's code, such as relational database files or GIS/CAD files.
Below is a schematic of the network to be built.
#include "epanet2_2.h"
void netbuilder()
{
int index;
EN_Project ph;
EN_createproject(&ph);
EN_init(ph, "", "", EN_GPM, EN_HW);
EN_addnode(ph, "J1", EN_JUNCTION, &index);
EN_setjuncdata(ph, index, 700, 0, "");
EN_addnode(ph, "J2", EN_JUNCTION, &index);
EN_setjuncdata(ph, index, 710, 250, "");
EN_addnode(ph, "J3", EN_JUNCTION, &index);
EN_setjuncdata(ph, index, 710, 500, "");
EN_addnode(ph, "R1", EN_RESERVOIR, &index);
EN_setnodevalue(ph, index, EN_ELEVATION, 650);
EN_addnode(ph, "T1", EN_TANK, &index);
EN_settankdata(ph, index, 850, 120, 100, 150, 50.5, 0, "");
EN_addlink(ph, "P1", EN_PIPE, "J1", "J2", &index);
EN_setpipedata(ph, index, 10560, 12, 100, 0);
EN_addlink(ph, "P2", EN_PIPE, "J1", "T1", &index);
EN_setpipedata(ph, index, 5280, 14, 100, 0);
EN_addlink(ph, "P3", EN_PIPE, "J1", "J3", &index);
EN_setpipedata(ph, index, 5280, 14, 100, 0);
EN_addlink(ph, "P4", EN_PIPE, "J2", "J3", &index);
EN_setpipedata(ph, index, 5280, 14, 100, 0);
EN_addlink(ph, "PUMP", EN_PUMP, "R1", "J1", &index);
EN_addcurve(ph, "C1");
EN_setcurvevalue(ph, 1, 1, 1500, 250);
EN_setlinkvalue(ph, index, EN_PUMP_HCURVE, 1);
EN_saveinpfile(ph, "example2.inp");
EN_deleteproject(ph);
}