Pages

Book

Breaking the HEC-RAS Code
By Christopher Goodell, P.E., D.WRE



One of the most powerful, yet relatively unknown
features available in HEC-RAS is the 
HECRASController. 

The HECRASController API has a wealth of procedures which allow a programmer to manipulate HEC-RAS externally by setting input data, retrieving input or output data, and performing common functions such as opening and closing HEC-RAS, changing plans, running HEC-RAS, and plotting output. HECRASController applications are seemingly endless.  Not only can the retrieval and post-processing of output be automated, but with the HECRASController, real-time modeling and probabilistic experiments like Monte Carlo are possible.  If you have HEC-RAS on your computer, 
         You already have the HECRASController!        
              
                                                              


“Breaking the HEC-RAS Code” explains how the HECRASController works, provides example applications of the HECRASController, and catalogs the vast array of programming procedures (with explanations and examples on how to use them) embedded in the HECRASController.  This book, along with the companion Excel Workbook, which contains VBA code for all of the HECRASController procedures will have you controlling and automating HEC-RAS in no time.  

"This book is an awesome tool
to make changes in the HEC-RAS
interface.  Also, the steps to follow
in each process are very well
explained.  In our case, for Monte
Carlo simulations!"
-Juan Pinos,
Environmental Engineer, Univ. of
Cuenca, Ecuador

This is a "must-have" book for all HEC-RAS users. 


Professionals: Give yourself an edge for the next proposal and do something groundbreaking with HEC-RAS. 



Students: Improve your coursework, and make yourself marketable by adding the skills offered in this book.





Breaking the HEC-RAS Code is now available for purchase.  Get your copy here.



NOW AVAILABLE!!!  
The HECRASController Code Excel Workbook-A Companion to "Breaking the HEC-RAS Code".   This workbook includes examples of every subroutine and function in the HECRASController, along with example code for a range of HEC-RAS Automation projects. Over 150 procedures for controlling HEC-RAS are included and ready for you to use or modify on your own projects.  Get the HECRASController Code now!  Buy Now




What they saying about "Breaking the HEC-RAS Code"

“This book is the only complete resource that explains how to use the HECRASController in its entirety; and is comprehensive, easy to read, and well-documented.  Chris has been writing code around HEC-RAS to solve unique problems for years.  He has also suggested several ideas for expanding and improving the HECRASController.  Chris has done an outstanding job with this book.  Anyone with experience in HEC-RAS and a basic understanding of programming language will be able to use this book to help build applications that control HEC-RAS.  As the author and leader of the HEC-RAS development team, I highly recommend this book to anyone who wants to take HEC-RAS and expand its capabilities in order to solve challenging hydraulic engineering problems.
-Gary Brunner, P.E., D.WRE, HEC-RAS Lead Developer, Hydrologic Engineering Center


Breaking the HEC-RAS Code presents detailed, well-organized instructions for one of the most underutilized yet powerful aspects of HEC-RAS.  Readers will continually say "I didn't know you could make HEC-RAS do that!" This book is a must for anybody who frequently uses HEC-RAS.  The examples are thorough and complete.  The instructions on coding are easy to understand even for beginner coders.”
-Brian Wahlin, Ph.D., P.E., D.WRE, Senior Hydraulic Engineer, WEST Consultants


"Chris Goodell’s Breaking the HEC-RAS Code is a comprehensive guide to HECRASController, a set of programming procedures that give the user control over the operation and behavior of the well-known Hydrologic Engineering Center’s River Analysis System (HEC-RAS) hydraulic modeling software.  By using this book, an HEC-RAS modeler can learn to customize and automate the complete process, including opening the software, modifying data input, running the simulation, and retrieving output from the HEC-RAS binary output file.  If you’ve written programs for the old HEC-2 software, predecessor to HEC-RAS, but were thwarted by the binary output secrets of HEC-RAS, you’ll be thrilled to learn the tricks using Chris’s thorough descriptions and examples based on Visual Basic for Applications (VBA).  If you’ve never written programs for modifying modeling software but are eager to jump in, this is a good place to begin.  Chris has done an excellent job in writing this book that is comprehensive and well thought out.  While maybe not for the casual HEC-RAS user, this book will be a tremendous resource for anyone who wishes to automate and control HEC-RAS to solve complex hydraulic engineering problems."
-Gary Wolff, P.E., D.WRE, Senior Hydraulic Engineer, Otak, Inc.


