Storing Variables in a Single State Variable

In this post, I will demonstrate the storing of all variables within a single state variable.  It may be desirable to store all variables within a single state variable since doing so can facilitate the updating of variables without having to go to each individual state variable.

In the figure below, we are storing two variables in the Initialization Tab of a state variable named "variables".  The variable names are "min_flow" and "max_flow".  We use the varPut command to be able to access these values in another state variable.  In the varPut command, we provide the names "min" and "max" as the names that can be accessed in another state variable and assign the values of "min_flow" and "max_flow" to those names.






We then access the values of these variables in a state variable named "minmaxflow".  The first step is to get the state variable named "variables".  We can then get the values assigned to "min" and "max" for use in the state variable named "minmaxflow".  In this example, I printed out the values for testing and visualization.

 



We then examine the console log to see the printed values.  This is shown below.



In the example above, I brought in the values for "min" and "max" into the Main tab of the "minmaxflow" state variable.  You can also bring them in once into the Initialization tab of "minmaxflow".  To do this, the Initialization tab of "minmaxflow" would contain the following:



The Main tab of "minmaxflow" would contain the following (note that I duplicated names in varPut and varGet to demonstrate that this does not seem to cause issues with the coding):



The results for the printed values are the same as above:



Comments

  1. Hi Kevin. Thanks a lot for this blog. I was able to make my first script in HEC-ResSim thanks to you. I would like to make a rule that allow me to use an external time series. I have added an external time series to the model an it appears in the script rule module under external time series, but when I try to run my simulation I got an error. It seems it can not read the External Time Series although it appears there... any thoughts?

    ReplyDelete

Post a Comment