12
2 Motivation
REAL, PARAMETER :: G = 9.81 ! acceleration due to gravity
REAL, PARAMETER :: RHOREF = 1028.0 ! reference density
REAL, PARAMETER :: PI = 3.14159265359 ! pi
Text after a pronunciation mark is treated as a comment and ignored by the compiler. Although not required, comments are very useful aids to highlight the structure
of the program and as reminders for future uses. Parameters that are allowed to
change values during the program’s execution are declared with:
REAL :: wspeed ! wind speed
INTEGER :: k ! grid index
CHARACTER(3) :: txt
In this example, “txt” is a character with three letters. One-dimensional and twodimensional arrays are declared with:
REAL :: eta(0:nx+1) ! sea-level elevation
REAL :: w(0 nz+1,0:nx+1) ! vertical velocity
With nx=11 and nz = 5, for instance, “eta” obtains 11+2 = 13 so-far unassigned
elements: eta(0), eta(1), · · · ..., eta(11), eta(12), and “w” is a two-dimensional array
of 13 columns and 7 rows. After the declaration section, values can be assigned to
these arrays using DO loops such as:
DO k = 0,nx+1
IF(k > 50) THEN
eta(k) = 1.0
ELSE
eta(k) = 0.0
END IF
END DO
This DO-loop repeats certain calculations for the index “k” running from 0 at
steps of 1 to nx+1. If the reader wants to do it the other way around, the solution is:
DO k = nx+1,0,−1
IF(k > 50) THEN
eta(k) = 1.0
ELSE
eta(k) = 0.0
END IF
END DO
This example also includes an IF statement. Options are “>” (greater than), “<”
(less than), “==” (equal to), “>=” (greater or equal), “<=” (less or equal), and “/=”
2 Motivation
REAL, PARAMETER :: G = 9.81 ! acceleration due to gravity
REAL, PARAMETER :: RHOREF = 1028.0 ! reference density
REAL, PARAMETER :: PI = 3.14159265359 ! pi
Text after a pronunciation mark is treated as a comment and ignored by the compiler. Although not required, comments are very useful aids to highlight the structure
of the program and as reminders for future uses. Parameters that are allowed to
change values during the program’s execution are declared with:
REAL :: wspeed ! wind speed
INTEGER :: k ! grid index
CHARACTER(3) :: txt
In this example, “txt” is a character with three letters. One-dimensional and twodimensional arrays are declared with:
REAL :: eta(0:nx+1) ! sea-level elevation
REAL :: w(0 nz+1,0:nx+1) ! vertical velocity
With nx=11 and nz = 5, for instance, “eta” obtains 11+2 = 13 so-far unassigned
elements: eta(0), eta(1), · · · ..., eta(11), eta(12), and “w” is a two-dimensional array
of 13 columns and 7 rows. After the declaration section, values can be assigned to
these arrays using DO loops such as:
DO k = 0,nx+1
IF(k > 50) THEN
eta(k) = 1.0
ELSE
eta(k) = 0.0
END IF
END DO
This DO-loop repeats certain calculations for the index “k” running from 0 at
steps of 1 to nx+1. If the reader wants to do it the other way around, the solution is:
DO k = nx+1,0,−1
IF(k > 50) THEN
eta(k) = 1.0
ELSE
eta(k) = 0.0
END IF
END DO
This example also includes an IF statement. Options are “>” (greater than), “<”
(less than), “==” (equal to), “>=” (greater or equal), “<=” (less or equal), and “/=”
