FORTRAN Programs on Linux/Unix: Guide for Aerospace Students, Study Guides, Projects, Research of Aerospace Engineering

Instructions for creating an executable file from a fortran text (.f90) file on standard linux/unix systems, such as those used in aerospace engineering. It covers the basics of compiling a fortran main program using the ifort compiler, legal filenames, and error messages. It also explains how to run the compiled program and compile a program with modules.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/02/2009

koofers-user-6yd-1
koofers-user-6yd-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
D. Haugli, Lecturer Aer E 160 Aerospace Engineering
9/12/2005 Compiling & Running Programs, Page 1 Iowa State University
Compiling & Running Programs
This document describes how to create an executable file from a FORTRAN text (.f90) file on
any standard Linux/Unix system (such as the Aerospace Engineering servers). An executable
file contains binary commands that the computer interprets to run a program.
This document assumes the reader is logged onto a Linux or Unix server.
Main Programs. To compile a FORTRAN main program, issue the command:
command prompt$ <insert compiler name> <insert main program name.f90>
The name of the compiler on the Aerospace Engineering servers is ifort. On Project Vincent
(isua.iastate.edu), the compiler is named f90. The program must be saved as standard
ASCII text in a file ending with .f90. Filenames must start with a letter, and may contain any
combination of letters, numbers and the underscore character; no other characters are allowed.
Example 1. Assume the following files contain FORTRAN programs. The
following names would be legal:
hello.f90 main.f90 program1.f90 Prob_1.f90
(Note: Unix and Linux are case sensitive, so Prob_1.f90 differs from prob_1.f90.)
The following names would be illegal:
hello.txt.f90 1.f90 prob3-1.f90 _pro.f90
Example 2. Assume the prompt looks like this: bash-3.0$. Compile the
program hello.f90 at the command prompt using the ifort compiler.
bash-3.0$ ifort hello.f90 <enter>
bash-3.0$
The second prompt in Example 2 would appear after the compiler successfully compiled
hello.f90. If the file had contained errors, a list of error messages would have appeared instead.
Generally, the first error in a list of errors causes some of the later errors; the later errors will be
eliminated when the first error is fixed. An “error” (sometimes called a “fatal error”) is so severe
that the compiler cannot create an executable file; A “warning” means that an executable file can
be created, but the compiler found evidence that something might not be correct in the code.
pf3

Partial preview of the text

Download FORTRAN Programs on Linux/Unix: Guide for Aerospace Students and more Study Guides, Projects, Research Aerospace Engineering in PDF only on Docsity!

D. Haugli, Lecturer Aer E 160 Aerospace Engineering

Compiling & Running Programs

This document describes how to create an executable file from a FORTRAN text (.f90) file on any standard Linux/Unix system (such as the Aerospace Engineering servers). An executable file contains binary commands that the computer interprets to run a program.

This document assumes the reader is logged onto a Linux or Unix server.

Main Programs. To compile a FORTRAN main program, issue the command:

command prompt$

The name of the compiler on the Aerospace Engineering servers is ifort. On Project Vincent (isua.iastate.edu), the compiler is named f90. The program must be saved as standard ASCII text in a file ending with .f90. Filenames must start with a letter, and may contain any combination of letters, numbers and the underscore character; no other characters are allowed.

Example 1. Assume the following files contain FORTRAN programs. The following names would be legal:

hello.f90 main.f90 program1.f90 Prob_1.f

(Note: Unix and Linux are case sensitive, so Prob_1.f90 differs from prob_1.f90.)

The following names would be illegal:

hello.txt.f90 1.f90 prob3-1.f90 _pro.f

Example 2. Assume the prompt looks like this: bash-3.0$. Compile the program hello.f90 at the command prompt using the ifort compiler.

bash-3.0$ ifort hello.f90 bash-3.0$

The second prompt in Example 2 would appear after the compiler successfully compiled hello.f90. If the file had contained errors, a list of error messages would have appeared instead. Generally, the first error in a list of errors causes some of the later errors; the later errors will be eliminated when the first error is fixed. An “error” (sometimes called a “fatal error”) is so severe that the compiler cannot create an executable file; A “warning” means that an executable file can be created, but the compiler found evidence that something might not be correct in the code.

D. Haugli, Lecturer Aer E 160 Aerospace Engineering

Example 3. Here is an example in which the command PROGRAM in first line of hello.f90 is misspelled. The code is:

PROGRM hello WRITE (,) “Hello World!” STOP END PROGRAM hello

Here is the command to compile the program, followed by the error messages from the compiler:

bash-3.0$ ifort hello.f fortcom: Error: hello.f90, line 1: Syntax error, found IDENTIFIER 'HELLO' when expecting one of: => =. ( : % PROGRM hello -------^ fortcom: Error: hello.f90, line 4: This name does not match the unit name. [HELLO] END PROGRAM hello ------------^ compilation aborted for hello.f90 (code 1)

In this case, the compiler could not exactly determine the error, but recognized that the error occurred in the first line of the program. When that line is corrected, the second error goes away, and the compile command is immediately followed by a second prompt:

bash-3.0$ ifort hello.f bash-3.0$

When the compiler successfully compiles a program, it creates a binary executable file named a.out in the same folder as the program. To run the program, type ./a.out (followed by ) at the command prompt.

Example 4. To run the program hello.f90 (after correctly compiling it, as in Example 3), the command and output appear as:

bash-3.0$ ifort hello.f bash-3.0$ ./a.out Hello World! bash-3.0$