Changes between Version 2 and Version 3 of RunEcosimViaConsoleApplication


Ignore:
Timestamp:
2011-03-07 19:49:01 (9 years ago)
Author:
jeroens
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RunEcosimViaConsoleApplication

    v2 v3  
    11= Run Ecosim via Console Application = 
    2  
    32This 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. 
    43 
    54This tutorial will extend the EweConsoleAppExample tutorial. 
    65 
    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{{{ 
    820  
    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 scenario 
    14         core.RunEcoSim(AddressOf EcosimResultsHandler) ' (7) Runs Ecosim with delegate 
    15  }}} 
    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 is  
    22     ' called at the end of every timestep. 
    23     ' One would obtain the results from the results object. 
    2421    Private Sub EcosimResultsHandler(ByVal iTime As Long, ByVal EcoSimResults As cEcoSimResults) 
    2522        System.Console.WriteLine("Time Step = " & iTime.ToString & _ 
    2623                                 "; Biomass of group 1 = " & EcoSimResults.Biomass(1).ToString & vbCrLf) 
    2724    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{{{ 
    3331  Time Step = 320; Biomass of group 1 = 0.993543 
    3432  Time Step = 321; Biomass of group 1 = 0.9935352 
     
    3735  Time Step = 324; Biomass of group 1 = 0.9935125 
    3836  Press a key to exit 
    39   }}} 
    40  
     37}}} 
    4138You 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.