Version 2 (modified by jeroens, 13 years ago) (diff)


Run Ecosim via Console Application

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.

This tutorial will extend the EweConsoleAppExample tutorial.

  1. Follow EweConsoleAppExample and ensure it runs.

  1. 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).

       core.LoadEcosimScenario(1)                  ' (6) Loads an ecosim scenario
       core.RunEcoSim(AddressOf EcosimResultsHandler) ' (7) Runs Ecosim with delegate

  1. 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.

   ' Ecosim delegate - a sub function/subroutine that is 
   ' called at the end of every timestep.
   ' One would obtain the results from the results object.
   Private Sub EcosimResultsHandler(ByVal iTime As Long, ByVal EcoSimResults As cEcoSimResults)
       System.Console.WriteLine("Time Step = " & iTime.ToString & _
                                "; Biomass of group 1 = " & EcoSimResults.Biomass(1).ToString & vbCrLf)
   End Sub

  1. Hit F5 or in the menu, Debug>Start Debugging. You should get the following output.

Time Step = 320; Biomass of group 1 = 0.993543
Time Step = 321; Biomass of group 1 = 0.9935352
Time Step = 322; Biomass of group 1 = 0.9935276
Time Step = 323; Biomass of group 1 = 0.99352
Time Step = 324; Biomass of group 1 = 0.9935125
Press a key to exit

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.