On 2/25/2009 10:02 AM, Dag Sverre Seljebotn wrote:
> However one would still need some hint about which C types correspond to
> which Fortran types (in size, though they won't be the same type) to be
> able to generate such a wrapper automatically? Any ideas?
Fortran has the intrinsic methods "selected_int_kind" and
"selected_real_kind" for obtaining the compiler's "kind numbers" for
given values of resolution or precision.
module kindtypes
use iso_c_binding
intrinsic :: kind, selected_int_kind, selected_real_kind
integer(c_int) :: i8 = selected_int_kind(2)
integer(c_int) :: i16 = selected_int_kind(4)
integer(c_int) :: i32 = selected_int_kind(9)
integer(c_int) :: i64 = selected_int_kind(16)
integer(c_int) :: r32 = selected_real_kind(p=5)
integer(c_int) :: r64 = selected_real_kind(p=13)
integer(c_int) :: c32 = selected_real_kind(p=5)
integer(c_int) :: c64 = selected_real_kind(p=13)
bind(C) :: i8, i16, i32, i64, r32, r64, c32, c64
end module
And now in C:
extern int i32; /* the kind of a 32-bit integer in Fortran */
In Cython you could create dictionaries mapping "kind to size" and "size
to kind".
If you write a Fortran 2003 for your Fortran 77 or 90 library, you do
not have to worry about compiler specific details when calling from C.
This includes functions for converting between C pointers and Fortran
pointers. You can e.g. pass a Fortran pointer in place of an
"assumed-shape array" in Fortran 90. Chasm will also give you the "dope
array struct" if it supports the Fortran compiler (vendor and version).
But with Fortran 2003, you do not have to worry about this, you can
leave this mess to the Fortran compiler.
Sturla Molden
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev