HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Procedure interface
Chapter 7186
! operands, as well as the derived types
! Define a derived type for the co-ordinates of a point
! in a graph
TYPE coord_pt
INTEGER :: x, y
END TYPE coord_pt
! define a derived type for the co-ordinates of a rectangle
TYPE rect_coords
TYPE(coord_pt) :: p1, p2
END TYPE rect_coords
! Interface block to define the logical operator .inrect.
! Evaluates to .TRUE. if the point operand lies inside
! the rectangle operand
INTERFACE OPERATOR (.inrect.)
MODULE PROCEDURE cmp_coords
END INTERFACE
CONTAINS
LOGICAL FUNCTION cmp_coords(pt, rect)
! returns .TRUE. if pt is inside rect
! arguments
TYPE (coord_pt), INTENT (IN) :: pt
TYPE (rect_coords), INTENT (IN) :: rect
cmp_coords = .FALSE. ! initialization
IF (pt%x >= rect%p1%x .AND. pt%x < rect%p2%x &
.AND. pt%y >= rect%p1%y .AND. pt%y < rect%p2%y) &
cmp_coords = .TRUE. ! pt is inside rect
END FUNCTION cmp_coords
END MODULE coord_op_def
PROGRAM main
! make the defined operation and the derived-type definitions
! of the operands accessible to this program unit
USE coord_op_def
! specify a value for the rectangle co-ordinates
TYPE (rect_coords) :: rectangle = &
rect_coords(coord_pt(3, 5), coord_pt(7, 10))
TYPE (coord_pt) :: point ! user will specify value for this
PRINT *, 'Enter two co-ordinates (integers) in a graph:'
READ *, point
! perform defined operation
IF (point .inrect. rectangle) THEN