next up previous contents
Next: READ and WRITE statements Up: General I/O Previous: General I/O

   
Introduction

In the preceeding sections we have only considered I/O (input output) to the user's terminal. Here we introduce the general I/O to all possible devices (including the user's terminal). READ inputs data from the device and WRITE outputs data to it. The statements have a format reference and an I/O list and also normally have a logical unit number that uniquely identifies the device. The normal sequence for I/O is as follows. First the OPEN statement is used to identify the device (and if necessary the file name). The statement may contain details about the state of file and the method of access. It also associates an arbitary logical unit number to the device. Next come READs and WRITEs to carry out the I/O and finally CLOSE to terminate the I/O. All these statements are used in the program below which transfers 10 records from a file INPUT.DAT to a file OUTPUT.DAT. Each record contains 3 real numbers in F10.4.

 
C       Open the files
        LUNIN=20
        LUNOUT=21
        OPEN(UNIT=LUNIN,FILE='INPUT.DAT',STATUS='OLD')
        OPEN(UNIT=LUNOUT,FILE='OUTPUT.DAT',STATUS='NEW')
 
C       Transfer the data
        DO 100 IREC=1,10
        READ(LUNIN,90000) X1,X2,X3
100     WRITE(LUNOUT,90000) X1,X2,X3
 
C       Close the files
        CLOSE(UNIT=LUNIN)
        CLOSE(UNIT=LUNOUT)
 
        STOP
 
90000   FORMAT(3F10.4)
 
        END



n west (APC)
2000-03-08