Skip to content

Commit

Permalink
Merge pull request #9 from USEPA/codedrop_lew_5113
Browse files Browse the repository at this point in the history
Processing v5.1.13 code drop
  • Loading branch information
michaeltryby authored Aug 23, 2018
2 parents e48febe + 5de638d commit 0ab0021
Show file tree
Hide file tree
Showing 57 changed files with 2,393 additions and 1,707 deletions.
150 changes: 85 additions & 65 deletions src/climate.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Version: 5.1
// Date: 03/20/14 (Build 5.1.001)
// 08/01/16 (Build 5.1.011)
// 05/10/18 (Build 5.1.013)
// Author: L. Rossman
//
// Various Constants
Expand All @@ -14,7 +15,7 @@
// General Constants
//------------------

#define VERSION 51011 //(5.1.011)
#define VERSION 51013
#define MAGICNUMBER 516114522
#define EOFMARK 0x1A // Use 0x04 for UNIX systems
#define MAXTITLE 3 // Max. # title lines
Expand Down
57 changes: 23 additions & 34 deletions src/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#define _CRT_SECURE_NO_DEPRECATE

#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>
#include "headers.h"

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

static char* ObjectWords[] =
{"NODE", "LINK", "CONDUIT", "PUMP", "ORIFICE", "WEIR", "OUTLET",
"SIMULATION", NULL};
static char* AttribWords[] =
{"DEPTH", "HEAD", "VOLUME", "INFLOW", "FLOW", "STATUS", "SETTING", //(5.1.008)
"TIMEOPEN", "TIMECLOSED","TIME", "DATE", "CLOCKTIME", "DAYOFYEAR", //(5.1.011)
"DAY", "MONTH", NULL}; //(5.1.011)
{"DEPTH", "HEAD", "VOLUME", "INFLOW", "FLOW", "STATUS", "SETTING",
"TIMEOPEN", "TIMECLOSED","TIME", "DATE", "CLOCKTIME", "DAYOFYEAR",
"DAY", "MONTH", NULL};
static char* RelOpWords[] = {"=", "<>", "<", "<=", ">", ">=", NULL};
static char* StatusWords[] = {"OFF", "ON", NULL};
static char* ConduitWords[] = {"CLOSED", "OPEN", NULL};
Expand All @@ -98,8 +98,8 @@ struct TVariable
struct TPremise
{
int type; // clause type (IF/AND/OR)
struct TVariable lhsVar; // left hand side variable //(5.1.008)
struct TVariable rhsVar; // right hand side variable //(5.1.008)
struct TVariable lhsVar; // left hand side variable
struct TVariable rhsVar; // right hand side variable
int relation; // relational operator (>, <, =, etc)
double value; // right hand side value
struct TPremise *next; // next premise clause of rule
Expand Down Expand Up @@ -148,7 +148,6 @@ double ControlValue; // value of controller variable
double SetPoint; // value of controller setpoint
DateTime CurrentDate; // current date in whole days
DateTime CurrentTime; // current time of day (decimal)
DateTime ElapsedTime; // elasped simulation time (decimal days)

//-----------------------------------------------------------------------------
// External functions (declared in funcs.h)
Expand Down Expand Up @@ -180,7 +179,7 @@ void deleteRules(void);

int findExactMatch(char *s, char *keyword[]);
int setActionSetting(char* tok[], int nToks, int* curve, int* tseries,
int* attrib, double* value);
int* attrib, double value[]);
void updateActionValue(struct TAction* a, DateTime currentTime, double dt);
double getPIDSetting(struct TAction* a, double dt);

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

//=============================================================================

// This function was revised to add support for r.h.s. premise variables. // //(5.1.008)

int addPremise(int r, int type, char* tok[], int nToks)
//
// Input: r = control rule index
Expand Down Expand Up @@ -389,9 +386,9 @@ int addPremise(int r, int type, char* tok[], int nToks)
if ( findmatch(tok[n], ObjectWords) >= 0 && n + 3 >= nToks )
{
err = getPremiseVariable(tok, &n, &v2);
if ( err > 0 ) return ERR_RULE; //(5.1.009)
if ( v1.attribute != v2.attribute) //(5.1.009)
report_writeWarningMsg(WARN11, Rules[r].ID); //(5.1.009)
if ( err > 0 ) return ERR_RULE;
if ( v1.attribute != v2.attribute)
report_writeWarningMsg(WARN11, Rules[r].ID);
}

// --- otherwise get value to which LHS variable is compared to
Expand Down Expand Up @@ -478,12 +475,11 @@ int getPremiseVariable(char* tok[], int* k, struct TVariable* v)
{
case r_DEPTH:
case r_HEAD:
case r_VOLUME: //(5.1.008)
case r_VOLUME:
case r_INFLOW: break;
default: return error_setInpError(ERR_KEYWORD, tok[n]);
}

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

}
////

else if ( obj == r_LINK || obj == r_CONDUIT ) switch (attrib)
{
Expand Down Expand Up @@ -520,7 +515,7 @@ int getPremiseVariable(char* tok[], int* k, struct TVariable* v)
case r_CLOCKTIME:
case r_DAY:
case r_MONTH:
case r_DAYOFYEAR: break; //(5.1.011)
case r_DAYOFYEAR: break;
default: return error_setInpError(ERR_KEYWORD, tok[n]);
}

