When using the -fpscomp options for Microsoft* Fortran PowerStation* compatibility, the following types of files are possible:
Formatted Sequential
Formatted Direct
Unformatted Sequential
Unformatted Direct
A formatted sequential file is a series of formatted records written sequentially and read in the order in which they appear in the file. Records can vary in length and can be empty. They are separated by carriage return (0D) and line feed (0A) characters as shown in the following figure.
Formatted Records in a Formatted Sequential File
An example of a program writing three records to a formatted sequential file is given below. The resulting file is shown in the following figure.
OPEN (3, FILE='FSEQ') ! FSEQ is a formatted sequential file by default. WRITE (3, '(A, I3)') 'RECORD', 1 WRITE (3, '()') WRITE (3, '(A11)') 'The 3rd One' CLOSE (3) END
Formatted Sequential File
In a formatted direct file, all of the records are the same length and can be written or read in any order. The record size is specified with the RECL option in an OPEN statement and should be equal to or greater than the number of bytes in the longest record.
The carriage return (CR) and line feed (LF) characters are record separators and are not included in the RECL value. Once a direct-access record has been written, you cannot delete it, but you can rewrite it.
During output to a formatted direct file, if data does not completely fill a record, the compiler pads the remaining portion of the record with blank spaces. The blanks ensure that the file contains only completely filled records, all of the same length. During input, the compiler by default also adds filler bytes (blanks) to the input record if the input list and format require more data than the record contains.
You can override the default blank padding on input by setting PAD='NO' in the OPEN statement for the file. If PAD='NO', the input record must contain the amount of data indicated by the input list and format specification. Otherwise, an error occurs. PAD='NO' has no effect on output.
An example of a program writing two records, record one and record three, to a formatted direct file is given below. The result is shown in the following figure.
OPEN (3,FILE='FDIR', FORM='FORMATTED', ACCESS='DIRECT',RECL=10) WRITE (3, '(A10)', REC=1) 'RECORD ONE' WRITE (3, '(I5)', REC=3) 30303 CLOSE (3) END
Formatted Direct File
Unformatted sequential files are organized slightly differently on different platforms. This section describes unformatted sequential files created by Intel Fortran when the -fpscomp option (such as -fpscomp ioformat) was specified. If you are accessing files from another platform that organizes them differently, see Converting Unformatted Data Overview.
The records in an unformatted sequential file can vary in length. Unformatted sequential files are organized in chunks of 130 bytes or less called physical blocks. Each physical block consists of the data you send to the file (up to 128 bytes) plus two 1-byte "length bytes" inserted by the compiler. The length bytes indicate where each record begins and ends.
A logical record refers to an unformatted record that contains one or more physical blocks. (See the following figure.) Logical records can be as big as you want; the compiler will use as many physical blocks as necessary.
When you create a logical record consisting of more than one physical block, the compiler sets the length byte to 129 to indicate that the data in the current physical block continues on into the next physical block. For example, if you write 140 bytes of data, the logical record has the structure shown in the following figure.
Logical Record in Unformatted Sequential File
The first and last bytes in an unformatted sequential file are reserved; the first contains a value of 75, and the last holds a value of 130. Fortran uses these bytes for error checking and end-of-file references.
The following program creates the unformatted sequential file shown in the following figure:
! Note: The file is sequential by default ! -1 is FF FF FF FF hexadecimal. ! CHARACTER xyz(3) INTEGER(4) idata(35) DATA idata /35 * -1/, xyz /'x', 'y', 'z'/ ! ! Open the file and write out a 140-byte record: ! 128 bytes (block) + 12 bytes = 140 for IDATA, then 3 bytes for XYZ. OPEN (3, FILE='UFSEQ',FORM='UNFORMATTED') WRITE (3) idata WRITE (3) xyz CLOSE (3) END
Unformatted Sequential File
An unformatted direct file is a series of unformatted records. You can write or read the records in any order you choose. All records have the same length, given by the RECL specifier in an OPEN statement. No delimiting bytes separate records or otherwise indicate record structure.
You can write a partial record to an unformatted direct file. Intel Fortran pads these records to the fixed record length with ASCII NULL characters. Unwritten records in the file contain undefined data.
The following program creates the sample unformatted direct file shown in the following figure:
OPEN (3, FILE='UFDIR', RECL=10,& & FORM = 'UNFORMATTED', ACCESS = 'DIRECT') WRITE (3, REC=3) .TRUE., 'abcdef' WRITE (3, REC=1) 2049 CLOSE (3) END
Unformatted Direct File