FORTRAN 77 Language Reference

Examples

Example 1: Formatted read, trap I/O errors, EOF, and I/O status:


       READ( 1, 2, ERR=8, END=9, IOSTAT=N ) X, Y 
       ... 
8     WRITE( *, * ) 'I/O error # ', N, ', on 1' 
       STOP 
9     WRITE( *, * ) 'EoF on 1' 
       RETURN 
       END 

Example 2: Direct, unformatted read, trap I/O errors, and I/O status:


       READ( 1, REC=3, IOSTAT=N, ERR=8 ) V 
       ... 
4     CONTINUE 
       RETURN 
8     WRITE( *, * ) 'I/O error # ', N, ', on 1' 
       END 

Example 3: List-directed read from keyboard:


       
READ(*,*) A, V
or
       READ*, A, V

Example 4: Formatted read from an internal file:


       CHARACTER CA*16 / 'abcdefghijklmnop' /, L*8, R*8
        READ( CA, 1 ) L, R
1     FORMAT( 2 A8 )

Example 5: Read an entire array:


       DIMENSION V(5) 
       READ( 3, '(5F4.1)') V 

Example 6: Namelist-directed read:


       CHARACTER SAMPLE*16 
       LOGICAL NEW*4 
       REAL DELTA*4 
       NAMELIST /G/SAMPLE,NEW,DELTA 
       ... 
       READ(1, G) 
            or 
       READ(UNIT=1, NML=G) 
            or 
       READ(1, NML=G)