KIND and Interface Block

I’m Trying to create an interface block for coupling a F90 code to a c subroutine library- we had been doing it with inline compiler directives at the location of the call, but I am trying to move it to an interface block in a module, that I would then USE…

 

      MODULE CInterface

      INTEGER, parameter :: ki4   = SELECTED_INT_KIND(9)
      INTEGER, parameter :: kindr = SELECTED_REAL_KIND(12) 

     INTERFACE
!
         SUBROUTINE xginst(text,sz,length,x1,y1)
            INTEGER(KIND=ki4):: sz,length
            CHARACTER(LEN=*) :: text
            REAL(kindr) :: x1,y1  
            !DEC$ ATTRIBUTES STDCALL :: xginst     
            !DEC$ ATTRIBUTES REFERENCE :: xginst   
         END SUBROUTINE xginst  
       END INTERFACE

      END MODULE CInterface

The problem is that it is not allowing parameters in the interface block, and I believe that not all of the compilers we use support the same integer values for sizes-

error S0087 : Non-constant expression where constant expression required
error S0081 : Illegal selector - KIND parameter has unknown value for data type

Does anyone know of a method that works to use parametric KINDs in an Interface Block?

-Russ Johns

Hi Russ,

This is a scoping issue. Meaning that the module’s parameters can not be seen within the interface. So you’ll either need to add the declaration of ki4 and kindr to each subroutine or better yet, put ki4 and kindr in their own module. For example:

      MODULE mykinds

      INTEGER, parameter :: ki4   = SELECTED_INT_KIND(9)
      INTEGER, parameter :: kindr = SELECTED_REAL_KIND(12)

      end module mykinds

      MODULE CInterface

      INTERFACE

         SUBROUTINE xginst(text,sz,length,x1,y1)
            use mykinds
            INTEGER(KIND=ki4):: sz,length
            CHARACTER(LEN=*) :: text
            REAL(kindr) :: x1,y1
            !DEC$ ATTRIBUTES STDCALL :: xginst
            !DEC$ ATTRIBUTES REFERENCE :: xginst
         END SUBROUTINE xginst
       END INTERFACE

      END MODULE CInterface

Hope this helps,
Mat