|
<< Click to Display Table of Contents >> OPEN |
![]() ![]()
|
A databank stores variables, and the OPEN statement is used to handle such databanks, for instance by reading a Gekko .gbk databank file. Gekko organizes databanks in the following manner (in memory):
Number |
Searchable |
Non-searchable |
|
Local |
|
1. |
First |
Ref |
2. |
Another databank |
|
3. |
Another databank |
|
... |
... |
|
n'th |
Last databank |
|
|
Global |
|
More info on this databank list on the databank search page. The first-position databank can always be referred to by for instance first:x, and the Ref (reference) databank by ref:x. Try to hit the F2 button to see a window with the databank list (use [Escape] to close the window).
Per default, when issuing for instance a prt x;, Gekko searches databanks in the second column of the above list. Gekko will first look in the Local databank, then in the first-position databank (often called 'Work'), then in the second-position, third-position etc. databanks, and finally in the Global databank. The Local databank is used to store temporary variables, for instance variables used in functions and procedures, whereas the Global databank is used to store permanent variables that can survive a RESET or RESTART. The Local and Global databanks are created at Gekko startup, but they are not shown in the databank list (F2) if they are empty (cf. LOCAL and GLOBAL). With prt x;, Gekko will not search for x in the Ref databank, since this databank is used for comparisons.
The OPEN statement reads variables from a databank file into a databank with the same name as the file (minus the extension). A databank opened in this way is called a 'named' databank (in contrast to READ or IMPORT which operate on the first-position and/or Ref databanks). Named databanks may be written to if they are opened with open <edit>, and the databanks are closed with the CLOSE statement. When opening named databanks, a newly opened databank is always put last in the databank list.
To open a databank file as the first databank in the list of databanks (cf. the F2 window), you may use open <first> (or open <edit> if you want it in first position and editable). The first-position databank is the bank in which timeseries are found per default, and the Ref databank is often used for multiplier purposes (analyzing differences between two banks, for instance prt <m>, prt <q>, etc.).
Variables in named databanks can be explicitly referred to by means of colon (:), for instance b1:x if the opened databank is the file b1.gbk, containing the variable x.
The order in which normal OPEN databanks (that is, opened with normal OPEN, not for instance OPEN<edit> or OPEN<first>) are opened is only of importance if option databank search = yes is set (which is default). So regarding a bank-less variable x, it depends upon the databank search settings how x is searched for in the different open databanks (cf. the databank search page). The variable @x (same as ref:x) is always x taken from the Ref (reference) databank, and b1:x is always x taken from the in-memory databank b1.
In sim-mode, databanks are not searched (corresponding to option databank search = no).
Syntax
open < EDIT FIRST LAST POS=... REF SAVE=... CREATE format COLS DATEFORMAT=... DATETYPE=... TRACE=... > filename1 AS alias1, filename2 AS alias2, ... ;
EDIT |
(Optional). The databank is opened in first position, as editable. (See also OPEN<create>). If the databank is already open, the databank will be moved to first position as editable. |
FIRST |
(Optional). The databank is opened in first position, as non-editable (protected). If the databank is already open, the databank will be moved to first position. |
SEC |
(Optional). The databank is opened in second position, as non-editable (protected). Short-hand for open <pos=2>. |
LAST |
(Optional). The databank is opened in last position, as non-editable (protected). Note: open <last> bank1; is equivalent to open bank1;. If the databank is already open, an error will be issued. |
POS= |
(Optional). Indicate an integer value. The databank is opened in the n-th position, as non-editable (protected) |
SAVE |
(Optional). With open <save=no>, Gekko will not write the databank to file when it is closed, even if the databank contents has changed. In that way, you may change the contents of a databank in RAM only (that is, the data is changed while the databank is open and the session lasts), but without altering the underlying databank file (.gbk). See also close <save=no>. |
CREATE |
(Optional). If this option is set, Gekko will accept an open <create> b1, even if b1.gbk does not exist beforehand. Regarding a non-existing file, this is similar to open <edit>, the difference is that open <edit> puts the bank in first position, as editable. The reason why <create> is not the default way of opening a databank is to avoid errors if a user misspells a databank name. |
TRACE |
(Optional). Default is yes. Set no to omit reading of data-traces. The databank will load faster and use less RAM (if traces are present). Only relevant for Gekko databanks (.gbk files). |
format |
(Optional). Can be aremos, csv, flat, gbk, gcm, gdx, pcim, prn, px, sdf, tsd, tsp, xls/xlsx. The default file format is gbk. See IMPORT for non-gbk formats. |
filename |
Filenames may contain an absolute path like c:\projects\gekko\bank.gbk, or a relative path \gekko\bank.gbk. Filenames containing blanks and special characters should be put inside quotes. Regarding reading of files, files in libraries can be referred to with colon (for instance lib1:bank.gbk), and "zip paths" are allowed too (for instance c:\projects\data.zip\bank.gbk). See more on filenames here. If the filename is set to '*', you will be asked to choose the file in Windows Explorer. The extension .gbk is automatically added, if it is missing. |
COLS
|
(Optional). Only for .xlsx and .csv files: this indicates whether the timeseries are running downwards in columns. Note that for .csv files, you indicate this in the first 'cell' (date/name). |
DATEFORMAT= DATETYPE= |
(Optional). These options control the date format for .xlsx and .csv files, and for the use of SHEET in Gekcel. DATEFORMAT can be either 'gekko' (default, for instance 2020q3 or 2020m11) or a format string like 'yyyy-mm-dd', and the latter may contain a first or last indicator, for instance 'yyyy-mm-dd last', which indicates for quarterly, monthly or weekly data that the last day of the quarter/month/week is used. DATETYPE can be either 'text' or 'excel'. In the former case, the dates are understood as text strings (for instance '2020q3' or '2020-09-30' for a quarterly date), and in the latter case (not relevant for .csv files), the date is understood as an Excel date, which basically counts the days since January 1, 1900. This number would correspond to 44104 for the date 2020-09-31, and can be shown in Excel in different ways depending upon date format settings, language settings, etc., but the internal number itself is unambiguous. When using SHEET in Gekcel, using DATETYPE='excel' is advised for consistency. |
alias |
(Optional). The name that is used when referencing the databank. Default is the filename minus extension. |
Example
The following illustrates basic databank logic:
reset; prt bk2:x; //now it works |
The first PRT prints x as 100, whereas the second PRT prints x as 200. The third PRT fails because databank searching has been switched off, but the fourth PRT works because the databank name is indicated with colon (:). After running the example, there will be the files bk1.gbk and bk2.gbk in your working folder. Note: after each open <edit>, a CLEAR is used to clear up the databank if it already exists as a file and contains data.
Notes
When loading a databank file, extension .gbk is automatically added if it is missing. Global time settings does not affect the OPEN statement, so all the data in the .gbk file is read into the databank regardless of how the timeperiod is set in Gekko.
See the IMPORT statement for more information on databank formats.
You can use series ?; to see what kinds of series reside in all open databanks (including their frequencies).
Databanks are opened as 'protected' (non-editable) as default, unless you use open<edit> or unlock with UNLOCK (see LOCK/UNLOCK). To get an editable databank in the second position or below, OPEN it and use UNLOCK afterwards.
You may use the isopen() function to test if a particular databank is open.
See the Gekko menu 'Options' --> 'Program dependency tracking' or use option global dependency tracking = ...; to activate dependency tracking, so that the use of external files (for instance program files, read/written databanks etc.) are shown as a list at the end of a Gekko session.
Related options
option databank create auto = yes;
option databank file cache = all;
option databank file copylocal = yes;
option databank file gbk compress = yes;
option databank file gbk internal = databank.data;
option databank file gbk underscore = no;
option databank search = yes;
option databank trace = yes;
option databank trace divide = no;
option databank trace dublets = no;
option folder bank = '';
option folder bank1 = '';
option folder bank2 = '';
bankname(), fromBank(), isOpen()
Related statements
CLEAR, CLONE, CLOSE, CLOSEALL, DELETE, EXPORT, IMPORT, LOCK, READ, RESET, RESTART, UNLOCK, WRITE