Merge pull request #834 from OpenWaterAnalytics/dev-curvetype

Include curve type in input file
This commit is contained in:
Lew Rossman
2025-03-12 18:30:09 -04:00
committed by GitHub
4 changed files with 35 additions and 12 deletions

View File

@@ -1,13 +1,13 @@
/* /*
***************************************************************************** *****************************************************************************
Project: OWA EPANET Project: OWA EPANET
Version: 2.2 Version: 2.3
Module: enumstxt.h Module: enumstxt.h
Description: text strings for enumerated data types Description: text strings for enumerated data types
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 06/24/2024 Last Updated: 03/10/2025
****************************************************************************** ******************************************************************************
*/ */
@@ -118,6 +118,14 @@ char *BackflowTxt[] = {w_NO,
w_YES, w_YES,
NULL}; NULL};
char *CurveTypeTxt[] = {c_VOLUME,
c_PUMP,
c_EFFIC,
c_HEADLOSS,
c_GENERIC,
c_VALVE,
NULL};
char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS, char *SectTxt[] = {s_TITLE, s_JUNCTIONS, s_RESERVOIRS,
s_TANKS, s_PIPES, s_PUMPS, s_TANKS, s_PIPES, s_PUMPS,
s_VALVES, s_CONTROLS, s_RULES, s_VALVES, s_CONTROLS, s_RULES,

View File

@@ -7,7 +7,7 @@ Description: saves network data to an EPANET formatted text file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 02/14/2025 Last Updated: 03/11/2025
****************************************************************************** ******************************************************************************
*/ */
@@ -34,6 +34,7 @@ extern char *TstatTxt[];
extern char *RptFlagTxt[]; extern char *RptFlagTxt[];
extern char *SectTxt[]; extern char *SectTxt[];
extern char *BackflowTxt[]; extern char *BackflowTxt[];
extern char *CurveTypeTxt[];
void saveauxdata(Project *pr, FILE *f) void saveauxdata(Project *pr, FILE *f)
/* /*
@@ -434,15 +435,20 @@ int saveinpfile(Project *pr, const char *fname)
// Write [CURVES] section // Write [CURVES] section
fprintf(f, "\n\n"); fprintf(f, "\n\n");
fprintf(f, s_CURVES); fprintf(f, s_CURVES);
fprintf(f, "\n;;%-31s\t%-12s\t%-12s", fprintf(f, "\n;;%-31s\t%-12s\t%-12s", "ID", "X-Value", "Y-Value");
"ID", "X-Value", "Y-Value");
for (i = 1; i <= net->Ncurves; i++) for (i = 1; i <= net->Ncurves; i++)
{ {
if (net->Curve[i].Comment) fprintf(f, "\n;%s", net->Curve[i].Comment); curve = &net->Curve[i];
for (j = 0; j < net->Curve[i].Npts; j++) if (curve->Comment) fprintf(f, "\n;%s", curve->Comment);
if (curve->Npts > 0)
{ {
curve = &net->Curve[i]; fprintf(f, "\n %-31s\t%-12.4f\t%-12.4f\t%s", curve->ID,
fprintf(f, "\n %-31s\t%-12.4f\t%-12.4f", curve->ID, curve->X[j], curve->Y[j]); curve->X[0], curve->Y[0], CurveTypeTxt[curve->Type]);
for (j = 1; j < curve->Npts; j++)
{
fprintf(f, "\n %-31s\t%-12.4f\t%-12.4f", curve->ID,
curve->X[j], curve->Y[j]);
}
} }
} }

View File

@@ -7,7 +7,7 @@ Description: parses network data from a line of an EPANET input file
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 02/14/2025 Last Updated: 03/10/2025
****************************************************************************** ******************************************************************************
*/ */
@@ -26,6 +26,7 @@ extern char *MixTxt[];
extern char *Fldname[]; extern char *Fldname[];
extern char *DemandModelTxt[]; extern char *DemandModelTxt[];
extern char *BackflowTxt[]; extern char *BackflowTxt[];
extern char *CurveTypeTxt[];
// Imported Functions // Imported Functions
extern int addnodeID(Network *, int, char *); extern int addnodeID(Network *, int, char *);
@@ -740,7 +741,7 @@ int curvedata(Project *pr)
Network *net = &pr->network; Network *net = &pr->network;
Parser *parser = &pr->parser; Parser *parser = &pr->parser;
int i; int i, ctype;
double x, y; double x, y;
Scurve *curve; Scurve *curve;
@@ -748,6 +749,11 @@ int curvedata(Project *pr)
if (parser->Ntokens < 3) return 201; if (parser->Ntokens < 3) return 201;
if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202); if (!getfloat(parser->Tok[1], &x)) return setError(parser, 1, 202);
if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202); if (!getfloat(parser->Tok[2], &y)) return setError(parser, 2, 202);
ctype = -1;
if (parser->Ntokens > 3)
{
ctype = findmatch(parser->Tok[3], CurveTypeTxt);
}
// Check if previous input line was for the same curve // Check if previous input line was for the same curve
if (parser->PrevCurve && strcmp(parser->Tok[0], parser->PrevCurve->ID) == 0) if (parser->PrevCurve && strcmp(parser->Tok[0], parser->PrevCurve->ID) == 0)
@@ -777,6 +783,7 @@ int curvedata(Project *pr)
curve->X[curve->Npts] = x; curve->X[curve->Npts] = x;
curve->Y[curve->Npts] = y; curve->Y[curve->Npts] = y;
curve->Npts++; curve->Npts++;
if (ctype >= 0) curve->Type = (CurveType)ctype;
// Save a reference to this curve for processing additional curve data // Save a reference to this curve for processing additional curve data
parser->PrevCurve = curve; parser->PrevCurve = curve;

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 02/11/2025 Last Updated: 03/10/2025
****************************************************************************** ******************************************************************************
*/ */
@@ -270,6 +270,8 @@
#define c_PUMP "PUMP" #define c_PUMP "PUMP"
#define c_EFFIC "EFFIC" #define c_EFFIC "EFFIC"
#define c_VOLUME "VOLUME" #define c_VOLUME "VOLUME"
#define c_VALVE "VALVE"
#define c_GENERIC "GENERIC"
//------- Text Phrases ------------------------------------ //------- Text Phrases ------------------------------------