Question

I have an example code to test my understanding of overloading subroutines in Fortran 90. Here is my example:

   module testint_mod
    use constants
    implicit none

    private :: testvReal
    private :: testvdpn

   interface testv
     module procedure testvReal
     module procedure testvdpn
   end interface
   contains

   subroutine testvReal(vR)
     implicit none
     real,intent(in) :: vR
     write(*,*) vR
   end subroutine

   subroutine testvdpn(vdpn)
     implicit none
     real(kind=dpn),intent(in) :: vdpn
     write(*,*) vdpn
   end subroutine

   end module testint_mod


   program testintmain
    use constants
    use testint_mod
   implicit none
   real :: r
   real(kind=dpn) :: d
   integer :: i

   interface testv
    module procedure testvdpn
   end interface

   r = 2.0
   d = dble(4.0)
   call testv(r)
   call testv(d)

   end program testintmain

Where constants includes: integer,parameter dpn = selected_real_kind(14)

I get the error:

   testint_main.F(10) : Error: Unresolved MODULE PROCEDURE specification name.   [T
   ESTVDPN]
           module procedure testvdpn
   -------------------------^

What am I doing wrong? Is overloading a function with selected_real_kind() not allowed?? I appreciate any help!

Was it helpful?

Solution

The specification in the main program of interface testv is problematic: the compiler is complaining that testvdpn cannot be resolved in the main program - and there is indeed nothing publicly accessible by that name. Further, testv is already accessible through use association of the module testint_mod in which it is defined. These three lines should be removed.

To answer the question asked later

Is overloading a function with selected_real_kind() not allowed?

If two procedures in a generic set are distinguished only by the kind type parameter of a real argument, then it doesn't matter should one (or more) come from a selected_real_kind result. However, care should be taken that the kind parameters really are distinct. It may be, for example, that the selected_real_kind(14) of the example returns the same kind as that of default real. This, and similar cases, would not be permitted. Although the compiler would surely moan.

Note also, for completeness, that for functions (rather than the subroutines of the question) disambiguation must be solely by the functions' arguments, not the results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top