Re: Unsolved indexing problem 2 weeks ago. [message #55737] |
Mon, 10 September 2007 08:56  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Harry,
I believe you would have to read your data 5 by 5 (or whatever), do this
in the for loop, setting a step of 5. Then, select data from i to i+5.
try to compute your average value (using where data gt -999). If there
is no valid data, write -999 as the new value. At last, you can write
the new data in the new array, 5 at a time again.
Jean
DirtyHarry wrote:
> G'day, Everyone!
>
> I posted this question about 2 weeks ago, but I couldn't make it at
> that time. I was so urgent and I just finished with the way of the Old
> Stone Age. I spent several hours to finish up this things with MS
> Excel... T.T. However, I got a chance to do the same thing, I want to
> make it with IDL this time. Please give me any idea.
>
> What I am trying to do now is to read in 16 lines at one time and
> compare the values of the second column for all 16 lines. Then, I
> either extract the one good value for output or I set the output to be
> unchanged. Once I've figured out what I want to output, I output all
> 16 lines at once and output the same value to the third column for
> each line.
>
> This exmaple data file is simplified for test simulation. With this
> file, I am testing with 5 lines instead of 16.
>
> aaa.txt
> 01 -999.9
> 02 -999.9
> 03 -999.9
> 04 0.13
> 05 -999.9
> 06 -999.9
> 07 0.17
> 08 -999.9
> 09 -999.9
> 10 -999.9
> 11 -999.9
> 12 -999.9
> 13 32.77
> 14 -999.9
> 15 -999.9
>
> This is the array that I want to make.
>
> 01 -999.9 0.13
> 02 -999.9 0.13
> 03 -999.9 0.13
> 04 0.13 0.13
> 05 -999.9 0.13
> 06 -999.9 0.17
> 07 0.17 0.17
> 08 -999.9 0.17
> 09 -999.9 0.17
> 10 -999.9 0.17
> 11 -999.9 -999.9
> 12 -999.9 -999.9
> 13 32.77 32.77
> 14 -999.9 -999.9
> 15 -999.9 -999.9
>
> I coded as shown below. However, As Conor pointed out 2 weeks ago, I
> am doing something different. I have changed several part of this
> code, but my trial has not been successful so far. Please give me any
> idea, recommendable functions, indexing tips, etc... Thanks.
>
> Harry
>
> ------------------------------------------------------------ ----------
> pro albedo_final
> close, /all
> data1 = 'D:\MODIS_ALL\aaa.txt'
> num_data = file_lines(data1)
> albedo_arr = fltarr(2, num_data)
> albedo_fin = fltarr(3, num_data)
> albedo_OK = 0.0
>
> openr, 2, data1
> readf, 2, albedo_arr
> close, 2
> c1 = 0
>
> openw, 1, 'bbb.txt'
> for i= 0, num_data-1 do begin
>
> dd = 5*(c1+1) +1
> if albedo_arr[0, i] lt DD then begin
> if (albedo_arr[1,i] gt 0 and albedo_arr[1,i] lt 1) then
> begin
> albedo_OK = albedo_arr[1,i]
> print, albedo_OK
> endif
> albedo_fin[0:1, i] = albedo_arr[0:1, i]
> albedo_fin[2, i] = albedo_OK
> endif
> c1 = c1+1
> endfor
> print, albedo_fin
> ;printf, 1, albedo_fin
> ;close, 1
> print, " It's done!"
> end
>
> This is the last result.
>
> 1.00000 -999.900 0.000000
> 2.00000 -999.900 0.000000
> 3.00000 -999.900 0.000000
> 4.00000 0.130000 0.130000
> 5.00000 -999.900 0.130000
> 6.00000 -999.900 0.130000
> 7.00000 0.170000 0.170000
> 8.00000 -999.900 0.170000
> 9.00000 -999.900 0.170000
> 10.0000 -999.900 0.170000
> 11.0000 -999.900 0.170000
> 12.0000 -999.900 0.170000
> 13.0000 -999.900 0.170000
> 14.0000 -999.900 0.170000
> 15.0000 -999.900 0.170000
>
|
|
|
Re: Unsolved indexing problem 2 weeks ago. [message #55832 is a reply to message #55737] |
Mon, 10 September 2007 22:32  |
jkj
Messages: 48 Registered: April 2007
|
Member |
|
|
I guess that this:
>> albedo_arr = fltarr(2, num_data)
followed by this:
>> openr, 2, data1
>> readf, 2, albedo_arr
fills up the array "albedo_arr" with the first two floats from each of
the first "num_data" lines?
I tend to be more explicit and read/parse each line separately - it's
nice to know when a line does not 'look' like what it should. I've
never noticed a performance hit, but I've never tried it the above
way, either. Some array operations are good and some blind you from
irregularities that should be caught!
while(not eof(2))do begin
line = ''
readf, 2, line
....check/process the line... do a write, whatever
endwhile
-Kevin
|
|
|