go to Trig home page   Guide to GAUSS Programming - a basic introduction


 
Input and output

GAUSS handles data on disk in a number of formats. It can read and create standard text files and older spreadsheet formats, as well as using its own format to store matrices, datasets or code samples.

In this section we shall also be covering briefly GAUSS's graphing capability.

1 Storing matrices (.fmt files)

GAUSS stores matrices in files with a .fmt extension. This is the default option - if no extension is given to file names, GAUSS will assume it is reading or writing a matrix file.

The commands for matrix files are

LOAD varName = fileName;
LOADM varName = fileName;
SAVE fileName = varName;

LOAD and LOADM are synonyms. The reason for using the latter is that there are other similar commands (LOADP, LOADS, LOADF, LOADK) which load different types of object (see LOAD in the manual). LOADM tells GAUSS that a matrix is being loaded, and so it will check other references accessing that variable to ensure that only legal operations are being carried out.

varName is the name of the variable in memory to be saved or loaded.; fileName is the name of the matrix file with no .fmt extension. For example,

SAVE "file1" = mat1;
LOADM mat2 = "file1";

creates a file on disk called file1.fmt which contains the matrix mat1. This is then read into a new matrix, mat2.

If the disk file has the same name as the variable, then fileName can be omitted:

LOADM eric;
SAVE lucy;

will load the matrix eric from the file eric.fmt, and then save the matrix lucy to a file called lucy.fmt.

An alternative is to have the name of the file in a string variable. To tell GAUSS that the name is contained in the string, the caret (^) operator has to be used. GAUSS then looks at the current value of the variable to see which name to use, instead of taking the variable name as a constant value. For example,

fileName = "file1";
LOADM mat1 = ^fileName;
fileName = "file2";
SAVE ^fileName = mat1;

This piece of code reads a matrix from file1.fmt and then saves it to file2.fmt. If the caret was left out, then GAUSS would be looking for files called "fileName". This indirect referencing is the more usual way of using file names: it allows for the program to prompt for names, rather than having them explicitly coded into the program. This is useful when the program does not know what files are to be used - for example, if a program is to be run on several sets of data.

You can also save GAUSS procedures, strings et cetera in the same manner, using variations on the LOAD command. See the Command Reference for details.

2 Datasets (.dat files)


GAUSS datasets are created by writing data from GAUSS or by taking an ASCII file and converting through a stand-alone program called ATOG.EXE (Ascii TO Gauss). As with the datasets for other econometric packages, they consist of rows of data split into fields. GAUSS will automatically add .dat to the filenames you give, and so there is no need to include the extension.

In older versions of GAUSS the actual dataset is held in a .dat (data) file, while a .dht (header) file contains the names of each of these fields, along with some other information about the data file. A program, Transdat, converts between data formats, as well as between different operating systems.

For information on ATOG, see the GAUSS User Guide (not the Command Reference).

Unlike the GAUSS matrices, reading from or writing to a GAUSS dataset is not a single, simple operation. For matrices, the whole object is being moved into memory or onto disk. By contrast, a GAUSS dataset is used in a number of stages. Firstly, the file must be opened; then it may be read from or written to, which may involve the whole file or just a few lines; finally, when references to the file are finished, it should be closed.

All files used will be given a handle by GAUSS; this is a scalar which is GAUSS's internal reference for that file. It will be needed for all operations on that file, and so should not be altered. The handle is needed because several files can be 'open' at one time (for example, reading from one, writing to another); precisely how many depends on the computer's configuration. Without the file handle, a dataset cannot be accessed, and if the file handle is overwritten then the wrong file may be used. So be careful with your handles.

2.1 Creating new datasets

A file must exist before it can be opened. To start a new dataset for writing, it must be created. This is done by

CREATE handle = fileName WITH colNames, columns, type;

handle is the handle GAUSS will return if it is successful in creating fileName. This fileName may be a constant like "file1", or it may be a string, referenced using the ^ operator (as for LOAD and SAVE). colNames is the list of names for the columns (usually a character vector) ; columns tells GAUSS how many columns of data there are (which is not necessarily the same as the number of names - it may be sensible to have some "spare" columns); and type is the storage precision of the data - integers, single precision, or double precision. For example,

