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 14 of 17 Topic 8147 of 8774
Post > Topic >>

Re: Problems in passing a function to a subroutine

by pa@[EMAIL PROTECTED] (Pierre Asselin) Apr 19, 2008 at 01:45 PM

deltaquattro <deltaquattro@[EMAIL PROTECTED]
> wrote:
> On 17 Apr, 21:31, nos...@[EMAIL PROTECTED]
 (Richard Maine) wrote:
>>
>> [real function func(x,p) where x is the argument and
>>  p is a real array encapsulating a bunch of parameters]

> but in this way I have to modify the interface to func, and all the
> calls to func, in quad and in all the subroutines used by quad.

You have to modify all the calls to func that are made from quad.
You have to modify all the calls to quad.

Now if you want to integrate a function F(x), already written,
that gets its parameters from a module or a common block, you
*don't* have to rewrite F.  Just wrap it:

new code:
    real function F_wrap(x,ignored)
    real x
    real, dimension(:) ignored
    F_wrap= F(x)
    return
    end

modified code:
    program integrate
    real, dimension(1):: dummy		! added
    ...
!   call quad(F, a,b)			! before
    call quad(F_wrap, a,b, dummy)	! after


> Also,
> I have to pass the parameters down all the subroutines, isn't it? I
> mean

> program integrate

> call quad(func,a,b) --> call quad(func,a,b,p)

Yes, all the calls to quad.  If you don't like that you can make
the "p" argument to quad optional.  If present, quad can pass it
on to its func call, otherwise quad can pass a dummy array like
the integrate program did above.  It is your responsibility to pass
a "p" argument to quad when you integrate a function that expects
one, and to write an F_wrap when you want to integrate a function
that's already written and takes no extra argument.

For what it's worth, the rewrites are never a big deal to me.
They're tedious, but the compiler complains until you've caught
all the loose bits.  There's no intricate thinking involved
and there are only so many calls to edit.

-- 
pa at panix dot com
 




 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 Sun Oct 12 23:37:52 CDT 2008.