Running HEC-HMS With Jython-V7
Running HEC-HMS With Jython-V7
Table of Contents
1 A JYTHON EXAMPLE................................................................................. 4
2 RUNNING THE SCRIPT VIA HEC-HMS.......................................................... 5
3 RUNNING THE SCRIPT VIA BATCH ............................................................. 6
4 RUNNING THE SCRIPT IN AN IDE ............................................................... 7
–2
– Running HEC-HMS with Jython
–3
A Jython example– Running HEC-HMS with Jython
1 A JYTHON EXAMPLE
An sample python script, compute_current.py, is shown below:
from hms.model import Project
from hms import Hms
myProject = Project.open('C:/Projects/castro/castro.hms')
myProject.computeRun('Current')
myProject.close()
Hms.shutdownEngine()
A Jython example– 4
Running the script via HEC-HMS– Running HEC-HMS with Jython
set "CLASSPATH=C:/Projects/hms/HEC-HMS/build/distributions/HEC-HMS-4.4-beta.2/
hms.jar;C:/Projects/hms/HEC-HMS/build/distributions/HEC-HMS-4.4-beta.2/lib/*"
C:/jython2.7.1/bin/jython -Djava.library.path="C:/Programs/HEC-HMS-4.4-beta.2/
bin;C:/Programs/HEC-HMS-4.4-beta.2/bin/gdal" compute_current.py
Line 1: The path to GDAL binaries prepends the the PATH environment variable. This is probably not
necessary unless you are working with the HMR52 storm in the met model. Paths to TauDEM and MPI
are not included because we will not be accessing these via scripting.
Lines 2-4: Other GDAL environment variables are configured. These are probably not necessary for
most scripting applications.
Line 5: Set the java classpath to include the path to hms.jar and dependent libraries. All of the
dependent libraries are located in the distribution lib directory. In this case a wildcard * indicates
that all libraries in the lib directory should be added to the classpath.
Line 6: Use the jython executable to execute the script. -Djava.library.path sets the path to native
libraries. Paths should include the distribution bin directory, where javaHeclib.dll and
WindowsEnvironment.dll reside, as well as the bin/gdal directory where gdal201.dll resides.
In Project Structure, add hms.jar as a library. You can optionally add the rest of the dependent library
jars here.
In the run configuration, set environment variables. See notes in the Running a script via batch
section. In this case the CLASSPATH environment variable is set to the distribution lib directory.
Alternatively you can add each jar explicitly in Project Structure | Libraries.
In the run configuration, set interpreter options to include -Djava.library.path. See notes in the
Running a script via batch section.
For the HEC-HMS API reference, see Scripting in the HEC-HMS User's Manual.
Happy scripting!