# Microsoft Fortran PowerStation Compatible Files (Windows*)

This topic only applies to Windows*.

When using the fpscomp option for Microsoft* Fortran PowerStation compatibility, the following types of files are possible:

- Formatted Sequential

- Formatted Direct

- Unformatted Sequential

- Unformatted Direct

- Binary Sequential

- Binary Direct

## Formatted Sequential Files

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

## Formatted Direct Files

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

Unformatted sequential files are organized slightly differently on different platforms. This section describes unformatted sequential files created by Intel® Fortran when the fpscomp option is specified.

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

## Unformatted Direct Files

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

## Binary Sequential Files

A binary sequential file is a series of values written and read in the same order and stored as binary numbers. No record boundaries exist, and no special bytes indicate file structure. Data is read and written without changes in form or length. For any I/O data item, the sequence of bytes in memory is the sequence of bytes in the file.

The next program creates the binary sequential file shown in the following figure:

    !  NOTE: 07 is the bell character
    !     Sequential is assumed by default.
    !
      INTEGER(1) bells(4)
      CHARACTER(4) wys(3)
      CHARACTER(4) cvar
      DATA bells /4*7/
      DATA cvar /' is '/,wys /'What',' you',' see'/
      OPEN (3, FILE='BSEQ',FORM='BINARY')
      WRITE (3) wys, cvar
      WRITE (3) 'what ', 'you get!'
      WRITE (3) bells
      CLOSE (3)
      END

Binary Sequential File

## Binary Direct Files

A binary direct file stores records as a series of binary numbers, accessible in any order. Each record in the file has the same length, as specified by the RECL argument to the OPEN statement. You can write partial records to binary direct files; any unused portion of the record will contain undefined data.

A single read or write operation can transfer more data than a record contains by continuing the operation into the next records of the file. Performing such an operation on an unformatted direct file would cause an error. Valid I/O operations for unformatted direct files produce identical results when they are performed on binary direct files, provided the operations do not depend on zero padding in partial records.

The following program creates the binary direct file shown in the following figure:

      OPEN (3, FILE='BDIR',RECL=10,FORM='BINARY',ACCESS='DIRECT')
      WRITE (3, REC=1) 'abcdefghijklmno'
      WRITE (3) 4,5
      WRITE (3, REC=4) 'pq'
      CLOSE (3)  END

Binary Direct File
Parent topic: Fortran I/O