User Tools

Site Tools


fortran

This is an old revision of the document!


Pointers on functions and subroutines in Fortran

example: main.f90

module HelloWorld

  procedure(), pointer :: ptr

  contains

  subroutine Hello1()
    print *,'Ahoj'
  end subroutine

  subroutine Hello2(a)
    integer, intent(in) ::  a
    print *,'Nazdar',a
  end subroutine

end module

program main
  use HelloWorld
  implicit none

  ptr => Hello1
  call ptr

  ptr => Hello2
  call ptr(2)

end program

output:

zdenka@pc209:~/simulations/fireball/ptr_func$ ifort -c main.f90 -o main.o;ifort main.o -o test;./test
 Ahoj
 Nazdar           2
fortran.1269006662.txt.gz · Last modified: 2011/02/18 13:14 (external edit)