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

Home » Public Forums » archive » Looping through structures
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
Looping through structures [message #92799] Tue, 01 March 2016 09:53 Go to next message
wdolan is currently offline  wdolan
Messages: 29
Registered: June 2015
Junior Member
So I am analyzing a years worth of data, which I got in the form of structures for each month.

For example

StrucJan has arrays (is tags the correct word?) called, lon, lat, gas_conc (we are measuring gas concentration). And StrucFeb also has the tags lon, lat, and gas_conc. Each month is in the same format.

I've got a bunch of code that does calculations with the January data. But I'm not sure how to loop over it so it does all the same calculations with the February data, and then the march, april, may etc. data (all of which are in the same format with the exact same tags).

Hopefully this makes sense!

Any ideas?
Re: Looping through structures [message #92800 is a reply to message #92799] Tue, 01 March 2016 10:16 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Hello,

On 03/01/16 12:53, Wayana Dolan wrote:
> So I am analyzing a years worth of data, which I got in the form of
> structures for each month.
>
> For example
>
> StrucJan has arrays (is tags the correct word?) called, lon, lat,
> gas_conc (we are measuring gas concentration). And StrucFeb also has
> the tags lon, lat, and gas_conc. Each month is in the same format.
>
> I've got a bunch of code that does calculations with the January
> data. But I'm not sure how to loop over it so it does all the same
> calculations with the February data, and then the march, april, may
> etc. data (all of which are in the same format with the exact same
> tags).
>
> Hopefully this makes sense!

Some methods are below...(not sure anonymous structures are required or not)

IDL> structjan={lat:1.0, lon:2.0, gas_conc:380.0}
IDL> structfeb={lat:3.0, lon:4.0, gas_conc:394.0}
IDL> structmar={lat:5.0, lon:6.0, gas_conc:403.0}


* Array
IDL> structyear = [structjan, structfeb, structmar]

IDL> help, structyear
STRUCTYEAR STRUCT = -> <Anonymous> Array[3]

IDL> help, structyear[2].gas_conc
<Expression> FLOAT = 403.000


* Hash
IDL> structyear=hash()
IDL> structyear['jan']=structjan
IDL> structyear['feb']=structfeb
IDL> structyear['mar']=structmar

IDL> help, structyear['mar'].gas_conc
<Expression> FLOAT = 403.000


* List
IDL> structyear=list()
IDL> structyear.add, structjan
IDL> structyear.add, structfeb
IDL> structyear.add, structmar

IDL> help, structyear[2].gas_conc
<Expression> FLOAT = 403.000


The usefulness of these to you depends mostly (I think) on how your
processing code cycles through the months. E.g. array and year assume
jan-dec is 0-11. Hash assumes a key (doesn't have to be a month string,
can be an integer number too.)

cheers,

paulv
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: FILE_LINES change in 8.4
Next Topic: TRICKY TASK USING AWK

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

Current Time: Wed Oct 08 11:27:29 PDT 2025

Total time taken to generate the page: 0.00438 seconds