Sun Studio 12: Fortran Programming Guide

2.5 Internal Files

An internal file is an object of type CHARACTER such as a variable, substring, array, element of an array, or field of a structured record. Internal file READ can be from a constant character string. I/O on internal files simulates formatted READ and WRITE statements by transferring and converting data from one character object to another data object. No file I/O is performed.

When using internal files:

Example: Sequential formatted read from an internal file (one record only):


demo% cat intern1.f
      CHARACTER X*80
      READ( *, ’(A)’ ) X
      READ( X, ’(I3,I4)’ ) N1, N2 ! This codeline reads the internal file X
      WRITE( *, * )  N1, N2
      END
demo% f95 -o tstintern intern1.f
demo% tstintern
 12 99
 12 99
demo%

Example: Sequential formatted read from an internal file (three records):


demo% cat intern2.f
      CHARACTER  LINE(4)*16
      DATA  LINE(1) / ’ 81  81 ’ /
      DATA  LINE(2) / ’ 82  82 ’ /
      DATA  LINE(3) / ’ 83  83 ’ /
      DATA  LINE(4) / ’ 84  84 ’ /
      READ( LINE,’(2I4)’) I,J,K,L,M,N
      PRINT *, I, J, K, L, M, N
      END
demo% f95 intern2.f
demo% a.out
   81  81  82  82  83  83
demo%

Example: Direct access read from an internal file (one record), in -f77 compatibility mode:


demo% cat intern3.f
      CHARACTER LINE(4)*16
      DATA  LINE(1) / ’ 81  81 ’ /
      DATA  LINE(2) / ’ 82  82 ’ /
      DATA  LINE(3) / ’ 83  83 ’ /
      DATA  LINE(4) / ’ 84  84 ’ /
      READ ( LINE, FMT=20, REC=3 ) M, N
20       FORMAT( I4, I4 )
      PRINT *, M, N
      END
demo% f95 -f77 intern3.f
demo% a.out
   83  83
demo%