4 Access Mode, Format and Record Size of Files

When a file is opened by one of FIO_OPEN, FIO_ASSOC, RIO_OPEN or RIO_ASSOC, then various attributes of the file need to be specified. These are the access mode, the format and the record size.

The access mode can be one of ’READ’, ’WRITE’, ’UPDATE’ or ’APPEND’. ’READ’ specifies that the file is to be opened for reading only. This is required if the protection of the file forbids writing to it, but it is good practice to always use this option for files that will only ever be read. ’WRITE’ specifies that a new file is created and the file is opened for writing to. This also allows the file to be read, as once a record has been written, it can then be read. ’UPDATE’ access opens an existing file for read and write access. ’APPEND’ opens an existing file for read and write access. Any records written to the file will be added to the end of the file current file. If the file does not exist, it will be created.

The format specifies the type of the file. It can be one of ’LIST’, ’FORTRAN’ or ’NONE’ (for FIO_OPEN and FIO_ASSOC), ’FORMATTED’ (for RIO_OPEN and RIO_ASSOC), or ’UNFORMATTED’. ’LIST’ specifies that the first character in a record should not be interpreted as a carriage control character, and is usually what is needed to produce simple text files. ’FORTRAN’ specifies that the first character in a record will be interpreted as a carriage control character. This may be useful when producing reports that are to be printed on a line printer. The FORTRAN 77 standard says that output record that are to be printed will have their first characters interpreted as carriage control characters, and implies, but does not state explicitly, that output records that are not be be printed will not have their first characters interpreted as carriage control characters. Unfortunately, it is rather vague as to what the term printing actually means. An additional source of confusion is that a standard FORTRAN OPEN statement will create files that do cause the first character of each record to be interpreted as a carriage control character on VMS, but not on Unix. In fact, Unix has no concept of the type of a file, so files that have carriage control characters in them need to be passed through a filter (often called fpr) for the carriage control characters to have their desired effect.

A format of ’NONE’ specifies that there is no carriage control character. This differs from a format of ’LIST’ on VMS or Ultrix as the file will print on a single line when listed on a terminal or printed on a printer. On SunOS, a format of ’NONE’ has the same effect as ’LIST’. It is best to avoid this option whenever possible. In fact, for formatted, sequential access files (i.e. simple text files), it is best to use a format of ’LIST’ whenever possible.

A format of ’FORMATTED’ will produce a formatted direct access file with RIO_OPEN or RIO_ASSOC and a format of ’UNFORMATTED’ will always produce an unformatted file.

The record size is generally only needed for direct access files created by RIO_OPEN and RIO_ASSOC. In other cases it should be specified as zero, which causes FIO to use the default size of a record. In fact it is a violation of the FORTRAN 77 standard to give a record length when opening a sequential file. However, VMS requires the record length to be given when creating records that are longer than the default of 133 bytes. If a record length is given to an FIO routine on Unix, it will ignore it.