fileName = "file1";
varNames = "Name" "age" "sex" "wage";
CREATE handle1 = ^fileName WITH ^varNames, 4, 4;

prepares a datafile called file1.dat for writing. A header file file1.dht will also be created, which records that the datafile should contain four columns, named "Name", "age", "sex" and "wage", and in single precision (type=4, the default).

CREATE is not needed very often - only when writing a brand new dataset. More usually datasets are ATOG conversions from ASCII files. Alternatively, matrices may be converted into datasets using the command

success = SAVED (variable, fileName, colNames);

where variable is the matrix to be saved, fileName and colNames are above, and success is a scalar variable set to true if the operation worked.

2.2 Opening datasets

A dataset must be opened for either reading or writing or "updating" (both). Once a dataset has been opened for one "mode" it cannot be switched to another. The command is

OPEN handle = fileName FOR mode VARINDXI offset

handle is a non-negative scalar, the file handle returned to you if the operation is successful (if the command did not work, the handle is set to -1). The file handle should always be set to zero before this command, to avoid the possibility of GAUSS trying to open a file already open. fileName is as above.

The mode is one of READ, APPEND, or UPDATE. If the mode is omitted, GAUSS defaults to READ. If READ is chosen, updating the file is not allowed. Choosing APPEND means that data can only be appended to the file; the existing contents cannot be read. UPDATE allows reading and writing.

When GAUSS opens the file with VARINDXI, it reads the names of fields (columns) and prefixes them all with "i" (for index). These can then be used to reference the columns of the dataset symbolically instead of using column numbers explicitly. This makes programs more readable, more easily adapted, and less likely to be upset by changes in the structure of the dataset.

Warning: this did not work in GAUSS 4.0 but was corrected by version 4.18.

In the above example, the four columns in the dataset created could be referred to as 1 to 4 or, equivalently but much more usefully, as iname, iage, isex, iwage. Using these index variables without VARINDXI causes some problems for GAUSS when it is checking a program prior to running it, so although VARINDXI is optional it should generally be included.

The offset scalar option shifts all these indexes by a scalar and so is useful if the data is to be concatenated horizontally to another matrix or dataset. However, usually it can be left out.

When a file is CREATEd, it is automatically opened in APPEND mode (obviously; there is nothing to be read as yet). However, creating new datasets is much rarer than accessing a preexisting dataset, and so OPEN is more common than CREATE.

As an example, to open the file created in the previous sub-section for reading, the command would be

OPEN handle1 = "file1" FOR READ VARINDXI;

which would give a file handle in handle1, and four scalar indexes: iname, iage, isex, and iwage, set to 1, 2, 3, and 4 respectively.

2.3 Reading, writing, and moving about

Econometric packages tend to treat datasets as single entity, albeit with elements that can be altered. For example, the TSP commands LOAD and SAVE are much more akin to the GAUSS matrix file loading and saving (there are GAUSS commands LOADD and SAVED which perform similar operations, but these are not covered here).

By contrast, a GAUSS dataset is explicitly composed of rows of data, and these rows are the basic unit of manipulation. One or more rows is read at a time; data is parcelled up into rows before being written. GAUSS maintains a file pointer which maintains the current position (ie row number) in the file. Generally, as rows are read from or written to the file, the row pointer is moved on. If the row pointer currently points to the start of the file and ten rows are read, the row pointer now indicates that row eleven is the current row.

Reading and writing thus moves sequentially through the file. To move around the file, or to find out where the file pointer currently is, use

currPos = SEEKR (handle, rowNum);

handle is the handle returned by OPEN or CREATE. rowNum is the row number to which the file pointer is to be moved; if it is set to -1, then SEEKR will not move the file position. This is useful because, whatever the value of rowNum, currPos is now a scalar holding the current row number. Thus setting rowNum to -1 can be used to determine the current position. So, to move, for example, five rows back in the file requires finding out the current row number and then resetting the file pointer:

currPos = SEEKR (handle, -1);
currPos = SEEKR (handle, currPos-5);

After this operation, currPos should show that the file pointer has been moved back five rows.

Trying to move before the start or after the end of a file will cause the program to crash: GAUSS will not be able to trap this error. The function ROWSF giving the number of rows in a file can be used to avoid this error).

To read data, the command is

dataMat = READR (handle, numLines);

which reads numLines rows from the file referenced by handle into the data matrix dataMat. After the read, the file pointer will have been moved on to point to the first row after the block just read. Rows and columns in the dataset become rows and columns in the matrix. So, in our above example,

dataMat1 = READR (handle, 10);

reads ten lines from the dataset and creates a 10x4 matrix called dataMat1 which can be accessed like any other variable; the file pointer has been moved on ten rows.

GAUSS will not check for end-of-file; this has to be done by the user. Attempting to read past the end of the file will cause the program to crash. This can be avoided by using a standard procedure called EOF:

atEof = EOF(handle);

which sets atEof to true if the file pointer is at the end of file handle and false otherwise.

Writing data is just the reverse. The command

result = WRITER (handle, dataMat);

will try to add dataMat into the file at the current file position. dataMat must have the same number of columns as the data currently in the file, or GAUSS will fail. Data in the dataset will be overwritten, and the file pointer will be moved on to just after the written block. If the file pointer is currently at the end of the file, the extra rows will be appended to the file. Thus, existing datasets can only be added to at the end; odd rows cannot be inserted (except by some particularly astute or wilful programming).

result is the number of lines actually written to disk. If result is less than the number of rows in dataMat, then clearly something has gone wrong with the write operation - possibly disk full, or trying to write to a read-only file. Thus the operation

numWrit = WRITER (handle, dataMat1);

using the 10x4 matrix read above should lead to numWrit being equal to 10; if not, something has gone wrong.

The column names stored with the dataset can be used to refer to the matrix columns by using the "i" prefix and the names. Thus, to print all the "name" and "sex" fields in the example matrix, two equivalent commands are

PRINT $dataMat1[., 1] dataMat1[., 3];
PRINT $dataMat1[., iname] dataMat1[., isex];

but the second form is clearly much more readable. It also makes for more easily maintained programs, as changes to the dataset will not affect the symbolic column references - GAUSS will make sure "isex" and "iname" refer to the right column.

2.4 Closing datasets

Files should always be closed when reading or writing is finished. GAUSS will automatically do this when leaving the GAUSS environment or when it encounters an END statement (see Section 5, Program Control). However, having files open unnecessarily may slow the system down; may prevent new (and useful) files being opened; may be mistakenly altered by the program; and may be corrupted or lose data due to system failure.

Files are closed by the CLOSE command:

result = CLOSE (handle);

If the file for handle was closed successfully, then result will be set to 0; otherwise, it will be -1. The reason the handle is set to 0 on success and -1 on failure is because valid handles are all positive numbers; therefore, GAUSS uses zero and negative numbers to indicate the state of the file handle. If the CLOSE worked, then handle should be set to zero, to signify that there is no open file attached with this handle (this information is used by OPEN and CREATE). This could be combined by using

handle = CLOSE (handle);

as recommended by the GAUSS manual. However, if this operation is unsuccessful, then the above formulation means that the original value of the handle is lost. A better option is to use a temporary variable and test it; for example,

result = CLOSE (handle1);
IF result == 0;
handle1 = 0;
ELSE;
PRINT "Close failed on file number " handle1;
ENDIF;

This also allows a meaningful error message to be displayed. Note that this use of 0 or -1 is inconsistent with the definition of true and false as 0 and 1; however, if you use false/not-false (as recommended earlier) then logical operators will operate correctly. Another reason to use zero/non-zero rather than relying on 0/1 for Boolean operations...

An alternative is to use one of the following:

CLOSEALL;
CLOSEALL handle1, handle2, ... handlex;

which closes all or a specified list of files. The first form does not set file handles to zero; this should still be done by the program. The second form sets handles to zero, but GAUSS is silent on the possibility of the closure failing.

3 Text files

