Skip to content

Commit 0ab0021

Browse files
authored
Merge pull request #9 from USEPA/codedrop_lew_5113
Processing v5.1.13 code drop
2 parents e48febe + 5de638d commit 0ab0021

57 files changed

Lines changed: 2393 additions & 1707 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/climate.c

Lines changed: 85 additions & 65 deletions
Large diffs are not rendered by default.

src/consts.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Version: 5.1
66
// Date: 03/20/14 (Build 5.1.001)
77
// 08/01/16 (Build 5.1.011)
8+
// 05/10/18 (Build 5.1.013)
89
// Author: L. Rossman
910
//
1011
// Various Constants
@@ -14,7 +15,7 @@
1415
// General Constants
1516
//------------------
1617

17-
#define VERSION 51011 //(5.1.011)
18+
#define VERSION 51013
1819
#define MAGICNUMBER 516114522
1920
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
2021
#define MAXTITLE 3 // Max. # title lines

src/controls.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#define _CRT_SECURE_NO_DEPRECATE
5555

5656
#include <string.h>
57-
#include <malloc.h>
57+
#include <stdlib.h>
5858
#include <math.h>
5959
#include "headers.h"
6060

@@ -65,19 +65,19 @@ enum RuleState {r_RULE, r_IF, r_AND, r_OR, r_THEN, r_ELSE, r_PRIORITY,
6565
r_ERROR};
6666
enum RuleObject {r_NODE, r_LINK, r_CONDUIT, r_PUMP, r_ORIFICE, r_WEIR,
6767
r_OUTLET, r_SIMULATION};
68-
enum RuleAttrib {r_DEPTH, r_HEAD, r_VOLUME, r_INFLOW, r_FLOW, r_STATUS, //(5.1.008)
69-
r_SETTING, r_TIMEOPEN, r_TIMECLOSED, r_TIME, r_DATE, //(5.1.010)
70-
r_CLOCKTIME, r_DAYOFYEAR, r_DAY, r_MONTH}; //(5.1.011)
68+
enum RuleAttrib {r_DEPTH, r_HEAD, r_VOLUME, r_INFLOW, r_FLOW, r_STATUS,
69+
r_SETTING, r_TIMEOPEN, r_TIMECLOSED, r_TIME, r_DATE,
70+
r_CLOCKTIME, r_DAYOFYEAR, r_DAY, r_MONTH};
7171
enum RuleRelation {EQ, NE, LT, LE, GT, GE};
7272
enum RuleSetting {r_CURVE, r_TIMESERIES, r_PID, r_NUMERIC};
7373

7474
static char* ObjectWords[] =
7575
{"NODE", "LINK", "CONDUIT", "PUMP", "ORIFICE", "WEIR", "OUTLET",
7676
"SIMULATION", NULL};
7777
static char* AttribWords[] =
78-
{"DEPTH", "HEAD", "VOLUME", "INFLOW", "FLOW", "STATUS", "SETTING", //(5.1.008)
79-
"TIMEOPEN", "TIMECLOSED","TIME", "DATE", "CLOCKTIME", "DAYOFYEAR", //(5.1.011)
80-
"DAY", "MONTH", NULL}; //(5.1.011)
78+
{"DEPTH", "HEAD", "VOLUME", "INFLOW", "FLOW", "STATUS", "SETTING",
79+
"TIMEOPEN", "TIMECLOSED","TIME", "DATE", "CLOCKTIME", "DAYOFYEAR",
80+
"DAY", "MONTH", NULL};
8181
static char* RelOpWords[] = {"=", "<>", "<", "<=", ">", ">=", NULL};
8282
static char* StatusWords[] = {"OFF", "ON", NULL};
8383
static char* ConduitWords[] = {"CLOSED", "OPEN", NULL};
@@ -98,8 +98,8 @@ struct TVariable
9898
struct TPremise
9999
{
100100
int type; // clause type (IF/AND/OR)
101-
struct TVariable lhsVar; // left hand side variable //(5.1.008)
102-
struct TVariable rhsVar; // right hand side variable //(5.1.008)
101+
struct TVariable lhsVar; // left hand side variable
102+
struct TVariable rhsVar; // right hand side variable
103103
int relation; // relational operator (>, <, =, etc)
104104
double value; // right hand side value
105105
struct TPremise *next; // next premise clause of rule
@@ -148,7 +148,6 @@ double ControlValue; // value of controller variable
148148
double SetPoint; // value of controller setpoint
149149
DateTime CurrentDate; // current date in whole days
150150
DateTime CurrentTime; // current time of day (decimal)
151-
DateTime ElapsedTime; // elasped simulation time (decimal days)
152151

153152
//-----------------------------------------------------------------------------
154153
// External functions (declared in funcs.h)
@@ -180,7 +179,7 @@ void deleteRules(void);
180179

181180
int findExactMatch(char *s, char *keyword[]);
182181
int setActionSetting(char* tok[], int nToks, int* curve, int* tseries,
183-
int* attrib, double* value);
182+
int* attrib, double value[]);
184183
void updateActionValue(struct TAction* a, DateTime currentTime, double dt);
185184
double getPIDSetting(struct TAction* a, double dt);
186185

