saving arrays within loop [message #53593] |
Sun, 22 April 2007 06:15  |
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  |
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.
|
|
|