FORTRAN 77 Language Reference

Examples

Example 1: Formatted write with trap I/O errors and I/O status:


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

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


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

Example 3: Direct, alternate syntax (equivalent to above example):


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

@

Example 4: List-directed write to screen:


       WRITE( *, * ) A, V 
or 
       PRINT *, A, V 

Example 5: Formatted write to an internal file:


       CHARACTER CA*16, L*8 /'abcdefgh'/, R*8 /'ijklmnop'/
       WRITE( CA, 1 ) L, R
1      FORMAT( 2 A8 ) 

Example 6: Write an entire array


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

:

Example 7: Namelist-directed write:.


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