/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_calc/calc_zonmean_T.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/calc_zonmean_T.m

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


Revision 1.10 - (hide annotations) (download)
Tue Jun 14 03:39:46 2016 UTC (9 years, 1 month ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x
Changes since 1.9: +4 -0 lines
- calc_zonmean_T.m : test for mygrid.LATS_MASKS
- calc_mermean_T.m : compute averages along meridians
- gcmfaces_lines_zonal.m : define also LATS, LONS, and LONS_MASKS

1 gforget 1.9 function [fldOut,X,Y,weightOut]=calc_zonmean_T(fldIn,method,fldType);
2     % CALC_ZONMEAN_T(budgIn,method,fldType)
3     % computes zonal average of fldIn (or its fields recursively).
4 gforget 1.4 %
5 gforget 1.9 % If method is 1 (default) then mskCedge (from mygrid.LATS_MASKS)
6     % and volume elements used; if method is 2 then mskCedge and surface
7     % elements are used; if method is -1 or -2 then mskC is used (from mygrid)
8     % instead of mskCedge to define the averaging footpring.
9     %
10     % If fldType is 'intensive' (default) then fldIn is mutliplied by
11     % RAC (method=2 or -2) or RAC.*hFacC*DRF (method=1 or -1).
12 gforget 1.1
13     global mygrid;
14    
15 gforget 1.10 if ~isfield(mygrid,'LATS_MASKS');
16     error('please execute gcmfaces_lines_zonal to define mygrid.LATS_MASKS');
17     end;
18    
19 gforget 1.9 if isempty(who('fldType')); fldType='intensive'; end;
20     if isempty(who('method')); method=1; end;
21    
22     if isa(fldIn,'struct');
23     list0=fieldnames(fldIn);
24     fldOut=[];
25     for vv=1:length(list0);
26     tmp1=getfield(fldIn,list0{vv});
27     if isa(tmp1,'gcmfaces');
28     [tmp2,X,Y,weightOut]=calc_zonmean_T(tmp1,method,fldType);
29     fldOut=setfield(fldOut,list0{vv},tmp2);
30     end;
31     end;
32     return;
33     end;
34    
35 gforget 1.1 %initialize output:
36 gforget 1.9 n3=max(size(fldIn.f1,3),1); n4=max(size(fldIn.f1,4),1);
37     fldOut=NaN*squeeze(zeros(length(mygrid.LATS_MASKS),n3,n4));
38     weightOut=NaN*squeeze(zeros(length(mygrid.LATS_MASKS),n3,n4));
39 gforget 1.1
40     %use array format to speed up computation below:
41 gforget 1.9 fldIn=convert2gcmfaces(fldIn);
42     n1=size(fldIn,1); n2=size(fldIn,2);
43     fldIn=reshape(fldIn,n1*n2,n3*n4);
44    
45     %set rac and hFacC according to method
46     if abs(method)==1;
47     rac=reshape(convert2gcmfaces(mygrid.RAC),n1*n2,1)*ones(1,n3*n4);
48     if n3==length(mygrid.RC);
49     hFacC=reshape(convert2gcmfaces(mygrid.hFacC),n1*n2,n3);
50     hFacC=repmat(hFacC,[1 n4]);
51     DRF=repmat(mygrid.DRF',[n1*n2 n4]);
52     else;
53     hFacC=reshape(convert2gcmfaces(mygrid.mskC(:,:,1)),n1*n2,1)*ones(1,n3*n4);
54     hFacC(isnan(hFacC))=0;
55     DRF=repmat(mygrid.DRF(1),[n1*n2 n3*n4]);
56     end;
57     weight=rac.*hFacC.*DRF;
58 gforget 1.7 else;
59 gforget 1.9 weight=mygrid.mskC(:,:,1).*mygrid.RAC;
60     weight=reshape(convert2gcmfaces(weight),n1*n2,1)*ones(1,n3*n4);
61 gforget 1.1 end;
62 gforget 1.9
63 gforget 1.6 %masked area only:
64 gforget 1.9 weight(isnan(fldIn))=0;
65     weight(isnan(weight))=0;
66     mask=weight; mask(weight~=0)=1;
67     fldIn(isnan(fldIn))=0;
68    
69     ny=length(mygrid.LATS_MASKS);
70     for iy=1:ny;
71    
72     if method>0;
73     %get list of points that form a zonal band:
74     mm=convert2gcmfaces(mygrid.LATS_MASKS(iy).mskCedge);
75     mm=find(~isnan(mm)&mm~=0);
76     else;
77     if iy>1&iy<ny;
78     tmpMin=0.5*(mygrid.LATS(iy-1)+mygrid.LATS(iy));
79     tmpMax=0.5*(mygrid.LATS(iy)+mygrid.LATS(iy+1));
80     elseif iy==1;
81     tmpMin=-Inf;
82     tmpMax=0.5*(mygrid.LATS(iy)+mygrid.LATS(iy+1));
83     elseif iy==ny;
84     tmpMin=0.5*(mygrid.LATS(iy-1)+mygrid.LATS(iy));
85     tmpMax=+Inf;
86     end;
87     mm=convert2gcmfaces(mygrid.YC>=tmpMin&mygrid.YC<tmpMax);
88     mm=find(~isnan(mm)&mm~=0);
89     end;
90 gforget 1.6
91 gforget 1.9 if strcmp(fldType,'intensive');
92     tmp1=nansum(fldIn(mm,:).*weight(mm,:),1)./nansum(weight(mm,:),1);
93     tmp2=nansum(weight(mm,:),1);
94     else;
95     tmp1=nansum(fldIn(mm,:).*mask(mm,:),1)./nansum(weight(mm,:),1);
96     tmp2=nansum(weight(mm,:),1);
97     end;
98    
99     %store:
100     fldOut(iy,:,:)=reshape(tmp1,n3,n4);
101     weightOut(iy,:,:)=reshape(tmp2,n3,n4);
102 gforget 1.7
103     end;
104 gforget 1.1
105 gforget 1.7 X=[]; Y=[];
106 gforget 1.9 if size(fldOut,2)==length(mygrid.RC);
107 gforget 1.7 X=mygrid.LATS*ones(1,length(mygrid.RC));
108     Y=ones(length(mygrid.LATS),1)*(mygrid.RC');
109 gforget 1.9 elseif size(fldOut,2)==1;
110 gforget 1.7 X=mygrid.LATS;
111     Y=ones(length(mygrid.LATS),1);
112     end;
113 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22