From 803bad0bf05aff1e195030e6efb1c41e31f34f90 Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Mon, 5 Aug 2019 14:08:18 -0400 Subject: [PATCH] Fixes EN_setlinkvalue bug --- src/epanet.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 78e631f..7694b82 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -3890,7 +3890,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu if (Link[index].Type == PUMP) { patIndex = ROUND(value); - if (patIndex <= 0 || patIndex > net->Npats) return 205; + if (patIndex < 0 || patIndex > net->Npats) return 205; pumpIndex = findpump(&p->network, index); net->Pump[pumpIndex].Upat = patIndex; } @@ -3923,7 +3923,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu if (Link[index].Type == PUMP) { curveIndex = ROUND(value); - if (curveIndex <= 0 || curveIndex > net->Ncurves) return 205; + if (curveIndex < 0 || curveIndex > net->Ncurves) return 205; pumpIndex = findpump(&p->network, index); net->Pump[pumpIndex].Ecurve = curveIndex; } @@ -3942,7 +3942,7 @@ int DLLEXPORT EN_setlinkvalue(EN_Project p, int index, int property, double valu if (Link[index].Type == PUMP) { patIndex = ROUND(value); - if (patIndex <= 0 || patIndex > net->Npats) return 205; + if (patIndex < 0 || patIndex > net->Npats) return 205; pumpIndex = findpump(&p->network, index); net->Pump[pumpIndex].Epat = patIndex; } @@ -4068,13 +4068,14 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project p, int linkIndex, int curveIndex) if (!p->Openflag) return 102; if (linkIndex < 1 || linkIndex > net->Nlinks) return 204; if (PUMP != net->Link[linkIndex].Type) return 0; - if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206; + if (curveIndex < 0 || curveIndex > net->Ncurves) return 206; // Assign the new curve to the pump pumpIndex = findpump(net, linkIndex); pump = &p->network.Pump[pumpIndex]; pump->Ptype = NOCURVE; pump->Hcurve = curveIndex; + if (curveIndex == 0) return 0; // Update the pump curve's parameters and convert their units updatepumpparams(p, pumpIndex);