[ncl-talk] Monthly average at each selected time

Dennis Shea shea at ucar.edu
Mon Aug 12 08:23:42 MDT 2019

```*NCL: calculate_monthly_values
<http://www.ncl.ucar.edu/Document/Functions/Contributed/calculate_monthly_values.shtml>*
----
*T*he CDO has a *monmean *operator but I am not sure how to extract 6-hrly
subsets.
*CDO:* https://code.mpimet.mpg.de/projects/cdo
----
NCL:

x   = f>X
printVarSummary(x)                        ; [time | ...] x [lat | ...] x
[lon | ...]
; [time | ...] x
[lev |...] x [lat | ...] x [lon | ...]

time = x&time                                  ; "seconds/minutes/days
since ..."
TIME   = *cd_calendar*(time, 0)             ; type float
year    = toint( TIME(:,0) )               ; toint strips meta data
month = toint( TIME(:,1) )
day     = toint( TIME(:,2) )               ; day of month
hour   = toint( TIME(:,3) )               ; hour of day

;  x(time,lat,lon)

do hh=0,18,6
ihr  := ind(hour.eq.hh)      ; indices
if (hh.eq.0) then
x00 = *calculate_monthly_values*(x(ihr,:,:), "avg", 0, False)
x00 at long_name = "00Z: Monthly Mean: "+x00 at long_name
printVarSummary(x00)

elseif (hh.eq. 6) then
x06 = calculate_monthly_values(x(ihr,:,:), "avg", 0, False)
x06 at long_name = "06Z: Monthly Mean: "+x06 at long_name
printVarSummary(x06)

elseif (hh.eq.12) then
x12 = calculate_monthly_values(x(ihr,:,:), "avg", 0, False)
x12 at long_name = "12Z: Monthly Mean: "+x12 at long_name
printVarSummary(x12)

elseif (hh.eq.18) then
x18 = calculate_monthly_values(x(ihr,:,:), "avg", 0, False)
x18 at long_name = "18Z: Monthly Mean: "+x18 at long_name
printVarSummary(x18)
end if
print("------------------------------------------------")
end do

Make appropriate changes for X being other dimension ranks

X(time) => x(ihr)
X(time,pts) => x(ihr,:)
X(time,lat,lon) => x(ihr,:,:)
X(time,lev,lat,lon) => x(ihr,:,:,:)

Good luck

On Sun, Aug 11, 2019 at 1:52 PM Setareh Rahimi via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Dear all,
>
> I have a nc file for my study area, containing hourly values for 6 months
> at 00, 06, 12, 18. What I am looking for is to have an average for each
> month over each mentioned time, like :
>  April average at 00, 06, 12, 18.
>
> How can I do this? Is there any function doing this, please?
> Best wishes,
>
> --
> S.Rahimi
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190812/6b996eb5/attachment.html>
```