Input can be taken from ASCII (i.e. normal alphanumeric text) files using the LOAD command described above. This is augmented by the addition of square brackets which indicate the ASCII nature of the file:

LOAD varName[] = fileName;
LOAD varName[r, c] = fileName;

In the first case, GAUSS will load the contents of fileName into the column vector varName, which can then be checked for size and reshaped. This is the preferred option for loading ASCII files. Items can be numeric or text and should be separated by spaces or commas. Line breaks are treated as white space: GAUSS does not use them to distinguish rows. Text items longer than eight characters will be truncated.

The second form loads the file into an r by c matrix. If there are too many elements in the file for the matrix, then the extra ones will not be read; if the file does not contain enough data items, then the ones found will be repeated until the matrix is full.

3.1 ASCII input examples

Supposing the file "eric.txt" contained

loaves 5
fishes 2
fishermen 2

Then

LOAD menu1[] = "eric.txt";
LOAD menu2[2, 2] = "eric.txt";
LOAD menu3[4, 2] = "eric.txt";

produces a 6x1 column vector called menu1 and two matrices called menu2 and menu3:

menu1
loaves
5.0
fishes
2.0
fisherme
2.0
menu2
loaves 5.0
fishes 2.0
menu3
loaves 5.0
fishes 2.0
fishermen 2.0
loaves 5.0

Note the truncation of "fishermen", and the lack of quote marks around the text items. Quote marks would have been acceptable to GAUSS.

3.2 RESHAPE

RESHAPE is a standard GAUSS function which changes the shape of the matrix. The format is

newMat = RESHAPE (oldMat, r, c);

where newMat is now an r by c matrix formed from the elements of oldMat. If newMat and oldMat do not have the same number of elements, then the rules for filling up the matrix are as for the LOAD command. Thus these two pieces of code are equivalent:

LOAD tempMat[] = "eric.txt";
menu = RESHAPE (tempMat, 3, 2);
or LOAD menu[3, 2] = "eric.txt";

but the first is a better solution. It allows for checking the number of elements read, which can be used to test for errors in the input data.

Warning

Neither RESHAPE or LOAD[r, c] will send an error message if they do not find the correct number of elements to fill the output matrix. They will always return a matrix of the desired size. This is why it is important to check the number of elements read in before reshaping them into a matrix.

3.3 ASCII Output

Producing ASCII output files is no different from displaying on the screen. GAUSS allows for all output to be copied and redirected to a disk file. Thus anything which appears on the screen also appears in the disk file. To produce an ASCII file therefore requires that (i) an output file is opened; (ii) PRINT is used to display all the information to go into the output file (iii) the output file is closed when no more output is to be sent to it.

The relevant command to begin this process is OUTPUT:

OUTPUT FILE = fileName ON;
OUTPUT FILE = fileName RESET;

Both will instruct GAUSS to send a copy of everything it displays, from that point onward, to the file fileName. If fileName does not already exist, then these two are identical; but if the file does exist, then the first form ensures that any output is appended to the existing contents of the file, while the second empties the file before GAUSS starts writing to it. If no file name is given, then GAUSS will use the default "output.out". There is no default extension for output files.

Once a file has been opened, it can be closed and opened any number of times by combining the above commands with

OUTPUT OFF;

These commands will all work on the last recorded file name given. The FILE=fileName bit could be included here as well if the user wishes to swap between different output files; generally, however, only one output file is used for a program, and so naming the file explicitly is superfluous.

An analogous command SCREEN switches screen output on and off. These two commands are independent and so screen display off and file output on is a perfectly acceptable combination.

3.3.1 Example uses of OUTPUT

Example 1 sends output to one file only, "eric.txt"; Example 2 sends output to two different files, "eric1.txt" and "eric2.txt":

Example 1   Example 2
OUTPUT FILE="eric.txt" RESET;
  :
OUTPUT OFF:
  :
OUTPUT ON;
  :
OUTPUT OFF
  :
OUTPUT ON;
  :
  OUTPUT FILE= "eric1.txt" RESET;
  :
OUTPUT OFF;
  :
OUTPUT FILE="eric2.txt" RESET;
  :
