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

Chapter 16: Software Development

16.5 FORTRAN Programming

There is some additional information about using FORTRAN in the UNIX environment that you will find useful to know.

16.5.1 External Reference and Entry Point Names

In order to avoid conflicts with the C runtime library when FORTRAN and C programs are included in a single program, most UNIX f77 compilers internally append an underscore to FORTRAN external references and entry point names. At Fermilab we have set up all f77 compilers to do this by default.

16.5.2 Separate Compilation of FORTRAN Subprograms: fsplit

By default, most f77 compilers pre-link all the source code being compiled, even when you specify the -c option. If you compile a library with a single f77 statement, it will usually contain a single module, and be linked as a whole.

The fsplit utility identifies and extracts subprograms from the original FORTRAN source file into individual files in the current directory. These files can then be compiled separately so that they retain their identity when assembled into a library.

The names of the extracted individual files are taken from their corresponding subprogram names. On some systems fsplit will overwrite any pre-existing file, including the original source file, whose name matches any of the subprogram names.

See the man pages for more information on fsplit.

16.5.3 AIX-Specific Issues

You must CALL EXIT to avoid having a STOP message printed on stdout at program termination.

The OPEN statement parameter READONLY is unavailable. All files are opened with WRITE access. This makes file sharing problematic under AIX.

16.5.4 Loading Block Data Modules

Many UNIX f77 compilers enforce the standard restriction that variables in COMMON must be initialized only in BLOCKDATA subprograms.

To ensure the loading of BLOCKDATA subprograms from libraries, declare the BLOCKDATA program name as EXTERNAL in some important module which you know will be loaded.

16.5.5 Program Control

Command Line Arguments

A FORTRAN program can easily evaluate arguments included on the command line that runs the program. A couple of examples follow.

N = IARGC ()

Sets N to the number of command line arguments

CALL GETARG(I , STR)

Puts the I'th argument into string STR

Environment Variables

The GETENV subprogram provides the values of environment variables. For example, to copy the value of variable MY_OUT into string OUTFILE, include in your source file:

CALL GETENV ( 'MY_OUT' , OUTFILE )

Printing

The usual FORTRAN carriage control characters placed in the first column of formatted output files are not interpreted by most UNIX text handling utilities. Use the UNIX asa utility to convert such FORTRAN output files to an equivalent standard ASCII text form. asa handles blanks, 0, 1 and + in column 1, removing any other characters. See the man pages for asa for details.

16.5.6 Future FORTRAN Enhancements

AIX XLF 3

This document describes the AIX XLF 2 compiler. IBM's standard f77 compiler, XLF 3, is not yet available at Fermilab.

FORTRAN 90

The FORTRAN 90 standard includes FORTRAN 77 as a subset, and makes standard many of the extensions in common use. FORTRAN 90 is not yet commonly installed at Fermilab, and in fact we recommend that you avoid using FORTRAN 90 extensions until it is widely available. This document is written for f77 users.


UNIX at Fermilab - 10 Apr 1998

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