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.

PRINT *, 'The point lies inside the rectangle.'<br />

ELSE<br />

PRINT *, 'The point lies outside the rectangle.'<br />

END IF<br />

END PROGRAM main<br />

Program units and procedures<br />

Procedure interface<br />

Here are the command lines to compile and execute the program, along with the output from<br />

asamplerun:<br />

$ f90 def_op.f90<br />

$ a.out<br />

Enter two co-ordinates (integers) in a graph:<br />

4,8<br />

The point lies inside the rectangle.<br />

Defined assignment<br />

The ASSIGNMENT clause can be used with the INTERFACE statement to specify one or more<br />

subroutines that extend—or overload—the assignment operator. Each subroutine must have<br />

exactly two arguments. The first argument can have either the INTENT(OUT) or the<br />

INTENT(INOUT) attribute; the second argument must have the INTENT(IN) attribute. The<br />

first argument corresponds to the variable on the left-hand side of an assignment statement,<br />

and the second to the expression on the right-hand side.<br />

Similarly to generic names and defined operators, there can be more than one defined<br />

assignment, but each occurrence of the assignment statement must resolve to a unique,<br />

specific subroutine. The subroutine whose dummy arguments match the left-hand and<br />

right-hand sides of the assignment statement in kind, type, and rank is selected and invoked<br />

from the list of subroutines specified in the defined-assignment interface block.<br />

The following example, def_assign.f90, illustrates defined assignment. The assignment<br />

consists of performing an elementary statistical analysis of the data on the right-hand<br />

operand and storing the results in the left-hand operand. As noted in the comments, when a<br />

module is defined in the same file as any USE statements that references the module, the<br />

definition must lexically precede the USE statements. For information about modules and the<br />

USE statement, see “Modules” on page 158.<br />

Example 7-10 def_assign.f90<br />

! Note that, if a module definition and any USE statements that<br />

! reference the definition are in the same file, then the<br />

! definition must lexically precede the USE statements.<br />

MODULE def_assign_stats<br />

! Defines the derived-type operands and extends the assignment<br />

! operator to perform a statistical analysis of the data in<br />

! raw_data<br />

! input data<br />

Chapter 7 155

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

Saved successfully!

Ooh no, something went wrong!