rewrite the coordinate getter

currently controlled from input2.c lines 297-298. will need to add a
flag to not load the coordinates.
This commit is contained in:
Elad Salomons
2015-09-12 16:34:52 +03:00
parent 186f21f9a7
commit 4d6bcef623
6 changed files with 32 additions and 159 deletions

View File

@@ -239,7 +239,6 @@ int DLLEXPORT ENopen(char *f1, char *f2, char *f3)
/* Free temporary linked lists used for Patterns & Curves */ /* Free temporary linked lists used for Patterns & Curves */
freeTmplist(Patlist); freeTmplist(Patlist);
freeTmplist(Curvelist); freeTmplist(Curvelist);
freeTmplist(Coordlist);
/* If using previously saved hydraulics then open its file */ /* If using previously saved hydraulics then open its file */
if (Hydflag == USE) ERRCODE(openhydfile()); if (Hydflag == USE) ERRCODE(openhydfile());
@@ -1290,8 +1289,13 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y)
**---------------------------------------------------------------- **----------------------------------------------------------------
*/ */
{ {
*x = Coord[index].X[0]; if (!Openflag) return(102);
*y = Coord[index].Y[0]; if (index < 1 || index > Nnodes) return(203);
// check if node have coords
if (Coord[index].HaveCoords == 0) return(254);
*x = Coord[index].X;
*y = Coord[index].Y;
return 0; return 0;
} }
@@ -2775,7 +2779,6 @@ void initpointers()
X = NULL; X = NULL;
Patlist = NULL; Patlist = NULL;
Curvelist = NULL; Curvelist = NULL;
Coordlist = NULL;
Adjlist = NULL; Adjlist = NULL;
Aii = NULL; Aii = NULL;
Aij = NULL; Aij = NULL;
@@ -2885,12 +2888,10 @@ int allocdata()
{ {
// node demand // node demand
Node[n].D = NULL; Node[n].D = NULL;
/* Allocate memory for coord data */ /* ini coord data */
Coord[n].X = (double *) calloc(1, sizeof(double)); Coord[n].X = 0;
Coord[n].Y = (double *) calloc(1, sizeof(double)); Coord[n].Y = 0;
if (Coord[n].X == NULL || Coord[n].Y == NULL) return(101); Coord[n].HaveCoords = 0;
Coord[n].X[0] = 0;
Coord[n].Y[0] = 0;
} }
} }
@@ -3189,6 +3190,7 @@ char *geterrmsg(int errcode)
case 250: sprintf(Msg,ERR250); break; case 250: sprintf(Msg,ERR250); break;
case 251: sprintf(Msg,ERR251); break; case 251: sprintf(Msg,ERR251); break;
case 253: sprintf(Msg,ERR253); break; case 253: sprintf(Msg,ERR253); break;
case 254: sprintf(Msg,ERR254); break;
/* File Errors */ /* File Errors */
case 301: strcpy(Msg,ERR301); break; case 301: strcpy(Msg,ERR301); break;

View File

@@ -65,13 +65,11 @@ int addnodeID(int, char *); /* Adds node ID to data base */
int addlinkID(int, char *); /* Adds link ID to data base */ int addlinkID(int, char *); /* Adds link ID to data base */
int addpattern(char *); /* Adds pattern to data base */ int addpattern(char *); /* Adds pattern to data base */
int addcurve(char *); /* Adds curve to data base */ int addcurve(char *); /* Adds curve to data base */
int addcoord(char *); /* Adds coord to data base */
STmplist *findID(char *, STmplist *); /* Locates ID on linked list */ STmplist *findID(char *, STmplist *); /* Locates ID on linked list */
int unlinked(void); /* Checks for unlinked nodes */ int unlinked(void); /* Checks for unlinked nodes */
int getpumpparams(void); /* Computes pump curve coeffs.*/ int getpumpparams(void); /* Computes pump curve coeffs.*/
int getpatterns(void); /* Gets pattern data from list*/ int getpatterns(void); /* Gets pattern data from list*/
int getcurves(void); /* Gets curve data from list */ int getcurves(void); /* Gets curve data from list */
int getcoords(void); /* Gets coordinate data from list */
int findmatch(char *,char *[]); /* Finds keyword in line */ int findmatch(char *,char *[]); /* Finds keyword in line */
int match(char *, char *); /* Checks for word match */ int match(char *, char *); /* Checks for word match */
int gettokens(char *); /* Tokenizes input line */ int gettokens(char *); /* Tokenizes input line */

View File

