• Keine Ergebnisse gefunden

ACCBSSING FORMATTBD FILBS

Im Dokument IRIS R8 (Seite 26-31)

2.4 FORMATTED FILES

2.4.2 ACCBSSING FORMATTBD FILBS

This section includes examples of the use of WRITE, READ, PRINT, MAT READ and MAT WRITE statements on formatted files. The general syntax of these statements is shown in Section 3.

Error 15 is generated if the program variable type is different from the file item type, except when data is transferred between binary and numeric types.

Data are always translated to the precision of the destination variable/item. However, if a number outside the range +/-7999 is read into a 1% variable, the value +/-7999 is read or written and error 15 is generated.

For example, suppose a formatted file had the following record layout:

~ Variable Length/precision

0 A$ 12 character

1 Al 1%

2 A2 2%

3 A3 3%

4 A4 4%

The following lines manipulate data in this file:

10 DIM 3%,A3,4%,A4 760 READ 'C,R,4;A3

Line 760 reads item 4, a preclslon 4% variable, into A3, which is a 3% variable. This is accomplished by modifying the 4% value to fit into the 3% variable.

SM-030-00l2-02

POINT 4 Data Corporation 2-12 IRIS DATA FILES IRIS Business BASIC Manual

2.4.2.1 WRITB for Foraatted Files

For formatted files, a single WRITE statement may write into sequential items of a single record only. An error results if a variable type does not match the item type in the file.

An explicit WRITE to record zero is used to define the format of a formatted file newly built from within a BASIC program, as described in Section 2.4.4.

The following examples show the use of the WRITE statement on formatted files.

200 WRITE '4, 19; F, Yl+3, "EXAMPLE", D-E

Line 200 sets item zero of record 19 of the file open on channel 4 to the value of F, item one of the same record to the value of (Yl+3), item two to the string value EXAMPLE, and item three to the value of (D-E). Items zero, one and three must be formatted as numerics; item two must be formatted as a string.

700 WRITE IC-l, 2*R, 8; 0,2 A, MS[4,Ql;

In line 700, the channel number is given by the value of the expression (C-l) and the record number is given by the value of the expression (2*R). The item number may also be an expression.

The line sets item 8 of the specified record to 0, item nine to the value of (2 A), and item ten to characters four through the value of Q of the string MS. The final semicolon leaves the specified record unlocked while the statement is executed, as described in Section 2.3.4.

SM-030-0012-02

POINT 4 Data Corporation 2-13

IRIS DATA FILES IRIS Business BASIC Manual

2.4.2.2 READ For Formatted Files

2.4.2.3 PRINT for Poraatted Piles

The PRINT statement can be used on formatted files, and results in output of one or more strings. Output must be to an ASCII string item. The use of PRINT on formatted files requires a thorough knowledge of how PRINT operates. POINT 4 suggests the use of alternate statements, such as LET USING.

2.4.2.4 MAT WRITB Statement for Foraatted Files

When using MAT WRITE, the entire matrix, string or variable is written into a single item. The item type in the file must be binary.

If the item is too small, then the data are truncated; no error message is given. No data conversion takes place; the user's program must ensure that the data will later be read back into the same type of variable.

The following examples show the use of the MAT WRITE statement on formatted files.

910 MAT WRITE tl, 20; A

Line 910 writes all elements of the matrix A into item zero of record 20 of the file open on channell.

300 MAT WRITE tc, 2*R, 8; B

Line 300 writes all elements of the matrix B into item 8 of the record given by the value of (2*R) of the file open on channel C.

700 MAT WRITE tL, R, 3; B$

Line 700 writes the string B$ into item 3 of record R of the file open on channel L. Item three must be a binary field. The system WRITEs the entire contents of B$, including all zero bytes, to the end of B$ or until the item is full, whichever occurs first.

SM-030-00l2-02

POINT 4 Data Corporation 2-15

IRIS DATA FILES IRIS Business BASIC Manual

2.4.2.5 The KAT READ State.ent for Pormatted Piles

When using MAT READ, the entire matrix or string is read into a single item. The type of the item must be binary. If the item is too small, then the data are truncated; no error message is given. No data conversion takes place; the program must ensure that the data is read into the type of variable which matches the data form.

The following examples show the use of the MAT READ statement on formatted files.

400 MAT READ 12, 21; M

Line 400 reads all the elements of the matrix M into item zero of record 21 of the file open on channel 2.

600 MAT READ IJ, R+3, 7; N

Line 600 reads all the elements of the matrix N into item 7 of the record given by the value of (R+3) of the file open on channel J.

800 MAT READ '3, 10, 2; A$

Line 800 reads the string A$ into item 2 of record 10 of the file open on channel 3. Item two must be a binary field. The system READS the entire contents of B$, including all zero bytes, until A$ is full or to the end of the item, whichever occurs first.

5"-030-0012-02

POINT 4 Data Corporation 2-16 IRIS DATA PILES IRIS Business BASIC Manual

Im Dokument IRIS R8 (Seite 26-31)