Re: monthly climatology

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed, 4 Apr 2007 08:52:39 -0600 (MDT)

On Wed, 4 Apr 2007, Sijikumar S wrote:

> 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

Siji,

I think there are a few things wrong here, but I can't be certain
without seeing more of your script.

Your loop looks like it should be giving you the expected "1981"
values for "year" and "yy", but without actually seeing a full
print of "yy" and "year", I can't be certain.

Also, in your loop you have:

    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

How and where are "nn" and "mm" defined?

Can you do one of two things: either send me your script and
data so I can run it here, or else add more print statements
so I can see what's going on:

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

Thanks,

--Mary

>
>
>
>
>
>
> 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 - 08:52:39 MDT

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