- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm new to Intel's Fortran compiler v10. My past experience was with F90/F95 with Absoft compiler on Linux box. I'm trying to define the Fortran interface to the following C++ function compiled using MS VS 2005 on WinXP x64 box:
typedef int ExitStatus;
typedef void* OoModtranHandle;
extern ExitStatus __stdcall SETCARD2C1(OoModtranHandle h,
float *zm,
float *p,
float *t,
float *wmol2c1[],
char *pType,
char *tType,
char *mType[],
int ml,
float *wmol2c2[],
float *wmol2c2x[],
char *mXType);
Any assisstance would be greatly appreciated
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the C code is in a lib project to be called by IVF then interfaceare generated via /gen-interfaces andend up in the F90's folder as X.mod.f90's.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim is correct that x64 does not support __stdcall, though I think you can still use the keyword.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Silly me, you're quite right, Fortran can generate interfaces for its own functions and not for C and these have to be hand rolled.
Incidentally, why do the Fortran interfaces ignore INTENT? It would handy if they handled this attribute.
Any chance of a basic sample on C interop?
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, a sample using the C interop features would be a good idea - I also plan to write a "Dr. Fortran" article about it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
interface
function SETCARD2C1 (h, zm, p, t, wmol2c1, pType, tType, mType, &
ml, wmol2c2, wmol2c2x, mXtype)
use ISO_C_BINDING
integer(C_INT) :: SETCARD2C1
!DEC$ ATTRIBUTES STDCALL,REFERENCE,DECORATE,ALIAS:"SETCARD2C1" :: SETCARD2C1
type(C_PTR), intent(INOUT) :: h
real(C_FLOAT), intent(INOUT) :: zm
real(C_FLOAT), intent(INOUT) :: p
real(C_FLOAT), intent(INOUT) :: t
real(C_FLOAT), dimension(*), intent(INOUT) :: wmol2c1
character(*), intent(INOUT) :: pType
!DEC$ ATTRIBUTES REFERENCE :: pType
character(*), intent(INOUT) :: tType
!DEC$ ATTRIBUTES REFERENCE :: tType
character(*), intent(INOUT) :: mType
!DEC$ ATTRBUTES REFERENCE :: mType
integer(C_INT), VALUE, intent(IN) :: ml
real(C_FLOAT), dimension(*), intent(INOUT) :: wmol2c2
real(C_FLOAT), dimension(*), intent(INOUT) :: wmol2c2x
character(*), intent(INOUT) :: mXType
!DEC$ ATTRIBUTES REFERENCE :: mXType
end function SETCARD2C1
end interface
To explaijn some of this. The ATTRIBUTES directive for the function is strictly not needed on x64, but this will ensure portability to IA-32 if need be. The character arguments need the REFERENCE attribute for each one to prevent a length from being passed. I added INTENT attributes from guesses, but I'd recommend changing these to IN or OUT where appropriate.
The "h" argument is declared in C as a pointer to VOID, or in other words, a "handle". There are various ways of representing this in Fortran but I chose to use type C_PTR, declared in ISO_C_BINDING, here. There are other choices, but this one is probably closest to the origiinal intent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The module generated for
subroutine
for2 [Alias:'_for2'] ( i, r, c, d )implicit none
complex, intent(inout) :: c[REFERENCE] double precision, intent(inout) :: d[REFERENCE] integer, intent(inout) :: i[REFERENCE] real, intent(inout) :: r[REFERENCE]< stuff >
returnend
, where theINTENT of all arguments is specified, is
!COMPILER-GENERATED INTERFACE MODULE: Wed Oct 03 11:55:33 2007
MODULE FOR2_mod
INTERFACE
SUBROUTINE FOR2(I,R,C,D)
INTEGER(KIND=4) :: I
REAL(KIND=4) :: R
COMPLEX(KIND=4) :: C
REAL(KIND=8) :: D
END SUBROUTINE FOR2
END INTERFACE
END MODULE FOR2_mod
in which there is no mention of INTENT.
Where are Dr Fortran newsletters available? I haven't seen one for eons.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Thanks for the help. I do need togenerate both IA-32 and x64 versions of the code.All the variables are inputs to a wrapper we're using to connect some legacy Fortran with a new C++ version of MODTRAN. The example was the worst case interface.
I'm also interested in reading the Dr Fortran articles.
Thanks again,
Dick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're using an old compiler version. With the current 10.0.027 I get:
!COMPILER-GENERATED INTERFACE MODULE: Wed Oct 03 13:33:21 2007
MODULE FOR2_mod
INTERFACE
SUBROUTINE FOR2(I,R,C,D)
INTEGER(KIND=4), INTENT(INOUT) :: I
REAL(KIND=4), INTENT(INOUT) :: R
COMPLEX(KIND=4), INTENT(INOUT) :: C
REAL(KIND=8), INTENT(INOUT) :: D
END SUBROUTINE FOR2
END INTERFACE
END MODULE FOR2_mod
However I notice that the alias you specified was not used - that's a bug and I'll report it.
A link to the continued adventures of Dr. Fortran is at the bottom of every one of my posts. Dick, you can read the older items here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's interesting. I have IVF 9.1 and 10.0.027 on VS2005. For the most part I only use the current version. Now I get the same interface as you do. The only way that I could have generated an interface without INTENT was that at the time of generation the function didn't have it specified and only when I deleted the debug folder and recompiled were the previous x.mod.f90's replaced. Now I know that it works as I expected (ie, with INTENT and all).
Thanks,
Gerry

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page