Re: SIZE() vs. N_ELEMENTS() [message #67249] |
Sat, 18 July 2009 02:40 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Jul 16, 3:59 pm, wlandsman <wlands...@gmail.com> wrote:
> On Jul 16, 2:39 pm, wlandsman <wlands...@gmail.com> wrote:
> Is there any situation now where
>
>> one must use SIZE() to get the number of elements rather than
>> N_ELEMENTS().
>
> Immediately after posting I realized that the answer to the above
> question is "yes". In the following code using ASSOC(), N_Elements(a)
> equals 1, but size(a,/N_elements) equals 2. --Wayne
>
...
*poof* = sound of my mind being blown.
|
|
|
Re: SIZE() vs. N_ELEMENTS() [message #67321 is a reply to message #67249] |
Thu, 16 July 2009 13:25  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
> Yes, but which is *correct*? :-)
As usual, what is correct depends on the question you are asking.
There is one ASSOC variable, but it is mapped to a structure with 2
elements.
I presume the Prize Chairman will spend his time under the Carribbean
Sun pondering this conundrum. Have fun!
--Wayne
> Tough competition this month though, in the form of Scope_VarFetch
> and Execute as suggestions to the poor guy who wanted
> to know what an array was.
To be fair, it wasn't clear to me from the original question whether
it was from a beginner or not. I know in the past that I have made
the opposite mistake of answering a question from an expert with an
explanation for a beginner...
|
|
|
Re: SIZE() vs. N_ELEMENTS() [message #67322 is a reply to message #67321] |
Thu, 16 July 2009 13:11  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
wlandsman writes:
> Immediately after posting I realized that the answer to the above
> question is "yes". In the following code using ASSOC(), N_Elements(a)
> equals 1, but size(a,/N_elements) equals 2. --Wayne
>
>
> b =3D {a:indgen(10),b:fltarr(100)}
> openw,lun,'test.dat',/get_lun
> writeu,lun,replicate(b,12)
> close,lun
>
> openr,lun,'test.dat'
> c =3D replicate(b,2)
> a =3D assoc(lun,c)
> print,size(a,/n_elements)
> print,N_elements(a)
By the way, since the Prize Chairman is leaving in about
half an hour for a little mid-summer beach action in
the Caribbean with his new Latin lover (a fox to hear
him tell it), he has decided to award this month's
most obscure post prize to Wayne. Tough competition
this month though, in the form of Scope_VarFetch
and Execute as suggestions to the poor guy who wanted
to know what an array was.
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: SIZE() vs. N_ELEMENTS() [message #67323 is a reply to message #67322] |
Thu, 16 July 2009 13:04  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
wlandsman writes:
> Immediately after posting I realized that the answer to the above
> question is "yes". In the following code using ASSOC(), N_Elements(a)
> equals 1, but size(a,/N_elements) equals 2. --Wayne
>
>
> b =3D {a:indgen(10),b:fltarr(100)}
> openw,lun,'test.dat',/get_lun
> writeu,lun,replicate(b,12)
> close,lun
>
> openr,lun,'test.dat'
> c =3D replicate(b,2)
> a =3D assoc(lun,c)
> print,size(a,/n_elements)
> print,N_elements(a)
Yes, but which is *correct*? :-)
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: SIZE() vs. N_ELEMENTS() [message #67324 is a reply to message #67323] |
Thu, 16 July 2009 12:59  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Jul 16, 2:39 pm, wlandsman <wlands...@gmail.com> wrote:
Is there any situation now where
> one must use SIZE() to get the number of elements rather than
> N_ELEMENTS().
Immediately after posting I realized that the answer to the above
question is "yes". In the following code using ASSOC(), N_Elements(a)
equals 1, but size(a,/N_elements) equals 2. --Wayne
b = {a:indgen(10),b:fltarr(100)}
openw,lun,'test.dat',/get_lun
writeu,lun,replicate(b,12)
close,lun
openr,lun,'test.dat'
c = replicate(b,2)
a = assoc(lun,c)
print,size(a,/n_elements)
print,N_elements(a)
|
|
|