From b30a857319dfcc01a857c15f7412d5f2b6c1150f Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Wed, 18 Jun 2025 10:43:36 -0400 Subject: [PATCH] Fix Trace Node bug See issue #859 --- src/epanet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index a3c2849..b872751 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -1825,7 +1825,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, const char *chemName, Quality *qual = &p->quality; double *Ucf = p->Ucf; - int i, oldQualFlag, traceNodeIndex; + int i, oldQualFlag, traceNodeIndex = 0; double ccf = 1.0; if (!p->Openflag) return 102; @@ -1837,6 +1837,7 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, const char *chemName, if (traceNodeIndex == 0) return 212; } + qual->TraceNode = traceNodeIndex; oldQualFlag = qual->Qualflag; qual->Qualflag = qualType; qual->Ctol *= Ucf[QUALITY]; @@ -1851,8 +1852,6 @@ int DLLEXPORT EN_setqualtype(EN_Project p, int qualType, const char *chemName, } if (qual->Qualflag == TRACE) // Source trace analysis { - qual->TraceNode = findnode(net, traceNode); - if (qual->TraceNode == 0) return 212; strncpy(qual->ChemName, w_TRACE, MAXID); strncpy(qual->ChemUnits, u_PERCENT, MAXID); strcpy(rpt->Field[QUALITY].Units, u_PERCENT); @@ -2086,6 +2085,7 @@ int DLLEXPORT EN_deletenode(EN_Project p, int index, int actionCode) // ... update node's entry in the hash table hashtable_update(net->NodeHashTable, net->Node[i].ID, i); } + if (index < p->quality.TraceNode) (p->quality.TraceNode)--; // If deleted node is a tank, remove it from the Tank array if (nodeType != EN_JUNCTION)