"I have been working with the HEC-RAS software package for over 14 years.  When Chris gave me the opportunity to review his new book, I was very excited.  Through his hard work, he has opened the window to utilize HEC-RAS in countless new ways and provides engineers a way to bring more value to projects and clients.  I would not consider myself a programmer, but thanks to this book, I have a very good starting point and road map to use HEC-RAS in new and exciting ways."
-Matt Zeve, P.E., CFM, ASCE HEC-RAS Instructor and Houston Area Manager, IEA, Inc.


"Chris Goodell’s new book Breaking the HEC-RAS Code is essential for any frequent HEC-RAS user.  It provides great insights into how to most easily customize and optimize use of the code, as well as some of the program’s lesser known capabilities.  When I first used HEC-2, one had to know exactly how many blank spaces to type in order to fill an eight column cell.  There were no routines to debug an input data set. This book simplifies HEC-RAS and also magnifies the efficiencies of hydraulic modeling.  I would expect something of this quality from Chris, who worked on the HEC-RAS Development Team and is an internationally-recognized expert in the intricacies of HEC-RAS."
-Jeffrey B. Bradley, Ph.D., P.E., D.WRE, F.ASCE, Past-President EWRI and AAWRE of ASCE


"I just wanted to let you know that I have been enjoying reading and using your book.  I received my copy late last week and the fact that I enjoy most about it is that; it is well written and presented in an easily understandable manner.  I can't wait to start writing my own code and conduct my own experiments.  We have various situations here in the State, where we could utilize some of the techniques that you presented in the book."
-Mandar Nangare, M.S., CFM, North Dakota State Water Commission.



"Awesome Book! If you work with HEC-RAS get this book, I can 't say it any plainer than that. Even if you do not know much about VBA code the explanations by the author are clear and complete. I am using it to write some custom forms for model reviews and not once did I have that "ok, but how do you do the middle step?" problem, nothing is left out. There are many examples that you can take from the book verbatum and just modify a couple of lines to get the input or output variable you want for a form. The HEC-RAS wisdom in this book is worth a lot more than the price, costs less than one hour of an engineer's billable time, but will save many hours with automated procedures. I have only a little vba programming experience and did not have any issues with learning and using the examples and modifying them. The explanation of how HEC-RAS handles data was great! If you use HEC-RAS and don't get the book at the very least be sure to check out The RAS Solution Blog, I have found a lot of tips and tricks and just plain wisdom there."
-Richard T. Smith, P.E., Floodplain Specialist, Boulder County Trnasportation Department.




ERRATA SHEET

Thanks to all who have found these "errata" and took the time to let me know.

1.  Page 18, subroutine at the top of the page.  The last line of code before End Sub should read RC.Project_Open strFilename

2.  Pages 38 and 43.  The function GetCurrentPlanName is called in the subroutines written on these two pages.  The GetCurrentPlanName code is NOT a RASController procedure and is not presented anywhere in the book.  This is code I've written myself to retrieve the current plan name title for a RAS Project.  I've included the VBA code for GetCurrentPlanName at then end of this Errata Sheet.   You should be able to copy and paste it right into your VBA module.  

3.  Page 86.  A few corrections to the subroutine WriteRiversReachesNodes().
     a.  zOpenRASProjectByRef should be OpenRASProjectByRef.  
     b.  Dim typRASGeometry As mRASController.TypeRASGeom should be                                          Dim typRASGeometry As TypeRASGeom.  

     c.  zGetRiversReachesNodes should be GetRiversReachesNodes