@@ -345,8 +344,6 @@ int controls_evaluate(DateTime currentTime, DateTime elapsedTime, double tStep)
345344

346345
//=============================================================================
347346

348-
// This function was revised to add support for r.h.s. premise variables. // //(5.1.008)
349-
350347
int addPremise(int r, int type, char* tok[], int nToks)
351348
//
352349
// Input: r = control rule index
@@ -389,9 +386,9 @@ int addPremise(int r, int type, char* tok[], int nToks)
389386
if ( findmatch(tok[n], ObjectWords) >= 0 && n + 3 >= nToks )
390387
{
391388
err = getPremiseVariable(tok, &n, &v2);
392-
if ( err > 0 ) return ERR_RULE; //(5.1.009)
393-
if ( v1.attribute != v2.attribute) //(5.1.009)
394-
report_writeWarningMsg(WARN11, Rules[r].ID); //(5.1.009)
389+
if ( err > 0 ) return ERR_RULE;
390+
if ( v1.attribute != v2.attribute)
391+
report_writeWarningMsg(WARN11, Rules[r].ID);
395392
}
396393

397394
// --- otherwise get value to which LHS variable is compared to
@@ -478,12 +475,11 @@ int getPremiseVariable(char* tok[], int* k, struct TVariable* v)
478475
{
479476
case r_DEPTH:
480477
case r_HEAD:
481-
case r_VOLUME: //(5.1.008)
478+
case r_VOLUME:
482479
case r_INFLOW: break;
483480
default: return error_setInpError(ERR_KEYWORD, tok[n]);
484481
}
485482

