NCO:
Not sure if it can be done via the ncea operator
due to differing number of time steps [records].
NCL:
The following is an *untested* approach.
Implicitly, it uses day-of-year rather than calendar
date to perform the averaging. If you want to use
calendar date as the method of computing averages
then you will have to use ut_calendar.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
diri = "./" ; input directory
fili = systemfunc("cd "+diri+" ; ls hgt*nc")
print(fili)
nfil = dimsizes(fili)
f = addfile(diri+"hgt.2000.nc", "r") ; leap year file; 6hrly
dim_leapyr = getfilevardimsizes(f, "hgt") ; (1464,level,lat,lon)
H = new( dim_leapyr, "float") ; create array
H = 0.0
N = 1460 ; 6hr non-leap year
nyrs = nfil ; one file per year
nleap= 0
do nf=0,nfil-1
f = addfile(diri+fili(nf), "r")
nt = getfilevardimsizes(f,"time")
H(0:nt-1,:,:,:) = (/ H(0:nt-1,:,:,:) + short2flt(f->hgt) /)
if (nt.ne.N) then
nleap = nleap+1
end if
end do ; nf loop
H(0:N-1,:,:,:) = H(0:N-1,:,:,:)/nyrs ; average the 1st 1460
if (nleap.ne.0) then
H(N:,:,:,:) = H(N:,:,:,:)/nleap ; average of leap years
end if
; add meta data
H@long_name = "Geopotential height"
H@units = "m"
H!0 = "time"
H!1 = "level"
H!2 = "lat"
H!3 = "lon"
time = fspan(1,366.75,N+4)
time@long_name = "day of climatological year: day.fraction_of_day"
H&time = time
H&level = f->level
H&lat = f->lat
H&lon = f->lon
printVarSummary(H)
On 12/30/10 1:45 AM, Guangtao dong wrote:
> Hello
> I want to use ncl or nco to get an 7 years averaged nc data from
> follow input data :
> hgt.1998.nc <http://hgt.1998.nc>,hgt.1999.nc
> <http://hgt.1999.nc>,hgt2000.nc <http://hgt2000.nc>,hgt.2001.nc
> <http://hgt.2001.nc>,hgt.2002.nc <http://hgt.2002.nc>,hgt.2003.nc
> <http://hgt.2003.nc>,hgt.2004.nc <http://hgt.2004.nc>.
> in which hgt.2000.nc <http://hgt.2000.nc> and hgt.2004.nc
> <http://hgt.2004.nc> have 1464 times and the other have 1460 times
> And i want a output file have 1464 times .
> can anyone help me? Thank you!
>
>
>
> _______________________________________________
> 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 Thu Dec 30 17:01:34 2010
This archive was generated by hypermail 2.1.8 : Tue Jan 04 2011 - 09:16:52 MST