# Re: monthly climatology

From: Sijikumar S <sijikumar_at_nyahnyahspammersnyahnyah>
Date: Wed, 4 Apr 2007 12:15:45 +0200

Hi ,

While I am trying to write a script to calculate monthly average from daily
data with an idea given by Shea few months back, got struck in a loop.

do nyr=0,nyrs-1
do nmo=1,nmos
i = ind(year.eq.year(nyr) .and. nmo.eq.mm)
xMon(:,:,nn) = dim_avg_Wrap(x(:,:,i))
delete(i)
end do
end do

The loop always works with first year instead of increasing to next one.

To test the loop, a separate array for year created like this

Variable: yy
Type: integer
Total Size: 84 bytes
21 values
Number of Dimensions: 1
Dimensions and sizes: [21]
Coordinates:
(0) 1980
................
(20) 1999

and the loop is modified as shown below

do nyr=0,1
print(nyr)
print(yy(nyr))
print(year(nyr))
do nmo=1,nmos
i = ind(year.eq.yy(nyr) .and. nmo.eq.mm)
xMon(:,:,nn) = dim_avg_Wrap(x(:,:,i))
delete(i)
end do
end do

Print statement yeilds

Variable: nyr
(0) 0

Variable: yy (subsection)
(0) 1980

Variable: year (subsection)
(0) 1980

Variable: nyr
(0) 1

Variable: yy (subsection)
(0) 1980 ; here I expect 1981

Variable: year (subsection)
(0) 1980 ;here I expect 1981

thanks for any help

Siji

On 2/22/07, Dennis Shea <shea_at_cgd.ucar.edu> wrote:
>
>
> There is no built-in function for this operation.
>
> It is easy to create one.
>
> If you have time in units of (say) yyyymmdd
> you could do something like [ untested]
>
> You will have to adjust to how you want the data returned.
>
> function calcMonMean_DayValues( time[*], x[*])
> begin
> ntim = dimsizes(time)
>
> yrStrt = time(0)/10000 ; yyyymmdd
> yrLast = time(ntim-1)/10000
>
> nyrs = (yrLast-yrStrt+1)
> nmos = 12
>
> year = time/10000
> mmdd = time - year*10000
> mm = mmdd/100
> dd = mmdd - mm*100
>
> xMon = new ( (/nyrs,nmos/), typeof(x), getFillValue(x))
>
> do nyr=0,nyrs-1
> do nmo=1,nmos
>
> i = ind(year.eq.year(nyr) .and. nmo.eq.mm)
> xMon(nyr,nmo-1) = avg( x(1) )
>
> delete(i)
> end do
> end do
>
> xMon_at_long_name = "Monthly Mean:
> if (isatt(x,"long_name")) then
> xMon_at_long_name = "Monthly Mean: "+x_at_long_name
> end if
>
> if (isatt(x,"units")) then
> xMon_at_units = x_at_units
> end if
>
> return (xMon)
> end
>
>
>

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Apr 04 2007 - 04:15:45 MDT

This archive was generated by hypermail 2.2.0 : Wed Apr 11 2007 - 08:36:47 MDT