4.2 Long Surface Gravity Waves
75
END MODULE decla
The module “calcu” reads:
MODULE calcu
USE decla
CONTAINS
!+++++++++++++++++++++++++++++++++++++++++++
SUBROUTINE init
x = 2.0
y = 1.0
RETURN
END SUBROUTINE init
!+++++++++++++++++++++++++++++++++++++++++++
SUBROUTINE squaresum
real :: sum ! declaration of local variable
sum = x+y
z = sum
∗
sum
RETURN
END SUBROUTINE squaresum
END MODULE calcu
As the reader learns from this example, modules can be used to share parameters,
variables and subroutines. With sound use of modules, subroutines, and functions,
FORTRAN codes can attain a much clearer structure.
4.2.14 Structure of the Following FORTRAN Codes
FORTRAN codes of the following exercises consist of three files a main code,
one module for declarations and another module comprising subroutines (Fig. 4.8).
Compiling a FORTRAN code that contains modules consists of two steps. The modules are compiled f rst with:
g95 -c file2 f9 f le3.f95
Then, the module f les can be linked with the main code via:
g95 -o run.exe file1.f9 f le2.o f le3.o
The code can then be executed by entering “run.exe” in the Command Prompt
window.
75
END MODULE decla
The module “calcu” reads:
MODULE calcu
USE decla
CONTAINS
!+++++++++++++++++++++++++++++++++++++++++++
SUBROUTINE init
x = 2.0
y = 1.0
RETURN
END SUBROUTINE init
!+++++++++++++++++++++++++++++++++++++++++++
SUBROUTINE squaresum
real :: sum ! declaration of local variable
sum = x+y
z = sum
∗
sum
RETURN
END SUBROUTINE squaresum
END MODULE calcu
As the reader learns from this example, modules can be used to share parameters,
variables and subroutines. With sound use of modules, subroutines, and functions,
FORTRAN codes can attain a much clearer structure.
4.2.14 Structure of the Following FORTRAN Codes
FORTRAN codes of the following exercises consist of three files a main code,
one module for declarations and another module comprising subroutines (Fig. 4.8).
Compiling a FORTRAN code that contains modules consists of two steps. The modules are compiled f rst with:
g95 -c file2 f9 f le3.f95
Then, the module f les can be linked with the main code via:
g95 -o run.exe file1.f9 f le2.o f le3.o
The code can then be executed by entering “run.exe” in the Command Prompt
window.
