Print

Print


I recently wrote:

> I've been away from Fortran for a while (but am getting back to it), so
> I hope someone can spot my obvious error.
>
> I want to numerically integrate a function.  Here's some pseudocode:

Here's some real code which has the same problem, using NUMERICAL
RECIPES integration routines.  These are the Fortran90 versions; I've
successfully used the Fortran77 ones, so know what I'm doing in general.
Thus, it seems that I am missing something in Fortran90/95, or there is
a bug in the compiler.  Note that, in contrast to the Fortran77 case,
the user-supplied function to be integrated is in a module used by the
main program, as opposed to being an external function.

MODULE Q_TEST
USE NRTYPE
CONTAINS
FUNCTION Q(Z)
! same error whether using the commented-out lines or the two following
! them, so the problem is not the fancy dimension stuff
!REAL(SP), DIMENSION(:), INTENT(IN)  ::  Z
!REAL(SP), DIMENSION(SIZE(Z))  ::  Q
REAL(SP)  ::  Z
REAL(SP)  ::  Q
Q = 1.0/(1+Z)**3 ! the real integrand is more complicated :-)
END FUNCTION Q
END MODULE Q_TEST

PROGRAM TEST
USE Q_FUNC
USE NRTYPE
USE NR, ONLY: QTRAP, QSIMP, QROMB
IMPLICIT NONE
REAL(SP)  ::  INTEGRAL, A, B
READ*, A, B
INTEGRAL = QTRAP(Q,A,B)
INTEGRAL = QSIMP(Q,A,B)
INTEGRAL = QROMB(Q,A,B)
END PROGRAM TEST

The error messages are like:

%F90-E-ERROR, The characteristics of the associated actual function
result differ from the characteristics of the dummy function result.
(12.4.1.2, 12.2.2)   [Q]

There must be some simple change which will get rid of the error message
above!

(I like the references to the standard in the error message, but they
don't help me here.)