UB Information Technology

Documentation

f77

Documentation print footer; appears at "bottom" of first page.

Adobe Reader 7 for Windows

Platform: Windows

f77

Platform: UNIX

Introduction

f77 is the FORTRAN compiler. It compiles FORTRAN programs into object files which are passed to the link editor to create an executable program. f77 is available on UBUnix.

Setup

Ensure that you are using the default system path, or that it has been included in your path.

f77 Conventions

The compiler name is f77. The filename of a FORTRAN program must have the extension of .f or .for. A comment in FORTRAN begins with C or * in column one, and continues through the end of the line. A completely blank line is also a comment line. Program statements start at column seven, and the default maximum line length is 72 columns. Statement continuation lines can be indicated by a nonblank, nonzero character in column six or an ampersand (&) in column one. Lines starting with a D in column one are compiled as debug lines. The convention for source code is uppercase, but this is not required. The compiler is not case-sensitive, except when assigning character string constants.

File Organization

Programs can be stored in multiple files by grouping sets of related functions into a file. Dividing the program into several logical parts can simplify the task of programming. Each file can be compiled separately, and linked together to create one executable file.

Compilation

To compile a program, use the following command:
f77 files -o exefile

files is a list of all program filenames separated by spaces. exefile is the name of the file that contains the executable. To run your program, type the name of the executable file. Output will be sent to your terminal (standard output).

f77 Compilation Example

Use an editor such as Emacs or vi to enter text for a program called hello.f:

      C This is a Comment Line.
PROGRAM HELLO
C This program greets the user.
CHARACTER NAME *8
C NAME is an 8 character string.
PRINT*, ’Please type in your name:’
READ*, NAME
C Read an 8 character string.
PRINT 5, NAME
5 FORMAT(’Hello ’, A)
C Print two strings.
END

To compile the program and generate an executable file called hello, enter:
f77 hello.f -o hello

This compiles hello.f and puts the executable in a file called hello. To execute the program, enter:
hello

The following will be displayed:
Please type in your name:

Now enter:
John

The program's response will be:
Hello John

Redirecting Input and Output

To redirect the output of a program to a file, use > after the executable file followed by the output filename. If hello is an executable file and outputfile is the name of the file to which you want output to go, use:
hello > outputfile

To redirect both errors and output, replace > with >&. In a similar way you can redirect a file to the standard input of a program. To do this, use < after the executable file followed by the input filename:
hello < inputfile

Input and output redirection can be used together. For example, you can use redirection on the above sample program. Put the previous example in a file named inputfile. Now at the command line, enter:
John

Now at the command line, enter:
hello < inputfile > outputfile

The input to the hello program comes from inputfile. The file outputfile then contains:
Hello John

Command Line Options

Option Description
-g Retains debugging information for use with debuggers such as dbx
-o filename Specifies the executable filename. If the -o option is not used, the executable is named a.out
-Ldir Places dir in the beginning of the library search path for compiler and loader
-lname Links library name into program
-O Optimizes object code

Using Libraries

Two common FORTRAN libraries are:

Library Description
m Mathematical functions
imsl IMSL math routines

 

To use functions in a library, link the library with your program. This is done by entering the -l command line option:
f77 program.f -llib

lib is the object library name. Some of the math and floating point library routines also require a header file to be included at the top of the program:
#include <lib.h>

lib is the library name. For example, to use double precision math functions, place the following at the top of your FORTRAN program:
#include <f77_floatingpoint.h>

Then compile the program by entering:
f77 program.f -lm

An executable named a.out is generated.

Runtime Errors

A runtime error is an error reported during program execution. A segmentation fault is a runtime error that occurs when an invalid memory address (such as Null) is referenced. Typically, these problems occur when using pointers or accessing data outside of defined array bounds.

Additional Information

Command Description
dbx A source level C debugger
make Maintains, updates, and regenerates related programs and files
rcs Revision control system; stores old versions of programs
ld Link Editor; links object files

 

To read the online manual page, at the UNIX prompt, enter:
man f77

Related Documents

Document Information

Title: f77
Document Category: UNIX
Document Number: UNX-006