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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: CALL_EXTERNAL and structures [message #9325] Mon, 23 June 1997 00:00
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
Re: CALL_EXTERNAL and structures [message #9326 is a reply to message #9325] Mon, 23 June 1997 00:00 Go to previous message
rivers is currently offline  rivers
Messages: 228
Registered: March 1991
Senior Member
In article <33AE2A0D.481@vision.ee.ethz.ch>, Hubert Rehrauer <rehrauer@vision.ee.ethz.ch> writes:
> Hello,
>
> I got the following problem. I want to call a C function that modifies a
> IDL structure. This works pretty well, except for structure tags that
> have an array-type.
> /*
> IDL input:
>
> $ cc -G -Kpic -c -lm -v idltest.c
> $ ld -G -o idltest.so idltest.o
> a= 5L
> b = DBLARR(4)
> data ={ first: a, second: b }

...

> /* content of the file 'idltest.c' */
> typedef struct {
> long first;
> double * second;
> } data;

The declaration "double * second" is your problem. "second" is not a pointer
to a double, it is an array of doubles, i.e. the array occupies memory
immediately after the long "first", not at a location pointed to by a pointer
after "first". I have not tried it, but I predict that if you change the
declation and code to:

typedef struct {
long first;
double second[4];
} data;
...
d->first = 25;
d->second[0] = 1.4;
d->second[2] =3.8;

that it will work.

____________________________________________________________
Mark Rivers (773) 702-2279 (office)
CARS (773) 702-9951 (secretary)
Univ. of Chicago (773) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars.uchicago.edu (e-mail)

or:
Argonne National Laboratory (630) 252-0422 (office)
Building 434A (630) 252-0405 (lab)
9700 South Cass Avenue (630) 252-1713 (beamline)
Argonne, IL 60439 (630) 252-0443 (FAX)
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Thu Oct 09 21:14:50 PDT 2025

Total time taken to generate the page: 1.43935 seconds