New features and bug fixes

This commit is contained in:
Michael Tryby
2014-05-05 18:07:03 -04:00
parent 993cfce8a4
commit 0cd38fd697
16 changed files with 718 additions and 368 deletions

View File

@@ -9,6 +9,7 @@ DATE: 5/8/00
11/19/01
6/24/02
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHOR: L. Rossman
US EPA - NRMRL
@@ -43,8 +44,12 @@ extern char *RptFlagTxt[];
extern char *SectTxt[];
/*** Updated 6/24/02 ***/
void savemapinfo(FILE *ftmp)
void saveauxdata(FILE *f) //(2.00.12 - LR)
/*
------------------------------------------------------------
Writes auxilary data from original input file to new file.
------------------------------------------------------------
*/
{
int sect,newsect;
char *tok;
@@ -55,14 +60,10 @@ void savemapinfo(FILE *ftmp)
rewind(InFile);
while (fgets(line,MAXLINE,InFile) != NULL)
{
/* Skip blank lines & those beginning with a comment */
strcpy(s,line);
tok = strtok(line,SEPSTR);
if (tok == NULL) continue;
if (*tok == ';') continue;
/* Check if line begins with a new section heading */
if (*tok == '[')
strcpy(s,line);
tok = strtok(s,SEPSTR);
if (tok != NULL && *tok == '[')
{
newsect = findmatch(tok,SectTxt);
if (newsect >= 0)
@@ -76,7 +77,7 @@ void savemapinfo(FILE *ftmp)
case _VERTICES:
case _LABELS:
case _BACKDROP:
case _TAGS: fwrite(s, sizeof(char), strlen(s), ftmp);
case _TAGS: fprintf(f, "%s", line); //(2.00.12 - LR)
}
continue;
}
@@ -91,13 +92,14 @@ void savemapinfo(FILE *ftmp)
case _VERTICES:
case _LABELS:
case _BACKDROP:
case _TAGS: fwrite(s, sizeof(char), strlen(s), ftmp);
case _TAGS: fprintf(f, "%s", line); //(2.00.12 - LR)
}
}
}
/*** End of update ***/
//// This function was heavily modified. //// //(2.00.12 - LR)
int saveinpfile(char *fname)
/*
-------------------------------------------------
@@ -105,38 +107,16 @@ int saveinpfile(char *fname)
-------------------------------------------------
*/
{
int i,j,n;
double d,kc,ke,km,ucf;
/*** Updated 6/24/02 ***/
char s[MAXLINE+1], s1[MAXLINE+1], s2[MAXLINE+1];
int i,j,n;
double d,kc,ke,km,ucf;
char s[MAXLINE+1], s1[MAXLINE+1], s2[MAXLINE+1];
Pdemand demand;
Psource source;
FILE *f;
FILE *f;
/*** Updated 6/24/02 ***/
FILE *ftmp;
/* Open the new text file */
/* Copy [RULES], [COORDS], [VERTICES], [LABELS], [BACKDROP] & [TAGS] */
/* sections from original input file to new input file */
ftmp = NULL;
if (InFile)
{
ftmp = tmpfile();
if (ftmp) savemapinfo(ftmp);
}
/* Open text file */
if ((f = fopen(fname,"wt")) == NULL)
{
if (ftmp) fclose(ftmp);
return(102);
}
/*** End of update ***/
if ((f = fopen(fname,"wt")) == NULL) return(308);
/* Write [TITLE] section */
@@ -151,7 +131,7 @@ int saveinpfile(char *fname)
fprintf(f,"\n\n[JUNCTIONS]");
for (i=1; i<=Njuncs; i++)
fprintf(f,"\n %-15s %12.2f", Node[i].ID, Node[i].El*Ucf[ELEV]);
fprintf(f,"\n %-31s %12.4f", Node[i].ID, Node[i].El*Ucf[ELEV]);
/* Write [RESERVOIRS] section */
@@ -161,9 +141,9 @@ int saveinpfile(char *fname)
if (Tank[i].A == 0.0)
{
n = Tank[i].Node;
sprintf(s," %-15s %12.2f",Node[n].ID, Node[n].El*Ucf[ELEV]);
sprintf(s," %-31s %12.4f",Node[n].ID, Node[n].El*Ucf[ELEV]);
if ((j = Tank[i].Pat) > 0)
sprintf(s1," %-15s",Pattern[j].ID);
sprintf(s1," %-31s",Pattern[j].ID);
else
strcpy(s1,"");
fprintf(f, "\n%s %s", s,s1);
@@ -178,7 +158,7 @@ int saveinpfile(char *fname)
if (Tank[i].A > 0.0)
{
n = Tank[i].Node;
sprintf(s," %-15s %12.2f %12.2f %12.2f %12.2f %12.2f %12.2f",
sprintf(s," %-31s %12.4f %12.4f %12.4f %12.4f %12.4f %12.4f",
Node[n].ID,
Node[n].El*Ucf[ELEV],
(Tank[i].H0 - Node[n].El)*Ucf[ELEV],
@@ -187,7 +167,7 @@ int saveinpfile(char *fname)
sqrt(4.0*Tank[i].A/PI)*Ucf[ELEV],
Tank[i].Vmin*SQR(Ucf[ELEV])*Ucf[ELEV]);
if ((j = Tank[i].Vcurve) > 0)
sprintf(s1,"%-15s",Curve[j].ID);
sprintf(s1,"%-31s",Curve[j].ID);
else
strcpy(s1,"");
fprintf(f, "\n%s %s", s,s1);
@@ -205,21 +185,18 @@ int saveinpfile(char *fname)
kc = Link[i].Kc;
if (Formflag == DW) kc = kc*Ucf[ELEV]*1000.0;
km = Link[i].Km*SQR(d)*SQR(d)/0.02517;
/*** Updated 6/24/02 ***/
sprintf(s," %-15s %-15s %-15s %12.2f %12.2f",
sprintf(s," %-31s %-31s %-31s %12.4f %12.4f",
Link[i].ID,
Node[Link[i].N1].ID,
Node[Link[i].N2].ID,
Link[i].Len*Ucf[LENGTH],
d*Ucf[DIAM]);
if (Formflag == DW) sprintf(s1, "%12.4f %12.4f", kc, km);
else sprintf(s1, "%12.2f %12.4f", kc, km);
else sprintf(s1, "%12.4f %12.4f", kc, km);
if (Link[i].Type == CV) sprintf(s2,"CV");
else if (Link[i].Stat == CLOSED) sprintf(s2,"CLOSED");
else strcpy(s2,"");
fprintf(f,"\n%s %s %s",s,s1,s2);
/*** End of update ***/
}
}
@@ -229,14 +206,14 @@ int saveinpfile(char *fname)
for (i=1; i<=Npumps; i++)
{
n = Pump[i].Link;
sprintf(s," %-15s %-15s %-15s",
sprintf(s," %-31s %-31s %-31s",
Link[n].ID,
Node[Link[n].N1].ID,
Node[Link[n].N2].ID);
/* Pump has constant power */
if (Pump[i].Ptype == CONST_HP)
sprintf(s1, " POWER %.2f", Link[n].Km);
sprintf(s1, " POWER %.4f", Link[n].Km);
/* Pump has a head curve */
else if ((j = Pump[i].Hcurve) > 0)
@@ -245,7 +222,7 @@ int saveinpfile(char *fname)
/* Old format used for pump curve */
else
{
fprintf(f, "\n%s %12.2f %12.2f %12.2f 0.0 %12.2f",s,
fprintf(f, "\n%s %12.4f %12.4f %12.4f 0.0 %12.4f",s,
-Pump[i].H0*Ucf[HEAD],
(-Pump[i].H0 - Pump[i].R*pow(Pump[i].Q0,Pump[i].N))*Ucf[HEAD],
Pump[i].Q0*Ucf[FLOW],
@@ -260,7 +237,7 @@ int saveinpfile(char *fname)
strcat(s,s1);
if (Link[n].Kc != 1.0)
sprintf(s1, " SPEED %.2f", Link[n].Kc);
sprintf(s1, " SPEED %.4f", Link[n].Kc);
else strcpy(s1,"");
strcat(s,s1);
@@ -285,7 +262,7 @@ int saveinpfile(char *fname)
}
km = Link[n].Km*SQR(d)*SQR(d)/0.02517;
sprintf(s," %-15s %-15s %-15s %12.2f %5s",
sprintf(s," %-31s %-31s %-31s %12.4f %5s",
Link[n].ID,
Node[Link[n].N1].ID,
Node[Link[n].N2].ID,
@@ -293,8 +270,8 @@ int saveinpfile(char *fname)
LinkTxt[Link[n].Type]);
if (Link[n].Type == GPV && (j = ROUND(Link[n].Kc)) > 0)
sprintf(s1,"%-15s %12.2f", Curve[j].ID, km);
else sprintf(s1,"%12.2f %12.2f",kc,km);
sprintf(s1,"%-31s %12.4f", Curve[j].ID, km);
else sprintf(s1,"%12.4f %12.4f",kc,km);
fprintf(f, "\n%s %s", s,s1);
}
@@ -302,15 +279,12 @@ int saveinpfile(char *fname)
/* Write [DEMANDS] section */
fprintf(f, "\n\n[DEMANDS]");
/*** Updated 11/19/01 ***/
ucf = Ucf[DEMAND];
for (i=1; i<=Njuncs; i++)
{
for (demand = Node[i].D; demand != NULL; demand = demand->next)
{
sprintf(s," %-15s %12.2f",Node[i].ID,ucf*demand->Base);
sprintf(s," %-31s %14.6f",Node[i].ID,ucf*demand->Base);
if ((j = demand->Pat) > 0) sprintf(s1," %s",Pattern[j].ID);
else strcpy(s1,"");
fprintf(f,"\n%s %s",s,s1);
@@ -324,7 +298,7 @@ int saveinpfile(char *fname)
{
if (Node[i].Ke == 0.0) continue;
ke = Ucf[FLOW]/pow(Ucf[PRESSURE]*Node[i].Ke,(1.0/Qexp));
fprintf(f,"\n %-15s %12.2f",Node[i].ID,ke);
fprintf(f,"\n %-31s %14.6f",Node[i].ID,ke);
}
/* Write [STATUS] section */
@@ -335,7 +309,7 @@ int saveinpfile(char *fname)
if (Link[i].Type <= PUMP)
{
if (Link[i].Stat == CLOSED)
fprintf(f, "\n %-15s %s",Link[i].ID,StatTxt[CLOSED]);
fprintf(f, "\n %-31s %s",Link[i].ID,StatTxt[CLOSED]);
/* Write pump speed here for pumps with old-style pump curve input */
else if (Link[i].Type == PUMP)
@@ -346,7 +320,7 @@ int saveinpfile(char *fname)
Pump[n].Ptype != CONST_HP &&
Link[i].Kc != 1.0
)
fprintf(f, "\n %-15s %-.2f",Link[i].ID, Link[i].Kc);
fprintf(f, "\n %-31s %-.4f",Link[i].ID, Link[i].Kc);
}
}
@@ -354,9 +328,9 @@ int saveinpfile(char *fname)
else if (Link[i].Kc == MISSING)
{
if (Link[i].Stat == OPEN)
fprintf(f, "\n %-15s %s",Link[i].ID,StatTxt[OPEN]);
fprintf(f, "\n %-31s %s",Link[i].ID,StatTxt[OPEN]);
if (Link[i].Stat == CLOSED)
fprintf(f, "\n%-15s %s",Link[i].ID,StatTxt[CLOSED]);
fprintf(f, "\n%-31s %s",Link[i].ID,StatTxt[CLOSED]);
}
}
@@ -368,7 +342,7 @@ int saveinpfile(char *fname)
{
for (j=0; j<Pattern[i].Length; j++)
{
if (j % 6 == 0) fprintf(f,"\n %-15s",Pattern[i].ID);
if (j % 6 == 0) fprintf(f,"\n %-31s",Pattern[i].ID);
fprintf(f," %12.4f",Pattern[i].F[j]);
}
}
@@ -379,7 +353,7 @@ int saveinpfile(char *fname)
for (i=1; i<=Ncurves; i++)
{
for (j=0; j<Curve[i].Npts; j++)
fprintf(f,"\n %-15s %12.4f %12.4f",
fprintf(f,"\n %-31s %12.4f %12.4f",
Curve[i].ID,Curve[i].X[j],Curve[i].Y[j]);
}
@@ -422,7 +396,7 @@ int saveinpfile(char *fname)
/* Print timer control */
case TIMER:
fprintf(f, "\n%s AT %s %.2f HOURS",
fprintf(f, "\n%s AT %s %.4f HOURS",
s, ControlTxt[TIMER], Control[i].Time/3600.);
break;
@@ -441,7 +415,7 @@ int saveinpfile(char *fname)
for (i=1; i<=Nnodes; i++)
{
if (Node[i].C0 == 0.0) continue;
fprintf(f, "\n %-15s %12.3f",Node[i].ID,Node[i].C0*Ucf[QUALITY]);
fprintf(f, "\n %-31s %14.6f",Node[i].ID,Node[i].C0*Ucf[QUALITY]);
}
/* Write [SOURCES] section */
@@ -451,7 +425,7 @@ int saveinpfile(char *fname)
{
source = Node[i].S;
if (source == NULL) continue;
sprintf(s," %-15s %-8s %12.2f",
sprintf(s," %-31s %-8s %14.6f",
Node[i].ID,
SourceTxt[source->Type],
source->C0);
@@ -467,7 +441,7 @@ int saveinpfile(char *fname)
for (i=1; i<=Ntanks; i++)
{
if (Tank[i].A == 0.0) continue;
fprintf(f, "\n %-15s %-8s %12.4f",
fprintf(f, "\n %-31s %-8s %12.4f",
Node[Tank[i].Node].ID,
MixTxt[Tank[i].MixModel],
(Tank[i].V1max/Tank[i].Vmax));
@@ -479,25 +453,25 @@ int saveinpfile(char *fname)
fprintf(f, "\n ORDER BULK %-.2f", BulkOrder);
fprintf(f, "\n ORDER WALL %-.0f", WallOrder);
fprintf(f, "\n ORDER TANK %-.2f", TankOrder);
fprintf(f, "\n GLOBAL BULK %-.4f", Kbulk*SECperDAY);
fprintf(f, "\n GLOBAL WALL %-.4f", Kwall*SECperDAY);
fprintf(f, "\n GLOBAL BULK %-.6f", Kbulk*SECperDAY);
fprintf(f, "\n GLOBAL WALL %-.6f", Kwall*SECperDAY);
if (Climit > 0.0)
fprintf(f, "\n LIMITING POTENTIAL %-.4f", Climit);
fprintf(f, "\n LIMITING POTENTIAL %-.6f", Climit);
if (Rfactor != MISSING && Rfactor != 0.0)
fprintf(f, "\n ROUGHNESS CORRELATION %-.4f",Rfactor);
fprintf(f, "\n ROUGHNESS CORRELATION %-.6f",Rfactor);
for (i=1; i<=Nlinks; i++)
{
if (Link[i].Type > PIPE) continue;
if (Link[i].Kb != Kbulk)
fprintf(f, "\n BULK %-15s %-.4f",Link[i].ID,Link[i].Kb*SECperDAY);
fprintf(f, "\n BULK %-31s %-.6f",Link[i].ID,Link[i].Kb*SECperDAY);
if (Link[i].Kw != Kwall)
fprintf(f, "\n WALL %-15s %-.4f",Link[i].ID,Link[i].Kw*SECperDAY);
fprintf(f, "\n WALL %-31s %-.6f",Link[i].ID,Link[i].Kw*SECperDAY);
}
for (i=1; i<=Ntanks; i++)
{
if (Tank[i].A == 0.0) continue;
if (Tank[i].Kb != Kbulk)
fprintf(f, "\n TANK %-15s %-.4f",Node[Tank[i].Node].ID,
fprintf(f, "\n TANK %-31s %-.6f",Node[Tank[i].Node].ID,
Tank[i].Kb*SECperDAY);
}
@@ -508,20 +482,18 @@ int saveinpfile(char *fname)
fprintf(f, "\n GLOBAL PRICE %-.4f", Ecost);
if (Epat != 0)
fprintf(f, "\n GLOBAL PATTERN %s", Pattern[Epat].ID);
fprintf(f, "\n GLOBAL EFFIC %-.2f", Epump);
fprintf(f, "\n GLOBAL EFFIC %-.4f", Epump);
fprintf(f, "\n DEMAND CHARGE %-.4f", Dcost);
for (i=1; i<=Npumps; i++)
{
if (Pump[i].Ecost > 0.0)
fprintf(f, "\n PUMP %-15s PRICE %-.4f",
fprintf(f, "\n PUMP %-31s PRICE %-.4f",
Link[Pump[i].Link].ID,Pump[i].Ecost);
if (Pump[i].Epat > 0.0)
fprintf(f, "\n PUMP %-15s PATTERN %s",
fprintf(f, "\n PUMP %-31s PATTERN %s",
Link[Pump[i].Link].ID,Pattern[Pump[i].Epat].ID);
/*** Updated 3/1/01 ***/
if (Pump[i].Ecurve > 0.0)
fprintf(f, "\n PUMP %-15s EFFIC %s",
fprintf(f, "\n PUMP %-31s EFFIC %s",
Link[Pump[i].Link].ID,Curve[Pump[i].Ecurve].ID);
}
@@ -558,22 +530,22 @@ int saveinpfile(char *fname)
if (Qualflag == CHEM)
fprintf(f, "\n QUALITY %s %s", ChemName, ChemUnits);
if (Qualflag == TRACE)
fprintf(f, "\n QUALITY TRACE %-15s", Node[TraceNode].ID);
fprintf(f, "\n QUALITY TRACE %-31s", Node[TraceNode].ID);
if (Qualflag == AGE)
fprintf(f, "\n QUALITY AGE");
if (Qualflag == NONE)
fprintf(f, "\n QUALITY NONE");
fprintf(f, "\n DEMAND MULTIPLIER %-.2f", Dmult);
/*** Updated 11/19/01 ***/
fprintf(f, "\n EMITTER EXPONENT %-.2f", 1.0/Qexp);
fprintf(f, "\n VISCOSITY %-.4f", Viscos/VISCOS);
fprintf(f, "\n DIFFUSIVITY %-.4f", Diffus/DIFFUS);
fprintf(f, "\n SPECIFIC GRAVITY %-.4f", SpGrav);
fprintf(f, "\n DEMAND MULTIPLIER %-.4f", Dmult);
fprintf(f, "\n EMITTER EXPONENT %-.4f", 1.0/Qexp);
fprintf(f, "\n VISCOSITY %-.6f", Viscos/VISCOS);
fprintf(f, "\n DIFFUSIVITY %-.6f", Diffus/DIFFUS);
fprintf(f, "\n SPECIFIC GRAVITY %-.6f", SpGrav);
fprintf(f, "\n TRIALS %-d", MaxIter);
fprintf(f, "\n ACCURACY %-.8f", Hacc);
fprintf(f, "\n TOLERANCE %-.8f", Ctol*Ucf[QUALITY]);
fprintf(f, "\n CHECKFREQ %-d", CheckFreq);
fprintf(f, "\n MAXCHECK %-d", MaxCheck);
fprintf(f, "\n DAMPLIMIT %-.8f", DampLimit);
/* Write [REPORT] section */
@@ -622,33 +594,27 @@ int saveinpfile(char *fname)
}
}
}
for (i=0; i<MAXVAR; i++)
for (i=0; i<FRICTION; i++)
{
/*** Updated ********************************************************/ //(2.00.11 - LR)
if (Field[i].Enabled == TRUE)
{
fprintf(f, "\n %-20sPRECISION %d", Field[i].Name, Field[i].Precision);
if (Field[i].RptLim[LOW] < BIG)
fprintf(f, "\n %-20sBELOW %.4f", Field[i].Name, Field[i].RptLim[LOW]);
fprintf(f, "\n %-20sBELOW %.6f", Field[i].Name, Field[i].RptLim[LOW]);
if (Field[i].RptLim[HI] > -BIG)
fprintf(f, "\n %-20sABOVE %.4f", Field[i].Name, Field[i].RptLim[HI]);
fprintf(f, "\n %-20sABOVE %.6f", Field[i].Name, Field[i].RptLim[HI]);
}
else fprintf(f, "\n %-20sNO", Field[i].Name);
/********************************************************************/
else fprintf(f, "\n %-20sNO", Field[i].Name);
}
fprintf(f, "\n");
/*** Updated *****************************************/ //(2.00.11 - LR)
/* Copy data from scratch file to new input file */
if (ftmp != NULL)
{
fseek(ftmp, 0, SEEK_SET);
while ( (j = fgetc(ftmp)) != EOF ) fputc(j, f);
fclose(ftmp);
}
/*****************************************************/
/* Save auxilary data to new input file */
saveauxdata(f);
fprintf(f, "\n\n[END]");
/* Close the new input file */
fprintf(f, "\n[END]");
fclose(f);
return(0);
}