Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a Fortran subroutine from Java

Tags:

java

fortran

I have a huge subroutine written in Fortran that I need to use in a Java program. How can I call it? I am using ubuntu 10.04.

like image 461
rhombidodecahedron Avatar asked Jul 12 '10 20:07

rhombidodecahedron


2 Answers

Have a look at this document, it details the process of integrating native code (fortran / c) with Java. The result will, of course, be platform dependent.

like image 137
extraneon Avatar answered Oct 22 '22 18:10

extraneon


The paper that @extraneon refers you to is the way I integrated a Fortran subroutine into a Java program a couple of years ago. However, if I was trying to do it again today I would look into using the interoperability with C features which are defined in the Fortran 2003 standard and implemented by recent versions of some compilers. I hope that I could compile the Fortran subroutine to look, to JNI, like it was written in C. This way you could cut out the C wrapper.

And if your compiler doesn't implement the interoperability with C features, ditch and get one that does.

EDIT: another thought occurs to me: If the Fortran subroutine is huge in its execution time you should think about integrating it with Java by having Java put some input data into a file, and modifying the Fortran to get its inputs from the file. Then the Java program could make a call to the system to start the Fortran. Pass back the results in the same way. This is a real kludge, but you will probably find it easier to implement than going via JNI. Furthermore, you could implement this as a stop-gap while you wrestle with JNI and interoperability etc.

like image 4
High Performance Mark Avatar answered Oct 22 '22 18:10

High Performance Mark