OPEN

<< Click to Display Table of Contents >>

Navigation:  Gekko User Manual > Gekko statements >

OPEN

Previous pageReturn to chapter overviewNext page

The OPEN statement opens databanks. In general, there are (potentially) the following databanks in Gekko:

 

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 reference databank by ref:x.

 

In sim-mode, the order in the above list is not significant, since all banks that are not the first-position or local/global databank must be referred to by either bankname (like b2:x) or operators (like prt<m>x;, to print the difference between first:x and ref:x). In other modes, for instance data-mode, Gekko will search for variables in the databanks shown in the 'Searchable' column. Note here that the Ref databank is never searchable, since the purpose of the Ref databank is to ease different kinds of comparisons.

 

When looking for a variable x in a statement (for instance prt x; or at the right-hand side of an expression (for instance = x;), Gekko will look first in the Local databank (if it contains variables), 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. These databanks are created at Gekko startup, but they are not shown in the databank list (F2) if they are empty. The same goes for the Ref databank, which is not shown in the F2 list if empty. Therefore, when Gekko starts up in a clean state, only the first-position databank (default: Work) is shown in the F2 list.

 

The OPEN statement reads timeseries from a databank file into a databank with the same name as the file (minus the extension). A databank opened in the way is called a 'named' databank (in contrast to READ which operates on the first-position and/or reference databanks). Named databanks may be written to if they are opened with OPEN<edit>, and the databanks are closed with the CLOSE statement.

 

NOTE: Gekko opens up databanks in the last position in the databank list. This behavior deviates from AREMOS and is only relevant for data- or mixed-mode users.

 

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 reference databanks is often used for multiplier purposes (analyzing differences between two banks, for instance via MULPRT, PLOT<m>, etc.).

 

Variables in named (OPEN) databanks are referred to by means of colon (:), for instance adam:x if the opened databank is the file adam.gbk, containing the variable x. Note that you can get the list of available in-memory databanks by means of the F2 key.

 

The order in which normal OPEN databanks (that is, opened with OPEN, not for instance OPEN<edit>, OPEN<first> or OPEN<ref>) are opened is only of importance if option databank search = yes is set (it is set to no as default in sim-mode, but set to yes as default in data-mode). So regarding a bank-less variable like 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 reference databank, and adam:x is always x taken from the in-memory databank adam.

 

With option databank search = yes, which is default, Gekko will search for a bank-less variable x first in the Local databank, then all numbered databanks in the F2 window (bank number 1, 2, and so on), and finally in the Global databank.

 

 


 

Syntax

 

open < EDIT  FIRST  LAST  POS=...  REF  SAVE=...  CREATE format  COLS DATEFORMAT=...  DATETYPE=... TRACE=... > filename1  AS  alias1, filename2  AS  alias2, ... ;

 

EDIT

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

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.

LAST

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

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

If this option is set, Gekko will accept an open <createb1, 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 tsd, gbk, pcim, csv, prn, xls, xlsx. The default file format is gbk.

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. [New in 3.0.5].

alias

(Optional). The name that is used when referencing the databank. Default is the filename minus extension.

 

 

 


 

Example

 

Opening a .gbk file called bk1 is done with

 

open bk1;

 

or by

 

open *;

 

and then selecting the databank. Afterwards, you may reference variables in the databank by means of for instance:

 

prt fy, @fy, bk1:fy;

 

This will print out the fy variable from the first-position, reference, and bk1 databanks. You may use an AS alias to shorten the databank name:

 

open bk1 as b;
prt fy, @fy, b:fy;

 

Try pressing F2 to open up the databanks window. This window provides an overview regarding the different open databanks (including Work and Ref).

 

If you open up two databanks like this:

 

open bank1;
open bank2;

 

bank1 will show up above bank2 in the databank list, because the OPEN statement puts databank in the last position on the list. The following yields the same:

 

open bank1, bank2;

 

You may use open<first>, open<pos=n>, open<last> to open a databank in a specific position on the databank list (F2). The statement open<edit>mybank; is the same as open<first>mybank; unlock mybank; -- and in that case, a subsequent xx1 = 100; will put the series xx1 into mybank:

 

open <edit> mybank;
xx1 = 100;
close mybank;

 

After the CLOSE statement, the altered databank is automatically written to file, so mybank.gbk will contain the xx1 series.

 

 

 


 

Note

 

To get an editable databank in the second position or below, OPEN it and use UNLOCK afterwards.

 

When reading, 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).

 

Banks are opened as 'protected' (non-editable) as default, unless you use open<edit> or unlock with UNLOCK (see LOCK/UNLOCK).

 

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 file copylocal = yes; [yes|no]

OPTION databank search = no; [yes|no]

OPTION folder bank = [empty];

OPTION folder bank1 = [empty];

OPTION folder bank2 = [empty];

 

 

 


 

Related statements

 

READ, WRITE, CLONE, LOCK, UNLOCK, CLEAR, CLOSE, CLOSEALL, DELETE