02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

CONTAINS<br />

CONTAINS<br />

Introduces an internal procedure or a module procedure.<br />

Syntax<br />

CONTAINS<br />

Description<br />

The CONTAINS statement introduces an internal procedure or a module procedure, separating<br />

it from the program unit that contains it. The statement can be used in:<br />

274<br />

A main program, external subprogram, or module subprogram; in each case, it precedes<br />

one or more internal procedures.<br />

A module, where it precedes any module procedures.<br />

When a CONTAINS statement is present, at least one subprogram must follow it.<br />

Examples<br />

The first example illustrates CONTAINS introducing an internal subroutine. It also illustrates<br />

how the internal subroutine mechanism can provide an alternative to the FORTRAN 77<br />

statement function mechanism.<br />

PRINT *, double_real(6.6)<br />

CONTAINS<br />

FUNCTION double_real (x); REAL x<br />

double_real = 2.0 * x<br />

END FUNCTION<br />

END<br />

The next example illustrates a main program with an internal procedure part.<br />

PROGRAM electric ! Program header<br />

REAL current ! Specification part<br />

current = 100.5 ! Execution part begins<br />

CALL compute_resistance( voltage, current, resistance )<br />

CONTAINS ! Internal procedure part<br />

SUBROUTINE compute_resistance( v, i, r )<br />

REAL i<br />

r = v / i<br />

END SUBROUTINE<br />

END PROGRAM electric<br />

Chapter 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!