The interface thing


alb
09-22-2006, 07:12 AM
Hello,

i need some help on the interface declaration of the function to be
integrated in qsimp.f90 and trapzd.f90.
It says:

INTERFACE
FUNCTION func(x)
USE nrtype
REAL(SP), DIMENSION(:), INTENT(IN) :: x
REAL(SP), DIMENSION(size(x)) :: func
END FUNCTION func
END INTERFACE

Now I tried to integrate the following function

FUNCTION test(m)
USE nrtype
IMPLICIT NONE
REAL(SP), DIMENSION(1) :: m
REAL(SP), DIMENSION(SIZE(m)) :: test
test = m**2
RETURN
END FUNCTION test

by calling

myres = QSIMP(test,-1.,1.)

The result however is NaN. Could anyone tell me what the function
has to look like to get the thing working?

Regards,
alb

gnunesjr
03-01-2007, 04:37 PM
This seems to be a pretty quiet forum.....

Your problem is that your are trying to set the size of m in your function. The routine trapzd will set the size of m (in some elegant, parallel, f90 kind of way).

In your function definition, in the line
REAL(SP), DIMENSION(1) :: m
replace the "1" with a ":" and everything will work fine.

(On my system, I do not get the NaN result, but a message from the nrerror routine. Are you not taking advantage of the full nr package?)