Please send all questions & assignments to:
hzeng@cset.sp.utoledo.edu

 

The f77 Compiler

When you telnet to the class server (et791.ni.utoledo.edu) and log into your account, you will have access to the GNU f77 FORTRAN compiler. This page provides you with the information needed to use the f77 compiler.

Compiling a FORTRAN 77 Program

The following commands can be used to compile a FORTRAN 77 program on the class server. In this example, the f77 utility is used to compile a FORTRAN 77 program named prog.for:

et791:~$ f77 prog.for
et791:~$ mv a.out prog
The f77 utility calls the GNU preprocessor, the FORTRAN 77 compiler, the assembler, and the link editor. The link editor creates an executable file named (by default) a.out. The second command renames a.out to prog. If you fail to rename the a.out file, the next use of the f77 utility will overwrite the executable file.

The compiler should produce an object-code file which has the appropriate UNIX permissions for an executable file. It is, however, worth checking the file to make certain that this is true. If it is not, the command below can be used to make the object code file (now named prog) executable so that you can run it and test it for logic and/or runtime errors.

et791:~$ chmod 755 prog
The -o argument (or parameter) can be used to speed up this process. The following two commands achieve the same results as the three above:
et791:~$ f77 -o prog prog.for
et791:~$ chmod 755 prog
With this approach, there is no need to rename the a.out executable file as it has not been generated! Instead, the object-code file has been named prog as specified by the -o argument.

Order is not importnat with the -o parameter. The following command is also valid.

et791:~$ f77 prog.for -o prog

GNU C and F77 Compilers

The C and F77 compilers are integrated; f77 is a program to call gcc with options to recognize programs written in Fortran (ANSI FORTRAN 77, also called F77). gcc processes input files through one or more of four stages: preprocessing, compilation, assembly, and linking. Source code filename extensions indicate the specific language:
.f
FORTRAN source code
.for
FORTRAN source code

For example, to compile the FORTRAN 77 program grades.for we could use the f77 command as shown below:

et791:~$ f77 grades.for

However, as with the f77 utility, a slightly more complex form of the command is both faster and more useful:

et791:~$ f77 -Wall -g grades.for -o grades

Each of the arguments in this command are explained as follows:

-Wall
instructs the f77 compiler to list all warning messages. These warning messages usually indicate programming errors, and we will ask for all possible warnings, as clues to what we might have done wrong.
-g
tells the compiler to generate special code that will allow us to use a debugger. We will introduce the debugger at a later time.
-o grades
indicate that the compiler should put its output (the "executable code") in a file called grades. If you do not specify a file name for the executable code, then the compiler places its result in a file named a.out.

Running a Program

It is important to remember that the compiler creates a file which is executable, meaning that you can run it by simply typing its name at the UNIX prompt.
et791:~$ program_name 
If you type the name of an executable file and it does not run (i.e., you get an error message) try typing a "./" (dot slash) followed by the program_name, and then press the [Enter] key.
et791:~$ ./program_name 
One of these two methods should work for you. Once the program is finished, you will see the UNIX prompt.

Note: The "./" is needed to run the program because of a "path" issue.

    Click on the button at left to return to the calling page.

 

There have been visitors since 11/26/2003

Added to the Web: September 1, 1999.
Last updated: October 2, 1999.
Web page design by Dan Solarek.

http://cset.sp.utoledo.edu/cset4250/