Pages

Monday, October 8, 2018

Using the HEC-RAS Controller with the R programming environment


Hey all HEC-RAS Controllers-

Charlie Ferguson of the University of Cambridge recently emailed me about some questions about automating HEC-RAS using the HECRASController and the R programming environment.  While "Breaking the HEC-RAS Code" was written around use of VBA for automating HEC-RAS, there are several other programming languages out there that will work.  R is a powerful programming language for statistical computing and graphics.  I've seen it used before and it is quite impressive.  In talking with folks interested in automating HEC-RAS, besides VBA and Visual Studio, Python and R seem to be the programming languages/platforms most people are talking about.  You can read up more on R here.  


Unfortunately I don't have experience using R (yet).  So I'm opening this up to the HECRASController community out there for assistance.  The following is Mr. Ferguson's call for help and collaboration regarding automating HEC-RAS using R.  Please comment below and respond directly to Mr. Ferguson if you wish to share ideas.


The HEC RAS Controller has been used in several different environments (VBA, Matlab etc.) and I am trying to establish how to get it working in R. From what I can find online, there have already been several attempts and would really appreciate any advice or collaboration.

So far I have followed a similar process to ‘Toby’ in this post on the online HEC RAS Controller help forum. The process relies on an R package called R-DCOMClient. A slight difference in my script is to construct the variable ‘strMessages’ as an empty character matrix;
-------
strMessages<-matrix(character())
--------
which appears to satisfy the data type required by the underlying COM method (Compute_CurrentPlan).

However, I’ve then found another error stemming from R-DCOMClient requiring a related R package called ‘R-DCOMServer’. Unfortunately, as far as I’m aware, this package and its prerequisites are no longer available (also, for separate reasons, I need to use an R version no older than 3.1.).  This means I’ve hit a dead-end.

I am wondering whether anyone has found a way past this problem OR has found an entirely different solution for running controller in R?

Any advice or offers to collaborate would be welcome!

3 comments:

  1. I am happy to see other HEC-RAS R users!

    I have not tried using the controller from R but I would be interested to know if there is a solution to this problem.

    I have written R scripts to do things like rewrite parts of geometry files and access the hdf files to retrieve results.

    Looking forward to some discussion on this topic.

    ReplyDelete
  2. I have done many things successfully in MatLab with this book. I have done a few plotting and GIS analyses of RAS output with R. I’m certain more can be done, but I haven’t dug into it substantially yet. I’m very interested in having some R packages for RAS developed.

    ReplyDelete
  3. This doesn't quite work yet. But perhaps others can help this along. Maybe we build a temp vbs script to run the plan?

    strRASProject = "C:\\Users\\m.modeler\\Documents\\HEC_RAS_EXAMPLES\\Example Projects\\1D Unsteady Flow Hydraulics\\Balde Eagle Creek\\BaldEagle.prj"
    comName<-"RAS503.HECRASController"

    pathofvbscript = paste0(getwd(),"\\runRAS.vbs")

    sink(pathofvbscript)
    cat("Dim HRC As New ",comName, "\n", sep="")
    cat("Dim strRASProject As String\n")
    cat('strRASProject = "',strRASProject,'"\n', sep="")
    cat("HRC.Project_Open strRASProject\n")
    cat("Dim lngMessages As Long\n")
    cat("Dim strMessages() As String\n")
    cat("HRC.Compute_CurrentPlan lngMessages, strMessages\n")
    cat("HRC.QuitRas")
    sink()

    shell(shQuote(normalizePath(pathofvbscript)), "cscript", flag = "//nologo")
    file.remove(pathofvbscript)

    ReplyDelete

Note: Only a member of this blog may post a comment.