Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: Problems in...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 15 of 17 Topic 8147 of 8656
Post > Topic >>

Re: Problems in passing a function to a subroutine

by Charles Coldwell <coldwell@[EMAIL PROTECTED] > Apr 18, 2008 at 02:03 PM

glen herrmannsfeldt <gah@[EMAIL PROTECTED]
> writes:

> Ron Shepard wrote:
>>  deltaquattro <deltaquattro@[EMAIL PROTECTED]
> wrote:
>
>>>However, the function to be integrated depends on many parameters, not
>>>only on x. How can I pass it to quad? Is it better to modify the
>>>interface in quad (and all the subroutines called by quad), or to
>>>create a module containing func and all the modules needed by it? Have
>>>you ever met a similar problem? Thanks
>
>> This is the standard interface problem.  Do not modify your quad()
>> subroutine.  If you do that, then you might as well not even use the
>> dummy subroutine, you could just hardwire the call to your specific
>> code, eliminating all advantages of having a modular reusable quad()
>> routine for numerical integration.
>
> (Snip on the use of COMMON or MODULE to pass static data
> between routines.)
>
> Note, though, that neither COMMON or MODULE allows for reentrant
> calls.  If, for example, one wanted to integrate a function inside
> a recursive routine one would have to be very careful.
>
> Even more, some have done double integrals through calling routines
> like quad from inside the called function.  The Fortran 66 solution
> to such problems was more than one copy of quad, each with a different
> name.  (quad1, quad2, etc.) and more variables in COMMON.
>
> Quoting Richard Maine from a thread on Fortran templates:
>
>   "I agree that something like templates can be useful in
>   some situations.  But note that, depending on details,
>   the particular scenario described above can usually be
>   handled better in other ways. Typically, all you need
>   is an equivalent of a C void pointer, along with the data
>   size.  Then you can do it all in a single procedure, with
>   no need for templates. I've done this exact thing for a
>   long time, as I also have Fortran code that p***** data
>   via sockets. So have other people. This one is done a lot."
>
> In a method related to the one Richard mentions, quad
> could be written to accept a single variable, either a
> C void pointer or unlimited polymorphic,
> and pass this variable onto the called routine.

That would be called a "thunk" or "continuation" in other programming
languages ....

Chip

-- 
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"
GPG Key ID: 852E052F
GPG Key Fingerprint: 77E5 2B51 4907 F08A 7E92  DE80 AFA9 9A8F 852E 052F
 




 17 Posts in Topic:
Problems in passing a function to a subroutine
deltaquattro <deltaqua  2008-04-17 03:00:56 
Re: Problems in passing a function to a subroutine
Arjen Markus <arjen.ma  2008-04-17 04:26:52 
Re: Problems in passing a function to a subroutine
deltaquattro <deltaqua  2008-04-17 04:55:53 
Re: Problems in passing a function to a subroutine
Arjen Markus <arjen.ma  2008-04-17 05:12:26 
Re: Problems in passing a function to a subroutine
Ron Shepard <ron-shepa  2008-04-17 11:53:52 
Re: Problems in passing a function to a subroutine
glen herrmannsfeldt <g  2008-04-17 10:31:11 
Re: Problems in passing a function to a subroutine
nospam@[EMAIL PROTECTED]   2008-04-17 12:07:48 
Re: Problems in passing a function to a subroutine
nospam@[EMAIL PROTECTED]   2008-04-17 12:31:54 
Re: Problems in passing a function to a subroutine
glen herrmannsfeldt <g  2008-04-17 12:02:53 
Re: Problems in passing a function to a subroutine
"jamesgiles@[EMAIL P  2008-04-17 12:50:54 
Re: Problems in passing a function to a subroutine
deltaquattro <deltaqua  2008-04-18 05:08:42 
Re: Problems in passing a function to a subroutine
nospam@[EMAIL PROTECTED]   2008-04-18 08:26:29 
Re: Problems in passing a function to a subroutine
deltaquattro <deltaqua  2008-04-18 07:01:08 
Re: Problems in passing a function to a subroutine
pa@[EMAIL PROTECTED] (Pi  2008-04-19 13:45:06 
Re: Problems in passing a function to a subroutine
Charles Coldwell <cold  2008-04-18 14:03:31 
Re: Problems in passing a function to a subroutine
nospam@[EMAIL PROTECTED]   2008-04-18 08:41:23 
Re: Problems in passing a function to a subroutine
glen herrmannsfeldt <g  2008-04-18 08:15:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Aug 30 8:24:19 CDT 2008.