comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Calling fortran under unix
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Calling fortran under unix [message #7101] Wed, 02 October 1996 00:00 Go to previous message
dors is currently offline  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? :^) |
============================================================ ================
[Message index]
 
Read Message
Read Message
Previous Topic: The 'MAC' device and the 'CURSOR_IMAGE' keyword
Next Topic: Re: IDL 5.0

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 04:22:59 PDT 2025

Total time taken to generate the page: 0.80170 seconds