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


|