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

Home » Public Forums » archive » Re: Multidimensional arrays and CALL_EXTERNAL
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: Multidimensional arrays and CALL_EXTERNAL [message #60828] Fri, 20 June 2008 13:21 Go to next message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Fri, 20 Jun 2008, Dan wrote:

> Hi Lajos,
>
> This doesn't seem to be working for me.
>

Create a 4D array in IDL: arr=lindgen(2,3,4,5). Pass this array to
the C routine, and print the array elements in C. You will see the
pattern.

regards,
lajos
Re: Multidimensional arrays and CALL_EXTERNAL [message #60829 is a reply to message #60828] Fri, 20 June 2008 12:36 Go to previous messageGo to next message
Dan[1] is currently offline  Dan[1]
Messages: 7
Registered: June 2008
Junior Member
Hi Lajos,

This doesn't seem to be working for me.
Re: Multidimensional arrays and CALL_EXTERNAL [message #60830 is a reply to message #60829] Fri, 20 June 2008 11:24 Go to previous messageGo to next message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Fri, 20 Jun 2008, Dan wrote:

> Hi everyone,
>
> Now that I have gotten CALL_EXTERNAL to work correctly, I am trying to
> figure out how IDL stores multidimensional arrays in memory. Since
> CALL_EXTERNAL passes an arrays by reference (pointer to the first
> element of the array), the multidimensional arrays in C act like a 1-D
> array. I have figured out how to access elements of a 2D array
> (array(i, j) ---> array[i + i_size * j]), but haven't been able to
> figure out how to access elements from a 4D array.
>
> For example, how would I access element:
> array(i, j, k, m) from the pointer in C?
>

I have never used CALL_EXTERNAL, but my guess is:

array(i, j, k, m) ---> array[i
+ i_size * j
+ i_size * j_size * k
+ i_size * j_size * k_size * m]

regards,
lajos
Re: Multidimensional arrays and CALL_EXTERNAL [message #60968 is a reply to message #60829] Mon, 23 June 2008 05:15 Go to previous message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
Dan wrote:
> Hi Lajos,
>
> This doesn't seem to be working for me.

Dan,

It works for me; as an example:

multi.c
-------

#include <stdio.h>
#include "idl_export.h"

void do_work(float *a)
{
printf("%f\n",a[3+5*10+7*10*20+9*10*20*30]);
}

IDL_VPTR multi(int argc, IDL_VPTR argv[])
{
do_work((float *) argv[0]);
}

multi.pro
---------

pro multi
a=fltarr(10,20,30,40)

a[3,5,7,9]=3.14

junk=call_external('multi.so','multi',a,/unload)
end

Compile
-------

gcc -I /usr/local/rsi/idl/external/include -shared multi.c -o multi.so

does the above work for you? Can you post an example of code which fails?

Thanks,

Allan
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Runtime crashes
Next Topic: Java Bridge Import

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

Current Time: Wed Oct 08 15:28:51 PDT 2025

Total time taken to generate the page: 0.00505 seconds