486-
//// Added to release 5.1.010. //// //(5.1.010)
487483
// --- check for link TIMEOPEN & TIMECLOSED attributes
488484
else if ( link >= 0 &&
489485
( (attrib == r_TIMEOPEN ||
@@ -492,7 +488,6 @@ int getPremiseVariable(char* tok[], int* k, struct TVariable* v)
492488
{
493489

494490
}
495-
////
496491

497492
else if ( obj == r_LINK || obj == r_CONDUIT ) switch (attrib)
498493
{
@@ -520,7 +515,7 @@ int getPremiseVariable(char* tok[], int* k, struct TVariable* v)
520515
case r_CLOCKTIME:
521516
case r_DAY:
522517
case r_MONTH:
523-
case r_DAYOFYEAR: break; //(5.1.011)
518+
case r_DAYOFYEAR: break;
524519
default: return error_setInpError(ERR_KEYWORD, tok[n]);
525520
}
526521

@@ -544,7 +539,7 @@ int getPremiseValue(char* token, int attrib, double* value)
544539
// in the premise clause of a control rule.
545540
//
546541
{
547-
char strDate[25]; //(5.1.011)
542+
char strDate[25];
548543
switch (attrib)
549544
{
550545
case r_STATUS:
@@ -555,8 +550,8 @@ int getPremiseValue(char* token, int attrib, double* value)
555550

556551
case r_TIME:
557552
case r_CLOCKTIME:
558-
case r_TIMEOPEN: //(5.1.010)
559-
case r_TIMECLOSED: //(5.1.010)
553+
case r_TIMEOPEN:
554+
case r_TIMECLOSED:
560555
if ( !datetime_strToTime(token, value) )
561556
return error_setInpError(ERR_DATETIME, token);
562557
break;
@@ -580,7 +575,6 @@ int getPremiseValue(char* token, int attrib, double* value)
580575
return error_setInpError(ERR_DATETIME, token);
581576
break;
582577

583-
//// This code block added to release 5.1.011. //// //(5.1.011)
584578
case r_DAYOFYEAR:
585579
strncpy(strDate, token, 6);
586580
strcat(strDate, "/1947");
@@ -591,7 +585,6 @@ int getPremiseValue(char* token, int attrib, double* value)
591585
else if ( !getDouble(token, value) || *value < 1 || *value > 365 )
592586
return error_setInpError(ERR_DATETIME, token);
593587
break;
594-
////////////////////////////////////////////////////
595588

596589
default: if ( !getDouble(token, value) )
597590
return error_setInpError(ERR_NUMBER, token);
@@ -940,8 +933,8 @@ int executeActionList(DateTime currentTime)
940933
if ( Link[a1->link].targetSetting != a1->value )
941934
{
942935
Link[a1->link].targetSetting = a1->value;
943-
if ( RptFlags.controls && a1->curve < 0 //(5.1.011)
944-
&& a1->tseries < 0 && a1->attribute != r_PID ) //(5.1.011)
936+
if ( RptFlags.controls && a1->curve < 0
937+
&& a1->tseries < 0 && a1->attribute != r_PID )
945938
report_writeControlAction(currentTime, Link[a1->link].ID,
946939
a1->value, Rules[a1->rule].ID);
947940
count++;
@@ -955,8 +948,6 @@ int executeActionList(DateTime currentTime)
955948

956949
//=============================================================================
957950

958-
//// This function was re-written for release 5.1.011. //// //(5.1.011)
959-
960951
int evaluatePremise(struct TPremise* p, double tStep)
961952
//
962953
// Input: p = a control rule premise condition
@@ -1011,8 +1002,8 @@ double getVariableValue(struct TVariable v)
10111002
case r_MONTH:
10121003
return datetime_monthOfYear(CurrentDate);
10131004

1014-
case r_DAYOFYEAR: //(5.1.011)
1015-
return datetime_dayOfYear(CurrentDate); //(5.1.011)
1005+
case r_DAYOFYEAR:
1006+
return datetime_dayOfYear(CurrentDate);
10161007

10171008
case r_STATUS:
10181009
if ( j < 0 ||
@@ -1038,15 +1029,14 @@ double getVariableValue(struct TVariable v)
10381029
if ( i < 0 ) return MISSING;
10391030
return (Node[i].newDepth + Node[i].invertElev) * UCF(LENGTH);
10401031

1041-
case r_VOLUME: //(5.1.008)
1032+
case r_VOLUME:
10421033
if ( i < 0 ) return MISSING;
10431034
return (Node[i].newVolume * UCF(VOLUME));
10441035

10451036
case r_INFLOW:
10461037
if ( i < 0 ) return MISSING;
10471038
else return Node[i].newLatFlow*UCF(FLOW);
10481039

1049-
//// This section added to release 5.1.010. //// //(5.1.010)
10501040
case r_TIMEOPEN:
10511041
if ( j < 0 ) return MISSING;
10521042
if ( Link[j].setting <= 0.0 ) return MISSING;
@@ -1056,7 +1046,6 @@ double getVariableValue(struct TVariable v)
10561046
if ( j < 0 ) return MISSING;
10571047
if ( Link[j].setting > 0.0 ) return MISSING;
10581048
return CurrentDate + CurrentTime - Link[j].timeLastSet;
1059-
////
10601049

10611050
default: return MISSING;
10621051
}

src/culvert.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
// Project: EPA SWMM5
55
// Version: 5.1
66
// Date: 03/20/14 (Build 5.1.001)
7+
// 05/10/18 (Build 5.1.013)
78
// Author: L. Rossman
89
//
910
// Culvert equations for SWMM5
1011
//
1112
// Computes flow reduction in a culvert-type conduit due to
1213
// inlet control using equations from the FHWA HEC-5 circular.
1314
//
15+
// Build 5.1.013:
16+
// - C parameter corrected for Arch, Corrugated Metal, Mitered culvert.
1417
//-----------------------------------------------------------------------------
1518
#define _CRT_SECURE_NO_DEPRECATE
1619

@@ -105,7 +108,7 @@ static const double Params[58][5] = {
105108

106109
// Arch, Corrugated Metal
107110
{1.0, 0.0083, 2.00, 0.0379, 0.69}, //90 deg headwall
108-
{1.0, 0.0300, 1.00, 0.0463, 0.75}, //Mitered to slope
111+
{1.0, 0.0300, 1.00, 0.0473, 0.75}, //Mitered to slope //(5.1.013)
109112
{1.0, 0.0340, 1.50, 0.0496, 0.57}, //Thin wall projecting
110113

111114
// Circular Culvert

src/datetime.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ void datetime_decodeTime(DateTime time, int* h, int* m, int* s)
231231
{
232232
int secs;
233233
int mins;
234-
double fracDay = (time - floor(time)) * SecsPerDay; //(5.1.011)
235-
secs = (int)(floor(fracDay + 0.5)); //(5.1.011)
236-
if ( secs >= 86400 ) secs = 86399; //(5.1.011)
234+
double fracDay = (time - floor(time)) * SecsPerDay;
235+
secs = (int)(floor(fracDay + 0.5));
236+
if ( secs >= 86400 ) secs = 86399;
237237
divMod(secs, 60, &mins, s);
238238
divMod(mins, 60, h, m);
239239
if ( *h > 23 ) *h = 0;
@@ -512,8 +512,6 @@ int datetime_daysPerMonth(int year, int month)
512512

513513
//=============================================================================
514514

515-
//// New function added to release 5.1.011. //// //(5.1.011)
516-
517515
void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize, char* timeStamp)
518516

519517
// Input: fmt = desired date format code

src/datetime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ int datetime_daysPerMonth(int year, int month);
4646
// Functions for converting a DateTime value to a string
4747
void datetime_dateToStr(DateTime date, char* s);
4848
void datetime_timeToStr(DateTime time, char* s);
49-
void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize, //5.1.011
50-
char* timeStamp); //5.1.011
49+
void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize,
50+
char* timeStamp);
5151

5252
// Functions for converting a string date or time to a DateTime value
5353
int datetime_findMonth(char* s);

0 commit comments

Comments
 (0)