Re: nco

From: Dennis Shea (shea AT XXXXXX)
Date: Thu Oct 26 2000 - 14:16:47 MDT


GRID AVERAGING:

The NCO will not cell average like you describe.
NCO will do an average of 25 (.5 deg) cells to create a single 2.5
deg cell. The problem is that it's command line options are only
set up to specify one such average, not a set of them which is
what you need to rebin an entire grid.

You will need to use NCL to do this:

(1) If your data have a high degree of spatial autocorrelation,
    I'm not sure what you gain by doing bin averages.

(2) However, if u feel that bin averages are best for your problem ...
    Can you post a script where you have attempted to do this?

DAILY AVERAGE:

Re: NCO
The problem here is the same. You can specify a single daily
average, but not a series of them. The way around this is not
trivial, but you could set up a shell script to invoke ncra in
a loop with each invocation producing a file that contains a
single daily average. If desired ncrcat could then be used to
concatenate these daily files into larger files.

A 70-line NCL script that (hopefully) will what you want is included below.
The NCL script below could, with minor changes, be used on netCDF, HDF,
GRIB and COS-blocked CCM History Tape files. One
only has to change the "fext" variable and a few other lines.

It will always produce netCDF output. I used
what I call the "simple but inefficient" approach
to create the file. The nc file could be created more
efficiently using the "fileattdef", "filedimdef",
"filevarattdef", and "filevardef" procedures
but the script would have been more involved.

The "contributed.ncl" library has numerous user contributed functions.
I would suggest that users become familiar with its' contents.
   http://www.cgd.ucar.edu/csm/support/Document/contrib.shtml
In this code the "copy_VarAtts" is from this suite of functions.

;====================================================
load "/fs/cgd/data0/shea/nclGSUN/contributed.ncl"

begin
  fext = ".nc" ; input file ext

  diri = "/what/ever/dir/u/want/" ; input dir
  fili = (/ "ha0001" /) ; input file(s)

  diro = diri ; output dir
  filo = (/ "HA0001.nc" /) ; output files

  nfil = dimsizes (fili) ; # of files

  nTday= 2 ; # time steps/day
  con = 1./nTday

  do nf=0,nfil-1
     fi = addfile (diri+fili(nf)+fext, "r"); ref to input
     system ("/usr/bin/rm "+diro+filo(nf)) ; remove any pre-exist file
     fo = addfile (diro+filo(nf), "c") ; ref to output
     copy_VarAtts (fi, fo) ; copy file attributes
     fo@title = "Daily average via NCL" ; append more info
                                             ; special treatment for time
     time = fi->time
     nTim = dimsizes(time) ; # time steps on file
     nTim1= nTim-1 ; convenience

     TIME = time(0:nTim1:nTday) ; trick: create TIME with meta
     TIME = (time(0:nTim1:nTday) + time(1:nTim1:nTday))*con ; new time cv

     Var = getfilevarnames (fi) ; get all variables on file
     nVar = dimsizes (Var) ; # of variables

    do nv=nVar-1,0,1 ; loop thru each variable
                                             ; chk the file .. is it 3/4D
       nDim = dimsizes( filevardimsizes(fi, Var(nv)) ) ; # of dimensions [rank]
       print ("Var="+Var(nv)+" nDim="+nDim)
                                             ; copy 1D variables
       if (nDim.eq.1) then
           if (isfilevarcoord(fi, Var(nv), "time")) then ; is time cv present
               if (Var(nv).eq."time") then
                   fo->time = TIME
               else
                   fo->$Var(nv)$ = fi->$Var(nv)$(0:nTim1:nTday) ; copy every
nTday
               end if
           else
               fo->$Var(nv)$ = fi->$Var(nv)$ ; copy this 1D variable
           end if

           continue ; go to next iteration
       end if
                   
       if (nDim.ge.3) then
           x = fi->$Var(nv)$ ; 3D or 4D variable read to memory
           if (nDim.eq.3) then
               X = x(::nTday,:,:) ; "trick" to create variable
               X = (x(0:nTim1:nTday,:,:) + x(1:nTim1:nTday,:,:))*con ; day ave
           end if
           if (nDim.eq.4) then
               X = x(::nTday,:,:,:) ; "trick" to create variable
               X = (x(0:nTim1:nTday,:,:,:) + x(1:nTim1:nTday,:,:,:))*con ; day
ave
           end if

           X&time = TIME
           X@time_op = "daily average created via NCL script: dailyMean.ncl"

           fo->$Var(nv)$ = X ; write to netCDF
           delete (x) ; delete temporary
           delete (X)
       end if

    end do ; end variable loop
  end do ; end file loop
end

-------------------
good luck
Dennis Shea



This archive was generated by hypermail 2b29 : Thu Oct 26 2000 - 14:21:17 MDT