Welcome to the RAS Solution › Forums › HECRAS Controller › Closing HEC-RAS after every run
- This topic has 12 replies, 1,382 voices, and was last updated 7 years, 9 months ago by Anonymous.
-
AuthorPosts
-
February 24, 2017 at 12:06 am #8189AnonymousGuest
I’m trying to do a sensitivity analysis for HEC-RAS and have developed a code to run the model multiple times from MATLAB by varying geometry parameters. When i do this by calling the controller for HEC-RAS 4.1, the computation window opens and closes after every run. However, when i do the same using HEC-RAS 5.01, the computational window does not close by itself after every run, leading to an out of memory error. what is the right command to close hecras after every run from MATLAB?
February 24, 2017 at 8:41 pm #13520Chris G.KeymasterIn version 5 and later, you need to include the QuitRAS subroutine at the end of your procedure. See example below…
Sub QuitRAS()
‘**********************************************************
‘Demonstrates the QuitRAS subroutine.‘Written by Christopher Goodell
‘May 7, 2013‘Closes HEC-RAS. _
Every procedure that instantiates an HECRASController _
class must conclude with a call to the QuitRAS _
subroutine.‘Tested with the BEAVCREK.prj data set. Can be _
used with any HEC-RAS data set.
‘**********************************************************‘Open a new HEC-RAS Project
Dim RC As New RAS503.HECRASController
mSamples.OpenRASProjectByRef RC‘Show HEC-RAS
RC.ShowRAS‘Message the user to click to close HEC-RAS
MsgBox “Click OK to close HEC-RAS.”‘Close HEC-RAS
RC.QuitRAS ‘This is what you have to add to close HEC-RAS in Version 5 or later.End Sub
Sub OpenRASProjectByRef(ByRef RC As RAS503.HECRASController)
‘**********************************************************
‘Demonstrates Project_Open subroutine and how to pass the _
HECRASController as a reference.‘Written by Christopher Goodell
‘July 3, 2012‘Opens a RAS project by being called from another _
subroutine
‘**********************************************************‘Open the HEC-RAS Project
Dim strFilename As String
Sheets(“RASProjects”).Select
strFilename = Range(“C4”).Value
RC.Project_Open strFilenameEnd Sub
February 24, 2017 at 9:21 pm #13521AnonymousGuestThank you for this information Chris.
February 25, 2017 at 3:45 am #13522AnonymousGuestIn continuation with the previous doubt, when i run the unsteady model within a loop, the lines after the “h.Compute_CurrentPlan(0,0)” in the matlab script start executing before the HEC-RAS model is run. I tried different commands like “waitfor” to delay to pause the execution of the subsequent lines but with no success.
Could you tell me what mistake I’m making here? Thanks in advance.
Regards,
BharathFebruary 27, 2017 at 11:26 pm #13523Chris G.KeymasterBharath-
There are three arguments to include with the Compute_CurrentPlan Function.
1. nmsg (long). the number of returned messages
2. msg() (string). messages returned from the HECRASController during computations.
3. BlockingMode (boolean). True or False. If blocking mode is set to false, then code will continue to be readh while HEC-RAS is computing. So you want this to be set to True. You omitted the BlockingMode argument from your Compute_CurrentPlan call, so by default it is set to false. Your call should look more like this (in VBA syntax):‘Compute the current plan.
Dim lngMessages As Long
Dim strMessages() As String
Dim blnDidItCompute As Boolean
blnDidItCompute = RC.Compute_CurrentPlan(lngMessages, strMessages(), True)With the 3rd argument set to “True”, the code will pause while HEC-RAS is computing.
March 1, 2017 at 7:57 pm #13524SALAKAParticipantHi Chris,
first thanks for your work here.
Currently I’m trying to solve a problem when controlling HEC-RAS from Matlab. I’m writing
to this thread as it seems to be a very similar problem.Basically I can’t get the blocking mode working, so HEC-RAS gets closed before finishing
the computation.Currently the Code launches the computation with this line:
h.Compute_CurrentPlan(0,0);
To enable the blocking mode I tried several combination of arguments, but always get the error:
No method ‘Compute_CurrentPlan’ with matching signature found for class ‘COM.RAS503_HECRASCONTROLLER’.
What are the right arguments for Compute_CurrentPlan to enable the blocking mode?Thanks for your help, regards
SaskiaMarch 1, 2017 at 8:13 pm #13525Chris G.KeymasterAs mentioned above, the arguments are:
‘Compute the current plan.
Dim lngMessages As Long
Dim strMessages() As String
Dim blnDidItCompute As BooleanblnDidItCompute = RC.Compute_CurrentPlan(lngMessages, strMessages(), True)
With the 3rd argument set to “True”, the code will pause while HEC-RAS is computing.
Let me know if this works. I’ll check around to see if there is a MatLab compatibility issue with this command.
March 1, 2017 at 8:48 pm #13526SALAKAParticipantHi Chris,
I now tried it using Excel with VBA, and there your code works perfectly.
When using matlab I can’t get this to work. As explained before I always
get an error that the method ‘Compute_CurrentPlan’ doesn’t work with the
passed arguments.But for now that’s no problem for me, as it’s working with VBA. Thank you!
SaskiaMarch 1, 2017 at 8:59 pm #13527Chris G.KeymasterThis from Arturo Leon: “The error says: No method ‘Compute_CurrentPlan’ with matching signature found for class ‘COM.RAS503_HECRASCONTROLLER’. It appears that the Matlab class was not defined. In our paper I defined the class as “h”, so to perform any operation the “h. XXXXXX” needs to be used, including defining each instance of HEC-RAS. For using HEC-RAS in parallel computing or to do multiple computations in series, h is replaced by a vector h(i) where “i” is the ID of the simulation (e.g., 1 to 100). For instance, to open a single instance of HEC-RAS 5.0, h=actxserver(‘RAS500.HECRASCONTROLLER’) is used in the paper. I would suggest the student to check our paper available at: http://www2.egr.uh.edu/~aleon3/papers_PDF/Journal/HEC_RAS_Controller.pdf”
March 1, 2017 at 9:52 pm #13528BharathParticipantHi Chris,
Thanks for providing me with this information. I tried this technique, but it looks like I’m stuck with a problem that seems trivial, but I’m missing it.
Could you explain to me what ‘h.Compute_CurrentPlan(0,0)’ means exactly? both zeros are integers whereas the syntax for this shows
‘Compute_CurrentPlan(handle, int32, SafeArray Pointer(string))’.Trying to introduce a third Boolean term within the bracket results in the following error.
Error using
COM.RAS501_HECRASCONTROLLER/Compute_CurrentPlan
Invoke Error, Dispatch Exception: Exception
occurred.or
No method ‘Compute_CurrentPlan’ with
matching signature found for class
‘COM.RAS501_HECRASCONTROLLER’.I guess it is due to my incomplete understanding of the term “SafeArray Pointer” and how this particular command works.
Any help would be much appreciated as I’m heading towards a deadline and I’m stuck here.
Warm regards,
BharathMarch 2, 2017 at 1:14 am #13529Chris G.KeymasterI don’t know MatLab well enough to say what the problem is.
March 2, 2017 at 8:07 pm #13530BharathParticipantThank you Chris. I’ll try and build on your suggestion and see if I can find a solution.
September 11, 2017 at 9:09 pm #13531MarceroliParticipantI’m using QuitRas for closing HECRAS into a “for”. It works perfectly but every iteration it ask me if I want to save the project before leave HEC-Ras and I don’t want to click YES hundred of times. Is there any way to skip that message when I use the QuitRas subroutine?
-
AuthorPosts
- You must be logged in to reply to this topic.