This shows you the differences between two versions of the page.
fortran [2010/03/19 15:02] zdech |
fortran [2011/02/18 13:13] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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 | ||
- | |||
- | ===== It works with both ifort and gfortran-4.4 ===== | ||
- | |||
- | |||
- | ====== Links - new features in fortran 95/2003: ====== | ||
- | [[ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1648.pdf|The New Features of Fortran 2003]] | ||
- | |||
- | [[http://www-users.york.ac.uk/~mijp1/COL/fortran_2003.pdf|Fortran 2003: the latest Fortran Standard]] | ||