Re: Calling fortran under unix [message #7101] |
Wed, 02 October 1996 00:00  |
dors
Messages: 8 Registered: June 1994
|
Junior Member |
|
|
You can also write your wrapper functions in FORTRAN if you are not
into C. I can write FORTRAN and C but when taking a piece of existing
FORTRAN code I find it much easier to stay in FORTRAN. And in this
case FORTRAN has all the power you need (DEC FORTRAN does anyway). I
politely disagree that writing in FORTRAN is a problem. Everyone has
their own favorite language. They aren't the real limitation, any
task can be done in any language, it is all a matter of efficiency.
Here are some test files for a very simple example, only passing
longs and strings. Many more complicated examples could be created,
but this should get the main point across. There is much
documentation in the IDL manuals on all of this for many
architectures. And I remember seeing some example files somewhere in
the idl source tree.:
IDL:
PRO pass
a = long(10)
b = 'I can pass strings!!'
c = long(9)
print, 'calling FORTRAN'
result = CALL_EXTERNAL ('simple.so','simple_',a,b,c,VALUE=[0,1,0])
print, 'back in IDL'
print, 'result=', result
END
--------------------------------------
FORTRAN:
c Interface routine
function simple (argc, argv)
INTEGER*8 argc, argv(*)
INTEGER*4 temp1
simple=sum (%VAL(argv(1)),%val(argv(2)),%val(argv(3)))
return
END
c desired function
function sum (a, b, c)
integer*4 sum
integer*4 a,c
character*20 b
print*, 'Executing FORTRAN'
print*, a
print*, b
print*, c
sum=a+c
print*, 'Leaving FORTRAN'
return
end
-------------------------------------
Here are the statements I used to compile (I know I have some extra
libraries here but it is a compile statement I coppied from another
project and I don't feel like sorting through what is needed :^)) Also
I assume you can do the same with the f90 compiler but I haven't used
it yet.:
f77 -c -o simple.o simple.for
ld -o simple.so -shared simple.o -lUfor -lfor -lFutil -lm -lots -lc
-------------------------------------
Note 1: Make sure you think about the use of pass by value versus pass
by reference when it comes to strings.
Note 2: Make sure you know the pointer size on your machine, on my DEC
Alpha it is integer*8, if this is not true for your machine you will
get a segmentation fault unless you make the appropriate changes.
Note 3: IDL will not pass integer*8's as data, there is no internal
format for that, nor will it pass real*16's.
Good luck,
Eric
--
\
\ O,
\___________\/ )_________/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Eric E. Dors \| Internet: eric.dors@unh.edu |
| 203 Van Allen Hall | |
| Iowa City, IA 52242 | |
============================================================ ================
| "if free particles were truly free..." |
| "they wouldn't be represented by bras, <k| " |
| ---oh no, how did a physics joke make it in here? :^) |
============================================================ ================
|
|
|