Re: array dimension change [message #63136] |
Wed, 29 October 2008 06:59  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Oct 28, 6:57 pm, xiao <littledd...@gmail.com> wrote:
> Hi~ guys~ I have a question here. I wrote a small program like the
> following, but why the two print statement print out the same thing?
> It is suppose to print out the different elements because i know the
> contents are different in the original array. I can name another
> array with same dimension and do the same thing , then it works, the
> elements changed , but why it did not change as the following?
> Many Thanks~
>
> soilw00 = Read_Binary('/nas/rstor6/xzhang/RAMS/build/60/soil/AVNdat/fh .
> 0024_tl.press_gr.onedeg.SoilW', Data_Type = 4, Data_Dims =
> [360,181,4])
>
> help,soilw00
>
> print, soilw00(265:325,110:130,0)
>
> for kk=0,4-1 do begin
> for jj=0,181-1 do begin
> for ii=0,360-1 do begin
> soilw00(ii,jj,kk)=soilw00(359-ii,jj,kk)
> endfor
> endfor
> endfor
First of all, the loops through jj and kk are really expensive. Get
rid of them!
for ii=0,360-1 do begin
soilw00[ii,*,*]=soilw00[359-ii,*,*]
endfor
Secondly, I think what you really wanted was:
for ii=0,360/2-1 do begin
soilw00[ii,*,*]=soilw00[359-ii,*,*]
endfor
In your original case, you first reverse the structure and then
reverse it back again to get what you started with!
Finally, why don't you just use the built-in REVERSE function?
soilw00 = reverse(soilw00, 1)
-Jeremy.
|
|
|
|
Re: array dimension change [message #63260 is a reply to message #63136] |
Wed, 29 October 2008 13:17  |
xiao zhang
Messages: 81 Registered: June 2008
|
Member |
|
|
On Oct 29, 8:59 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Oct 28, 6:57 pm, xiao <littledd...@gmail.com> wrote:
>
>
>
>> Hi~ guys~ I have a question here. I wrote a small program like the
>> following, but why the two print statement print out the same thing?
>> It is suppose to print out the different elements because i know the
>> contents are different in the original array. I can name another
>> array with same dimension and do the same thing , then it works, the
>> elements changed , but why it did not change as the following?
>> Many Thanks~
>
>> soilw00 = Read_Binary('/nas/rstor6/xzhang/RAMS/build/60/soil/AVNdat/fh .
>> 0024_tl.press_gr.onedeg.SoilW', Data_Type = 4, Data_Dims =
>> [360,181,4])
>
>> help,soilw00
>
>> print, soilw00(265:325,110:130,0)
>
>> for kk=0,4-1 do begin
>> for jj=0,181-1 do begin
>> for ii=0,360-1 do begin
>> soilw00(ii,jj,kk)=soilw00(359-ii,jj,kk)
>> endfor
>> endfor
>> endfor
>
> First of all, the loops through jj and kk are really expensive. Get
> rid of them!
>
> for ii=0,360-1 do begin
> soilw00[ii,*,*]=soilw00[359-ii,*,*]
> endfor
>
> Secondly, I think what you really wanted was:
>
> for ii=0,360/2-1 do begin
> soilw00[ii,*,*]=soilw00[359-ii,*,*]
> endfor
>
> In your original case, you first reverse the structure and then
> reverse it back again to get what you started with!
>
> Finally, why don't you just use the built-in REVERSE function?
>
> soilw00 = reverse(soilw00, 1)
>
> -Jeremy.
Thank you ~~~ the reverse works~~~ :)
|
|
|