load, loadf, loadk, loadm, loadp, loads#

Purpose#

Loads from a disk file.

Format#

load [[path=path]]x, y[ ]=filename, z = filename;

Remarks#

All the loadxx commands use the same syntax, they only differ in the types of symbols you use them for:

Format, Format

matrix

Format

string

Format

function (fn)

Format

keyword (keyword)

Format

procedure (proc)

If no filename is given, as with x above, then the symbol name the file is to be loaded into is used as the filename, and the proper extension is added.

If more than one item is to be loaded in a single statement, the names should be separated by commas.

The filename can be either a literal or a string. If the filename is in a string variable, then the ^ (caret) operator must precede the name of the string, as in:

filestr = "mydata/char";
loadm x = ^filestr;

If no extension is supplied, the proper extension for each type of file will be used automatically as follows:

Format

.fmt - matrix file or delimited ASCII file

Format

.fmt - matrix file or delimited ASCII file

Format

.fst - string file

Format

.fcg - user-defined function (fn) file

Format

.fcg - user-defined keyword (keyword) file

Format

.fcg - user-defined procedure (proc) file

These commands also signal to the compiler what type of object the symbol is so that later references to it will be compiled correctly.

A dummy definition must exist in the program for each symbol that is loaded in using Format, Format, or Format. This resolves the need to have the symbol initialized at compile time. When the load executes, the dummy definition will be replaced with the saved definition:

proc corrmat;
endp;

loadp corrmat;
y = corrmat;

keyword regress(x); endp;
loadk regress;
regress x on y z t from data01;

fn sqrd=;
loadf sqrd;
y = sqrd(4.5);

To load GAUSS files created with the save command, no brackets are used with the symbol name.

If you use save to save a scalar error code 65535 (i.e., error(65535)), it will be interpreted as an empty matrix when you load it again.

ASCII data files#

Note

This function is a deprecated function. Consider using csvReadM() instead.

To load ASCII data files, square brackets follow the name of the symbol.

Numbers in ASCII files must be delimited with spaces, commas, tabs, or newlines. If the size of the matrix to be loaded is not explicitly given, as in:

load x[] = data.asc;

GAUSS will load as many elements as possible from the file and create an Nx1 matrix. This is the preferred method of loading ASCII data from a file, especially when you want to verify if the load was successful. Your program can then see how many elements were actually loaded by testing the matrix with the rows command, and if that is correct, the Nx1 matrix can be reshape’d to the desired form. You could, for instance, put the number of rows and columns of the matrix right in the file as the first and second elements and reshape the remainder of the vector to the desired form using those values.

If the size of the matrix is explicitly given in the Format command, then no checking will be done. If you use:

load x[500,6] = data.asc;

GAUSS will still load as many elements as possible from the file into an Nx1 matrix and then automatically reshape it using the dimensions given.

If you Format data from a file, data.asc, which contains nine numbers (1 2 3 4 5 6 7 8 9), then the resulting matrix will be as follows:

load x[1,9] = data.asc;
x = 1 2 3 4 5 6 7 8 9
load x[3,3] = data.asc;
    1 2 3
x = 4 5 6
    7 8 9
load x[2,2] = data.asc;
x = 1 2
    3 4
load x[2,9] = data.asc;
x = 1 2 3 4 5 6 7 8 9
    1 2 3 4 5 6 7 8 9
load x[3,5] = data.asc;
    1 2 3 4 5
x = 6 7 8 9 1
    2 3 4 5 6

Load and save paths#

Format accepts pathnames. The following is legal:

loadm k = /gauss/x;

This will load /gauss/x.fmt into k.

If the path= subcommand is used with Format and save, the path string will be remembered until changed in a subsequent command. This path will be used whenever none is specified. There are four separate paths for:

#. Format, Format #. Format, Format #. Format #. save

Setting any of the four paths will not affect the others. The current path settings can be obtained (and changed) with the sysstate() function, cases 4-7.

loadm path = /data;

This will change the Format path without loading anything.

load path = /gauss x,y,z;

This will load x.fmt, y.fmt, and z.fmt using /gauss as a path. This path will be used for the next Format if none is specified.

The Format path or save path can be overridden in any particular Format or save by putting an explicit path on the filename given to Format from or save to as follows:

loadm path = /miscdata;
loadm x = /data/mydata1, y, z = hisdata;

In the above program:

/data/mydata1.fmt would be loaded into a matrix called x.

/miscdata/y.fmt would be loaded into a matrix called y.

/miscdata/hisdata.fmt would be loaded into a matrix called z.

oldmpath = sysstate(5,"/data");
load x, y;
call sysstate(5,oldmpath);

This will get the old Format path, set it to /data, load x.fmt and y.fmt, and reset the Format path to its original setting.

See also

Functions loadd(), dataload(), save, let, con(), cons(), sysstate()