Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating and accessing fortran dynamic array in c function

I can create and use dynamic two dimensional array in Fortran (in 77 standard). Now, I wanted to create my dynamic two dimensional array in C function (using let's say 'malloc') from Fortran program and be able to access it through Fortran program. In Fortran I also want to be able to do smth like a(1:n,2) or a(1,2), and also be able to pass and retrieve my array from Fortran subroutines. Please, can you show me example, and take your time to explain (if possible, I would really appreciate it) how the memories will be aligned? Thanks a ton! Also if two dimensional will not be possible to work directly, I am fine with creation of single dimensional array in C function, but accessing it from Fortran as it was a two dimensional array... Thanks!!!

like image 764
tester Avatar asked Feb 20 '23 00:02

tester


1 Answers

No you can not create dynamic array in FORTRAN 77 standard.

You also can not create Fortran "dynamic" array using malloc, any try to deallocate it from Fortran will lead to crash. (You can of course use it in normal ways as a static a array.)

Also If you explicitly request FORTRAN 77, don't use notation like a(1:n,2). It is not supported in this standard.

In Fortran 2003 there is iso_c_binding, but nothing like that exists in FORTRAN 77, you can only pass assumed size arrays and take care of any name mangling used by your compiler (i.e. trailing underscores in Fotran procedure names from C).

like image 72
Vladimir F Героям слава Avatar answered Mar 16 '23 00:03

Vladimir F Героям слава