fortran-iso-c-binding

How should multiple Fortran strings be passed to C?

回眸只為那壹抹淺笑 提交于 2019-12-12 12:49:10
问题 To pass a Fortran string to C, a hidden parameter is also passed with the variable's size. Here's a working fortran definition, and the C (actually C++/CLI) method: interface subroutine AppendExtension( + Filename) + bind(C, name="AppendExtension") character *1, intent(inout):: Filename end subroutine AppendExtension end interface and here's the C++/CLI that gets called: extern "C" { void __declspec(dllexport) __cdecl AppendExtension( char * name, int buffersize) { String^ clistr = gcnew

Sleep in Fortran

喜欢而已 提交于 2019-12-12 08:19:19
问题 Does anyone know of an way to sleep for a given number of milliseconds in Fortran? I do not want to use non-portable system calls so anything intrinsic to Fortran or C libraries would be preferred. 回答1: Using the Fortran ISO C Binding to use the C library sleep to sleep in units of seconds: module Fortran_Sleep use, intrinsic :: iso_c_binding, only: c_int implicit none interface ! should be unsigned int ... not available in Fortran ! OK until highest bit gets set. function FortSleep (seconds)

Fortran/C Mixing : How to access dynamically allocated C array in Fortran?

百般思念 提交于 2019-12-12 04:59:03
问题 I'm currently experiencing an memory issue: I have a main program coded in Fortran which calls a C/C++ subroutine to perform some tasks and store data in a dynamically allocated array. The thing is I need to have access to these data when back to the Fortran main program. I tried to declare a C pointer (TYPE(C_PTR)) in fortran to point to the array but it doesn't seem to work. The array is present within the C subroutine but I get a segfault when trying to access it when I'm back to the main

Metis with Fortran

与世无争的帅哥 提交于 2019-12-12 04:46:53
问题 I am using metis 5 with Fortran. I am using the PartGraphRecursive function with the simple example given in the manual. The code is given as which is not the working condition. program main implicit none integer,parameter::nvtxs=15, Edges=22 integer::xadj(nvtxs+1),adjncy(2*Edges) integer::objval, part(nvtxs) xadj=[0, 2, 5, 8, 11, 13, 16, 20, 24, 28, 31, 33, 36, 39, 42, 44] adjncy=[1, 5, 0, 2, 6, 1, 3, 7, 2, 4, 8, 3, 9, 0, 6, 10, 1, 5, 7, 11, 2, 6, 8, 12, 3, 7, 9, 13, 4, 8, 14, 5, 11, 6, 10,

Passing 2d array from Fortran to C [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-12 03:20:04
问题 This question already has answers here : Passing a two dimentional array from Fortran to C (2 answers) Closed 4 years ago . I am having difficulty passing a 2d array from Fortran to C function. However, after all the support the following code is functional 100%. The following is my C function: #include <stdio.h> void print2(void *p, int n) { printf("Array from C is \n"); double *dptr; dptr = (double *)p; for (int i = 0; i < n; i++) { for (int j = 0; j<n; j++) printf("%.6g \t",dptr[i*n+j]);

Calling C from fortran (ifort, gfortran)

可紊 提交于 2019-12-11 22:12:39
问题 I'm a C programmer who has to update a huge Fortran 2003 program by adding a single call to a C function. First, I need to write a minimal Fortran wrapper (in modern, free-form Fortran, no shouting) that will correctly call the C function with a string that contains a loop counter (and the date/time, if possible), from within a loop. This should be "easy", but none of the searches I've done yielded enough snippets for me to create a working program. I'm using recent 64-bit versions of

diffptr_t fortran with iso_c_bindings

喜夏-厌秋 提交于 2019-12-11 10:10:27
问题 I'd like to have a kind of diffptr_t in fortran with iso_c_bindings. The memory distance result must be a signed int. type(c_ptr) :: start,ref type(c_int) :: res start=c_loc(my_struct%a) ref=c_loc(my_struct%b%c) res=start-ref Compilation error: This binary operation is invalid for this data type. An arithmetic or LOGICAL type is required in this context. Thanks 回答1: You cannot do pointer arithmetic in standard Fortran. You have to rely on the processor dependent binary correspondence between

Binding C++ and Fortran

喜夏-厌秋 提交于 2019-12-11 04:22:53
问题 I want to combine C++ and Fortran together. My Fortran code will use a C++ function and C++ function changes variables of Fortran and sends them back. The C++ function is built with other C++ codes, e.g. the C++ function will use some sub-function in other .cpp file. I make the Fortran code with ifort and I added that C++ function as one object file, test.o in my Fortran makefile. I also put every needed C++ .o file(support test.o) in makefile. It shows the error #6633, "The type of the

how to mix fortran and C++ in visual studio 2010?

假装没事ソ 提交于 2019-12-10 17:57:08
问题 I am trying to call the c++ function from Fortran main program. to do that I followed the bellow steps in visual Studio 2010: To create a C++ static library project On the menu bar, choose File, New, Project. In the left pane of the New Project dialog box, expand Installed, Templates, Visual C++, and then select Win32. In the center pane, select Win32 Console Application. Specify a name for the project—for example, MathFuncsLib—in the Name box. Specify a name for the solution—for example,

Interoperability of C variadic function and Fortran

ε祈祈猫儿з 提交于 2019-12-10 12:57:35
问题 Is there a way to declare a C variadic function and call it from Fortran? I need to call this function to compute some dot products between vectors labeled with a string. My idea was to declare something like the following, where the variable list of arguments contains string literals. If the variable list of arguments is empty, then I would do a lookup among the standard labels and perform the calculation. If the user specified two labels I would retrieve those two vectors and get their dot