@@ -48,7 +48,6 @@ char *Tok[MAXTOKS]; /* Array of token strings */
/* Used in INPUT3.C: */ /* Used in INPUT3.C: */
STmplist *PrevPat; /* Pointer to pattern list element */ STmplist *PrevPat; /* Pointer to pattern list element */
STmplist *PrevCurve; /* Pointer to curve list element */ STmplist *PrevCurve; /* Pointer to curve list element */
STmplist *PrevCoord; /* Pointer to coordinate list element */
/* Defined in enumstxt.h in EPANET.C */ /* Defined in enumstxt.h in EPANET.C */
extern char *SectTxt[]; /* Input section keywords */ extern char *SectTxt[]; /* Input section keywords */
@@ -79,7 +78,6 @@ int netsize()
MaxRules = 0; MaxRules = 0;
MaxCurves = 0; MaxCurves = 0;
sect = -1; sect = -1;
MaxCoords = 0;
/* Add a default pattern 0 */ /* Add a default pattern 0 */
MaxPats = -1; MaxPats = -1;
@@ -121,8 +119,6 @@ int netsize()
break; break;
case _CURVES: errcode = addcurve(tok); case _CURVES: errcode = addcurve(tok);
break; break;
// case _COORDS: errcode = addcoord(tok); //06.02.2010-woohn
// break;
} }
if (errcode) break; if (errcode) break;
} }
@@ -176,7 +172,6 @@ int readdata()
Npats = MaxPats; Npats = MaxPats;
PrevPat = NULL; PrevPat = NULL;
PrevCurve = NULL; PrevCurve = NULL;
PrevCoord = NULL;
sect = -1; sect = -1;
errsum = 0; errsum = 0;
@@ -245,7 +240,6 @@ int readdata()
/* Get pattern & curve data from temp. lists */ /* Get pattern & curve data from temp. lists */
if (!errcode) errcode = getpatterns(); if (!errcode) errcode = getpatterns();
if (!errcode) errcode = getcurves(); if (!errcode) errcode = getcurves();
//if (!errcode) errcode = getcoords();
if (!errcode) errcode = getpumpparams(); if (!errcode) errcode = getpumpparams();
/* Free input buffer */ /* Free input buffer */
@@ -300,7 +294,8 @@ int newline(int sect, char *line)
case _OPTIONS: return(optiondata()); case _OPTIONS: return(optiondata());
/* Data in these sections are not used for any computations */ /* Data in these sections are not used for any computations */
case _COORDS: return (0); //return(coordata()); //case _COORDS: return (0); //uncomment to not load the coordinates
case _COORDS: return(coordata()); //comment out to load the coordinates
case _LABELS: return(0); case _LABELS: return(0);
case _TAGS: return(0); case _TAGS: return(0);
case _VERTICES: return(0); case _VERTICES: return(0);
@@ -520,43 +515,6 @@ int addcurve(char *id)
return(0); return(0);
} }
int addcoord(char *id)
/*
**-------------------------------------------------------------
** Input: id = curve ID label
** Output: returns error code
** Purpose: adds a new curve to the database
**--------------------------------------------------------------
*/
{
STmplist *c;
/* Check if ID is same as last one processed */
if (Coordlist != NULL && strcmp(id,Coordlist->ID) == 0) return(0);
/* Check that coordinate was not already created */
if (findID(id,Coordlist) == NULL)
{
/* Update coordinate count & create new list element */
(MaxCoords)++;
c = (STmplist *) malloc(sizeof(STmplist));
if (c == NULL) {
return(101);
}
else {
/* Initialize list element properties */
// c->i = MaxCoords; // bug! if coordinates are not in the same order as junctions, then this is a BAD assumption
// do this later: c->i = findnode(id);
strncpy(c->ID,id,MAXID);
c->x = NULL;
c->y = NULL;
c->next = Coordlist;
Coordlist = c;
}
}
return(0);
}
STmplist *findID(char *id, STmplist *list) STmplist *findID(char *id, STmplist *list)
/* /*
@@ -749,65 +707,6 @@ int getcurves(void)
return(0); return(0);
} }
int getcoords(void)
/*
**-----------------------------------------------------------
** Input: none
** Output: returns error code
** Purpose: retrieves curve data from temporary linked list
**-----------------------------------------------------------
*/
{
int i,j,n;
double x;
SFloatlist *xFloatList, *yFloatList;
STmplist *coordinateList;
/* Start at head of coordinate list */
coordinateList = Coordlist;
/* Traverse list of coordinates */
while (coordinateList != NULL)
{
// BAD! ---> i = coordinateList->i;
i = findnode(coordinateList->ID);
if (i >= 1 && i <= MaxNodes)
{
/* Save coordinate ID */
strcpy(Coord[i].ID, coordinateList->ID);
n = 1; //Coord[i].Npts
/* Traverse list of x,y data */
x = BIG;
xFloatList = coordinateList->x;
yFloatList = coordinateList->y;
j = n - 1;
while (xFloatList != NULL && yFloatList != NULL && j >= 0)
{
/* Check that x data is in ascending order */
if (xFloatList->value >= x)
{
sprintf(Msg,ERR230,coordinateList->ID);
writeline(Msg);
return(200);
}
x = xFloatList->value;
/* Save x,y data in Curve structure */
Coord[i].X[j] = xFloatList->value;
xFloatList = xFloatList->next;
Coord[i].Y[j] = yFloatList->value;
yFloatList = yFloatList->next;
j--;
}
}
coordinateList = coordinateList->next;
}
return(0);
}
int findmatch(char *line, char *keyword[]) int findmatch(char *line, char *keyword[])
/* /*

View File

@@ -42,8 +42,6 @@ extern char *Fldname[];
extern char *Tok[MAXTOKS]; extern char *Tok[MAXTOKS];
extern STmplist *PrevPat; extern STmplist *PrevPat;
extern STmplist *PrevCurve; extern STmplist *PrevCurve;
extern STmplist *PrevCoord;
extern int Ntokens; extern int Ntokens;
@@ -592,45 +590,23 @@ int coordata()
*/ */
{ {
double x, y; double x, y;
SFloatlist *fx, *fy; int j;
STmplist *c;
/* Check for valid curve ID */ /* Check for valid node ID */
if (Ntokens < 3) return(201); if (Ntokens < 3) return(201);
if (
PrevCoord != NULL &&
strcmp(Tok[0],PrevCoord->ID) == 0
) c = PrevCoord;
else c = findID(Tok[0],Coordlist);
// c = findID(Tok[0],Coordlist);
if (c == NULL) return(205);
/* Check for valid data */ /* Check for valid data */
if ((j = findnode(Tok[0])) == 0) return(203);
if (!getfloat(Tok[1],&x)) return(202); if (!getfloat(Tok[1],&x)) return(202);
if (!getfloat(Tok[2],&y)) return(202); if (!getfloat(Tok[2],&y)) return(202);
/* Add new data point to curve's linked list */ /* Save coord data */
fx = (SFloatlist *) malloc(sizeof(SFloatlist)); strncpy(Coord[j].ID, Node[j].ID, MAXID);
fy = (SFloatlist *) malloc(sizeof(SFloatlist)); Coord[j].X = x;
if (fx == NULL || fy == NULL) return(101); Coord[j].Y = y;
fx->value = x; Coord[j].HaveCoords = 1;
fx->next = c->x;
c->x = fx;
fy->value = y;
fy->next = c->y;
c->y = fy;
//Curve[c->i].Npts++;
/* Save the pointer to this curve */
PrevCoord = c;
return(0); return(0);
/* Save coordn data */
//Coord[Njuncs].X = x;
//Coord[Njuncs].Y = y;
} /* end of coordata */ } /* end of coordata */
int demanddata() int demanddata()

