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

Problems Interfacing Fortran with C

JKrob1
Beginner
216 Views

All,

 

Got some Fortran code that needs to call a C subroutine. Below is the Fortran code:

 

SUBROUTINE DP_UGB2 ( idata, lendat, iarray, rarray, kxky, grid, iret )

C* Input parameters: *
C* IDATA (*) INTEGER Packed data *
C* LENDAT INTEGER Length of IDATA
C* IARRAY (4) INTEGER iuscal, kx, ky, iscan_mode *
C* RMSVAL (1) REAL Missing data value *
C* *
C* Output parameters: *
C* KXKY INTEGER Number of grid points *
C* GRID (KXKY) REAL Grid data *
C* IRET INTEGER Return code *
C* 0 = normal return *

C************************************************************************
use ISO_C_BINDING
use gemgrib2_list

INCLUDE 'GEMPRM.PRM'

INTEGER idata(*), iarray(*), lendat, iuscal, kx, ky, kxky,
+ iscan_mode, iret
REAL grid(*), rarray(*), rmsval

interface
  subroutine gb2_ugem (idata, iuscal, rmsval, kx, ky, iscan_mode,
+                                          kxky, grid, iret) bind(C,name='gb2_ugem')
    use, intrinsic :: iso_c_binding
    integer(c_int) :: idata(*)
    integer(c_int), value :: iuscal
    real(c_float), value :: rmsval
    integer(c_int), value :: kx 
    integer(c_int), value :: ky
    integer(c_int), value :: iscan_mode
    integer(c_int), value :: kxky
    real(c_float) :: grid(*)
    integer(c_int), value :: iret
  end subroutine gb2_ugem
end interface

LOGICAL DEBUG
COMMON /PDEBUG/ DEBUG

!C-----------------------------------------------------------------------
IF(DEBUG) write(25,*)'DP_UGB2 START'

iret = 0
kxky = 0

iuscal = iarray(1)
kx = iarray(2)
ky = iarray(3)
iscan_mode = iarray(4)
rmsval = rarray(1)

CALL gb2_ugem ( idata, iuscal, rmsval, kx, ky, iscan_mode,
+ kxky, grid, iret )


IF(DEBUG) write(25,*)'DP_UGB2 END'

RETURN
END

 

and here is the C routine being called:

 

void gb2_ugem( int idata[], int *iuscal, float *rmsval, int *kx,
int *ky, int *scan_mode, int *kxky, float grid[], int *iret )

 

Compiler responds with this error:

S-DPUGB2.FOR(33): error #6623: The procedure name of the INTERFACE block conflicts with a name in the encompassing scoping unit. [GB2_UGEM]

 

I thought I had the INTERFACE correct...but I guess not

 

Thanks in advance,

Jeff

0 Kudos
2 Replies
Arjen_Markus
Honored Contributor I
166 Views

I would look for other occurrences of the name "gb2_ugem" in the various modules you use. There is either a different routine with the same name or there is another interface block with that name.

0 Kudos
JohnNichols
Valued Contributor III
127 Views
SUBROUTINE DP_UGB2 ( idata, lendat, iarray, rarray, kxky, grid, iret )

C* Input parameters: *
C* IDATA (*) INTEGER Packed data *
C* LENDAT INTEGER Length of IDATA
C* IARRAY (4) INTEGER iuscal, kx, ky, iscan_mode *
C* RMSVAL (1) REAL Missing data value *
C* *
C* Output parameters: *
C* KXKY INTEGER Number of grid points *
C* GRID (KXKY) REAL Grid data *
C* IRET INTEGER Return code *
C* 0 = normal return *

C************************************************************************
use ISO_C_BINDING
use gemgrib2_list

INCLUDE 'GEMPRM.PRM'

INTEGER idata(*), iarray(*), lendat, iuscal, kx, ky, kxky,
+ iscan_mode, iret
REAL grid(*), rarray(*), rmsval

interface
  subroutine gb2_ugem (idata, iuscal, rmsval, kx, ky, iscan_mode,
+                                          kxky, grid, iret) bind(C,name='gb2_ugem')
    use, intrinsic :: iso_c_binding
    integer(c_int) :: idata(*)
    integer(c_int), value :: iuscal
    real(c_float), value :: rmsval
    integer(c_int), value :: kx 
    integer(c_int), value :: ky
    integer(c_int), value :: iscan_mode
    integer(c_int), value :: kxky
    real(c_float) :: grid(*)
    integer(c_int), value :: iret
  end subroutine gb2_ugem
end interface

LOGICAL DEBUG
COMMON /PDEBUG/ DEBUG

!C-----------------------------------------------------------------------
IF(DEBUG) write(25,*)'DP_UGB2 START'

iret = 0
kxky = 0

iuscal = iarray(1)
kx = iarray(2)
ky = iarray(3)
iscan_mode = iarray(4)
rmsval = rarray(1)

CALL gb2_ugem ( idata, iuscal, rmsval, kx, ky, iscan_mode,
+ kxky, grid, iret )


IF(DEBUG) write(25,*)'DP_UGB2 END'

RETURN
END
0 Kudos
Reply