Operating System - OpenVMS
1753666 Members
6054 Online
108799 Solutions
New Discussion юеВ

Calling Fortran from JAVA

 
Adriano Veronez
New Member

Calling Fortran from JAVA

how calling a fortran routines from java ?
10 REPLIES 10
Willem Grooters
Honored Contributor

Re: Calling Fortran from JAVA

I think the easiest way is probably to write interfacing routines in C, that can handle the differences in the passing mechanisms. Interfacing to C is standard availability in Java - so is the way strings are terminated; this is very different from the way Fortan (and other VMS-native languages) handle parameters.

Willem
Willem Grooters
OpenVMS Developer & System Manager
Arch_Muthiah
Honored Contributor

Re: Calling Fortran from JAVA

Adriano,

The calling mechanism for bot VMS C and VMS Fortran are same in VMS, probably you can call 4tran from Java. I have no exp in Java.


archunan


Regards
Archie
Robert Gezelter
Honored Contributor

Re: Calling Fortran from JAVA

Adriano,

Having had some experience with the JNI (Jave Native Interface), if you are careful, you can probably construct routines in FORTRAN, without a C/C++ intermediary.

It is true that C/C++ is the "planned for" target language, but the issue can be handled in FORTRAN. The main problem will be being careful to use only UPPER case external names, as FORTRAN is case-blind.

- Bob Gezelter, http://www.rlgsc.com
Steven Schweda
Honored Contributor

Re: Calling Fortran from JAVA

I don't see a reason to drag C into this,
either. DEC/Compaq/HP Fortran (formerly
known as FORTRAN) should be able to do
anything you need (just like practically
every other DEC/Compaq/HP language on VMS).

> FORTRAN is case-blind

HELP FORTRAN /NAMES

I haven't done any mixed language code for a
(long) while, but a quick look at the current
User Manual suggests that all the old %DESCR,
%LOC, %REF, and %VAL tricks are still there,
plus a bunch of new ones. You do need to
figure out what the Java code is actually
passing, but that's always true. And you
may need to build a few descriptors in your
interface functions, but you'd need to do
that in C, too.

I'd say that you can write any needed
interface functions in the language you like
best, but adding a new language (like C) to a
project has some obvious disadvantages.

For Fortran info:

http://h71000.www7.hp.com/doc/fortran.html

http://h71000.www7.hp.com/doc/82final/6443/6443pro.html

http://h71000.www7.hp.com/doc/82final/6443/6443pro_029.html#ch_fort_call_conv
Rick Retterer
Respected Contributor

Re: Calling Fortran from JAVA

Adriano,
I don't have a working example, but there are several "how'to's" on the web. I found this one to be fairly complete:

http://www.csharp.com/javacfort.html

And there are others...

Of course we also have the example from the OpenVMS Java FAQ page...

http://h18012.www1.hp.com/java/faq/ovms.html#4.0

Cheers,
Rick Retterer
- Rick Retterer



Adriano Veronez
New Member

Re: Calling Fortran from JAVA

Rick Retterer
[Adriano,
I don't have a working example, but there are several "how'to's" on the web. I found this one to be fairly complete:

http://www.csharp.com/javacfort.html

And there are others...

Of course we also have the example from the OpenVMS Java FAQ page...

http://h18012.www1.hp.com/java/faq/ovms.html#4.0

Cheers,
Rick Retterer ]

http://www.csharp.com/javacfort.html <- I want this but for VMS. and using Cxx (Compilator C installed)
Rick Retterer
Respected Contributor

Re: Calling Fortran from JAVA

Adriano,
I just received this example from Hartmut Becker, who did a Decus presentation on what you are seeking to do.

Here is the example he provided, that I'm passing along to you.

Cheers,
Rick

- Rick Retterer



Richard J Maher
Trusted Contributor

Re: Calling Fortran from JAVA

Hi

I couldn't find out any more about a Java related comment in the source code for the VMS Image Activator, via in comp.os.vms. So maybe someone here can shed some light on what this particular VMS developer was talking about: -

From COV>

Is VMS Security being dumbed-down for Java?
-------------------------------------------

Hi,

I have been unable to locate anyone who both could and would answer a couple of questions for me regarding the image activator's treatment of logical names, so in desperation I've begun to toy with the idea of wading through a copy of the VMS source listings, that someone was kind enough to show me. A quick glance revealed a developer's comment that I found quite striking, and I was wondering if anyone here could shed any further light on the issue.

Now, comments are just that, comments and quite often bear no resemblance to what the code is actually doing, and you're free to read as little or as much into them as you like, but see what you think anyway. From
SYSIMGACT.LIS 3-Oct-2004 line 1820 onwards: -

! the following code seems like a good idea, and maybe would be some day.
! but, in fact, untrusted names are required for privileged execution of
Java. . .


"Damn your logic Spock! the Javans are a peaceful people and mean us no harm."
"Shields-Down Mr Sulu. . ."

It's a given that not everyone is as easily given to superlative as me so the horizontal ellipses could be a roll-of-the-eyes, an outpouring of exacerbation, a cry for help, or simply "I'm not gonna fill up the source
listing with the rest of this fascinating tale". Or non of the above? Anyway
FYI.

Regards Richard Maher

P R Stone_1
Advisor

Re: Calling Fortran from JAVA

I have not called Fortran from Java but have called Basic.

The way I did it was to take the JNI example given by HP to link to C. That way you can 'easily' create the required Java and C headers , linkages etc.

From the C I could then call my Basic functions. This also allowed me to translate Java strings to C strings to DESCRIPTOR strings.

I suppose in theory I could go directly to Basic but it would be a lot of extra fiddly bespoke work!