OUTPUT OFF;
  :
OUTPUT FILE="eric1.txt" ON;
  :

3.3.2 OUTWIDTH

Because GAUSS is treating the output as something to be "displayed" (even if only to a file), it retains the concept of only having a certain number of characters on a "line". The default is eighty characters, the standard screen width. This means that sending a matrix with a large number of columns to an output file may lead to the matrix being broken up, with "overflow" columns being put on new lines. The way to avoid this is to use

OUTWIDTH numChars;

where numChars is the nominal line width, and can be anything from 2 to 256. If this is set to 256, then this tells GAUSS to leave out all extraneous line breaks - new lines will only start with a new row of the matrix.

Note that output on the screen may still be wrapped around. This does not affect the layout of the output file - it is just the display's functionality, and nothing to do with GAUSS.

4 Keyboard input

GAUSS take input directly from the keyboard through two functions:

string = CONS;
mat = CON(r, c);

The first of these reads in a string variable, pure and simple. The second reads elements for a matrix of dimension r by c, and works differently in different versions of GAUSS.

In GAUSS versions prior to 4.0, CON will prompt the user with a question mark and will treat all white space as merely separating matrix elements. Thus, the CON command will read exactly r by c elements; it will not let the program continue until it has read enough data points. It will also break off the moment it has enough items. Suppose the program was given the instruction

data = CON(2, 3);

and the user attempted to enter

0 1 2 3 4 5 6

GAUSS would stop when it had read the "5". The fact that there was another item to be read is irrelevant to filling a 2x3 matrix. If the user types ahead and is not aware that GAUSS has filled the CON matrix, then the "6" will be read as the first bit of input next time any console input is required.

Moreover, CON will not allow editing of the data already entered. If the user entered the above sequence and then decided that 0 should be changed to 1, CON will not allow it. As each item is entered, CON notes it, stores it, and moves on to the next item. There is no going back. This means that program employing CON should make any unsuspecting user aware of the importance of getting input right first time. This theme will be returned to in later sections.

GAUSS 4.0 has a vastly improved matrix editor, and it uses this to underpin CON. In GAUSS 4.0 the user is given co-ordinates, can edit numbers, and can also enter strings. The downside is that the system is even more opaque to a new user; for example, there is no obvious way to get out of the editor (enter 'x' in a cell). There is help available by typing '?', but if you want an inexperienced user to run your program then you must give them adequate instructions.

Unix input varies because of the way distributed systems handle input streams. You may find that the system does nothing until carriage return (the 'enter' key) is pressed.

All in all, CON is to be avoided if you possibly can. The same effect can be achieved by combining CONS with STOF (which converts the numbers in a string into a numeric matrix). Much safer and easier for the user. See some of the procedures in the file datautil.gl for an example.

If using the STOF(CONS) combination, be aware that when GAUSS converts the string it leaves character data in place. You may need to do a second round of conversion if you are worried about getting bad data.

5 Spreadsheets, database files, and other product formats

GAUSS 4.0 and 5.0 for Windows can import data directly from Excel spreadsheets. For multiple-page spreadsheets, you can specify both the sheet and the cell range to upload. It will try to maintain character and numeric data characteristics.

GAUSS will also export data to these third-party formats. However, it writes these data files in the earliest compatible version. For example, although it understands Excel spreadsheets up to version 7, it will save them as version 2.1 by default.

However, despite introducing spreadsheet importing in version 4.0, Aptech ditched these commands in version 5.0 and implemented a second set of commands. The appropriate commands are:
Version 4 Version 5
{mat,names} =
  IMPORT(fileName,range,sheet);
:
okay =
  EXPORT(mat,fileName,names);
mat =
  SPREADSHEETREADM(fileName,range,sheet);
:
okay =
  SPREADSHEETWRITE(mat,fileName,range,sheet);

In version 4: If the first row contains text, GAUSS assumes that these are column headings and creates an appropriate matrix of variable names. If it only finds numeric data, it creates a vector of column names as "C1", "C2" and so on. When exporting, the situation reverses and you can supply column names.

