Re: loop problem

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 19 2012 - 08:34:17 MDT

Hi Torben,

Perhaps the "k = 0" should be inside the first "do while" loop?

Also, you don't need to keep recreating sml_temp inside the loop. You can do it once outside the loop:

> sml_temp = new(dimsizes(y),float) ; dim: x,y,t
> do while (i.le.n-1) ; loop for different cases

If you need to, you can set sml_temp to all missing inside the loop before you start assigning it.
This is only necessary if you are not assigning all values of sml_temp inside the second do loop:

sml_temp = sml_temp@_FillValue

I think your "do" loops can be simplified by using regular "do" rather than "do while":

nt = dimsizes(t)
do i=0,n-1
  . . .
  do k=0,nt-1
    . . .
  end do
end do

This way you don't need the "i = 0", "k = 0" initializers, or the "i=i+1" and "k=k+1" incrementors at all.

--Mary

On Mar 16, 2012, at 9:39 PM, Torben Mueller wrote:

> Dear NCL community,
>
> I have a problem with the loop sketched below.
> All my input arrays (ts and x) have defined values at all times).
> Basically, I run through a number of cases and create a temporary
> lon*lat*time matrix, average over the time dimension and assign it to
> a new array with a time-average lon*lat matrix for every case n.
> However in my final array (sml), I only get correct values for the
> first i loop (i=0), afterwards I only get fill values.
> Is there maybe a problem running once over an inner dimension and once
> over an outer dimension?
>
> Thank you very much in advance!
>
> sml = new(dimsizes(x),float) ; dim:n,x,y
>
> i = 0
> k = 0
>
> do while (i.le.n-1) ; loop for different cases
>
> sml_temp = new(dimsizes(y),float) ; dim: x,y,t
>
> do while (k.le.dimsizes(t)-1) ; time loop
> sml_temp(:,:,k) = ts(i,k)*x(:,:,k)
> k=k+1
> end do
>
> ; average over the time dimension
> sml(i,:,:) = dim_avg_n_Wrap(sml_temp,2)
>
> i=i+1
> end do
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 19 08:34:26 2012

This archive was generated by hypermail 2.1.8 : Tue Mar 20 2012 - 15:27:15 MDT