Re: diurnal cycle over a subregion

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 14 Dec 2007 10:22:38 -0700 (MST)

On Wed, 12 Dec 2007 jimmyc_at_iastate.edu wrote:

> All I have a 3 dimensional array (i,j,time) of 3-hrly rain rate and want to
> compute the diurnal cycle.
>
> I attempted to do a loop like this
> n=0
> do days=0,30
> do hr=0,7
> n=n+1
> do ix=43,61
> do iy=71,92
> if(rain(iy,ix,hr) .gt. 0.0000)then
> rdc(hr) = rain(iy,ix,hr) + rdc(hr)
> cnt(hr) = cnt(hr) + 1
> end if
> end do
> end do
> end do
> end do

All,

James figured out the problem using WRAPIT and Fortran code, but I just
wanted to point out that you usually can avoid nested loops like this,
by using NCL's array syntax, and the "ind" or "where" functions.

For example, the above loop can be partially improved by
removing the "hr" loop. (BTW, I'm not sure what the "days" loop
is doing here, because "days" is not referenced by anybody,
so it appears that the exact same calculations are being
done 31 times).

Anyway, here's a slight (untested) code change that would help:

   do days=0,30
      n=n+1
      do ix=43,61
        do iy=71,92
          ihr = ind(rain(iy,ix,:).gt.0.0000)
          if(.not.any(ismissing(ihr))) then
            rdc(ihr) = rain(iy,ix,ihr) + rdc(ihr)
            cnt(ihr) = cnt(ihr) + 1
          end if
          delete(ihr) ; necessary as it may be different size next time
        end do
      end do
    end do

--Mary

> Now the code gets into the if block but the value of rdc is the _FillValue of
> -999 . So, the documentation states that when asigning one variable to
> another they need to be the same shape. Is there a way to do the sum either
> more simply than with loops or am I stuck in Fortran language techniques?
>
> I do define the rdc,cnt,rain arrays prior to the loop.
> And I can printVarSummary all of them, just no values accumulate in the rdc
> array.
>
> Thanks for your time.
>
> --
> James Correia, Jr. PhD.
> Email: jimmyc @ iastate.edu
> Email: jimmyc42 @ gmail.com
> Web: http://bruce.agron.iastate.edu/jimmyc/
> *********************************************
>
> "Wisdom. Strength. Courage. Generosity. Each of us are born with one of
> these. We must find the other three inside of us."
> from "Into the West"
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Dec 14 2007 - 10:22:38 MST

This archive was generated by hypermail 2.2.0 : Mon Dec 17 2007 - 08:25:02 MST