You can also use the IMPORT/EXPORT commands for communicating with a variety of other file formats, including Lotus, Quattro and dBase files. GAUSS uses the filename extension as a clue to the type of file, although these can be overridden.

In version 5: The import command just returns a matrix and it's up to the user to break off row or column headings. When writing, particular areas of the spreadsheet can be targetted.

Warning: while the obsolete v4.0 commands still exist in v5.0, they only work correctly if the read spreadsheet has column names. GAUSS 5 assumes that column names exist and so will automatically chop off the top row. If your spreadsheet file has no column headings, you will lose a row of data.

Please also note that
  • although v4.0 starts numbering spreadsheets from 0, v5.0 numbers them from 1
  • EXPORT in v4 returns a 0 if the operation failed; SPREADSHEETWRITEM returns a 0 if the operation succeeded
  • The v5 commands do not appear to work if Excel is not installed on your computer
  • if a full path is not specified, v4 uses the working directory but v5 appears to use the system default document directory
Enjoy.

Using the import and export functions is much more convenient than using ASCII files as intermediaries, as well as being more reliable. However, if you are running your program on something other than GAUSS 4.0+ for Windows, you will need to go back to ASCII files for data exchange.

If you are using Unix, do not have the latest version of GAUSS, or wish to access data in several different formats, then the excellent program DMBS/Copy from Conceptual Software will translate GAUSS matrices and datasets on disk into several spreadsheet formats, as well as all the other major statistical packages. It is cross-platform, extremely easy to use and highly recommended.

6 Binary data - unlimited text input

GAUSS has a number of commands (FOPEN, FGETS, FPUTS et cetera) to access files at the binary level. These read and write strings with or without carriage returns. As string data is effectively accessible at the binary level, this allows you to interact directly with all file types. Strings read in can be converted to binary data and then to other formats if necessary. This is also useful for communicating with other products: for example, reading in data from a file to be passed on to a third-party foreign language DLL.

This is also the only way you can access text strings over eight characters. Using LOAD[] would just trim each word to at most eight characters. Direct file reading means that a string of any length can be read in.

However, because this is something you are unlikely to use, we will not cover it further here.

7 Graphics

One feature of GAUSS I/O that performs well is the graphing package. The way GAUSS draws a graph is to provide functions which draw the graphs and only draw the graphs. All other attributes are set using variables. So, to create a graph involves setting one variable to the title, another to the type of lines wanted, another to the colour scheme, another to the scaling of the y axis, and so on. When all this has been done, the relevant graph function is called, and it uses all the information previously set to draw the graph with the right characteristics.

7.1 Essential preparations

Any program drawing graphs needs to have the line

LIBRARY PGRAPH;

in it. This should go at the start of the program. This tells GAUSS where all the specialised graph-drawing routines are to be found. If this line is omitted, graphs cannot be drawn.

The LIBRARY line should only appear once, but

GRAPHSET;

can be called repeatedly. This resets all the graph variables back to their default values. Obviously, this should appear before the options for the next graph are written; otherwise any options chosen will be reset to the defaults. Note that this is not a necessary statement; it is an easy method of returning all settings to their default values. It is recommended you do this at the beginning of the program as well to clear any settings left over from previous programs.

7.2 Options to be set

There are an enormous amount of options to be set - almost eighty. These are all detailed in the System and Graphics Manual. They all begin with "_p" to make them easily identifiable. These are set just like any other variables - the manual details what information is to be expected in each. For example, consider the instructions

_pcolor = ZEROS(2,1);
_pcolor[1] = col1;
_pcolor[2] = col2;
  :
_pbartyp = {2 1, 2 2, 2 3};

The _pcolor instruction sets colours for the XY and XYZ graphs. It is a 2x1 vector implying, in this case, that there are two series to be plotted. The first series will be plotted in the colour "col1", the second in "col2", both of which are variables.

