DIGITAL Fortran 90
User Manual for
DIGITAL UNIX Systems


Previous Contents Index

7.4.3.2 Record Overhead

Record overhead refers to bytes associated with each record that are used internally by the file system and are not available when a record is read or written. Knowing the record overhead helps when estimating the storage requirements for an application. Although the overhead bytes exist on the storage media, do not include them when specifying the record length with the RECL specifier in an OPEN statement.

The various record types each require a different number of bytes for record overhead, as described in the following table:
Record Type Organization Record Overhead
Fixed-length Sequential files None.
Fixed-length Relative files None if the -vms option was omitted (the default). One byte if the -vms option was specified.
Variable-length Sequential files Eight bytes per record for overhead.
Segmented Sequential files Four bytes per record for overhead. One additional padding byte (space) is added if the specified record size is an odd number.
Stream Sequential files None required.
Stream_CR Sequential files One byte per record for overhead.
Stream_LF Sequential files One byte per record for overhead.

7.4.3.3 Maximum Record Length

The maximum record length is 2.147 billion bytes (2,147,483,647 minus the bytes for record overhead). When considering very large record sizes, also consider limiting factors like system virtual memory.

For More Information

7.4.4 Other File Characteristics

Other file characteristics include:

When you need to display or print formatted data that uses Fortran carriage control, consider using the fpr command as a filter through a pipe to reformat the records into operating system line printer format.

The units used for specifying record length depend on the form of the data:

For More Information:

7.5 File Operations: OPEN, INQUIRE, CLOSE Statements

This section discusses considerations for opening a file (OPEN statement), obtaining file characteristics and run-time attributes (INQUIRE statement), and closing a file (CLOSE statement).

7.5.1 Opening Files: The OPEN Statement

To open a file, you should use a preconnected file (such as for terminal output) or explicitly OPEN files. Although you can also implicitly open a file, this prevents you from using the OPEN statement to specify the file connection characteristics and other information.

7.5.1.1 Using Preconnected Standard I/O Files

If you do not use an OPEN statement to open logical unit 5, 6, or 0 and do not set the appropriate environment variable (FORTn), unit number 5 is associated with stdin , unit 6 with stdout , and unit 0 with stderr . At run time, DIGITAL Fortran 90 implicitly opens (preconnects) units 5, 6, and 0 and associates them with their respective operating system standard I/O files if the corresponding FORTn environment variable is not set.

You can change these preconnected files by using one of the following:

Table 7-4 lists the DIGITAL Fortran 90 environment variables and the standard I/O file associations for the preconnected files.

Table 7-4 Preconnected Files and Environment Variables
Unit DIGITAL Fortran 90 Environment Variable Equivalent DIGITAL UNIX Standard I/O File
5 FORT5 Standard input, stdin
6 FORT6 Standard output, stdout
0 FORT0 Standard error, stderr

To change the characteristics of the connection to a preconnected unit, explicitly open the preconnected unit number.

To redirect input or output from the standard preconnected files at run-time, you can set the appropriate DIGITAL Fortran 90 I/O environment variable (see Section 7.5.1.7) or use the appropriate shell redirection character in a pipe (such as > or <).

For More Information:

7.5.1.2 OPEN Statement Specifiers

The OPEN statement connects a unit number with an external file and allows you to explicitly specify file attributes and run-time options using OPEN statement specifiers. Once you open a file, you should close it before opening it again unless it is a preconnected file.

If you open a unit number that was opened previously (without being closed), one of the following occurs:

You can use the INQUIRE statement (see Section 7.5.2) to obtain information about a whether or not a file is opened by your program.

Especially when creating a new file using the OPEN statement, examine the defaults (see the description of the OPEN statement in the DIGITAL Fortran Language Reference Manual) or explicitly specify file attributes with the appropriate OPEN statement specifiers.

Table 7-5 lists the OPEN statement functions and their specifiers.

Table 7-5 OPEN Statement Functions and Specifiers
Category, Functions, and OPEN Statement Specifiers
Identify File and Unit
  UNIT specifies the logical unit number.
  FILE (or NAME 1) and DEFAULTFILE 1 specify the directory and/or file name of an external file.
  STATUS or TYPE 1 indicates whether to create a new file, overwrite an existing file, open an existing file, or use a scratch file.
  STATUS or DISPOSE 1 specifies the file existence status after CLOSE.
File and Record Characteristics
  ORGANIZATION 1 indicates the file organization (sequential or relative).
  RECORDTYPE 1 indicates which record type to use.
  FORM indicates whether records are formatted or unformatted.
  CARRIAGECONTROL 1 indicates the terminal control type.
  RECL or RECORDSIZE 1 specifies the record size (see Section 7.4.4).
Special File Open Routine
  USEROPEN 1 names the routine that will open the file to establish special context that changes the effect of subsequent DIGITAL Fortran 90 I/O statements (see Section 7.7).
