Skip to content

Instantly share code, notes, and snippets.

@Sharpie
Created March 30, 2010 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sharpie/349107 to your computer and use it in GitHub Desktop.
Save Sharpie/349107 to your computer and use it in GitHub Desktop.
Demonstration of using Fortran 2003 procedure pointers
program procTest
implicit none
integer :: n
interface
function forced()
integer:: forced
end function forced
function ideal()
integer:: ideal
end function ideal
function oseen()
integer:: oseen
end function oseen
end interface
procedure(forced), pointer:: funPointer => NULL()
write(*,'(A)') "Please enter the type of vortex calculation you wish to use."
read(*,*) n
select case( n )
case( 1 )
funPointer => forced
case( 2 )
funPointer => ideal
case DEFAULT
funPointer => oseen
end select
write(*,'(A,I3)') "You chose function: ", funPointer()
stop
end program
function forced()
implicit none
integer:: forced
forced = 1
return
end function forced
function ideal()
implicit none
integer:: ideal
ideal = 2
return
end function ideal
function oseen()
implicit none
integer:: oseen
oseen = 3
return
end function oseen
@cameronbracken
Copy link

Sweet! Had no idea about this. What is the deal with it being a fortran 2003 thing? Which version of gfortran supports this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment