Changes between Version 2 and Version 3 of RunEcosimViaConsoleApplication
- Timestamp:
- 2011-03-07 19:49:01 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
RunEcosimViaConsoleApplication
v2 v3 1 1 = Run Ecosim via Console Application = 2 3 2 This tutorial will guide you through how to make an console application that would run Ecosim and Ecospace. You can extend these to make applications such as monte carlos routines, or create/modify multiple databases. 4 3 5 4 This tutorial will extend the EweConsoleAppExample tutorial. 6 5 7 1. Follow EweConsoleAppExample and ensure it runs. 6 1. Load the EweConsoleAppExample project and ensure it runs. 7 8 2. Before the line where the model is closed, insert the following code to load and run the first available Ecosim Scenario: 9 10 {{{ 11 12 core.LoadEcosimScenario(1) 13 core.RunEcoSim(AddressOf EcosimResultsHandler) 14 15 16 }}} 17 3. You have just told Ecosim to run, calling to a subroutine !EcosimResultsHandler for every time step. This subroutine does not exist yet, and you will need to create it for Ecosim to be able to execute. Add the following subroutine to the module EwE7:[[BR]][[BR]] 18 19 {{{ 8 20 9 2. After step (5) (Line 21 = 'Console.!WriteLine...'), add the following code to Load an Ecosim Scenario and run Ecosim with a delegate (name of a function that should be called at the end of every timestep).10 11 {{{12 13 core.LoadEcosimScenario(1) ' (6) Loads an ecosim scenario14 core.RunEcoSim(AddressOf EcosimResultsHandler) ' (7) Runs Ecosim with delegate15 }}}16 17 3. Add the following code after the sub routine {{{ End Sub }}} which is the function that you defined in step (7). The following sub routine will print the biomass of group 1 at every timestep.18 19 {{{20 21 ' Ecosim delegate - a sub function/subroutine that is22 ' called at the end of every timestep.23 ' One would obtain the results from the results object.24 21 Private Sub EcosimResultsHandler(ByVal iTime As Long, ByVal EcoSimResults As cEcoSimResults) 25 22 System.Console.WriteLine("Time Step = " & iTime.ToString & _ 26 23 "; Biomass of group 1 = " & EcoSimResults.Biomass(1).ToString & vbCrLf) 27 24 End Sub 28 }}} 29 30 4. Hit F5 or in the menu, Debug>Start Debugging. You should get the following output. 31 32 {{{ 25 26 27 }}} 28 4. Hit F5 or in the menu, Debug>Start Debugging. You should get the following output. 29 30 {{{ 33 31 Time Step = 320; Biomass of group 1 = 0.993543 34 32 Time Step = 321; Biomass of group 1 = 0.9935352 … … 37 35 Time Step = 324; Biomass of group 1 = 0.9935125 38 36 Press a key to exit 39 }}} 40 37 }}} 41 38 You can run the code by loading the EweConsoleAppExample tutorial, and overwrite its file EwE7.vb with the code file found at the bottom of this page.