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

Home » Public Forums » archive » saving arrays within loop
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
saving arrays within loop [message #53593] Sun, 22 April 2007 06:15 Go to next message
rkombiyil is currently offline  rkombiyil
Messages: 59
Registered: March 2006
Member
Dear listmembers,

I am wondering what is the best way to tackle this situation, in order
to "avoid using loops". Maybe it's trivial, but please be kind, newbie
here, still in the learning process...
--
I have binary datafiles (daily records for every minute from a given
station) which I could read using anonymous structures without any
problem. What I am trying to do is to read data from different
stations and group them into one big array, having indices =
(number_of_stations, data_having_dimensions_of_dim).

For example, I have tried this.. Outside the loop, I define the struct
and replicate the struct and within the loop, read the complete
datafile ('data', having dimensions of1440,31) from different
stations.
-----------------------------------------------------------

numdays=31 & numhrs= 24L & numins=60L

dim=numdays*numhrs*numins

;------------------
;stations is a string array containing station ID

for i=0,n_elements(stations)-1 do begin
-------
-------
;---------> this doesn't work, problem with indexing? <-----

temp=fltarr(n_elements(stations),dim)
temp[i,*]=reform(data.temp,dim)

-------
-------

endfor

;----------------------------------------
I think, the problem is the way I am imagining arrays, those data
(data.temp having dimension, dim) doesn't go into array 'temp' , such
that I have:

temp[0,*], temperature values for the first station
temp[1,*], for the second station and so on..

But only, the last station values get stored?! Do I need to index the
individual station temp values? I didn't think so.

What is it that I am doing which is so obviously wrong? I am brain
dead, please help! Sorry for the long mesg, hope I am "clear".
TIA,
~rk
Re: saving arrays within loop [message #53706 is a reply to message #53593] Tue, 24 April 2007 09:29 Go to previous message
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
> for i=0,n_elements(stations)-1 do begin
> temp=fltarr(n_elements(stations),dim)
> endfor

You are re-declaring (filling with zeroes) your output array on each
pass through the loop. This is why only the last value is stored.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: surface vs. shade_surf
Next Topic: Re: error reading a large number of binary files

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

Current Time: Wed Oct 08 15:49:34 PDT 2025

Total time taken to generate the page: 0.00688 seconds