File Access, Processing, and Position
  ACCESS indicates the access mode (direct or sequential).
  SHARED 1 indicates that other users can access the same file and activates record locking. Ignored in the current version of DIGITAL Fortran 90 for DIGITAL UNIX Systems (see Section 7.6.2).
  POSITION indicates whether to position the file at the beginning of file, before the end-of-file record, or leave it as is (unchanged).
  ACTION or READONLY 1 indicates whether statements will be used to only read records, only write records, or both read and write records.
  MAXREC 1 specifies the maximum record number for direct access.
  ASSOCIATEVARIABLE 1 specifies the variable containing next record number for direct access.
Record Transfer Characteristics
  BLANK indicates whether to ignore blanks in numeric fields.
  DELIM specifies the delimiter character for character constants in list-directed or namelist output.
  PAD, when reading formatted records, indicates whether padding characters should be added if the item list and format specification require more data than the record contains.
  BLOCKSIZE 1 specifies the block physical I/O buffer size.
  BUFFERCOUNT 1 specifies the number of physical I/O buffers.
  CONVERT 1 specifies the format of unformatted numeric data (see Chapter 10).
Error Handling Capabilities
  ERR specifies a label to branch to if an error occurs.
  IOSTAT specifies the integer variable to receive the error (IOSTAT) number if an error occurs.
File Close Action
  DISPOSE identifies the action to take when the file is closed.


1This specifier is a DIGITAL Fortran extension

For More Information:

7.5.1.3 Methods to Specify the Unit, File Name, and Directory

You can choose to assign files to logical units by using one of the following methods:

The following sections discuss these methods.

7.5.1.4 Accessing Files: Implied and Explicit File and Pathnames

Most I/O operations involve a disk file, keyboard, or screen display. Other DIGITAL UNIX devices can also be used:

For information on USEROPEN routines, see Section 7.7.

You can access the terminal screen or keyboard by using preconnected files, as described in Section 7.5.1. Otherwise, this chapter discusses disk files.

A complete file specification consists of a file name usually preceded by a pathname that specifies a directory. The pathname can be in one of two forms:

Directory names and file names should not contain any operating system wildcard characters (such as *, ?, and the [ ] construct). You can use the tilde (~) character as the first character in a pathname to refer to a top-level directory as in the C shell.

When specifying files, keep in mind that trailing and leading blanks are removed from character expression names, but not from Hollerith (numeric array) names.

File names are case sensitive and can consist of uppercase and lowercase letters. For example, the following file names represent three different files:


   myfile.for 
   MYfile.for 
   MYFILE.for 

You can associate a logical unit with a directory (if needed) and file name by using an environment variable assignment (see Section 7.5.1.7) or by using the OPEN statement (see Section 7.5.1.6). When an OPEN statement provides a pathname that contains only a directory (no file name) and an environment variable provides the file name, the OPEN statement and environment variable can work together to provide the complete directory and file name.

7.5.1.5 How DIGITAL Fortran 90 Applies a Default Pathname and File Name

DIGITAL Fortran 90 provides the following possible ways of specifying all or part of a file specification (directory and file name), such as /usr/proj/testdata :

DIGITAL Fortran 90 recognizes environment variables for each logical I/O unit number in the form of FORTn, where n is the logical I/O unit number. If a file name is not specified in the OPEN statement and the corresponding FORTn environment variable is not set for that unit number, DIGITAL Fortran 90 generates a file name in the form fort.n , where n is the logical unit number.

Certain DIGITAL Fortran 90 environment variables are recognized and preconnected files exist for certain unit numbers, as described in Section 7.5.1.7.

When using scratch files, you can use the TMPDIR environment variable to specify where the scratch file gets created (see Section 7.4.2).

Performing an implied OPEN means that the FILE and DEFAULTFILE specifier values are not specified and an environment variable is used, if present.

Examples of Applying Default Pathnames and File Names

For example, for an implied OPEN of unit number 3, DIGITAL Fortran 90 would check the environment variable FORT3. If the environment variable FORT3 was set, its value is used. If it is not set, the system supplies the file name fort.3 .

In Table 7-6, assume the current directory is /usr/smith and the I/O uses unit 1, as in the statement READ (1,100).

Table 7-6 Examples of Applying Default Pathnames and File Names
OPEN FILE
Value
OPEN DEFAULTFILE Value FORT1 Environment
Variable Value
Resulting Pathname
not specified not specified not specified /usr/smith/fort.1 (1)
not specified not specified test.dat /usr/smith/test.dat (2)
not specified not checked /usr/tmp/t.dat /usr/tmp/t.dat (3)
not specified /tmp not specified /tmp/fort.1 (4)
not specified /tmp testdata /tmp/testdata (5)
not specified /usr lib/testdata /usr/lib/testdata (6)
file.dat /usr/group not checked /usr/group/file.dat (7)
/tmp/file.dat not checked not checked /tmp/file.dat (8)
file.dat not specified not specified /usr/smith/file.dat (9)


Previous Next Contents Index