Dinamica EGO script language and command line tool

What will you learn?

As a model becomes more and more complex, you may find useful to save it in EGO format to keep developing the model using EGO programming language on a text editor, (e.g. NotePad++ or Context). For example, the Amazon logging model (Merry et al, 2009) developed in Dinamica EGO involves more than one thousand script lines. Both script formats (EGOML/XML, EGO) are 100% compatible, so users can move a model freely between the graphical interface and a text editor. Note that reopening a saved script in the graphical interface and saving it again may reformat some inputs and outputs according to the current script generation options — the resulting model is semantically equivalent, but may not be byte-for-byte identical to the original. Advanced modelers will greatly benefit from this well structured and tractable programming language.

Open again the model “simulate_deforestation_from_1997_2000_30years_ahead.xml”. To make the model more intelligible on the text editor, you first need to name some key functors with aliases and then add comments to parts of the model. Let's do this. Select the Edit Functor tool and click on the Categorical Map “23267_1997.ers”.

Write in the alias field “initial_landscape”, click on Calc Distance Map and write the alias “distance_to_deforested”. Now save the model in EGO format.

Open in a text editor, the model “simulate_deforestation_from_1997_2000_30years_ahead.ego”. The EGO script is as follows:

Now that you have learned a bit about programming with EGO script language, another resource available in Dinamica EGO is the Command Line Tool. Any model saved in Dinamica EGO, either EGOML/XML or EGO, can be run from the command prompt. Running the model from the command prompt might increase model performance, as the model becomes free of the burden of the graphical interface.

To run Dinamica EGO from the command line, run DinamicaConsole from a command prompt. The executable is located in the Dinamica EGO installation folder. On Windows, the executable name includes the major version number: DinamicaConsole7, DinamicaConsole8, etc. On Linux, the executable is simply DinamicaConsole. For the full list of parameters accepted by the Command Line Tool, see Dinamica Console.

TIP: another way to loosely couple other computer programs with Dinamica EGO is by means of functor Run External Process, available in the Control Tab. By using this functor, you will be able to make a call to an external program from within Dinamica, pass to this program intermediate results and feed its output back again into the Dinamica EGO model.

Next Session