- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all....
I have a strange problem while binding a fortran function for using it in java....
I can call several Fortran routines from java and it works fine. But when it comes to a given Fortran function, i have a SIGSEV fault in Java. The only way to fix this up (that I found) is to add "VALUE" on the arguments of the function in the Function. When I do this, the Java binding works well and I get the expected result. The BIG problem is that the Fortran call is not working anymore. So I have been obliged to duplicate the function in the Fortran lib, one with the "VALUE" tag (that I use from Java) and one without the tag (for Fortran call) !! I don't understand what happens and how I could correct this...
My Fortran :
FUNCTION XESM(M,N,T,ILCOM) BIND(C,name='xesm') ! IMPLICIT NONE INTEGER, VALUE :: M,N,ILCOM ! REAL(8), VALUE :: T REAL(8) :: XESM ! write(*,*) 'received : ',M,N,T RETURN END
My Java :
public class TestJNA { public interface EOS extends Library { EOS INSTANCE = (EOS) Native.loadLibrary("eos.so", EOS.class); double xesm(int M, int N, double T, int IC); } public static void main(String[] args) { NativeLibrary.addSearchPath("eos.so", "./lib/"); EOS eosdll = EOS.INSTANCE; int IC=0 ; int M=1, N=1 ; double T=1500.; double ES = eosdll.xesm(M,N,T,IC); } }
To summarize, I need the "VALUE" tag to get java working correctly (but the regular Fortran call fails), and vice versa....I would greatly appreciate your help.. Thanks in advance...
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried to use IntByReference and DoubleByReference types from om.sun.jna.ptr. (instead of int and double) and it seems to work...
I don't know it this is the right way to solve the problem...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you need is an "explicit interface" for the function that is visible to the Fortran caller. The easiest way to do this is to enclose function XESM in a module and then USE the module from other places in your Fortran code that call XESM. That way all the attributes of the interface will be seen by the Fortran caller.
For example:
module XESM_MOD contains function XESM .... end function XESM end module XESM_MOD
and then in your Fortran procedures:
subroutine SOMESUB ... use XESM_MOD ... ret = XESM(....) ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page