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

Home » Public Forums » archive » Re: basic array-structure understanding question
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: basic array-structure understanding question [message #63675 is a reply to message #63674] Wed, 19 November 2008 07:41 Go to previous messageGo to previous message
m_schellens is currently offline  m_schellens
Messages: 31
Registered: February 2005
Member
I am sure David has an appropiate link for this issue,
but for now:

On 19 Nov., 15:21, julia.waltersp...@gmail.com wrote:
> hi everybody
>
> This is what does not get into my head:
>
> I have one array containing my data.
> I have a second array containing the times when the data was
> collected.
> They have the same lenght.
>
> I put them into one structure because we all like structures and I
> learned about their advantages.
>
> now:
>
> IN SHORT are those arrays linked somehow? in other words: when working
> with a structure, does IDL know which value matches the corresponding
> date, given the data and the date array have the same length. Are
> those arrays somehow connected or are they completely independent from
> each other?

As you described, they are semantically linked.
I. e. structure.data[ i] corresponds to structure.time[ i] for all i.
For IDL there is no such association.


> IN LONG:  if I want to get e.g. all the data from all Januarys from
> 2000 to 2007, can I do it somehow like
>
> all_jan = structure.data (where(structure.time EQ 200?01??????) )..
> then it would automatically "select" only the right values. (and then
> I would have to make a separate array of the corresponding dates, make
> those two new arrays a structure so that I can plot data vs. date all
> in one?)
>
> or do I have to do it via some indexing, like:
> all_jan = where (structure.time EQ 200?01??????)  )
>
> and then apply the index to my array of data?


Both ways are fine. In the first case the index array (output of
WHERE) is a temporary variable,
in the second case you make it a (normal) variable named all_jan.

In the first case your selected data is in all_jan.
In the second case the indices are in all_jan and you have to create
the selected data by using
structure.data[ all_jan]

It is quite simple, no magic.
What might seem like magic is the
EQ (or any other logical) operator working on arrays.
WHERE just returns the inidices where the elements of the
expression (structure.time EQ 200?01??????) (which is a byte array)
are 'true'
(depends on the data type. For integers including byte 'true' is NE
0).
(you are aware that 'structure.time EQ 200?01??????' is pseudo code)

To understand this better, do:

IDL> eqArr = structure.time EQ 200?01??????
IDL> whereArr = where(eqArr)
IDL> print,eqArr
IDL> print,whereArr

You should however use the second case and check the result for -1
(IF all_jan[0] EQ -1 THEN ...)
as this is the result of WHERE if no elements are 'true'.

HTH,
Marc
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: bake a cake
Next Topic: Re: LAPACK routines

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

Current Time: Sat Nov 29 13:14:10 PST 2025

Total time taken to generate the page: 1.36333 seconds