tags:

views:

75

answers:

2

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.

A: 

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.

extraneon
+1  A: 

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.

High Performance Mark