2.2 First Steps with Finite Differences
11
2.2.11 The First FORTRAN Code
Write a f rst FORTRAN code that prints “Hello World” on the display. This is an
old tradition among modellers. The solution is the code:
PROGRAM firs
write(6,
∗
)“Hello World”
END PROGRAM firs
FORTRAN programs start with a PROGRAM name statement and finis with a
END PROGRAM name statement. My program is called “first” but the reader is
free to choose a different name. Save this fil as “first f95”
2.2.12 How to Compile and Run FORTRAN Codes
Open the Command Prompt window (on Windows systems this is found under
Start => All Programs => Accessories => Command Prompt) and move to the
folder containing your FORTRAN source file
Step 1: Compile the program by entering the command:
g95 -o first. xe first f9
where “-o” specifie the name of the executable program.
Step 2: Correct errors until the compiler does not return any error messages.
Step 3: If the compiling process was successful, the newly created fil “first. xe”
can be executed by simply double-clicking its icon in a f le window or by
entering “first in the Command Prompt window.
The result of this will be the display of “Hello World” in the Command Prompt
window. Congratulations!
2.2.13 A Quick Start to FORTRAN
All constants, parameters, variables and arrays have to declared before use. Hereby,
full numbers called “integer” (−3, 0, 1, 3, etc.) are distinguished from decimal numbers called “real” (1.2, 4.2, −5.23, etc.). Other options are logical expressions (true
or false) and text (characters). Constant parameters are declared at the beginning of
the code with:
INTEGER, PARAMETER :: nx = 11 ! horizontal dimension
INTEGER, PARAMETER :: nz = 5 ! vertical dimension
11
2.2.11 The First FORTRAN Code
Write a f rst FORTRAN code that prints “Hello World” on the display. This is an
old tradition among modellers. The solution is the code:
PROGRAM firs
write(6,
∗
)“Hello World”
END PROGRAM firs
FORTRAN programs start with a PROGRAM name statement and finis with a
END PROGRAM name statement. My program is called “first” but the reader is
free to choose a different name. Save this fil as “first f95”
2.2.12 How to Compile and Run FORTRAN Codes
Open the Command Prompt window (on Windows systems this is found under
Start => All Programs => Accessories => Command Prompt) and move to the
folder containing your FORTRAN source file
Step 1: Compile the program by entering the command:
g95 -o first. xe first f9
where “-o” specifie the name of the executable program.
Step 2: Correct errors until the compiler does not return any error messages.
Step 3: If the compiling process was successful, the newly created fil “first. xe”
can be executed by simply double-clicking its icon in a f le window or by
entering “first
The result of this will be the display of “Hello World” in the Command Prompt
window. Congratulations!
2.2.13 A Quick Start to FORTRAN
All constants, parameters, variables and arrays have to declared before use. Hereby,
full numbers called “integer” (−3, 0, 1, 3, etc.) are distinguished from decimal numbers called “real” (1.2, 4.2, −5.23, etc.). Other options are logical expressions (true
or false) and text (characters). Constant parameters are declared at the beginning of
the code with:
INTEGER, PARAMETER :: nx = 11 ! horizontal dimension
INTEGER, PARAMETER :: nz = 5 ! vertical dimension
