Changed coordinates are saved to INP
Added a flag which controls the loading of coordinates at epanet.c line 213. When set to TRUE coordinates are loaded and users can use the ENgetcoord and ENsetcoord functions. Changes are then saved when ENsaveinpfile is called. When set to FALSE coordinates are not loaded and can't be retrieved or changed. When saved, the COORD section is copied from the original INP file.
This commit is contained in:
27
src/epanet.c
27
src/epanet.c
@@ -210,7 +210,8 @@ int DLLEXPORT ENopen(char *f1, char *f2, char *f3)
|
||||
SaveHflag = FALSE;
|
||||
SaveQflag = FALSE;
|
||||
Warnflag = FALSE;
|
||||
|
||||
Coordflag = TRUE;
|
||||
|
||||
/*** Updated 9/7/00 ***/
|
||||
Messageflag = TRUE;
|
||||
Rptflag = 1;
|
||||
@@ -1291,8 +1292,10 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y)
|
||||
{
|
||||
if (!Openflag) return(102);
|
||||
if (index < 1 || index > Nnodes) return(203);
|
||||
if (!Coordflag) return(255);
|
||||
|
||||
// check if node have coords
|
||||
if (Coord[index].HaveCoords == 0) return(254);
|
||||
if (Coord[index].HaveCoords == FALSE) return(254);
|
||||
|
||||
*x = Coord[index].X;
|
||||
*y = Coord[index].Y;
|
||||
@@ -1313,10 +1316,11 @@ int DLLEXPORT ENsetcoord(int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y)
|
||||
{
|
||||
if (!Openflag) return(102);
|
||||
if (index < 1 || index > Nnodes) return(203);
|
||||
if (!Coordflag) return(255);
|
||||
|
||||
Coord[index].X = x;
|
||||
Coord[index].Y = y;
|
||||
Coord[index].HaveCoords = 1;
|
||||
Coord[index].HaveCoords = TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2880,14 +2884,17 @@ int allocdata()
|
||||
Control = (Scontrol *) calloc(MaxControls+1,sizeof(Scontrol));
|
||||
Pattern = (Spattern *) calloc(MaxPats+1, sizeof(Spattern));
|
||||
Curve = (Scurve *) calloc(MaxCurves+1, sizeof(Scurve));
|
||||
Coord = (Scoord *) calloc(MaxNodes+1, sizeof(Scoord));
|
||||
if (Coordflag == TRUE)
|
||||
{
|
||||
Coord = (Scoord *) calloc(MaxNodes+1, sizeof(Scoord));
|
||||
}
|
||||
ERRCODE(MEMCHECK(Tank));
|
||||
ERRCODE(MEMCHECK(Pump));
|
||||
ERRCODE(MEMCHECK(Valve));
|
||||
ERRCODE(MEMCHECK(Control));
|
||||
ERRCODE(MEMCHECK(Pattern));
|
||||
ERRCODE(MEMCHECK(Curve));
|
||||
ERRCODE(MEMCHECK(Coord));
|
||||
if (Coordflag == TRUE) ERRCODE(MEMCHECK(Coord));
|
||||
}
|
||||
|
||||
/* Initialize pointers used in patterns, curves, and demand category lists */
|
||||
@@ -2911,9 +2918,12 @@ int allocdata()
|
||||
// node demand
|
||||
Node[n].D = NULL;
|
||||
/* ini coord data */
|
||||
Coord[n].X = 0;
|
||||
Coord[n].Y = 0;
|
||||
Coord[n].HaveCoords = 0;
|
||||
if (Coordflag == TRUE)
|
||||
{
|
||||
Coord[n].X = 0;
|
||||
Coord[n].Y = 0;
|
||||
Coord[n].HaveCoords = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3213,6 +3223,7 @@ char *geterrmsg(int errcode)
|
||||
case 251: sprintf(Msg,ERR251); break;
|
||||
case 253: sprintf(Msg,ERR253); break;
|
||||
case 254: sprintf(Msg,ERR254); break;
|
||||
case 255: sprintf(Msg,ERR255); break;
|
||||
|
||||
/* File Errors */
|
||||
case 301: strcpy(Msg,ERR301); break;
|
||||
|
||||
@@ -77,7 +77,11 @@ void saveauxdata(FILE *f) /
|
||||
switch(sect)
|
||||
{
|
||||
case _RULES:
|
||||
case _COORDS:
|
||||
case _COORDS: if (Coordflag == FALSE)
|
||||
{
|
||||
fprintf(f, "%s", line);
|
||||
}
|
||||
break;
|
||||
case _VERTICES:
|
||||
case _LABELS:
|
||||
case _BACKDROP:
|
||||
@@ -92,7 +96,11 @@ void saveauxdata(FILE *f) /
|
||||
switch(sect)
|
||||
{
|
||||
case _RULES:
|
||||
case _COORDS:
|
||||
case _COORDS: if (Coordflag == FALSE)
|
||||
{
|
||||
fprintf(f, "%s", line);
|
||||
}
|
||||
break;
|
||||
case _VERTICES:
|
||||
case _LABELS:
|
||||
case _BACKDROP:
|
||||
@@ -615,6 +623,21 @@ int saveinpfile(char *fname)
|
||||
}
|
||||
fprintf(f, "\n\n");
|
||||
|
||||
/* Write [COORDINATES] section */
|
||||
|
||||
if (Coordflag == TRUE)
|
||||
{
|
||||
fprintf(f, "\n\n[COORDINATES]");
|
||||
for (i=1; i<=Nnodes; i++)
|
||||
{
|
||||
if (Coord[i].HaveCoords == TRUE)
|
||||
{
|
||||
fprintf(f,"\n %-31s %14.6f %14.6f",Node[i].ID,Coord[i].X,Coord[i].Y);
|
||||
}
|
||||
}
|
||||
fprintf(f, "\n\n");
|
||||
}
|
||||
|
||||
/* Save auxilary data to new input file */
|
||||
|
||||
saveauxdata(f);
|
||||
|
||||
@@ -294,8 +294,11 @@ int newline(int sect, char *line)
|
||||
case _OPTIONS: return(optiondata());
|
||||
|
||||
/* Data in these sections are not used for any computations */
|
||||
//case _COORDS: return (0); //uncomment to not load the coordinates
|
||||
case _COORDS: return(coordata()); //comment out to load the coordinates
|
||||
case _COORDS: if (Coordflag == TRUE)
|
||||
{
|
||||
return(coordata());
|
||||
}
|
||||
else return(0);
|
||||
case _LABELS: return(0);
|
||||
case _TAGS: return(0);
|
||||
case _VERTICES: return(0);
|
||||
|
||||
@@ -604,7 +604,7 @@ int coordata()
|
||||
strncpy(Coord[j].ID, Node[j].ID, MAXID);
|
||||
Coord[j].X = x;
|
||||
Coord[j].Y = y;
|
||||
Coord[j].HaveCoords = 1;
|
||||
Coord[j].HaveCoords = TRUE;
|
||||
|
||||
return(0);
|
||||
} /* end of coordata */
|
||||
|
||||
@@ -495,6 +495,7 @@ AUTHOR: L. Rossman
|
||||
|
||||
#define ERR253 "Input Error 253: Function call error - No such demand category index."
|
||||
#define ERR254 "Input Error 254: Function call error - Node have no coordinates."
|
||||
#define ERR255 "Input Error 255: Function call error - Coordinates were not loaded."
|
||||
|
||||
#define ERR301 "File Error 301: identical file names."
|
||||
#define ERR302 "File Error 302: cannot open input file."
|
||||
|
||||
@@ -64,7 +64,8 @@ EXTERN char Msg[MAXMSG+1], /* Text of output message */
|
||||
SaveHflag, /* Hydraul. results saved flag */
|
||||
OpenQflag, /* Quality system opened flag */
|
||||
SaveQflag, /* Quality results saved flag */
|
||||
Saveflag; /* General purpose save flag */
|
||||
Saveflag, /* General purpose save flag */
|
||||
Coordflag; /* Load coordinates flag */
|
||||
EXTERN int MaxNodes, /* Node count from input file */
|
||||
MaxLinks, /* Link count from input file */
|
||||
MaxJuncs, /* Junction count */
|
||||
|
||||
Reference in New Issue
Block a user