View File

@@ -494,6 +494,7 @@ AUTHOR: L. Rossman
#define ERR251 "Input Error 251: function call contains invalid parameter code." #define ERR251 "Input Error 251: function call contains invalid parameter code."
#define ERR253 "Input Error 253: Function call error - No such demand category index." #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 ERR301 "File Error 301: identical file names." #define ERR301 "File Error 301: identical file names."
#define ERR302 "File Error 302: cannot open input file." #define ERR302 "File Error 302: cannot open input file."

View File

@@ -76,7 +76,6 @@ EXTERN int MaxNodes, /* Node count from input file */
MaxRules, /* Rule count */ MaxRules, /* Rule count */
MaxPats, /* Pattern count */ MaxPats, /* Pattern count */
MaxCurves, /* Curve count */ MaxCurves, /* Curve count */
MaxCoords, /* Coords count */
Nnodes, /* Number of network nodes */ Nnodes, /* Number of network nodes */
Ntanks, /* Number of tanks */ Ntanks, /* Number of tanks */
Njuncs, /* Number of junction nodes */ Njuncs, /* Number of junction nodes */
@@ -88,7 +87,6 @@ EXTERN int MaxNodes, /* Node count from input file */
Nrules, /* Number of control rules */ Nrules, /* Number of control rules */
Npats, /* Number of time patterns */ Npats, /* Number of time patterns */
Ncurves, /* Number of data curves */ Ncurves, /* Number of data curves */
Ncoords, /* Number of Coords */
Nperiods, /* Number of reporting periods */ Nperiods, /* Number of reporting periods */
Ncoeffs, /* Number of non-0 matrix coeffs*/ Ncoeffs, /* Number of non-0 matrix coeffs*/
DefPat, /* Default demand pattern */ DefPat, /* Default demand pattern */
@@ -159,7 +157,6 @@ EXTERN double *QTankVolumes;
EXTERN double *QLinkFlow; EXTERN double *QLinkFlow;
EXTERN STmplist *Patlist; /* Temporary time pattern list */ EXTERN STmplist *Patlist; /* Temporary time pattern list */
EXTERN STmplist *Curvelist; /* Temporary list of curves */ EXTERN STmplist *Curvelist; /* Temporary list of curves */
EXTERN STmplist *Coordlist; /* Temporary list of coordinates*/
EXTERN Spattern *Pattern; /* Time patterns */ EXTERN Spattern *Pattern; /* Time patterns */
EXTERN Scurve *Curve; /* Curve data */ EXTERN Scurve *Curve; /* Curve data */
EXTERN Scoord *Coord; /* Coordinate data */ EXTERN Scoord *Coord; /* Coordinate data */