eof#

Purpose#

Tests if the end of a file has been reached.

Format#

ret = eof(fh)#
Parameters:

fh (scalar) – file handle.

Returns:

ret (scalar) – 1 if end of file has been reached, else 0.

Examples#

Read each row from a dataset one at a time and compute the sum of each column.

// Get file name with full path to dataset
fname = getGAUSSHome("examples/credit.dat");

// Get file handle, to read from dataset
fh = dataOpen(fname, "read");

sum = 0;

// Iterate until reaching end of dataset
do until eof(fh);
    // Read one row of the dataset per iteration
    tmp = readr(fh, 1);

    sum = sum + tmp;
endo;

After the above code, sum will equal:

18087.6     1.89424e+06     141976     1183     22267     5380

GAUSS will keep reading until eof(fh) returns the value 1, which it will when the end of the dataset has been reached.

Remarks#

This function is used with readr() and the fgets() commands to test for the end of a file.

The seekr() function can be used to set the pointer to a specific row position in a dataset; the fseek() function can be used to set the pointer to a specific byte offset in a file opened with fopen().

See also

Functions open, readr(), seekr()