Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28459 Discussions

generic interface from external procedures

efengle
Novice
310 Views

I am having trouble creating a generic interface.  I have a module that has something like this:

interface do_something
   module procedure do_something_real4
   module procedure do_something_char
end interface do_something

In my source directory, I have separate source files for subroutines do_something_real and do_something_char.  When I compile my library, I get the error #7950: Procedure name in MODULE PROCEDURE statement must be the name of accessible module procedure.

I have tried creating interfaces for these subroutines in the same module source, much like:

interface
   subroutine do_something_real4
   ...
   end subroutine do_something_real4
   subroutine do_something_char
   ...
   end subroutine do_something_char
end interface

but I still get compiler issues.  Any help is greatly appreciated.

 

0 Kudos
3 Replies
mecej4
Honored Contributor III
310 Views

Without additional declarations, the "_real4" and "_char" have no meanings yet. The compiler has to have the information necessary to disambiguate the generic name to the specific names based on the types of the variables in the argument list of a subroutine invocation. See examples such as the file ...\mkl\interfaces\blas95\source\blas_interfaces.f90 for guidance. Here is a short extract from that file:

INTERFACE F77_COPY
  PURE SUBROUTINE SCOPY(N,X,INCX,Y,INCY)
    INTEGER, PARAMETER :: WP = KIND(1.0E0)
    REAL(WP), INTENT(IN) :: X(*)
    REAL(WP), INTENT(INOUT) :: Y(*)
    INTEGER, INTENT(IN) :: INCX
    INTEGER, INTENT(IN) :: INCY
    INTEGER, INTENT(IN) :: N
  END SUBROUTINE SCOPY
  PURE SUBROUTINE DCOPY(N,X,INCX,Y,INCY)
    INTEGER, PARAMETER :: WP = KIND(1.0D0)
    REAL(WP), INTENT(IN) :: X(*)
    REAL(WP), INTENT(INOUT) :: Y(*)
    INTEGER, INTENT(IN) :: INCX
    INTEGER, INTENT(IN) :: INCY
    INTEGER, INTENT(IN) :: N
  END SUBROUTINE DCOPY

As you can see, when the generic name F77_COPY is called, the compiler will use the specific name SCOPY if the second and fourth arguments of single precision real, and will use DCOPY if they are double precision real, etc.

0 Kudos
FortranFan
Honored Contributor II
310 Views

Try this:

module m

   implicit none

   private

   interface do_something
      module procedure do_something_real4
      module procedure do_something_char
   end interface do_something

   public :: do_something

contains

   subroutine do_something_real4( rval )

      real, intent(in) :: rval

      print *, " rval = ", rval

      return

   end subroutine do_something_real4

   subroutine do_something_char( sval )

      character(len=*), intent(in) :: sval

      print *, " sval = ", sval

      return

   end subroutine do_something_char

end module m
program p

   use m, only : do_something

   implicit none

   call do_something( 0.0 )
   call do_something( "foo" )

   stop

end program p

 

0 Kudos
efengle
Novice
310 Views

So all this time I have been having this issue, I was using an older version of ifort (12.1).  I switched over the a more recent version (15.0.1) and issues have been resolved.  Thanks for the help.

0 Kudos
Reply