Fortran User's Guide

A Quick Start

This section provides a quick overview of how to use the Sun Fortran compilers to compile and run Fortran programs. A full reference to command-line options appears in the next chapter.


Note -

The command line examples in this chapter primarily show f77 usages. Except where noted, equivalent usages of f90 are similarly valid; however, the printed output may be slightly different.


The very basic steps to running a Fortran application involve using an editor to create a Fortran source file with a .f, .for, .f90, .F, or .F90 filename suffix; invoking the compiler to produce an executable; and finally, launching the program into execution by typing the name of the file:

Example: This program displays a message on the screen:


demo% cat greetings.f
     PROGRAM GREETINGS
     PRINT *, 'Real programmers write Fortran!'
     END
demo% f77 greetings.f 
greetings.f:
  MAIN greetings:
demo% a.out 
 Real programmers write Fortran!
demo%

In the example, f77 compiles source file greetings.f and compiles the executable program onto the file, a.out, by default. To launch our program, the name of the executable file, a.out, is typed at the command prompt

Traditionally, UNIX compilers write executable output to the default file called a.out. It can be awkward to have each compilation write to the same file. Moreover, if such a file already exists, it will be overwritten by the next run of the compiler. Instead, use the -o compiler option to explicitly specify the name of the executable output file:


demo% f77 -o greetings greetings.f 
greetings.f: 
MAIN greetings: 
demo%

In the preceeding example, to -o option tells the compiler to write the executable code to the file greetings. (By convention, executable files usually are given the same name as the main source file, but without an extension.)

Alternatively, the default a.out file could be renamed via the mv command after each compilation. Either way, run the program by typing the name of the executable file:


demo% greetings 
 Real programmers write Fortran! 
demo%

The next sections of this chapter discuss the conventions used by the f77 and f90 commands, compiler source line directives, and other issues concerning the use of these compilers. The next chapter describes the command-line syntax and all the options in detail.