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:
The name of the character object receiving the data appears in place of the unit number on a WRITE statement. On a READ statement, the name of the character object source appears in place of the unit number.
A constant, variable, or substring object constitutes a single record in the file.
With an array object, each array element corresponds to a record.
Direct I/O on internal files. (The Fortran 95 standard includes only sequential formatted I/O on internal files.) This is similar to direct I/O on external files, except that the number of records in the file cannot be changed. In this case, a record is a single element of an array of character strings. This non-standard extension is only available in FORTRAN 77 compatibility mode by compiling with the -f77 flag.
Each sequential READ or WRITE statement starts at the beginning of an internal file.
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% |