For the code
module norm_mod
implicit none
private
public :: l2_norm
intrinsic :: norm2
interface l2_norm
procedure :: norm2, norm2_int
end interface l2_norm
contains
function norm2_int(v) result(vnorm)
integer, intent(in) :: v(:)
real :: vnorm
integer :: n
n = size(v)
vnorm = sqrt(real(sum(v**2)))
end function norm2_int
end module norm_mod
!
program test_norm
use norm_mod, only: l2_norm
implicit none
integer, allocatable :: v(:)
v = [10,20,30]
print*,l2_norm(v)
print*,norm2(real(v))
print*,l2_norm(real(v))
end program test_norm
gfortran says
interface_procedure.f90:26:7:
26 | print*,l2_norm(real(v))
| 1
Error: There is no specific function for the generic 'l2_norm' at (1)
I thought it would use the intrinsic norm2 in this case, since it is one of the procedures in the interface of l2_norm. If I comment out line 26 the program compiles and runs fine, so my version of gfortran does implement norm2.
Beliavsky schrieb am Freitag, 18. Februar 2022 um 18:59:37 UTC+1:
For the code
module norm_mod
implicit none
private
public :: l2_norm
intrinsic :: norm2
interface l2_norm
procedure :: norm2, norm2_int
end interface l2_norm
contains
function norm2_int(v) result(vnorm)
integer, intent(in) :: v(:)
real :: vnorm
integer :: n
n = size(v)
vnorm = sqrt(real(sum(v**2)))
end function norm2_int
end module norm_mod
!
program test_norm
use norm_mod, only: l2_norm
implicit none
integer, allocatable :: v(:)
v = [10,20,30]
print*,l2_norm(v)
print*,norm2(real(v))
print*,l2_norm(real(v))
end program test_norm
gfortran says
interface_procedure.f90:26:7:
26 | print*,l2_norm(real(v))
| 1
Error: There is no specific function for the generic 'l2_norm' at (1)
I thought it would use the intrinsic norm2 in this case, since it is one of the procedures in the interface of l2_norm. If I comment out line 26 the program compiles and runs fine, so my version of gfortran does implement norm2.Your code runs afoul of a F2018 constraint dealing with procedure names appearing in named interfaces:
C1508 (R1507) A procedure-name shall denote a nonintrinsic procedure that has an explicit interface.
Regards
Reinhold
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 99:37:55 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,786 |