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 10 HP Fortran statements

CONTAINS

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Introduces an internal procedure or a module procedure.

Syntax

CONTAINS

Description

The CONTAINS statement introduces an internal procedure or a module procedure, separating it from the program unit that contains it. The statement can be used in:

  • A main program, external subprogram, or module subprogram; in each case, it precedes one or more internal procedures.

  • A module, where it precedes any module procedures.

When a CONTAINS statement is present, at least one subprogram must follow it.

Examples

The first example illustrates CONTAINS introducing an internal subroutine. It also illustrates how the internal subroutine mechanism can provide an alternative to the FORTRAN 77 statement function mechanism.

PRINT *, double_real(6.6)
CONTAINS
FUNCTION double_real (x); REAL x
double_real = 2.0 * x
END FUNCTION
END

The next example illustrates a main program with an internal procedure part.

PROGRAM electric     ! Program header
REAL current ! Specification part
current = 100.5 ! Execution part begins
CALL compute_resistance( voltage, current, resistance )
CONTAINS ! Internal procedure part
SUBROUTINE compute_resistance( v, i, r )
REAL i
r = v / i
END SUBROUTINE
END PROGRAM electric

The third example is of a module that contains a module subprogram, which in turn contains an internal subprogram.

MODULE one
CONTAINS
SUBROUTINE two(x) ! Module subprogram
CONTAINS
LOGICAL FUNCTION three(y) !Internal subprogram
END FUNCTION three
END SUBROUTINE two
END MODULE one

Related statements

SUBROUTINE and FUNCTION

Related concepts

For related information, see the following:

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