HP Fortran Programmer's Reference (September 2007)

Program units and procedures
Procedure interface
Chapter 7 187
PRINT *, 'The point lies inside the rectangle.'
ELSE
PRINT *, 'The point lies outside the rectangle.'
END IF
END PROGRAM main
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 def_op.f90
$ a.out
Enter two co-ordinates (integers) in a graph:
4,8
The point lies inside the rectangle.
Defined assignment
The ASSIGNMENT clause can be used with the INTERFACE statement to specify one or more
subroutines that extend—or overload—the assignment operator. Each subroutine must have
exactly two arguments. The first argument can have either the INTENT(OUT) or the
INTENT(INOUT) attribute; the second argument must have the INTENT(IN) attribute. The
first argument corresponds to the variable on the left-hand side of an assignment statement,
and the second to the expression on the right-hand side.
Similarly to generic names and defined operators, there can be more than one defined
assignment, but each occurrence of the assignment statement must resolve to a unique,
specific subroutine. The subroutine whose dummy arguments match the left-hand and
right-hand sides of the assignment statement in kind, type, and rank is selected and invoked
from the list of subroutines specified in the defined-assignment interface block.
The following example, def_assign.f90, illustrates defined assignment. The assignment
consists of performing an elementary statistical analysis of the data on the right-hand
operand and storing the results in the left-hand operand. As noted in the comments, when a
module is defined in the same file as any USE statements that references the module, the
definition must lexically precede the USE statements. For information about modules and the
USE statement, see “Modules” on page 190.
Example 7-10 def_assign.f90
! Note that, if a module definition and any USE statements that
! reference the definition are in the same file, then the
! definition must lexically precede the USE statements.
MODULE def_assign_stats
! Defines the derived-type operands and extends the assignment
! operator to perform a statistical analysis of the data in
! raw_data
! input data