numerical recipes compile question
THOMAS Paul Richard
prthomas@drfccad.cea.fr
Tue Jan 25 14:43:00 GMT 2005
I believe that the problem goes back a way and is related to
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16940 .
The fix given there works in your case too - comment out the IMPLICIT NONE
in the second line and your get rid of the no implicit type message and
pick up four correct warnings about the functions not returning values.
Adding a small test programme demonstrates that the module works...... as
long as you do not return an outerdiff(a,b) result to a temporary. See below
and PR19561.
Paul T
MODULE nrutil
! IMPLICIT NONE ! fix used in PR16940
INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
INTEGER, PARAMETER :: LGT = KIND(.true.)
INTEGER, PARAMETER :: SP = KIND(1.0)
INTEGER, PARAMETER :: DP = KIND(1.0D0)
INTERFACE outerdiff
MODULE PROCEDURE outerdiff_r,outerdiff_d,outerdiff_i
END INTERFACE
CONTAINS
FUNCTION arth_i(first,increment,n)
INTEGER(I4B), INTENT(IN) :: first,increment,n
INTEGER(I4B), DIMENSION(n) :: arth_i
arth_i = 1
END FUNCTION arth_i
!BL
FUNCTION outerdiff_r(a,b)
REAL(SP), DIMENSION(:), INTENT(IN) :: a,b
REAL(SP), DIMENSION(size(a),size(b)) :: outerdiff_r
outerdiff_r = 2.0
END FUNCTION outerdiff_r
!BL
FUNCTION outerdiff_d(a,b)
REAL(DP), DIMENSION(:), INTENT(IN) :: a,b
REAL(DP), DIMENSION(size(a),size(b)) :: outerdiff_d
outerdiff_d = 3.0
END FUNCTION outerdiff_d
!BL
FUNCTION outerdiff_i(a,b)
INTEGER(I4B), DIMENSION(:), INTENT(IN) :: a,b
INTEGER(I4B), DIMENSION(size(a),size(b)) :: outerdiff_i
outerdiff_i = 4
END FUNCTION outerdiff_i
!BL
FUNCTION lower_triangle(j,k,extra)
INTEGER(I4B), INTENT(IN) :: j,k
INTEGER(I4B), OPTIONAL, INTENT(IN) :: extra
LOGICAL(LGT), DIMENSION(j,k) :: lower_triangle
INTEGER(I4B) :: n
lower_triangle=(outerdiff(arth_i(1,1,j),arth_i(1,1,k)) > -n)
END FUNCTION lower_triangle
END MODULE nrutil
PROGRAM test
USE nrutil
REAL :: x(2) , y(3) , ans(2,3)
ans = outerdiff (x,y) !works fine
PRINT *, ans
PRINT *, outerdiff (x,y) !seg faults
END PROGRAM test
produces
$ ./a
2.000000 2.000000 2.000000 2.000000 2.000000
2.000000
Segmentation fault (core dumped)
More information about the Fortran
mailing list