[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arrays in Structures Question (newbie)
Mike Garrett wrote:
>
> Hej guys,
>
> I was writing some structures to hold some data values and I am having a
> hard time determining what is going inside IDL. Could someone explain why
> I keep gettin two values back when I am just asking for one? And why the
> values are getting switched down a level?
>
> IDL> pointdata([1]).distance([[44],[0]]) = 12
> IDL> print, pointdata([1]).distance([[44],[0]])
> 12
> 12
> IDL> pointdata([1]).distance([[44],[1]]) = 3
> IDL> print, pointdata([1]).distance([[44],[1]])
> 3
> 3
> IDL> print, pointdata([1]).distance([[44],[0]])
> 3
> 12
>
> Thanks for any help,
>
> Mike
Short answer:
IDL> pointdata[1].distance[44,0]=12
IDL> print, pointdata[1].distance[44,0]
Long answer:
The quantity [[44],[0]] in your statement is really the vector [44,0].
If you index an array with a vector, you get all of those elements. By
the way, don't use () to index an array unless you're using a very old
IDL. It confuses the compiler in some cases.
If you're really fond of lots and lots of punctuation, you could still
do:
IDL> print, pointdata([1]).distance([[44]],[[0]])
(note carefully the difference) but hopefully I've convinced you not to.
JD
--
J.D. Smith | WORK: (607) 255-6263
Cornell Dept. of Astronomy | (607) 255-5842
304 Space Sciences Bldg. | FAX: (607) 255-5875
Ithaca, NY 14853 |