Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Fortran

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Just wondering could anyone provide me with any information about using Fortran code (a DLL or otherwise) with Java.

I have a Fortran program that performs some heavy-weight calculations using Matrices among other things. I'd like to put a web interface on this using Java.

Could anyone enlighten me as to whether this is possible or not, and if so provide some pointers about how to go about doing this.

I found the following article on-line which gave me hope that this is possible.

http://www.math.ucla.edu/~anderson/JAVAclass/JavaInterface/JavaInterface.html

Many thanks in advance.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call a Windows DLL or Unix module with Java Native Interface. The first layer of code that you call has to be written in a special way to be callable, but it can then call anything else. So you could likely build a C/C++ layer that could call your Fortran module. Look for JNI tutorials.

You can also fire up another process and run any executable. Look at ProcessBuilder in JDK5 or System.runtime.exec() in earlier JDKs. It's possible but not trivial to hook streams up to the stdin, stdout and errout of the process and interact with it.

Either of those sound useful?
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it's possible with JNI.
Have a look at this straightforward example : Using JNI to invoke Fortran subroutines.

Regards
 
Liz Costelloe
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thank you very much for the replies, I'm very relieved that I wasn't heading into a dead-end.

Stan, JNI sounds like it will solve the problem nicely. I'm comfortable with Java and C++ but I'm a noobie to Fortran. The Fortran code belongs to someone else, I'm just offering a helping hand with the Java/Web side of things. Also, thanks for suggesting the alternative, I've used System.runtime.exec() in the past and it didn't occur to me that streams might be another approach to solving this problem - cheers!

Jean-Francois, thanks for the link. Really very helpful, it's concise and answered a lot of questions and problems that I was having, I'm very grateful.

Thanks again to you both!
 
reply
    Bookmark Topic Watch Topic
  • New Topic