/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_misc/runmean.m
ViewVC logotype

Diff of /MITgcm_contrib/gael/matlab_class/gcmfaces_misc/runmean.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2 by gforget, Thu Jun 23 19:02:48 2011 UTC revision 1.4 by gforget, Sat Aug 27 20:40:54 2011 UTC
# Line 5  function [fldOut]=runmean(fldIn,halfWind Line 5  function [fldOut]=runmean(fldIn,halfWind
5  %           dim is the dimension over which the rmw will be applied  %           dim is the dimension over which the rmw will be applied
6  %optional:  doCycle states whether the boundary condition is cyclic (1) or  %optional:  doCycle states whether the boundary condition is cyclic (1) or
7  %               not (0; default). If doCycle==0, the no. of averaged points  %               not (0; default). If doCycle==0, the no. of averaged points
8  %               decreases from 1+2*halfWindow to halfWindow at the edges.  %               decreases from 1+2*halfWindow to halfWindow at the edges,
9    %               and we mask all of those edge points with NaNs.
10  %output:    fldOut is the resulting field  %output:    fldOut is the resulting field
11  %  %
12  %notes:     - NaNs are discarded in the rmw, implying that an average is  %notes:     - NaNs are discarded in the rmw, implying that an average is
# Line 23  end; Line 24  end;
24  if nargin==3; doCycle=0; else; doCycle=varargin{1}; end;  if nargin==3; doCycle=0; else; doCycle=varargin{1}; end;
25    
26  %switch to array format if needed  %switch to array format if needed
27  if fld_isa_gcmfaces; fldOut=convert2array(fldOut); end;  if fld_isa_gcmfaces; fldIn=convert2array(fldIn); end;
28    
29  %switch dim to first dimension  %switch dim to first dimension
30  sizeIn=size(fldIn);  sizeIn=size(fldIn);
# Line 52  fldCnt=0*fldIn; Line 53  fldCnt=0*fldIn;
53  %apply the running mean  %apply the running mean
54  fldOut=zeros(sizeCur);  fldOut=zeros(sizeCur);
55  for tcur=-halfWindow:halfWindow  for tcur=-halfWindow:halfWindow
56        %To have halfWindow*2 coeffs rather than halfWindow*2+1, centered to the current
57        %point, it is convenient to reduce the weight of the farthest points to 1/2.
58        %This became necessary to get proper annual means, from monthly data, with halfWindow=6.
59        if abs(tcur)==halfWindow; fac=1/2; else; fac=1; end;
60      tmp1=circshift(fldIn,[tcur zeros(1,length(sizeCur)-1)]);      tmp1=circshift(fldIn,[tcur zeros(1,length(sizeCur)-1)]);
61      fldOut=fldOut+tmp1;      fldOut=fldOut+fac*tmp1;
62      tmp1=circshift(fldMsk,[tcur zeros(1,length(sizeCur)-1)]);      tmp1=circshift(fldMsk,[tcur zeros(1,length(sizeCur)-1)]);
63      fldCnt=fldCnt+tmp1;      fldCnt=fldCnt+fac*tmp1;
64  end  end
65    
66  fldCnt(fldCnt==0)=NaN;  fldCnt(fldCnt<2*halfWindow)=NaN;
67  fldOut=fldOut./fldCnt;  fldOut=fldOut./fldCnt;
68    
69  if ~doCycle;  if ~doCycle;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.22