Sunday, April 23, 2017

Use of Interface with Scripts and State Variables in HEC-ResSim

This post will demonstrate the use of the interface for scripts and state variables in HEC-ResSim.  This will be done by obtaining the day of each time step in a model simulation.

The time step in this model is hourly.

To obtain the day, I look at the methods that are available in the HecTime class.  I notice that there is a day() method available.

To get the details of this method, I look at javadocs (available in the installation of the HEC-ResSim software) under hec.heclib.util.  From the figure below, I can see that this method returns the day of the month in integer format.

I now need to look at how to access this method for the current time step.  Under the RunTimeStep class, I see a method termed getHecTime().

I look in hec.model.RunTimeStep in javadocs to get more information on this method and see that I can access the methods under the class HecTime by using this method.

In the code, I ask to get the day() method under the HecTime class by using the getHecTime() method under the RunTimeStep class.  I also add a print statement to test what this is giving me.

I look in the console log to see the result of this code.  Note that the day is repeated several times since this is an hourly time step model and the code is run at each time step.

Friday, April 21, 2017

Python Intermediate #8 - Simple text formatting in Python

In this post, I show a simple method for formatting text in Python.  In the example, we ask the user for three inputs:  name, occupation, and location.

I then show two different methods for printing the inputs into a sentence.

The first method shows a combination of the objects "name", "occupation", and "location" inserted into their correct positions between text.

The results of executing this code are as follows:

Instead of inserting the object names in between the text, we can use %s to indicate that the contents of an object will be inserted at that location.  The objects to be inserted then follow the % symbol.  This coding (with the original print statement commented out) is given below:

The results of executing this code are as follows: