Calculate a weighted running average. Missing values are allowed

**Note:** This function is only available in version 4.1.1 of
NCL. If your site is licensed for version 4.1, then you can get
version 4.1.1 for free. To get version 4.1.1 of NCAR Graphics
software, please contact your site representative. If you don't know
who your site representative is, then send email to ncarginf@ucar.edu or call (303)
497-1201.

function wgt_runave( x : float, wgt : float, kopt : integer )

*x*- An array with one or more dimensions. The rightmost dimension will
be the dimension on which the weighted running average is
performed. Missing values should be indicated by
*x*@_FillValue. If*x*@_FillValue is not set, then the NCL default (-999) will be assumed. *wgt*- Vector containing all the weights
*kopt*- End-point option (
*kopt*= 0 is the most frequently used)In the following, N=last point in the series:

kopt < 0 : utilize cyclic conditions e.g., nwgt=3 x(0) = w(0)*x(N) +w(1)*x(0)+w(2)*x(1) x(N) = w(0)*x(N-1)+w(1)*x(N)+w(2)*x(0) e.g., nwgt=4 at n=1 and n=N x(0) = w(0)*x(N-1)+w(1)*x(N) +w(2)*x(0)+w(3)*x(1) x(N) = w(0)*x(N-2)+w(1)*x(N-1)+w(2)*x(N)+w(3)*x(0) kopt = 0 : set unsmoothed beginning and end pts to x@_FillValue [most common] e.g., nwgt=3 , x(0) = x@_FillValue and x(N) = x@_FillValue , x(1) = w(0)*x(0)+w(1)*x(1)+w(2)*x(2) e.g., nwgt=4 , x(0),x(1),x(N-1) and x(N) = x@_FillValue , x(2) = w(0)*x(0)+w(1)*x(1)+w(2)*x(2)+w(3)*x(3) kopt > 0 : utilize reflective (symmetric) conditions e.g., nwgt=3 x(0) = w(0)*x(1) +w(1)*x(0)+w(2)*x(1) x(N) = w(0)*x(N-1)+w(1)*x(N)+w(2)*x(N-1) e.g., nwgt=4 x(0) = w(0)*x(2) +w(1)*x(1) +w(2)*x(0)+w(3)*x(1) x(N) = w(0)*x(N-2)+w(1)*x(N-1)+w(2)*x(N)+w(3)*x(N-1)

F(i) = SUM{w(j)*UF(i-(nwgt/2)+j-1)} from j=0,nwgt-1where

With the proper choice of weights, this "filter" can also be used to compute time differences and derivatives.

If the number of weights is even, the filter's center falls between series elements. In this case, the center is shifted one-half of a time increment towards the latter element.

x = wgt_runave (x, (/ 0.25, 0.50, 0.25 /), 0)

kopt = 0 wgt = (/ 0.0270, 0.05856, 0.09030, 0.11742, 0.13567, \ 0.1421, 0.13567, 0.11742, 0.09030, 0.05856, 0.027 /) y = wgt_runave (x(lat|:,lon|:,time|:), wgt, kopt)

kopt = 0 wlow = (/-0.0059591606, -0.0074864031, -0.0081766107, -0.0074769889 \ ,-0.0048789007, 0.0 , 0.0073407153, 0.0170670479 \ , 0.0288191067, 0.0419626250, 0.0556356004, 0.0688283154 \ , 0.0804876892, 0.0896329731, 0.0954676702 \ , 0.0974726419 \ ; central wgt , 0.0954676702, 0.0896329731, 0.0804876892 \ , 0.0688283154, 0.0556356004, 0.0419626250, 0.0288191067 \ , 0.0170670479, 0.0073407153, 0.0 , -0.0048789007 \ ,-0.0074769889, -0.0081766107,-0.0074864031, -0.0059591606 /) ylow = wgt_runave (x(lev|:,lat|:,lon|:,time|:), wlow, kopt) wmed = (/-0.0030384857, -0.0001341773, -0.0096723016, -0.0191709641 \ ,-0.0020017146, 0.0304306715, 0.0328072034, 0.0041075557 \ , 0.0033466748, 0.0419335015, 0.0283041151, -0.0923257264 \ ,-0.1947701551, -0.1020097578, 0.1433496840 \ , 0.2776877534 \ ; central weight , 0.1433496840, -0.1020097578, -0.1947701551 \ ,-0.0923257264, 0.0283041151, 0.0419335015, 0.0033466748 \ , 0.0041075557, 0.0328072034, 0.0304306715, -0.0020017146 \ ,-0.0191709641, -0.0096723016, -0.0001341773, -0.0030384857 /) ymed = wgt_runave (x(lev|:,lat|:,lon|:,time|:), wmed, kopt) whigh = (/ 0.0036193743, 0.0062672457, -0.0071490567, -0.0089978990 \ , 0.0125704103, 0.0117924147, -0.0207251125, -0.0144542141 \ , 0.0333056699, 0.0167834343, -0.0546750050, -0.0185972473 \ , 0.1009810886, 0.0197489990, -0.3186000638 \ , 0.4762599236 \ ; central weight ,-0.3186000638, 0.0197489990, 0.1009810886 \ ,-0.0185972473, -0.0546750050, 0.0167834343, 0.0333056699 \ ,-0.0144542141, -0.0207251125, 0.0117924147, 0.0125704103 \ ,-0.0089978990, -0.0071490567, 0.0062672457, 0.0036193743 /) yhigh = wgt_runave (x(lev|:,lat|:,lon|:,time|:), whigh, kopt)

In the above example it might be better to create a new variable
*xnew* rather than reorder the dimensions each time. For
example, if you are going to apply this filter for low, medium, and
high filters, it will be more efficient to create a new variable
*tnew*:

tnew = t(lev|:,lat|:,lon|:,time|:)and then use

kopt = -1 wgt = (/ 1., 3., 5., 3., 1. /) wgt = wgt/sum(wgt) ; normalize x = wgt_runave (x,wgt, kopt)

NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?