fortran-iso-c-binding

Fortran derived types containing derived types to be accessible from C

故事扮演 提交于 2019-12-23 01:19:19
问题 As an extension to this post, I have derived types which have as members derived types themselves. Example below: module simple use iso_c_binding TYPE SIMPLEF INTEGER :: A INTEGER, POINTER :: B, C(:) END TYPE SIMPLEF TYPE COMPLEXF INTEGER :: X TYPE (SIMPLEF) :: Y END TYPE COMPLEXF end module simple The aim is, as in the post above, to have similar derived types in C and to be able to pass values back and forth to Fortran. The solution can be seen here. However here it's not just a derived

Why aren't my fortran functions exported when using the BIND(C, NAME=“name”) attribute

泪湿孤枕 提交于 2019-12-22 22:52:31
问题 I am used to using the following syntax subroutine CalcA(A,N) !DEC$ ATTRIBUTES DLLEXPORT :: CALCA !DEC$ ATTRIBUTES ALIAS:'CalcA' :: CalcA IMPLICIT NONE ... end subroutine CalcA which produces an exported function in a .dll So now I am trying the new ISO_C_BINDING with the following code subroutine CalcA(A,N) BIND(C, NAME="CalcA") USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE ... end subroutine CalcA But the export function is not created So what am I missing here? How is the new iso_c_binding

Fortran-C interoperability and float arrays

拥有回忆 提交于 2019-12-21 05:57:13
问题 I have a large existing Fortran95 code. It uses real(dp), dimension(num) :: array to declare arrays. I want to join in some C code and found that I can do this by writing interfaces to the C-functions and declaring arrays as use iso_c_binding real(c_double), allocatable, target :: array(:) I have working fortran functions which call the C-functions as call myfunction(c_loc(array)); What is needed to pass the real(dp) array to myfunction? Apparently, I would need to make a C-pointer from it

About using Fortran function in C with iso_c_binding

限于喜欢 提交于 2019-12-18 09:34:54
问题 I learn Fortran's C interoperability for a few days to call a Fortran function DLL from C. Here I found this link: Use Fortran-code in C I try to create a Fortran DLL like this and my compiler is Intel Fortran compiler: module integration implicit none contains function Integrate(func, a,b, intsteps) result(integral) !DEC$ ATTRIBUTES DLLEXPORT :: Integrate interface real function func(x) real, intent(in) :: x end function func end interface real :: integral, a, b integer :: intsteps intent(in

Arrays of strings in Fortran-C bridges using iso_c_binding

早过忘川 提交于 2019-12-18 07:36:17
问题 I'm writing code that will call a C function from Fortran using Fortran's C interoperability mechanism (introduced in Fortran 2003 and implemented in newer versions of gfortran and ifort). This answer is almost what I need, but I can't quite get my head around what interface declaration I should use in Fortran for a C function that looks like this: int use_array(int n, char * array[]){ int i; for(i=0; i<n; i++){ printf("Item %d = %s\n",i,array[i]); } return n; } I'm not clear what the

ISO_C_BINDING Calling C routine from Fortran (with doubles and arrays)

六月ゝ 毕业季﹏ 提交于 2019-12-18 07:25:11
问题 I posted a similar question few weeks ago (iso_c_binding calling C routine with pointers from Fortran with arrays) and I found a solution to my problem. Now I modified few things and I am having some problems again. In the following a simplified version of my problem. I have a main program in fortran: program main_dummy ! compile: gcc -c dummy_trace.c ! f95 raytracing.f90 main_dummy.f90 dummy_trace.o -o main use, intrinsic :: ISO_C_BINDING use raytracing implicit none !real(kind=8) :: x_in(4)

calling C# from Fortran

点点圈 提交于 2019-12-14 03:53:39
问题 I’ve not found any posts on Stack Overflow that discuss calling C# from Fortran (I’m using Visual Studio 2010 with Intel Visual Fortran installed as well). However, there is a (very) limited # of posts[1, 2, 3 ] that discuss calling C/C++ from fortran. In one of the responses to these posts, it was suggested that calling C++ from Fortran is trickier than calling C, which raised my suspicions that C# may be trickier yet? Lacking a foundation in C/C++/C#, I’m wondering if the procedures laid

Does the abstract Fortran interface of a C callback function require bind(C) attribute?

谁都会走 提交于 2019-12-13 16:12:15
问题 Consider the following Fortran code, where the C-interoperable subroutine runFoo4C(...) bind(C, name="runFoo") in module Foo_mod takes a C-callback function pointer getLogFuncFromC() as an argument, module CallbackInterface_mod abstract interface function getLogFunc4C_proc(ndim,Point) result(logFunc) ! bind(C) use, intrinsic :: iso_c_binding, only : c_int32_t, c_double, c_int integer(c_int32_t), intent(in) :: ndim real(c_double), intent(in) :: Point(ndim) real(c_double) :: logFunc end

How to call a C function in Fortran and properly pass uint32_t arguments

半世苍凉 提交于 2019-12-13 13:55:00
问题 Hi I am using a Fortran 90 code to call a C function. Since I am manipulating addresses, the arguments of the C function should be properly matched in Fortran. I am using ifort and icc to compile the code and working on 64 bit machine. Some testing showed that this will work also with int32_t , although to prevent eventual pitfalls, I would like to keep the uint32_t The C functions I am calling has the following prototypes uint32_t encode_(uint32_t x, uint32_t y) uint32_t decode_(uint32_t dec

DCT of complex arrays with FFTW in Fortran: How to point to the imaginary part array?

*爱你&永不变心* 提交于 2019-12-13 04:09:20
问题 I am writing a pseudo-spectral CFD code in Fortran, which is essentially a time-stepper of the Navier-Stokes equations in a plane layer. It is really a 3d code in my case, but the problem can be very well understood in 2d, so I will stick to this case. Geometrically, my 2d plane layer is bounded by y=0 and y=1 , and is periodic along the other direction x . Without going too much into the weeds, an efficient discretisation is to decompose fields (e.g., velocity) on Chebyshev polynomials along