|
<< Click to Display Table of Contents >> Gekko programs |
![]() ![]()
|
When using Gekko in daily work, you will usually use Gekko program files, if you have a program that takes up more than a few statements, and the statement sequence will be run several times. A Gekko program file is an alternative to typing each statement interactively in the Gekko main window. An additional advantage of using Gekko programs i reproducibility and documentation. A Gekko program is characterized by two properties:
•It contains only Gekko statements.
•It is a system file with file extension .gcm.
To run a Gekko program file with the name data.gcm, type:
run data; //Gekko will add extension .gcm |
All the statements in the file will then be executed as if they were issued interactively from the statement window.
Below is an example of a Gekko program as it will look in Notepad (read more about editors: +toggle).
An editor like Window's in-built Notepad text editor can be used for Gekko programs, but this editor is not particularly advanced. It is advised to use a more capable text edit, because you may need to operate on blocks of code, search and replace in a more advanced fashion, etc. Additionally, but not least, more advanced editors allow code coloring (highlighting). This is the same kind of coloring seen in the above box illustrating the RUN statement: note that the semicolon is blue, and the comments are green. A particular handy possibility is the possibility to feed the editor with a list of Gekko statement names, so that these get their own color.
With a more advanced text editor, such coloring is possible, coloring for instance all the special symbols in one particular color, numbers in another color, text strings in a third color, etc. Some editors can even color different levels of nested parentheses in different colors.
•It is recommended to use VS Code for Gekko programs, because it is a free and very versatile editor, and because it contains in-built Gekko code coloring. Under 'Extensions', just search for 'Gekko', and it should show 'Gekko. Language support for Gekko Timeseries and Modeling Software'. •Alternatively, there is Sublime Text, for which there is a free open-source Gekko module available that handles text coloring. Sublime Text is free for evaluation purposes. •The possibilities regarding text editors are practically infinite, it basically comes down to personal preference.
|
// ----- file start ----- |
The above file first loads the historical databank hist1115.gbk. Next, the number of unemployed (ul) for the current period is calculated and printed.
It is advised to include comments in Gekko programs. This increases readability both for the user him/herself, but especially for other users who need to understand the contents of the file. Comments can be included in the file with either:
•// some text
•/* some text */
The former (// ...) only out-comments the rest of the current line, wheras the latter (/* ... */) can span several lines and is therefore practical for multi-line commentaries, or for out-commenting larger blocks of code (read about other ways of skipping code: +toggle).
You may out-comment code like this:
In that case, only x1 and x4 are calculated (// could have been used as well, on the two lines). An alternative is this:
Here, activating the two lines is a bit easier, just change into for instance if(1 == 1);. Or use a 'control' variable, like if(%cond == 1);, where the code is run only if the settings variable %cond is set to 1.
To stop execution of Gekko at a particular location, it is advised to insert a STOP statement, for instance
Now only the first line of the Gekko program file is run, after which Gekko stops, and the user can inspect variables or try to sort out bugs. Gekko cannot resume after a stop, but you may move the STOP statement and run the file again.
|
Besides gcm program files, Gekko also recognizes files named gekko.ini (henceforeward called the 'ini file'). The file usually contains a number of custom options that the user wants Gekko to set at startup. The options can, for example, set the folder structure for which Gekko should look for model files, bank files, and Gekko programs, along with other more general settings like setting the global time period, frequency, etc. The ini file is run automatically, if Gekko is started from a folder in which such a file exists (otherwise, the INI statement can execute the ini file on demand, and the RESTART statement resets Gekko and subsequenctly runs the ini file). An example of the contents of an ini file could be:
option folder bank = C:\Datop\bank\; |
The first two lines define the folders in which Gekko searches for data banks (option folder bank) or Gekko program files (option folder command). When bank and Gekko programs paths are defined as above, in subsequent statements it is not necessary to use full path indication if you open up a data bank or run a Gekko program. The third statement loads date variables from an external period.gcm file. Finally, a databank is read, and the global time is set.
It is a good idea to start your Gekko program with the following:
restart; |
which closes all data banks, clears everything (including options, etc.), and re-runs gekko.ini. A RESTART is essentially equivalent to closing the Gekko main window, and starting Gekko up again. Related to RESTART is the RESET statement, which also closes all data banks but omits to run any ini file.
reset; |
With RESET, a gekko.ini file is not searched for and run. There is the following equivalence: restart = reset; ini;. Since both RESTART and INI do not abort with an error if no ini file is found, if you need to be absolutely certain that a gekko.ini file is found and run (and no-one accidentally deleted the file), instead of restart; at the top of your Gekko program, you can use reset; run gekko.ini;. In that way, if the ini file is not found, Gekko will stop with an error.
If you need to clear the output window, you can use CLS (clear screen):
cls; |
Neither RESET nor RESTART clears the output window, so cls; RESTART; is often seen in combination.
Read more about Gekko programs in the sub-sections.