Tutorial - Reading Data Files

If you had to edit your program every time you wanted to run it with a different set of data things would get tedious. So the system has a routine for reading in a data file. This routine has options for specifying the format of the data and for where errors should be reported. We shall start with the simplest mode.

Overview

The data from the file will be read into an array. The record type of the array must be defined to be the correct type for the data and the array type itself must be a one dimensional open array. We will start with a simple table with two numbers per row, a sample index and a sample value. You will need the following two definitions in the global section :-

Type TResult = { Number index, Number value };
Type TResultArray = TResult[];

Within a routine you will need to declare an array variable to hold the data ( the array will normally be uninitialised ).

TResultArray dataset;

You will then need a function call to read in the data file.

dataset := ReadData("TUTSAMPLES:/results.txt");

The name of the source file will be a text string and could be passed to the program via the command line. The file name can be a simple DOS style name ( but as the file path delimiter is a backslash, which is the GraRLS escape character, you will need to escape it; to make life easier you can use the forward slash ). The file name can also used node names as defined in the ini files ( there will eventually be a tutorial covering this system ).

For this example there should be an entry in the supplied grarls.ini as follows :-

[= directory for the tutorial samples =]
TUTSAMPLES = "ROOT:/PublicDocs/Tutorials/Samples";

Finally you will need to do something with the data. The best way is to use the 'Over' statement.

Example

The example program uses the following data file - results.txt

data_read_1.grs Output of data_read_1.grs data_read_1

In a real program you will want to draw some axes. You may want to do a pass of the data to check it and to deduce the required scale factors. There are a number of example programs in the standard distribution.