Difference in allowing both subroutines and functions in an interface in Gfortran and Intel Fortran

Viewed 78

In Intel Fortran, I have following code running successfully (which relates to uniform random number generation)

module stats

implicit none
public :: runif
private :: runif_r, runif_r1
interface runif
    module procedure runif_r, runif_r1
end interface 

contains

!get uniform random vector using subroutine
subroutine runif_r(a,b,R) 
implicit none
real, intent(in) :: a,b 
real, intent(out) :: R(:)
call random_number(R)
R = a+(b-a)*R
end subroutine runif_r

!get one uniform random number using function
function runif_r1(a,b) result(r) 
implicit none
real, intent(in) :: a,b 
real r
call random_number(r)
r = a+(b-a)*r
end function runif_r1

end module stats


program test

! use stats
integer, parameter :: n=5
real :: x(n), x1

call runif(1.0, 3.0, x)
print*, x

x1 = runif(1.0, 3.0) 
print*, x1 

end program test

While I tried the code in gfortran, it says Error: In generic interface 'runif' at (1) procedures must be either all SUBROUTINEs or all FUNCTIONs te.f90:41.10:. I guess different compilers need different requests. How can I remedy this with as few changes as possible!

0 Answers
Related