Guest User

Fortran Interface

a guest
Dec 26th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. [tmp]» cat test.f90 (evan@aeroevan:~/src/tmp)
  2. program test
  3. use test_mod, only: func
  4. implicit none
  5. real :: a
  6. integer :: b
  7.  
  8. a = func(1.0, 2.0)
  9. print *, a
  10.  
  11. b = func(1, 2)
  12. print *, b
  13. end program test
  14.  
  15. module test_mod
  16. interface func
  17. module procedure func_real, func_integer
  18. end interface func
  19. contains
  20. function func_real(x, y) result(z)
  21. real, intent(in) :: x, y
  22. real :: z
  23. print *, "Calling real function"
  24. z = x + y
  25. end function func_real
  26. function func_integer(x, y) result(z)
  27. integer, intent(in) :: x, y
  28. integer :: z
  29. print *, "Calling integer function"
  30. z = x + y
  31. end function func_integer
  32. end module test_mod
  33. [tmp]» gfortran -o test test.f90 (evan@aeroevan:~/src/tmp)
  34. [tmp]» ./test (evan@aeroevan:~/src/tmp)
  35. Calling real function
  36. 3.0000000
  37. Calling integer function
  38. 3
  39. [tmp]» (evan@aeroevan:~/src/tmp)
Advertisement
Add Comment
Please, Sign In to add comment