Expand All @@ -544,7 +539,7 @@ int getPremiseValue(char* token, int attrib, double* value)
// in the premise clause of a control rule.
//
{
char strDate[25]; //(5.1.011)
char strDate[25];
switch (attrib)
{
case r_STATUS:
Expand All @@ -555,8 +550,8 @@ int getPremiseValue(char* token, int attrib, double* value)

case r_TIME:
case r_CLOCKTIME:
case r_TIMEOPEN: //(5.1.010)
case r_TIMECLOSED: //(5.1.010)
case r_TIMEOPEN:
case r_TIMECLOSED:
if ( !datetime_strToTime(token, value) )
return error_setInpError(ERR_DATETIME, token);
break;
Expand All @@ -580,7 +575,6 @@ int getPremiseValue(char* token, int attrib, double* value)
return error_setInpError(ERR_DATETIME, token);
break;

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

default: if ( !getDouble(token, value) )
return error_setInpError(ERR_NUMBER, token);
Expand Down Expand Up @@ -940,8 +933,8 @@ int executeActionList(DateTime currentTime)
if ( Link[a1->link].targetSetting != a1->value )
{
Link[a1->link].targetSetting = a1->value;
if ( RptFlags.controls && a1->curve < 0 //(5.1.011)
&& a1->tseries < 0 && a1->attribute != r_PID ) //(5.1.011)
if ( RptFlags.controls && a1->curve < 0
&& a1->tseries < 0 && a1->attribute != r_PID )
report_writeControlAction(currentTime, Link[a1->link].ID,
a1->value, Rules[a1->rule].ID);
count++;
Expand All @@ -955,8 +948,6 @@ int executeActionList(DateTime currentTime)

//=============================================================================

//// This function was re-written for release 5.1.011. //// //(5.1.011)

int evaluatePremise(struct TPremise* p, double tStep)
//
// Input: p = a control rule premise condition
Expand Down Expand Up @@ -1011,8 +1002,8 @@ double getVariableValue(struct TVariable v)
case r_MONTH:
return datetime_monthOfYear(CurrentDate);

case r_DAYOFYEAR: //(5.1.011)
return datetime_dayOfYear(CurrentDate); //(5.1.011)
case r_DAYOFYEAR:
return datetime_dayOfYear(CurrentDate);

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

case r_VOLUME: //(5.1.008)
case r_VOLUME:
if ( i < 0 ) return MISSING;
return (Node[i].newVolume * UCF(VOLUME));

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

//// This section added to release 5.1.010. //// //(5.1.010)
case r_TIMEOPEN:
if ( j < 0 ) return MISSING;
if ( Link[j].setting <= 0.0 ) return MISSING;
Expand All @@ -1056,7 +1046,6 @@ double getVariableValue(struct TVariable v)
if ( j < 0 ) return MISSING;
if ( Link[j].setting > 0.0 ) return MISSING;
return CurrentDate + CurrentTime - Link[j].timeLastSet;
////

default: return MISSING;
}
Expand Down
5 changes: 4 additions & 1 deletion src/culvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
// Project: EPA SWMM5
// Version: 5.1
// Date: 03/20/14 (Build 5.1.001)
// 05/10/18 (Build 5.1.013)
// Author: L. Rossman
//
// Culvert equations for SWMM5
//
// Computes flow reduction in a culvert-type conduit due to
// inlet control using equations from the FHWA HEC-5 circular.
//
// Build 5.1.013:
// - C parameter corrected for Arch, Corrugated Metal, Mitered culvert.
//-----------------------------------------------------------------------------
#define _CRT_SECURE_NO_DEPRECATE

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

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

// Circular Culvert
Expand Down
8 changes: 3 additions & 5 deletions src/datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ void datetime_decodeTime(DateTime time, int* h, int* m, int* s)
{
int secs;
int mins;
double fracDay = (time - floor(time)) * SecsPerDay; //(5.1.011)
secs = (int)(floor(fracDay + 0.5)); //(5.1.011)
if ( secs >= 86400 ) secs = 86399; //(5.1.011)
double fracDay = (time - floor(time)) * SecsPerDay;
secs = (int)(floor(fracDay + 0.5));
if ( secs >= 86400 ) secs = 86399;
divMod(secs, 60, &mins, s);
divMod(mins, 60, h, m);
if ( *h > 23 ) *h = 0;
Expand Down Expand Up @@ -512,8 +512,6 @@ int datetime_daysPerMonth(int year, int month)

//=============================================================================

//// New function added to release 5.1.011. //// //(5.1.011)

void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize, char* timeStamp)

// Input: fmt = desired date format code
Expand Down
4 changes: 2 additions & 2 deletions src/datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int datetime_daysPerMonth(int year, int month);
// Functions for converting a DateTime value to a string
void datetime_dateToStr(DateTime date, char* s);
void datetime_timeToStr(DateTime time, char* s);
void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize, //5.1.011
char* timeStamp); //5.1.011
void datetime_getTimeStamp(int fmt, DateTime aDate, int stampSize,
char* timeStamp);

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

0 comments on commit 0ab0021

Please sign in to comment.