From 70d5483361312799114225bb1846dc0b863da698 Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Tue, 11 Feb 2025 15:38:30 -0500 Subject: [PATCH] Add read/write of disabled controls to input file --- src/inpfile.c | 6 +++++- src/input3.c | 22 +++++++++++++++------- src/rules.c | 17 ++++++++++++++--- src/text.h | 3 ++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/inpfile.c b/src/inpfile.c index 9945a2a..b91e666 100644 --- a/src/inpfile.c +++ b/src/inpfile.c @@ -7,7 +7,7 @@ Description: saves network data to an EPANET formatted text file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 06/18/2024 +Last Updated: 02/11/2025 ****************************************************************************** */ @@ -519,7 +519,10 @@ int saveinpfile(Project *pr, const char *fname) fprintf(f, "\n%s AT %s %s", s, ControlTxt[TIMEOFDAY], clocktime(rpt->Atime, control->Time)); break; + + default: continue; } + if (control->isEnabled == FALSE) fprintf(f, " DISABLED"); } // Write [RULES] section @@ -529,6 +532,7 @@ int saveinpfile(Project *pr, const char *fname) { fprintf(f, "\nRULE %s", pr->network.Rule[i].label); writerule(pr, f, i); // see RULES.C + if (pr->network.Rule[i].isEnabled == FALSE) fprintf(f, "\nDISABLED"); fprintf(f, "\n"); } diff --git a/src/input3.c b/src/input3.c index 296e752..3d1a89c 100644 --- a/src/input3.c +++ b/src/input3.c @@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 05/11/2024 +Last Updated: 02/11/2025 ****************************************************************************** */ @@ -920,10 +920,10 @@ int controldata(Project *pr) ** Purpose: processes simple controls ** Formats: ** [CONTROLS] -** LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level -** LINK linkID setting AT TIME value (units) -** LINK linkID setting AT CLOCKTIME value (units) -** (0) (1) (2) (3) (4) (5) (6) (7) +** LINK linkID setting IF NODE nodeID {BELOW/ABOVE} level (DISABLED) +** LINK linkID setting AT TIME value (units) (DISABLED) +** LINK linkID setting AT CLOCKTIME value (units) (DISABLED) +** (0) (1) (2) (3) (4) (5) (6) (7) (8) **-------------------------------------------------------------- */ { @@ -932,7 +932,8 @@ int controldata(Project *pr) int i = 0, // Node index k, // Link index - n; // # data items + n, // # data items + isEnabled = TRUE; // Control enabled double setting = MISSING, // Link setting time = 0.0, // Simulation time level = 0.0; // Pressure or tank level @@ -944,6 +945,13 @@ int controldata(Project *pr) // Check for sufficient number of input tokens n = parser->Ntokens; if (n < 6) return 201; + + // Check if last token is "DISABLED" + if (match(parser->Tok[n-1], w_DISABLED)) + { + isEnabled = FALSE; + n = n - 1; + } // Check that controlled link exists k = findlink(net, parser->Tok[1]); @@ -1020,7 +1028,7 @@ int controldata(Project *pr) control->Time = (long)(3600.0 * time); if (ctltype == TIMEOFDAY) control->Time %= SECperDAY; control->Grade = level; - control->isEnabled = TRUE; + control->isEnabled = isEnabled; return 0; } diff --git a/src/rules.c b/src/rules.c index cf43365..1b009ad 100644 --- a/src/rules.c +++ b/src/rules.c @@ -1,13 +1,13 @@ /* ****************************************************************************** Project: OWA EPANET - Version: 2.2 + Version: 2.3 Module: rules.c Description: implements rule-based controls Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 05/15/2019 + Last Updated: 02/11/2025 ****************************************************************************** */ @@ -32,10 +32,11 @@ enum Rulewords { r_THEN, r_ELSE, r_PRIORITY, + r_DISABLED, r_ERROR }; char *Ruleword[] = {w_RULE, w_IF, w_AND, w_OR, - w_THEN, w_ELSE, w_PRIORITY, NULL}; + w_THEN, w_ELSE, w_PRIORITY, w_DISABLED, NULL}; enum Varwords { r_DEMAND, @@ -273,6 +274,16 @@ int ruledata(Project *pr) err = newpriority(pr); break; + case r_DISABLED: + if (rules->RuleState != r_THEN && rules->RuleState != r_ELSE && + rules->RuleState != r_PRIORITY) + { + err = 221; + break; + } + net->Rule[net->Nrules].isEnabled = FALSE; + break; + default: err = 201; } diff --git a/src/text.h b/src/text.h index 84b05db..087977e 100755 --- a/src/text.h +++ b/src/text.h @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 06/15/2024 + Last Updated: 02/11/2025 ****************************************************************************** */ @@ -196,6 +196,7 @@ #define w_THEN "THEN" #define w_ELSE "ELSE" #define w_PRIORITY "PRIO" +#define w_DISABLED "DISABLED" // ------ Input File Section Names ------------------------