fortran-iso-c-binding

Passing both scalars and arrays (of any dimensions) from Fortran to C

别说谁变了你拦得住时间么 提交于 2021-02-07 19:14:27
问题 I have the following Fortran subroutine named show_value that calls a C function named show_value : INTERFACE SUBROUTINE show_value(variable) BIND(C, name = "show_value") USE, INTRINSIC :: iso_c_binding TYPE(*) :: variable END SUBROUTINE END INTERFACE The C function show_value : void show_value(const void *variable) { printf("%d\n", *(int *) variable); } The Fortran subroutine works well when passing scalars to it. Example: INTEGER :: x x = 12 call show_value(x) This will call the C function

Passing both scalars and arrays (of any dimensions) from Fortran to C

丶灬走出姿态 提交于 2021-02-07 19:12:59
问题 I have the following Fortran subroutine named show_value that calls a C function named show_value : INTERFACE SUBROUTINE show_value(variable) BIND(C, name = "show_value") USE, INTRINSIC :: iso_c_binding TYPE(*) :: variable END SUBROUTINE END INTERFACE The C function show_value : void show_value(const void *variable) { printf("%d\n", *(int *) variable); } The Fortran subroutine works well when passing scalars to it. Example: INTEGER :: x x = 12 call show_value(x) This will call the C function

In Fortran2003, is 1D Assumed shape array interoperable with C?

佐手、 提交于 2021-02-05 08:36:06
问题 In Fortran 2003, the allocatable array is not interoperable with C. I suppose this has something to do with additional array information stored in memory which might disturb the C interpretation. But what if I declare a dummy argument as 1D assumed shape array? for example subroutine outter_subroutine(ma, size_ma) integer :: size_ma integer :: ma(size_ma) call fortran_subroutine(ma) end subroutine !----------------------------- subroutine fortran_subroutine(a) integer, intent(in) :: a(:)

How to receive a string from a C function called by Fortran by iso_c_binding?

江枫思渺然 提交于 2021-02-05 06:21:29
问题 I want to call a C function from Fortran and receive a string of characters defined in the C function. I searched, but I couldn't find a working, straightforward answer, so far. Actually I have found a workaround: receiving an array of characters instead, then using the intrinsic function transfer to put the result into a Fortran string. Here is my working code. Fortran main program: program pr implicit none character(200) :: stringa call strfromc(stringa) write (6,*) 'FPR stringa: "', trim

Fortran C++ binding - wrong value being read in DLL(C++)

一曲冷凌霜 提交于 2021-01-29 11:17:22
问题 I am trying to use Fortran with C++. I created a DLL(C++) by following this guide. However, instead of creating C++ MathClient.cpp program, which calls this DLL (as it is described in the guide), I created Fortran MathClient.F90 program, which calls this DLL. Fortran main code: PROGRAM MAIN USE MOD_INTERFACE IMPLICIT NONE INTEGER(C_INT) :: A, B INTEGER(C_INT) :: INDEX INTEGER(C_INT) :: CURRENT LOGICAL(C_BOOL) :: BOLEAN A = 1 B = 1 ! Initialize a Fibonacci relation sequence. CALL FIBONACCI

MPI Fortran support through the mpi_f08 module with gfortran

拈花ヽ惹草 提交于 2021-01-29 06:09:00
问题 I have some Fortran code I would like to paralelize with MPI. Appereantly, recomended way to use MPI (MPICH, in my case) with Fortran is through mpi_f08 module (mpi-forum entry on the matter), but I have trouble making it work, since corresponding mod file is simply not created (unlike mpi.mod , which works fine, but it's not up to date with Fortran standart). This discussion left me under the impression it's because gfortran can't build the F08 bindings. Below you can see my configuration,

Call specific C++ DLL from Fortran

拈花ヽ惹草 提交于 2021-01-24 11:11:42
问题 I received a DLL made in C++, and I'm building a Fortran program to call the C++ DLL. My compiler (gfortran) shows no warnings, but it crashes during runtime with the following description: forrtl: severe (157): Program Exception - access violation Image PC Routine Line Source MainDLL_v10.dll 0B7A6B01 Unknown Unknown Unknown MainDLL_v10.dll 0B7A1BEF Unknown Unknown Unknown ... I guess something is wrong with my call arguments. The C++ DLL includes the following: #include <DllClasses.h> ...

Call specific C++ DLL from Fortran

那年仲夏 提交于 2021-01-24 11:10:31
问题 I received a DLL made in C++, and I'm building a Fortran program to call the C++ DLL. My compiler (gfortran) shows no warnings, but it crashes during runtime with the following description: forrtl: severe (157): Program Exception - access violation Image PC Routine Line Source MainDLL_v10.dll 0B7A6B01 Unknown Unknown Unknown MainDLL_v10.dll 0B7A1BEF Unknown Unknown Unknown ... I guess something is wrong with my call arguments. The C++ DLL includes the following: #include <DllClasses.h> ...

Call specific C++ DLL from Fortran

不问归期 提交于 2021-01-24 11:09:58
问题 I received a DLL made in C++, and I'm building a Fortran program to call the C++ DLL. My compiler (gfortran) shows no warnings, but it crashes during runtime with the following description: forrtl: severe (157): Program Exception - access violation Image PC Routine Line Source MainDLL_v10.dll 0B7A6B01 Unknown Unknown Unknown MainDLL_v10.dll 0B7A1BEF Unknown Unknown Unknown ... I guess something is wrong with my call arguments. The C++ DLL includes the following: #include <DllClasses.h> ...

Call specific C++ DLL from Fortran

懵懂的女人 提交于 2021-01-24 11:06:21
问题 I received a DLL made in C++, and I'm building a Fortran program to call the C++ DLL. My compiler (gfortran) shows no warnings, but it crashes during runtime with the following description: forrtl: severe (157): Program Exception - access violation Image PC Routine Line Source MainDLL_v10.dll 0B7A6B01 Unknown Unknown Unknown MainDLL_v10.dll 0B7A1BEF Unknown Unknown Unknown ... I guess something is wrong with my call arguments. The C++ DLL includes the following: #include <DllClasses.h> ...