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 Programmingprocedures must be implemented by the user of the abstract type and what may or may not beoverridden. You can add the deferred binding to type-bound procedures that are not defined inthe abstract type, but these must be defined in all of its non-abstract type extensions. F2003 alsorequires that a deferred binding have an interface (or an abstract interface) associated with it.You use the following syntax for deferred bindings:procedure (interface-name), deferred :: procedure-nameBecause deferred bindings have an interface associated with them, there is no => followed by animplementation-name allowed in the syntax. For example, procedure, deferred :: foo=> bar is not allowed.<strong>The</strong> following module includes an integerList which extends the abstract type, list,previously defined.module integer_list_mod:type, extends(list) :: integerListcontainsprocedure :: addIntegerprocedure :: printList => printIntegerListgeneric :: add => addIntegerend type integerList:end module integer_list_modIn this example, printList() is defined as required by the deferred binding in list. You canuse the following implementation for the printList() type-bound procedure:subroutine printIntegerList(this)class(integerList) :: thisclass(*), pointer :: currcall this%reset() ! reset list iteratordo while(this%moreValues()) ! loop while there are values to printcurr => this%currentValue() ! get current valueselect type(curr)type is (integer)print *, curr ! print the integerend selectcall this%nextValue() ! increment the list iteratorend docall this%reset() ! reset list iteratorend subroutine printIntegerListprintIntegerList() prints the integers in the list. <strong>The</strong> list reset() procedure verifies thatthe list iterator is at the beginning of the list. <strong>The</strong>n the subroutine loops through the list, callingthe list's moreValues() function to determine if our list iterator has reached the end of thelist. <strong>The</strong> list's currentValue() function gets the value to which the list iterator is pointing. Aselect type accesses the integer value and prints it. Finally, the list's nextValue() procedureincrements the list iterator to access the next value.<strong>The</strong> following sample program uses the abstract list and integerList types. <strong>The</strong>sample program adds the integers one through ten to the list and then calls the integerList'sprintList() procedure. Next, the program traverses the list, places the integers into anarray, and then prints out the array. You can download the complete abstract_list_mod andinteger_list_mod modules from the <strong>PGI</strong> website.<strong>PGI</strong> <strong>Fortran</strong> <strong>Reference</strong> Guide 147

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

Saved successfully!

Ooh no, something went wrong!