next up previous 63
Next: Screen Mode
Up: Input/Output
Previous: Terminal I/O


Text File I/O

ICL can also read and write text files. In order to access files they must first be opened using one of the commands CREATE, OPEN or APPEND.

    CREATE MYFILE
will create a file called MYFILE and open it for output. MYFILE is the name used within ICL for the file. The file will appear in your default VMS directory as MYFILE.DAT.

The VMS file name may be specified explicitly by adding a second parameter to the CREATE, OPEN or APPEND command.

    OPEN  INFILE  DISK$DATA:[ABC]FOR008.DAT
opens an existing file for input and the file is known internally as INFILE.

The APPEND command opens an existing file for output. Anything written to the file is appended to the existing contents.

A line of text is written to a text file with the WRITE command. WRITE is similar to PRINT, the only difference being that its first parameter specifies the internal name of the file to which the data will be written.

Text is read from files with the commands READ, READR, READI and READL. These are analogous to the INPUT commands for terminal input. The first parameter specifies the internal name of the file. READ reads a line of text into a single string variable. The other commands read one or more real, integer or logical values.

When a file is no longer required it may be closed using the CLOSE command which has a single parameter, the internal name of the file.

The following example uses these procedures to read an input file containing three real numbers in free format, and output the same numbers as a formatted table.

    PROC REFORMAT

    {  Open input file and create output file  }

        OPEN INFILE
        CREATE OUTFILE

    {  Loop copying lines from input to output  }

        LOOP
           READR INFILE (R1) (R2) (R3)
           WRITE OUTFILE (R1:10:2) (R2:10:2) (R3:10:2)
        END LOOP

    END PROC

Note that no specific test for completion of the loop is included. When an end of file condition is detected on the input file the procedure will exit and return to the ICL$>$ prompt with an appropriate message. 4.1


next up previous 63
Next: Screen Mode
Up: Input/Output
Previous: Terminal I/O

ICL The Interactive Command Language for ADAM
Starlink Guide 5
J A Bailey
A J Chipperfield

9th June 1998
E-mail:starlink@jiscmail.ac.uk

Copyright © 2013 Science and Technology Facilities Council