Re: how to find the size of the array [message #2052] |
Wed, 25 May 1994 08:10 |
djackson
Messages: 31 Registered: June 1993
|
Member |
|
|
In article <thompson.769537570@serts.gsfc.nasa.gov>
thompson@serts.gsfc.nasa.gov (William Thompson) writes:
> vshvetsk@fourier.oac.uci.edu (Victor Shvetsky) writes:
[...]
>> is there a way to find out the size of the array from within the program?
>> For example: help, array gives you array(50,50)
>> Now, how can I get those dimensions into the variable?
[...]
> The SIZE() function returns this information. For example,
>
> IDL> SZ = SIZE(ARRAY)
> IDL> PRINT, SZ
> 2 50 50 4 2500
>
> The first element gives the total number of dimensions (zero for scalars).
> Following this are the dimensions, 50x50 in this example.
[...]
Just to add a slightly obscure trick:
If you know that ARRAY has 2 dimensions, it's easy to get the number of
columns and rows by indexing the SIZE() information, as in...
IDL> SZ = SIZE(ARRAY)
IDL> COLS = (SIZE(ARRAY))(1) ; note extra ()!
IDL> ROWS = (SIZE(ARRAY))(2)
IDL> PRINT, COLS, ROWS
50 50
Hope this helps!
-Dick
Dick Jackson djackson@ibd.nrc.ca Standard disclaimer
Institute for Biodiagnostics, National Research Council Canada
|
|
|
Re: how to find the size of the array [message #2060 is a reply to message #2052] |
Sat, 21 May 1994 09:26  |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
vshvetsk@fourier.oac.uci.edu (Victor Shvetsky) writes:
> I am currently writing a routine for our astrophysics department and I found
> a little question:
> is there a way to find out the size of the array from within the program?
> For example: help, array gives you array(50,50)
> Now, how can I get those dimensions into the variable?
> Thanks in advance
> Victor
The SIZE() function returns this information. For example,
IDL> SZ = SIZE(ARRAY)
IDL> PRINT, SZ
2 50 50 4 2500
The first element gives the total number of dimensions (zero for scalars).
Following this are the dimensions, 50x50 in this example. Then there is a code
specifying what the data type is--see the manual for details. The last number
gives the total number of elements in the array.
Bill Thompson
|
|
|