02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Program units and procedures<br />

Arguments<br />

Pointer dummy argument<br />

If the dummy argument has the POINTER attribute,theactualargumentmustalsohavethe<br />

POINTER attribute. Furthermore, they must match in kind, type, and rank. If the dummy<br />

argument does not have the POINTER attribute but the actual argument is a pointer, the<br />

argument association behaves as if the pointer actual argument were replaced by its target at<br />

the time of the procedure reference.<br />

Procedure dummy argument<br />

If a dummy argument is a procedure, the actual argument must be the name of an<br />

appropriate subprogram, and its name must have been declared as EXTERNAL in the calling<br />

unit or defined in an interface block (see “Procedure interface” on page 149). Internal<br />

procedures, statement functions, and generic names may not be passed as actual arguments.<br />

Iftheactualargumentisanintrinsicprocedure,theappropriatespecificnamemustbeused<br />

in the reference. It must have the INTRINSIC attribute.<br />

The following example, intrinsic_arg.f90, declares the intrinsics QSIN and QCOS with the<br />

INTRINSIC attribute so that they can be passed as arguments to the user-defined subroutine<br />

call_int_arg. Note that the dummy argument, trig_func, is declared in the subroutine<br />

with the EXTERNAL attribute to indicate that it is a dummy procedure. This declaration does<br />

not conflict with the declaration of the actual arguments in the main program unit because<br />

each occurs in different scoping units.<br />

Example 7-4 intrinsic_arg.f90<br />

PROGRAM main<br />

! declare the intrinsics QSIN and QCOS with the INTRINSIC<br />

! attribute to allow them to be passed as arguments<br />

REAL(16), INTRINSIC :: QSIN, QCOS<br />

CALL call_int_arg(QSIN)<br />

CALL call_int_arg(QCOS)<br />

END PROGRAM main<br />

SUBROUTINE call_int_arg(trig_func)<br />

! trig_func is an intrinsic function--see the declarations<br />

! of the actual arguments in the main program. trig_func<br />

! is declared here as EXTERNAL to indicate that it is a<br />

! dummy procedure.<br />

REAL(16), EXTERNAL :: trig_func<br />

REAL(16), PARAMETER :: pi=3.1415926<br />

INTEGER :: i<br />

142<br />

DO i = 0, 360, 45<br />

! Convert degrees to radians (i*pi/180) and call the<br />

Chapter 7

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

Saved successfully!

Ooh no, something went wrong!