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 */
freeTmplist(Patlist);
freeTmplist(Curvelist);
freeTmplist(Coordlist);
/* If using previously saved hydraulics then open its file */
if (Hydflag == USE) ERRCODE(openhydfile());
@@ -1290,9 +1289,14 @@ int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y)
**----------------------------------------------------------------
*/
{
*x = Coord[index].X[0];
*y = Coord[index].Y[0];
return 0;
if (!Openflag) return(102);
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;
}
int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value)
@@ -2770,12 +2774,11 @@ void initpointers()
Pattern = NULL;
Curve = NULL;
Control = NULL;
Coord = NULL;
Coord = NULL;
X = NULL;
Patlist = NULL;
Curvelist = NULL;
Coordlist = NULL;
Adjlist = NULL;
Aii = NULL;
Aij = NULL;
@@ -2885,12 +2888,10 @@ int allocdata()
{
// node demand
Node[n].D = NULL;
/* Allocate memory for coord data */
Coord[n].X = (double *) calloc(1, sizeof(double));
Coord[n].Y = (double *) calloc(1, sizeof(double));
if (Coord[n].X == NULL || Coord[n].Y == NULL) return(101);
Coord[n].X[0] = 0;
Coord[n].Y[0] = 0;
/* ini coord data */
Coord[n].X = 0;
Coord[n].Y = 0;
Coord[n].HaveCoords = 0;
}
}
@@ -3189,6 +3190,7 @@ char *geterrmsg(int errcode)
case 250: sprintf(Msg,ERR250); break;
case 251: sprintf(Msg,ERR251); break;
case 253: sprintf(Msg,ERR253); break;
case 254: sprintf(Msg,ERR254); break;
/* File Errors */
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 addpattern(char *); /* Adds pattern 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 */
int unlinked(void); /* Checks for unlinked nodes */
int getpumpparams(void); /* Computes pump curve coeffs.*/
int getpatterns(void); /* Gets pattern 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 match(char *, char *); /* Checks for word match */
int gettokens(char *); /* Tokenizes input line */
@@ -88,7 +86,7 @@ int pumpdata(void); /* Processes pump data */
int valvedata(void); /* Processes valve data */
int patterndata(void); /* Processes pattern data */
int curvedata(void); /* Processes curve data */
int coordata(void); /* Processes coordinate data */
int coordata(void); /* Processes coordinate data */
int demanddata(void); /* Processes demand data */
int controldata(void); /* Processes simple controls */
int energydata(void); /* Processes energy data */
@@ -287,4 +285,4 @@ int saveepilog(void); /* Saves output file epilog */
/* ------------ INPFILE.C --------------*/
int saveinpfile(char *); /* Saves network to text file */
#endif
#endif

View File

@@ -48,7 +48,6 @@ char *Tok[MAXTOKS]; /* Array of token strings */
/* Used in INPUT3.C: */
STmplist *PrevPat; /* Pointer to pattern list element */
STmplist *PrevCurve; /* Pointer to curve list element */
STmplist *PrevCoord; /* Pointer to coordinate list element */
/* Defined in enumstxt.h in EPANET.C */
extern char *SectTxt[]; /* Input section keywords */
@@ -79,7 +78,6 @@ int netsize()
MaxRules = 0;
MaxCurves = 0;
sect = -1;
MaxCoords = 0;
/* Add a default pattern 0 */
MaxPats = -1;
@@ -121,8 +119,6 @@ int netsize()
break;
case _CURVES: errcode = addcurve(tok);
break;
// case _COORDS: errcode = addcoord(tok); //06.02.2010-woohn
// break;
}
if (errcode) break;
}
@@ -176,7 +172,6 @@ int readdata()
Npats = MaxPats;
PrevPat = NULL;
PrevCurve = NULL;
PrevCoord = NULL;
sect = -1;
errsum = 0;
@@ -245,7 +240,6 @@ int readdata()
/* Get pattern & curve data from temp. lists */
if (!errcode) errcode = getpatterns();
if (!errcode) errcode = getcurves();
//if (!errcode) errcode = getcoords();
if (!errcode) errcode = getpumpparams();
/* Free input buffer */
@@ -300,7 +294,8 @@ int newline(int sect, char *line)
case _OPTIONS: return(optiondata());
/* 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 _TAGS: return(0);
case _VERTICES: return(0);
@@ -520,43 +515,6 @@ int addcurve(char *id)
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)
/*
@@ -749,65 +707,6 @@ int getcurves(void)
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[])
/*

View File

@@ -42,8 +42,6 @@ extern char *Fldname[];
extern char *Tok[MAXTOKS];
extern STmplist *PrevPat;
extern STmplist *PrevCurve;
extern STmplist *PrevCoord;
extern int Ntokens;
@@ -591,46 +589,24 @@ int coordata()
**--------------------------------------------------------------
*/
{
double x,y;
SFloatlist *fx, *fy;
STmplist *c;
double x, y;
int j;
/* Check for valid curve ID */
/* Check for valid node ID */
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[2],&y)) return(202);
/* Add new data point to curve's linked list */
fx = (SFloatlist *) malloc(sizeof(SFloatlist));
fy = (SFloatlist *) malloc(sizeof(SFloatlist));
if (fx == NULL || fy == NULL) return(101);
fx->value = x;
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);
/* Save coordn data */
//Coord[Njuncs].X = x;
//Coord[Njuncs].Y = y;
/* Save coord data */
strncpy(Coord[j].ID, Node[j].ID, MAXID);
Coord[j].X = x;
Coord[j].Y = y;
Coord[j].HaveCoords = 1;
return(0);
} /* end of coordata */
int demanddata()

View File

@@ -494,6 +494,7 @@ AUTHOR: L. Rossman
#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 ERR254 "Input Error 254: Function call error - Node have no coordinates."
#define ERR301 "File Error 301: identical file names."
#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 */
MaxPats, /* Pattern count */
MaxCurves, /* Curve count */
MaxCoords, /* Coords count */
Nnodes, /* Number of network nodes */
Ntanks, /* Number of tanks */
Njuncs, /* Number of junction nodes */
@@ -88,7 +87,6 @@ EXTERN int MaxNodes, /* Node count from input file */
Nrules, /* Number of control rules */
Npats, /* Number of time patterns */
Ncurves, /* Number of data curves */
Ncoords, /* Number of Coords */
Nperiods, /* Number of reporting periods */
Ncoeffs, /* Number of non-0 matrix coeffs*/
DefPat, /* Default demand pattern */
@@ -159,7 +157,6 @@ EXTERN double *QTankVolumes;
EXTERN double *QLinkFlow;
EXTERN STmplist *Patlist; /* Temporary time pattern list */
EXTERN STmplist *Curvelist; /* Temporary list of curves */
EXTERN STmplist *Coordlist; /* Temporary list of coordinates*/
EXTERN Spattern *Pattern; /* Time patterns */
EXTERN Scurve *Curve; /* Curve data */
EXTERN Scoord *Coord; /* Coordinate data */