Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fortran Java Interface 1

Status
Not open for further replies.

ArmenD

Programmer
Feb 3, 2005
101
US
hi,
I have fortran code that needs java interface. I heard jni is way to go.

are there any good src code examples that show how this is done.
both small and meduim/large src code examples are welcome.

i've been reading the api, but i need to c examples.
this is sort of a high priority project, so plz any input is welcome.

thanks in advnace,
armen
 
does anyone know how to pass primitive data types such as int, char from fortran to C and from C to fortran using JNI?
 
C to Fortran is very implementation dependent unless you have Fortran 2003. Which platform/compilers are you using?
 
ibm pc, using f77.
basically i have a fortran statistical package that i need to provide a graphical user interface for I/O.
so i decided to do it in java using JNI.
so c is the intermediary language that i need to use.
I am at the step of implementing native methods and I want to know if ppl have examples of parameter passing and function return types from c to fortran?

i also want to know how to create shared libraries(.dll) from the c and fortran code i have under windows/pc. there r insturctions for unix but i want those for windows.
 
Sorry - you need to be more specific. There are lots of different F77 compilers and every one has a different interface mechanism. I know about G77 (GNU) but I don't know about the others like Lahey, Salford, Watcom etc.
 
so for gnu(g77), would you happen to know the instructions for creating shared libraries with c/fortran?

any src code examples or compilation instructions would be appreciated.
 
So suppose my fortan program has (5 functions)
and I use JNI method to make use of existing fortran code
here is my ?,

should i declare prototypes of all 5 fortran functions in c or
should i declare only the topmost entry method(main) of fortran?

my inclination is that if my fortran main method has access to all variables in program, then i only need the topmost fortran main prototype funciton to be declared in c.
is this correct?
 
so all the examples I have seen, c calls a fortran subroutine.
Can c call a fortran program?
 
If you call a program i.e. via system, then the two programs will have to communicate through a file. I've only used Fortran calling C: not the other way round. Normally, it is easier to rewrite the code if it is the other way round. There are Fortran to C translators (f2c) which will do most of the work for you.
 
hi,
by the way thanks for your help thus far, but I have a quick follow up ?, regarding "Can c call a fortran program?"

ok so can't I write a 1 line c code that calls fortran program and the fortran program continues till it ends, and then returns to c code that called it and the program ends.

I dont know if there is a need for the c program and the fortran program to communicate. after all the only reason why i am using c is b/c java JNI method needs it. Is my understanding of the process thus far correct?

thanks again,
armen
 
Yes - it is basically Fortran calling C calling Java. Come to think of it, I don't think I've ever had C calling Fortran. I've always translated the Fortran into C and had it purely in C. It is only in graphics that I've had to use multiple languages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top