[Next] [Previous] [Up] [Top] [Contents] [Index]

Chapter 16: Software Development

16.7 C and FORTRAN I/O

This section mainly applies to FORTRAN. For C, all you need to know is that the RBIO and DAFT libraries mentioned below are available.

Recall that file names in UNIX are case sensitive. It is customary to use lower case for normal files, reserving upper case names like README for documentation and control files.

Note that you cannot use the shell metacharacter tilde (~) to specify a home directory within a C or FORTRAN program; ~ is valid only on a UNIX shell command line (for all shells but sh). logdir can be used within programs for this purpose (see section 6.1.2).

16.7.1 Records

The UNIX operating system treats a disk file as a sequence of bytes. Interpretation of data as records is entirely up to individual applications. The FORTRAN I/O libraries provide the necessary record handling for FORTRAN programs. READ statements return only the content of the records, and not the control words mentioned below.

Formatted records are terminated by a new-line character <Ctrl-l> (lower case L), consistent with other UNIX text handling programs.

Unformatted records are both preceded and followed by a 32 bit integer containing an exclusive byte count.

16.7.2 Tapes

Tapes of course have real physical records, and must be handled differently than disk files. A tape file is sometimes called 'character special' to indicate that it is not accessed on a character-by-character basis. Tape handling is covered in Chapter 15.

There are no industry-wide standard tape I/O routines callable from FORTRAN. Fermilab makes use of several locally-written packages, including:

RBIO

labeled and directoried tape access (see document SU0033)

DAFT

raw binary tape access (see document PN0504)

You can find C and FORTRAN examples in Appendix B of the DAFT User's Guide, document PN0504.

16.7.3 Standard Input and Output

In conformance with the FORTRAN standard, READs and WRITEs to unit * are directed to stdin and stdout. You can READ and WRITE to units 5, 6, and 0 without an OPEN. They are preconnected to stdin, stdout, and stderr, respectively. If you OPEN and write to any other unit number # without specifying a file name, a default name of fort.# will be used.


UNIX at Fermilab - 10 Apr 1998

[Next] [Previous] [Up] [Top] [Contents] [Index]