HP Fortran Programmer's Guide (B3908-90031; September 2011)

Compiling and linking
Special-purpose compilations
Chapter 286
How to use the -I and +moddir options to manage .mod files
Examples
Consider, for example, a program that consists of three files: main.f90, code.f90, and data.f90. The
main program unit is in main.f90, as follows.
Example 2-2 main.f90
PROGRAM keep_stats
! stats_code contains module procedures for operating
! on statistical database
USE stats_code
INTEGER :: n
! print prompt, using nonadvancing I/O
WRITE (*, FMT='(A)', ADVANCE='NO') 'Enter an integer '// &
'(hint: 77 is current average): '
READ *, n
IF (n == 0) THEN
PRINT *, 'But not that one.'
ELSE
CALL update_db(n)
IF (n >= get_avg()) THEN ! get_avg is in stats_code
PRINT *, 'Average or better.'
ELSE
PRINT *, 'Below average.'
END IF
END IF
END PROGRAM keep_stats
The first specification statement (USE) in the main program indicates that it uses the module stats_code.
This module is defined in code.f90, as follows:
Example 2-3 code.f90
! stats_code: a (partial!) package of module procedures for
! performing statistical operations
MODULE stats_code
! shared data to be used by procedures declared below
USE stats_db
CONTAINS ! module procedures
! update_db: updates shared variables in module stats_db
SUBROUTINE update_db (new_item)
INTEGER :: new_item
n_items = n_items +1