External Procedure

Steve Lionel (Intel)
Total Points:
115,325
Status Points:
115,325
Black Belt
July 4, 2009 6:20 AM PDT
Rate
 
|Best Answer
#3 Reply to #2
Oh, sorry, I misunderstood your question.

The Fortran 77 way is this:

subroutine callit (func, arg)
external func
integer func, arg
print *, func(arg)
end subroutine callit
When you call callit and pass your own function as the func argument, callit will call your function.

The Fortran 90 way is this:

subroutine callit (func, arg)
interface
  integer function func (arg)
  integer, intent(in) : arg
  end function func
end interface
integer, intent(in) :: arg
print *, func(arg)
end subroutine callit
This is wordier, true, but it provides more information to the compiler.  In particular, if callit is in a module, the compiler can check to make sure that the function you pass has the correct interface.

There's a Fortran 2003 way as well, with the new PROCEDURE declaration, but that's for another day.



Intel Software Network Forums Statistics

8488 users have contributed to 31627 threads and 100752 posts to date.
In the past 24 hours, we have 33 new thread(s) 138 new posts(s), and 198 new user(s).

In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to Crash when loading skeleton The post with the most views is Dear Steve, excuse me for a d

Please welcome our newest member chat1983