Reading Data

The file may be read using the READ command as in:

Command

Description

READ (1)A$

Causes PRO/5 to read the input on channel 1 until it encounters a field separator. See the CTL variable for a list of separators.

READ (1)A$,B$,A,B,C

Uses a number of variables instead of a single variable. PRO/5 "parses" the data read into the proper variables.

The example reads the variables A$, B$ and the numeric variables A, B, and C from the file. If PRO/5 ran out of data prior to placing values into all of the variables in the list, it would return either an !ERROR=1 or an !ERROR=2. The !ERROR=1 is returned when PRO/5 has a concept of record size with the device. Otherwise, an !ERROR=2 is returned because PRO/5 will keep retrieving characters until it satisfies the input request or you interrupt the read.

READ RECORD(1,SIZ=32)A$

Specifies a number of characters to retrieve. The example retrieves 32 characters from channel 1 and place them into the variable A$. The SIZ= option specifies the maximum number of characters to retrieve to fill any one item in the input list. The RECORD option on the READ tells PRO/5 to ignore field terminators while retrieving characters.

As an example, the following program will read all of the records from a file and print the first 32 characters of each record to the terminal:

0010 BEGIN
0020 INPUT (0,ERR=0020)FILE$
0030 OPEN(1,ERR=0010)FILE$
0040 READ RECORD(1,END=0060,SIZ=32)REC$
0050 PRINT REC$; GOTO 0040
0060 END

Line 10 initializes the workspace by closing all OPEN channels and CLEARing the data. Lines 20 and 30 simply guarantee we get a file name from the user and that it is OPENed. Line 40 reads the first 32 bytes of the record, letting PRO/5 advance the record pointer, until it reaches an end-of-file (!ERROR=2) that transfers control to line 60, which terminates the program.

The size of the data retrieved is always specified by the READ operation or by the actual record size of the file. Reading a file with a SIZ= specification different than the record size will result in a read size using the smaller of the two. In the case of files without record sizes a read operation using a RECORD specifier will generate an error unless a SIZ= is used. A read operation without a RECORD specifier will succeed as it retrieves one byte at a time until a terminator is found.

The data read from a file may be modified on a character by character basis using the TBL= option. The translation of characters is done on the data read and not on any key provided using the KEY= option.