Clicky

Fortran Wiki
interface_mod (changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #0 to #1: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

A simple Fortran 2003 example illustrating how one can define common procedure interfaces in a module and reuse them elsewhere.

! A module containing function interfaces
module interfaces
 implicit none
 abstract interface
 real function func(x)
 real :: x
 end function func
 end interface
end module interfaces
! A module containing a function which implements func
module functions
 implicit none
contains
 real function square(x)
 real :: x
 square = x*x
 end function square
end module functions
! A simple control program showing how to use the func interface
program main
 use interfaces
 use functions
 implicit none
 call print_func(square)
contains
 subroutine print_func(f)
 procedure(func) :: f
 print *, f(0.0)
 end subroutine print_func
end program main

Jason Blevins (7 May 2009) I wrote this example just to test the concept. I think the abstract interface and the procedure statement in print_func are the only places where the Fortran 2003 standard is needed. Is there any way to accomplish the same thing in Fortran 95 without duplicating the interface (and without using include)? I suppose the answer is probably no, and this is the reason that abstract interfaces were defined in Fortran 2003.

category: code

Created on May 7, 2009 16:58:24 by Jason Blevins (152.3.10.27) (1352 characters / 0.0 pages)
Edit | Views: Print | TeX | Source | Linked from: Code

AltStyle によって変換されたページ (->オリジナル) /