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

Home » Public Forums » archive » Call_external passing problem
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Call_external passing problem [message #36724] Tue, 21 October 2003 22:42 Go to previous message
isoaga2 is currently offline  isoaga2
Messages: 4
Registered: October 2003
Junior Member
Hi everyone, recently i've been using the call_external function a bit
to call fortran code through c wrappers and i thought i had it sorted
however i can't seem to see my mistake in this one...

Here are the three pieces of code i'm using and the output i'm
getting:

IDL CODE
------------------------------------------------------------ ----------------
pro hyper2

a = -11.5d0
b = 20.5d0
c = 5.d0
z = double((cos(!pi/3.)))
re = 0.d0
im = 0.d0
out = call_external('/home/david/PhD/Fortran/hyper.so', 'hyper', $
z, a, b, c, re, im)
stop
end


C WRAPPER
------------------------------------------------------------ ----------------
#include <stdio.h>

void hyper_cw(int argc, void *argv[])
{
extern void hyp_(); /* Fortran Routine */
int *argc;
double *z, *a, *b, *c, *re, *im;

z = (double *) argv[0];
a = (double *) argv[1];
b = (double *) argv[2];
c = (double *) argv[3];
re = (double *) argv[4];
im = (double *) argv[5];
hyp_(z,a,b,c,re,im);
}


FORTRAN CODE (or at least the beginning of it)
------------------------------------------------------------ ----------------
subroutine hyp(z,a,b,c,re,im)
real*8 zero,one,two,half
parameter (zero=0.d0,one=1.d0,two=2.d0,half=0.5d0)
integer flag,flag2,neps
real*8 a,b,c,z,w,f,f1,f2,gamm,tol,test,pi,machep,re2,
# alpha0,alpha1,rn,binom,eps,re,im,x1,x2,x3,x4,
# coeff1,coeff2,coeff3,coeff4,temp1,temp2,term,
# a1,b1,c1,a2,b2,c2,alpha2
logical fix
common /bcoeff/binom(5151)

write (6,*) z,a,b,c,re,im
write (6,*) zero,one,two,half

COMPILED AND LINKED WITH (under linux - Gentoo - PC)
------------------------------------------------------------ ----------------
g77 -c hyp.f
gcc -c hyper_cw.c
gcc -shared -o hyper_cw.so hyp.o hyper_cw.o -lg2c



Then when i run the idl program i get the following output:
IDL> hyper2
0.49999997 -11.5 20.5 0.49999997 20.5 -11.5
0. 1. 2. 0.5

Which shows that the fortran subroutine is getting the first three
arguments correctly, however the last three (c, re, im) are being
mixed up somehow. Can anyone see my mistake, its driving me nutty...

Thanx.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Java bridge: xml parsers
Next Topic: which OS is faster for idl? Win or Linux?

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

Current Time: Sat Oct 11 06:15:25 PDT 2025

Total time taken to generate the page: 1.35945 seconds