UB Information Technology

Documentation

f90

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

Adobe Reader 7 for Windows

Platform: Windows

f90

Platform: UNIX

Introduction

Fortran 90 is compatible with FORTRAN 77 and can be viewed as FORTRAN 77 with additional language features.

The new features include memory allocation, array operations, automatic arrays, pointers, defined operators, derived types, overloaded operations, generic interfaces, optional arguments, and modules. These features make it easier to write, understand, maintain, and reuse FORTRAN code. It is also possible to implement concepts from object-oriented programming such as data encapsulation, function overloading, classes, objects, and inheritance in Fortran 90.

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

Setup

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

f90 Conventions

There are two source code forms in f90: fixed form and free form. The fixed form is the old FORTRAN 77 source code form which is based on the punched card. Files ending in .f, .for, or .ftn are taken to be fixed form source files. The free form is the new form which eliminates the column restriction and allows inline comments, long names, and several statements on the same line. Files ending in .f90 are free form source files.

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:
f90 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. Type the name of the executable file to run your program. Output will be sent to your terminal (standard output).

f90 Compilation Example

Use an editor such as Emacs or vi to type in the following program named hello.f90:

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

To compile the program and generate an executable file named hello, type:
f90 hello.f90 -o hello

This compiles hello.f90 and puts the executable in a file named hello. Execute the program by typing:
hello

The following is displayed:
Please type in your name:

Now type:
John

The following is displayed:
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 and outputfile is the name of the file that you want output to go to, 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 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 following in a file named inputfile:
John

Now on the command line, type:
hello < inputfile > outputfile

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

Command Line Options

Option Description
-c Compiles only.
-g Retains debugging information for 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 to the program.
-Mdir Specifies an additional location for module files (.M files).
-O Optimizes object code.

Using Libraries

A software library is usually a set of subprograms that have been previously compiled and organized into a single binary library file. Each member of the set is called a library element or module.

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

lib is the object library name. For example, to use a personal library such as libmylib, compile the program by typing:
f90 program.f -lmylib

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 when accessing data outside of defined array bounds.

Linking Mixed Fortran 90 and FORTRAN 77 Compilations

As a general rule, if any of the object files that make up a program were compiled with f90, then the final link step must be done with f90. Use f77 to produce the executable file only if none of the .o object files were compiled with f90.

I/O Compatibility

Note

I/O compatibility requires that Fortran 90 1.1 programs be linked with programs compiled with FORTRAN 77 4.0. That is, Fortran 90 1.1 I/O is not compatible with FORTRAN 77 3.0.1 or earlier.

Fortran 90 and FORTRAN 77 use different I/O libraries. However, this should be transparent to the user. Programs can input and output to the same unit from both the Fortran 90 and FORTRAN 77 parts of the code.

 

 

Additional Information

Program 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 type:
man f90

An informative online book, Fortran 90 for the FORTRAN 77 Programmer, is available at

http://www.nsc.liu.se/~boein/f77to90.

Related Documents

Document Information

Title: f90
Document Category:  UNIX
Document Number: UNX-007