I have a fortran subroutine, which I want to wrap via jna.
I have created a dll from fortran file and subroutine's input parameter is string array (i.e. Character*8 arr(3))
So when I try to call it via jna, if Im not doing anything that changes the array's values, it doesn't crash, but when I change anything, i.e. arr(1) = "new_str" (in fortran) and then try to call it via jna, it throws illegal memory access..
I know that for regular strings i can use byte[] and it works fine, but JNA doesn't allow byte[][] which would probably handle this issue correctly..
So I've tried with String[] and StringArray, and even Pointer, but whenever I try to change the value of array's elements inside fortran's dll, I get an error with memorry access issue, while passing string as byte[] and changing it, goes well w/o issues..
Here's the example Im working on
FORTRAN:
SUBROUTINE STRARR(arr)
CHARACTER*8 :: arr(3)
arr(1)="newstr11"
arr(2)="newstr22"
arr(3)="newstr33"
END SUBROUTINE
JAVA:
interface F95Test extends com.sun.jna.Library {
F95Test lib = (F95Test) Native.loadLibrary("strarrtest", F95Test.class); // strarrtest is dll with the fortran subroutine
void STRARR(StringArray line);
}
public static void main(String[] args) throws UnsupportedEncodingException {
String[] a = {"str_tes1", "str_tes2", "str_tes3"};
StringArray sa = new StringArray(a);
F95Test.lib.STRARR(sa); //this is where it crashes with illegal memory access
for ( String az : a ) System.out.println(az);
}
Hope it's clear enough, I feel there's a simple solution for this, but I just can't seem to grab it yet..
Cheers