/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_legacy/nanrunmean.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_legacy/nanrunmean.m

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


Revision 1.1 - (show annotations) (download)
Thu Jun 23 19:02:44 2011 UTC (14 years ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
gcmfaces_misc	added headers to all routines
				added depthStretch.m and depthStretchPlot.m
				> removed myverticaldeform.m, verticalplot.m
				and runmean_cycle.m
				rewritten runmean.m
				> removed nanrunmean.m, nanrunmean_cycle.m and runmean_cycle.m
gcmfaces_legacy	added nanrunmean.m, nanrunmean_cycle.m, runmean_cycle.m
				myverticaldeform.m, verticalplot.m
plot_one_field	added example of depthStretchPlot
basic_diags_display_transport	added header

1 %this function does a running mean along dimension dim_cur,
2 %averaging over indices [-nb_cur:nb_cur]
3 %
4 function [field_out]=nanrunmean(field_in,nb_cur,dim_cur);
5
6 if nb_cur~=0
7
8 size_cur=size(field_in);
9
10 perm1to2=[1:length(size_cur)];
11 perm1to2=[dim_cur perm1to2(find(perm1to2~=dim_cur))];
12 perm2to1=[[1:dim_cur-1]+1 1 [dim_cur+1:length(size_cur)]];
13 size_cur2=size_cur(perm1to2);
14
15 field_in2=permute(field_in,perm1to2);
16
17 field_mask2=1*~isnan(field_in2);
18 field_in2(isnan(field_in2))=0;
19
20 field_out2=zeros(size_cur2);
21 count_out2=zeros(size_cur2);
22 for tcur=-nb_cur:nb_cur
23 tmp1=[tcur:tcur-1+size_cur2(1)];
24 tmp2=find(tmp1>=1&tmp1<=size_cur2(1));
25 field_out2(tmp2,:)=field_out2(tmp2,:)+field_in2(tmp1(tmp2),:);
26 count_out2(tmp2,:)=count_out2(tmp2,:)+field_mask2(tmp1(tmp2),:);
27 end
28
29 tmp1=find(count_out2>0);
30 field_out2(tmp1)=field_out2(tmp1)./count_out2(tmp1);
31 field_out2(count_out2==0)=NaN;
32
33 field_out=permute(field_out2,perm2to1);
34
35 else
36 field_out=field_in;
37 end%if nb_cur~=0
38
39

  ViewVC Help
Powered by ViewVC 1.1.22