Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 7 Program units and procedures

Internal procedures

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

An internal procedure is similar to an external procedure except that:

  • It must be defined within a hosting program unit—a main, external, or module program unit—following the CONTAINS statement.

  • It can be referenced by the host only.

  • It can access other entities by host association within the host.

  • It cannot have an ENTRY statement.

  • It cannot be passed as an argument.

  • It cannot contain an internal procedure.

The syntax of an internal procedure definition is the same as for an external procedure (see “Procedure definition”), except that it has no internal procedure part. The reference to an internal procedure is the same as for an external procedure; see “Procedure reference”.

The following example, int_func.f90, declares and references an internal function. Note that both the external procedure and the internal procedure have an assumed-shape array as a dummy argument, which requires the procedure to have an explicit interface (see “Procedure interface”). External procedures must be declared in an interface block to make their interface explicit; the interface of internal procedures is explicit by default.

Example 7-2 int_func.f90

PROGRAM main

! declare and initialize an array to pass to an external
! procedure
REAL, DIMENSION(3) :: values = (/2.0, 5.0, 7.0/)

! Because the dummy argument to print_avg is an assumed-shape
! array (see the definition of print_avg below), the
! procedure interface of print_avg must
! be made explicit within the calling program unit.

INTERFACE
SUBROUTINE print_avg(x)
REAL :: x(:)
END SUBROUTINE print_avg
END INTERFACE

CALL print_avg(values)
END PROGRAM main

! print_avg is an external subprogram
SUBROUTINE print_avg(x)
REAL :: x(:) ! an assumed-shape array

! reference the internal function get_avg
PRINT *, get_avg(x)

CONTAINS ! start of internal procedure part
REAL FUNCTION get_avg(a) ! get_avg is an internal procedure
! The interface of an internal procedure is explicit within
! the hosting unit, so this function may declare a as an
! assumed-shape array.
REAL a(:) ! an assumed-shape array

! references to the SUM and SIZE intrinsics
get_avg = SUM(a) / SIZE(a)
END FUNCTION get_avg

END SUBROUTINE print_avg

Here are the command lines to compile and execute the program, along with the output from a sample run:

$ f90 int_func.f90
$ a.out
4.66667
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.