Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Will W.
Date: Sep 1, 2008 21:02

The easy solution to this problem is to pass an internal function as
an argument, but of course that is not allowed in standard-conforming
Fortran 90+. What I mean by "internal function" is a function which
is CONTAINed by another function (or subroutine). Now just a little
more specific info so you can feel out the situation.

So what do I want to do?
------------------------------------
Say I want to create a module of integration routines in xy Cartesian
geometry for integrating a user-specified function, f(x,y) over a
polygon. Easy enough.

How do I want to do it?
---------------------------------
I want to use as many integration routines as I can find (e.g. in TOMS/
ACM/textbooks/etc) There is some great stuff out there, written in F77
especially. The difficulty comes in providing a "standardized"
interface to the various integration routines I have collected. I
don't want to go in and rewrite all those routines to accept f(x,y).
I want to write for each method a "wrapper function" of the form
(where ABC specifies some specific method--e.g. trapezoid rule):
Show full article (2.69Kb)
30 Comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Arjen Markus
Date: Sep 2, 2008 04:53

An intriguing question :).

I have not worked this out in any detail, but a half-forgotten
feature of FORTRAN 77 is the ENTRY statement. Basically, it defines
a facility that one would now probably use internal functions for,
but it might actually help here.

Something along these lines:

real function integrate_abc( f, n, pg, reltol )
... appropriate declarations

... preparation
call integabc( flocal, ... )
... completion
return

!
! Here it comes
!
entry flocal( pg )

flocal = f(pg)

end function
Show full article (0.96Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Arjen Markus
Date: Sep 2, 2008 07:01

On 2 sep, 13:53, Arjen Markus wrote:
> An intriguing question :).
>
> I have not worked this out in any detail, but a half-forgotten
> feature of FORTRAN 77 is the ENTRY statement. Basically, it defines
> a facility that one would now probably use internal functions for,
> but it might actually help here.
>
> Something along these lines:
>
> real function integrate_abc( f, n, pg, reltol )
>     ... appropriate declarations
>
>     ... preparation
>     call integabc( flocal, ... )
>     ... completion
>     return
>
> !
> ! Here it comes ...
Show full article (1.32Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Will W.
Date: Sep 2, 2008 07:08

On Sep 2, 10:01 am, Arjen Markus wrote:
> On 2 sep, 13:53, Arjen Markus wrote:
>
>
>
>> An intriguing question :).
>
>> I have not worked this out in any detail, but a half-forgotten
>> feature of FORTRAN 77 is the ENTRY statement. Basically, it defines
>> a facility that one would now probably use internal functions for,
>> but it might actually help here.
>
>> Something along these lines:
>
>> real function integrate_abc( f, n, pg, reltol )
>>     ... appropriate declarations
>
>>     ... preparation
>>     call integabc( flocal, ... )
>>     ... completion ...
Show full article (1.62Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Steve Lionel
Date: Sep 2, 2008 07:23

On Mon, 1 Sep 2008 21:02:59 -0700 (PDT), "Will W."
gmail.com> wrote:
>Side question
>--------------------
>Is there any possibility the ability to pass an internal function as
>an argument is going to be added to the standard?

This is in the current draft for Fortran 2008. Some compilers (e.g. Intel
Fortran) already support this.

--
Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"
Show full article (0.72Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Steve Lionel
Date: Sep 2, 2008 07:27

On Tue, 2 Sep 2008 04:53:56 -0700 (PDT), Arjen Markus
wrote:
>real function integrate_abc( f, n, pg, reltol )
> ... appropriate declarations
>
> ... preparation
> call integabc( flocal, ... )
> ... completion
> return
>
>!
>! Here it comes
>!
>entry flocal( pg )
>
> flocal = f(pg)
>
>end function
Show full article (0.86Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Dick Hendrickson
Date: Sep 2, 2008 08:02

Steve Lionel wrote:
> On Tue, 2 Sep 2008 04:53:56 -0700 (PDT), Arjen Markus
> wrote:
>
>> real function integrate_abc( f, n, pg, reltol )
>> ... appropriate declarations
>>
>> ... preparation
>> call integabc( flocal, ... )
>> ... completion
>> return
>>
>> !
>> ! Here it comes
>> !
>> entry flocal( pg )
>>
>> flocal = f(pg)
>>
>> end function ...
Show full article (1.03Kb)
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: Will W.
Date: Sep 2, 2008 08:28

On Sep 2, 10:23 am, Steve Lionel wrote:
> On Mon, 1 Sep 2008 21:02:59 -0700 (PDT), "Will W."
>
> gmail.com> wrote:
>>Side question
>>--------------------
>>Is there any possibility the ability to pass an internal function as
>>an argument is going to be added to the standard?
>
> This is in the current draft for Fortran 2008.  Some compilers (e.g. Intel
> Fortran) already support this.
GREAT. Do you happen to know as of which version it is supported for
Intel? We have 9.1 on our linux cluster and I would like to be able
to use it there. Thanks,
+W
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: James Van Buskirk
Date: Sep 2, 2008 09:26

"Will W." gmail.com> wrote in message
news:563f03fb-e1a2-4151-9686-b47b50fb39fb@56g2000hsm.googlegroups.com...
> On Sep 2, 10:23 am, Steve Lionel wrote:
>> On Mon, 1 Sep 2008 21:02:59 -0700 (PDT), "Will W."
>> gmail.com> wrote:
>>>Side question
>>>--------------------
>>>Is there any possibility the ability to pass an internal function as
>>>an argument is going to be added to the standard?
>> This is in the current draft for Fortran 2008. Some compilers (e.g.
>> Intel
>> Fortran) already support this.
> GREAT. Do you happen to know as of which version it is supported for
> Intel? We have 9.1 on our linux cluster and I would like to be able
> to use it there. Thanks,

Since approximately DVF.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
no comments
Re: Any suggested workarounds for writing wrappers for functions that are to be passed as arguments?         


Author: nospam
Date: Sep 2, 2008 09:49

Dick Hendrickson att.net> wrote:
> Steve Lionel wrote:
>> On Tue, 2 Sep 2008 04:53:56 -0700 (PDT), Arjen Markus
>> wrote:
...
>>> entry flocal( pg )
>> This is illegal - when entered through flocal, dummy argument f is not
>> allowed to be referenced since it is not in the dummy argument list of
>> flocal.
>
> It's also recursive. The function needs the RECURSIVE specifier.

Entry has a large number of "quirks" and special cases. At one time it
was on a list of features to be declared obsolescent. I don't recall
whether that survived the development process to date, but in any case,
I would not personally recommend using ENTRY for anything in new code. A
module provides a better way of doing most of this style of thing (where
two procedures share some of the same data).
Show full article (1.03Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Hypergeometric functions and beta functionssci.math ·
1 2 3 4