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

Home » Public Forums » archive » Re: CALL_EXTERNAL and structures
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: CALL_EXTERNAL and structures [message #9325] Mon, 23 June 1997 00:00 Go to previous message
Jeff Kommers is currently offline  Jeff Kommers
Messages: 2
Registered: June 1997
Junior Member
> Hubert Rehrauer <rehrauer@vision.ee.ethz.ch>
> In the following example the values of the tag 'second' can not be
> modified and I can't see why!

I think the problem is in the way you defined the structure in
'idltest.c':

> typedef struct {
> long first;
> double * second;
> } data;

If your IDL structure is defined like this

IDL> data = {first:0L, second:dblarr(4)}

then in your C program you would want to define the same structure.
That means the second tag should be a double, *not* a pointer to a
double. In fact, if data.second always has 4 or fewer elements, then
in C the second tag should be a "double second[4];".

But assuming that IDL is responsible for allocating memory for the
data structure, and that your C source code does not know how many
elements data.second is going to have, you could do something like
this:

/* content of the file 'idltestfix.c' */
typedef struct {
long first;
double second; /* Actually the first element in an array of doubles */
/* See IDL code */
} data;

long idltestfix( int argc, void * argv[])
{
data * d;
double * psecond;

d = (data * ) argv[0];

d->first = 25;
psecond = &d->second;
*psecond = 1.4;
*(psecond+2) =3.8;

return(0L);
}

On SunOS 4.1.3 with IDL 5.0 I did the following

IDL> $ acc -c -pic idltestfix.c
IDL> $ ld -o idltestfix.so -assert pure-text idltestfix.o
IDL> a = 5l
IDL> b = dblarr(4)
IDL> data = {first:a,second:b}
IDL> print, data
{ 5 0.0000000 0.0000000 0.0000000 0.0000000
}
IDL> check = call_external('idltestfix.so','idltestfix',data)
IDL> print, data
{ 25 1.4000000 0.0000000 3.8000000 0.0000000
}

Good luck

Jeff
[Message index]
 
Read Message
Read Message
Previous Topic: Re: Lat/Lon labels ala "gmt"
Next Topic: Re: Bug on IDL 5.0 (VMS 6.2) with alog10()

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

Current Time: Fri Oct 10 14:33:34 PDT 2025

Total time taken to generate the page: 0.32177 seconds