10.07.2015 Views

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

PGI Fortran Reference manual - The Portland Group

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

Object Oriented Programmingfrom the binding-name. <strong>The</strong> procedure-name can be either a module procedure or an externalprocedure with an explicit interface.In the example SELECT TYPE construct, the binding-name is initialize. Becauseprocedure-name was not specified, an implicit procedure-name, initialize, isalso declared. Another way to write that example is procedure :: initialize =>initialize.Type-Bound Procedure using Module Procedure<strong>The</strong> following example is a type-bound procedure that uses a module procedure.module shape_modtype shapeinteger :: colorlogical :: filledinteger :: xinteger :: ycontainsprocedure :: initializeend type shapetype, extends(shape) :: rectangleinteger :: lengthinteger :: widthend type rectangletype, extends(rectangle) :: squareend type squarecontainssubroutine initialize(sh, color, filled, x, y, length, width)! initialize shape objectsclass(shape) :: shinteger :: colorlogical :: filledinteger :: xinteger :: yinteger, optional :: lengthinteger, optional :: widthsh%color = colorsh%filled = filledsh%x = xsh%y = yselect type (sh)type is (shape)! no further initialization requiredclass is (rectangle)! rectangle or square specific initializationsif (present(length)) thensh%length = lengthelsesh%length = 0endifif (present(width)) thensh%width = widthelsesh%width = 0endifclass default! give error for unexpected/unsupported typestop 'initialize: unexpected type for sh object!'end selectend subroutine initializeend module<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 127

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

Saved successfully!

Ooh no, something went wrong!