4.  Pages 96-97.  A few corrections to the subroutine MonteCarloNValues().
     a.  Dim typGeom As mSamples.TypeRASGeom should be Dim typGeom As                                    TypeRASGeom.   Just remove the "mSamples."
     b.  Under the comment 'Define variables used in the For-Next Loop, intNumMessages                    should be lngNumMessages.  The same change should be made under the                          comment 'Compute the HEC-RAS project.
     c.  The function GetRandomNormal is referenced towards the bottom of page 96, but is                  not included in the book.  I've included this function below.  



Function GetCurrentPlanName(RC As RAS500.HECRASController) _
    As String
   
    '**********************************************************
    'Demonstrates the Plan_Names subroutine and _
        Plan_GetFilename function
    
    'Written by Christopher Goodell
    'June 28, 2014
    
    'Determines the current plan name, given the current plan _
        file.  Requires HECRASController as a parameter.
    '**********************************************************
    
    'Get all of the Plan Names in the project
    Dim lngPlanCount As Long, strPlanNames() As String
    Dim blnBasePlans As Boolean
    RC.Plan_Names lngPlanCount, strPlanNames(), blnBasePlans
    
    'Determine the current plan name.
    Dim i As Integer
    Dim strPlanFileNames() As String
    ReDim strPlanFileNames(1 To lngPlanCount)
    For i = 1 To lngPlanCount
        strPlanFileNames(i) = RC.Plan_GetFileName _
            (strPlanNames(i))
        If strPlanFileNames(i) = RC.CurrentPlanFile Then
            GetCurrentPlanName = strPlanNames(i)
        End If
    Next i


End Function


Function GetRandomNormal(ByVal Mean As Double, ByVal StdDev _
    As Double) As Double
    
    '**********************************************************
    'Demonstrates how to compute a Random Number about a _
        Normal Statistical Distribution
    
    'Written by Christopher Goodell
    'November 7, 2013
    
    'Computes a random number from a normal distribution. _
        Uses the Box-Muller Transformation Basic Form to _
        handle the transformation.
    '**********************************************************

    'Initialize the random-number generator
    Randomize
    
    'Box-Muller uses 2 random numbers (x1, x2) to generate 2 _
        random normally distributed numbers (y1, y2).  We'll _
        ignore the 2nd Number (y2).
    Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
    x1 = Rnd()
    x2 = Rnd()
    y1 = (-2 * Math.Log(x1)) ^ 0.5 * _
        Math.Cos(2 * 3.141592 * x2)
    y2 = (-2 * Math.Log(x1)) ^ 0.5 * _
        Math.Sin(2 * 3.141592 * x2)
    
    'Transform y1 about the input mean and standard deviation
    GetRandomNormal = (y1) * StdDev + Mean

End Function


5.  Pages 38.  The function GetCurrentPlanName is referenced in the code on this page, but is not included in the book.  I've included this function below. 



Function GetCurrentPlanName(RC As RAS503.HECRASController) _
    As String
  
    '**********************************************************
    'Demonstrates the Plan_Names subroutine and _
        Plan_GetFilename function
   
    'Written by Christopher Goodell
    'June 28, 2014
   
    'Determines the current plan name, given the current plan _
        file.  Requires HECRASController as a parameter.
    '**********************************************************
   
    'Get all of the Plan Names in the project
    Dim lngPlanCount As Long, strPlanNames() As String
    Dim blnBasePlans As Boolean
    RC.Plan_Names lngPlanCount, strPlanNames(), blnBasePlans
   
    'Determine the current plan name.
    Dim i As Integer
    Dim strPlanFileNames() As String
    ReDim strPlanFileNames(1 To lngPlanCount)
    For i = 1 To lngPlanCount
        strPlanFileNames(i) = RC.Plan_GetFileName _
            (strPlanNames(i))
        If strPlanFileNames(i) = RC.CurrentPlanFile Then
            GetCurrentPlanName = strPlanNames(i)
        End If
    Next i


End Function