This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
fortran [2010/03/19 14:47] zdech |
fortran [2010/03/22 10:59] zdech |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Pointers on functions ====== | + | ====== Pointers on functions and subroutines in Fortran ====== |
- | ---- | + | === It works with both ifort and gfortran-4.4 === |
- | ===== example: main.f90 ===== | + | |
+ | ===== example 1: main.f90 ===== | ||
module HelloWorld | module HelloWorld | ||
+ | | ||
procedure(), pointer :: ptr | procedure(), pointer :: ptr | ||
+ | | ||
contains | contains | ||
| | ||
Line 35: | Line 37: | ||
Ahoj | Ahoj | ||
Nazdar 2 | Nazdar 2 | ||
+ | ===== Example 2: main.f90 ===== | ||
+ | module HelloWorld | ||
+ | |||
+ | procedure(Hello1), pointer :: ptr | ||
+ | | ||
+ | contains | ||
+ | | ||
+ | subroutine Hello1(a,b) | ||
+ | integer, intent(in) :: a | ||
+ | real, intent(in) :: b | ||
+ | print *,'Ahoj',a,b | ||
+ | end subroutine | ||
+ | | ||
+ | subroutine Hello2(a,b) | ||
+ | integer, intent(in) :: a | ||
+ | real, intent(in) :: b | ||
+ | print *,'Nazdar',a,b | ||
+ | end subroutine | ||
+ | | ||
+ | end module | ||
+ | | ||
+ | program main | ||
+ | use HelloWorld | ||
+ | |||
+ | ptr => Hello1 | ||
+ | call ptr(1,1.0) | ||
+ | |||
+ | ptr => Hello2 | ||
+ | call ptr(2,2.0) | ||
+ | end program | ||
- | ==== Links - new features in fortran 95/2003: ==== | + | ====== Links - new features in fortran 95/2003: ====== |
[[ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1648.pdf|The New Features of Fortran 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]] | [[http://www-users.york.ac.uk/~mijp1/COL/fortran_2003.pdf|Fortran 2003: the latest Fortran Standard]] | ||