Vous êtes sur la page 1sur 11

Automating HEC-RAS with Excel

Virginia Lakes and Watersheds Conference, March 2015


Thomas Williams, PE
Amec Foster Wheeler

+ =?
Contents
1. What is HEC-RAS? (brief intro)
2. The HECRASController API
3. Excel VBA Demos
1. Multi-Model Run
2. RAS Output Extraction
3. Mannings n Calibration (sort of)
4. Tips
5. Conclusion

2
1. What is HEC-RAS?

Hydrologic
Engineering
Centers
River
Analysis
System

HEC-RAS allows you to


perform one-dimensional
steady flow, unsteady flow,
sediment transport/mobile
bed computations, and water
temperature modeling.
- USACE

3
2. The HECRASController API
What is an API?

API = Application Programmer Interface


In computer programming, an application programmer interface (API) is
a set of routines, protocols, and tools for building software
applications. An API expresses a software component in terms of its
operations, inputs, outputs, and underlying types.
- Wikipedia

Their Program
Your
Program API

4
2. The HECRASController API (contd)
The HECRASController API
The current version of the HECRASController has a wealth of
procedures that will allow a programmer to manipulate HEC-RAS
externally by setting input data, retrieving input or output data, and
performing common [HEC-RAS] functions
- Christopher Goodell, PE, D.WRE, Breaking the HEC-RAS Code, 2014

HEC-RAS
Excel
API

5
2. The HECRASController API (contd)
Accessing the API from Microsoft Excel
1. Click the Visual Basic button (on the Developer tab)
2. Create a new VBA module
3. Go to Tools > References, check HEC River Analysis System,
and click OK.
4. Write code!

6
2. The HECRASController API (contd)
A simple program
Sub RunHECRAS()
' Opens and runs a HEC-RAS model

' Declare variables


Dim ras As New HECRASController
Dim nmsg As Long
Dim strMessages() As String
Dim prjFilePath As String

' Open the model


prjFilePath = "C:\MyHecRasModel.prj"
ras.Project_Open (prjFilePath)

' Run the model


ras.Compute_CurrentPlan nmsg, strMessages

End Sub

7
2. The HECRASController API (contd)
Some example HECRASController
fuctions and subroutines:
Project_Open Geometry_SetMann
Opens a HEC-RAS model. Sets the Mannings n values for
Compute_CurrentPlan a cross section, horizontally
Runs the current flow/geometry varied.
regime. Add_BC
ExportGIS Adds a bridge/culvert.
Exports an *.sdf file that can be Edit_BC
read into ArcGIS using HEC- Opens the Bridge/Culvert Editor
GeoRAS. and displays the selected station.
Output_NodeOutput PlotPF
Returns an output value for a Displays the water surface profile
given node and profile. for a given River/Reach.

8
3. Excel VBA Demos
1. Multi-Model Run
2. RAS Output Extraction
3. Mannings n Calibration (sort of)

Cross your fingers!

9
4. Tips
Breaking the HEC-RAS Code
by Christopher Goodell, PE, D.WRE
The API is a little rough around the edges.
Provides a lot of functionality, but not everything
Inconsistencies:
Parameter names and types
Function / subroutine behavior
No official API documentation
HEC-RAS is public domain software, but not open source
HEC-RAS project (*.prj), geometry (*.g##), flow (*.f##), and plan
(*.p##) files are plain text.
Sometimes thats easier than using the API.
HEC-RAS output files (*.O##) are binary.

10
5. Conclusion

1. The HECRASController API is really useful


2. but it takes a little work to figure out.
3. Happy coding!

Questions?

Contact Info
Thomas Williams, PE
Amec Foster Wheeler
thomas.williams@amecfw.com

11

Vous aimerez peut-être aussi