User Tools

Site Tools


fortran

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fortran [2010/03/19 14:51]
zdech
fortran [2011/02/18 13:13] (current)
Line 1: Line 1:
 +**manual svn** [[http://​svnbook.red-bean.com/​en/​1.1/​ch03s05.html]]
 +
 +
 +
 ====== Pointers on functions and subroutines in Fortran ====== ====== Pointers on functions and subroutines in Fortran ======
  
-===== example: main.f90 =====+=== It works with both ifort 10 and gfortran-4.4 === 
 + 
 +===== example ​1: main.f90 =====
   module HelloWorld   module HelloWorld
   ​   ​
Line 35: Line 41:
    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
 +
 +==== output ====
 +  zdenka@pc209:​~/​simulations/​fireball/​ptr_func$ ifort -c main.f90 -o main.o;​ifort main.o -o test;./test
 +  Ahoj           ​1 ​  ​1.000000 ​   ​
 +  Nazdar ​          ​2 ​  ​2.000000 ​
  
-==== 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]]
  
fortran.1269006662.txt.gz · Last modified: 2011/02/18 13:14 (external edit)