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 };
6666enum 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 };
7171enum RuleRelation {EQ , NE , LT , LE , GT , GE };
7272enum RuleSetting {r_CURVE , r_TIMESERIES , r_PID , r_NUMERIC };
7373
7474static char * ObjectWords [] =
7575 {"NODE" , "LINK" , "CONDUIT" , "PUMP" , "ORIFICE" , "WEIR" , "OUTLET" ,
7676 "SIMULATION" , NULL };
7777static 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 };
8181static char * RelOpWords [] = {"=" , "<>" , "<" , "<=" , ">" , ">=" , NULL };
8282static char * StatusWords [] = {"OFF" , "ON" , NULL };
8383static char * ConduitWords [] = {"CLOSED" , "OPEN" , NULL };
@@ -98,8 +98,8 @@ struct TVariable
9898struct 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
148148double SetPoint ; // value of controller setpoint
149149DateTime CurrentDate ; // current date in whole days
150150DateTime 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
181180int findExactMatch (char * s , char * keyword []);
182181int setActionSetting (char * tok [], int nToks , int * curve , int * tseries ,
183- int * attrib , double * value );
182+ int * attrib , double value [] );
184183void updateActionValue (struct TAction * a , DateTime currentTime , double dt );
185184double 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-
350347int 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-
960951int 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 }
0 commit comments