- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to call a C routine from my Fortran main. I am having difficulty in prototyping two arrays, one 1D array and another a 2D array. Following some examples in the Visual Studio (V6.0), I trid declaring as
INTERFACE TO FUNCTION ADD2 [C,ALIAS:'_ADD2'] (a, b)
REAL*4 a [REFERENCE]
REAL*4 b [REFERENCE]
END
REAL*4 b [REFERENCE]
END
where a is 1D array and b is 2D array. I get the compiler error "Error: The shape matching rules of actual arguments and dummy arguments have been violated." Any help would be greatly appreciated.
Thanks,
Khandan
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have to specify that a andb are arrays:
INTERFACE
FUNCTION ADD2 (a, b)
!DEC$ATTRIBUTES C, ALIAS: "_ADD2":: ADD2
REAL*4 a(*)
REAL*4 b(*)
END FUNCTION
END INTERFACE
Syntax with brackets and INTERFACE TO is obsolete and not documented (although still supported for compatibility with old MS compilers) -- I suggest using official !DEC$ form.
Matching a 1-d dummy to a 2-d actual argument is allowed for assumed-size arrays. However, note that C function has to know the leading dimension of b somehow -- either as hard-coded or by using an extra argument. Note also that indexing such an array is reversed in Fortran and C, andindexing is also different (starting with 1 in Fortran and 0 in C), e.g.
REAL:: B(10,5)
B(7,3) <-> *(b + (3-1)*10 + (7-1)) <-> b[2][6]
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thnak you Yugoslav.
Your suggestions worked very well. I also have another problem in which I am calling a Fortran code from C where I need to transfer data back and forth via a COMMON BLOCK. I tried creating a C structure with fields corresponding to the common-block variables and declared as "extern struct block_name CBLOCK" as per on line help in V.Studio 6.0. When I step into Fortran, the values are not there. I would greatly appreciate any help with a simple example.
Thank you
Khandan

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