The _pbartype instruction sets the shading type and colour for a bar graph. It is a 3x2 matrix, implying three series. The first column in all three rows is 2 in this example, meaning that the bars have vertical cross-hatching for all three series. The second column is colour: series one to three are displayed in colours 1, 2, and 3 (what these colours actually mean on screen depends on the user's machine).

The most useful variable is

_plegstr = "legend A\000legend B\000Legend C";

This defines legends for each line when a graph is displaying multiple series - three in this case. The legends for each series must be separated by the code "\000". This is a null character telling GAUSS that one name has ended and another is beginning.

The relevant variables to be set are detailed with each graph type. In addition there are a number of general functions which control other settings, of which the most important are

TITLE(title);
XTICS(min, max, increment, subDivs);
XLABEL(title);

The first of these sets the title for the graph. XTICS (and the associated functions YTICS and ZTICS) allow for scaling of the X-axis. If this function is not called, GAUSS will work out its own scaling. min and max are the minimum and maximum values on the scale, with the scale increasing by increment; negative values for the increment are acceptable. subDivs is the number of minor ticks between each increment. Finally, XLABEL (and YLABEL and ZLABEL) provides a title for the X-axis.

All these options should be set before printing a graph. However, most of the defaults are quite sensible, and many options will not need changing. The defaults can be changed to the user's preference too; they are all in a file called PGRAPH.DEC (see the manual for details).

7.3 Displaying and printing graphs

GAUSS provides a number of graph types, including bar graphs, X-Y, log X-Y and histograms. All data for graphs comes in the form of matrices. When GAUSS finds a graph instruction, it displays the graph immediately using the current set of options or defaults. This is why all the options are set first. By the time GAUSS reaches a graph instruction, all it needs to produce the graph is the data given in the function call.

The graph data are in NxK matrices, where N is the number of data points and K is the number of series to be plotted. Whether multiple series are permitted or not depends on the graph: for example, multiple series are allowed in an X-Y graph. So

xSeries = SEQA(1, 1, 20);
ySeries = ZEROS(20, 3);
ySeries[., 1] = thisData;
ySeries[., 2] = thatData;
ySeries[., 3] = otherDat;
XY(xSeries, ySeries);

will plot an X-Y graph consisting three series, each of 20 data points. The series are the values held in thisData, thatData, and otherDat.

How the graph is displayed depends upon both the operating system and the version of GAUSS.

In the original DOS version, the graph is displayed full-screen and then remains on screen until a key is pressed. The escape key (ESC) lets the program continue, while others bring up menus for zooming into, printing or saving to disk the graph.

In early Unix versions, there was no graph displaying. Graphical files were simply saved to disk.

In later Unix versions (designed for X-windows) and GAUSS for Windows, GAUSS included functions to create graphical windows and place the results inside them. The user could direct graph output to particular windows. Printing and saving was part of the window function. In Version 4 and above, multiple graphs in the same window can easily be drawn, and saving files in other formats is also simplified considerably.

7.4 Using graphs in other programs

The graph can be saved to disk in a number of picture formats which other programs may or may not be able to read. The default format is .tkf, a proprietary format of Scientific Endeavours Foundation who provided the base for GAUSS' graphics capability.

In recent versions, the files can be converted to
  • enhanced metafile (.emf files)
  • encapsulated postscript (.eps files)
  • HPGL Plotter (.hpg files)
  • Windows bitmap (.bmp files)
Older versions of GAUSS created Lotus .pic files instead of .emf and Paintbox .pcx bitmaps instead of Windows bitmaps.

.emf, .eps and .bmp files are commonly readable across a range of programs, with .eps and .bmp being the most common. Encapsulated postscript is well-supported on Unix systems and to a lesser extent on Windows systems. Windows bitmap is universal on Windows systems and common elsewhere but is extraordinarily wasteful of space. A good solution is to save files as .bmp and then use a graphics package to convert them to a more parsimonious format such as GIF, JPEG or PNG.

If you are using TGAUSS (the command-line version of GAUSS) there are obviously no graphics windows with menus to save files. Files will be saved in TKF format. However, there are command line functions to convert .tkf files into PostScript and Encapsulated Postscript files; respectively, tkf2ps and tkf2eps. These are of course also accessible from the Windows version of GAUSS but there is less need for them.

[ previous page ] [ next page ]