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

Contents 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.12 - (show annotations) (download)
Sat Nov 19 15:22:40 2016 UTC (8 years, 8 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.11: +8 -5 lines
- grid_load.m: remove call to gcmfaces_lines_zonal and gcmfaces_lines_transp
- calc_MeridionalTransport.m, calc_mermean_T.m, calc_overturn.m, calc_zonmean_T.m,
  calc_zonmedian_T.m, gcmfaces_section.m, diags_display.m, diags_grid_parms.m, figureL.m,
  example_transports_disp.m: call gcmfaces_lines_zonal and / or gcmfaces_lines_transp to
  initialize LATS_MASKS, LONS_MASKS, or LINES_MASKS if needed.

1 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 %
5 % 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
13 gcmfaces_global;
14
15 if isempty(who('fldType')); fldType='intensive'; end;
16 if isempty(who('method')); method=1; end;
17
18 %check that LATS_MASKS has already been defined:
19 if ~isfield(mygrid,'LATS_MASKS');
20 fprintf('one-time initialization of gcmfaces_lines_zonal: begin\n');
21 gcmfaces_lines_zonal;
22 fprintf('one-time initialization of gcmfaces_lines_zonal: end\n');
23 end;
24
25 if isa(fldIn,'struct');
26 list0=fieldnames(fldIn);
27 fldOut=[];
28 for vv=1:length(list0);
29 tmp1=getfield(fldIn,list0{vv});
30 if isa(tmp1,'gcmfaces');
31 [tmp2,X,Y,weightOut]=calc_zonmean_T(tmp1,method,fldType);
32 fldOut=setfield(fldOut,list0{vv},tmp2);
33 end;
34 end;
35 return;
36 end;
37
38 %initialize output:
39 n3=max(size(fldIn.f1,3),1); n4=max(size(fldIn.f1,4),1);
40 fldOut=NaN*squeeze(zeros(length(mygrid.LATS_MASKS),n3,n4));
41 weightOut=NaN*squeeze(zeros(length(mygrid.LATS_MASKS),n3,n4));
42
43 %use array format to speed up computation below:
44 fldIn=convert2gcmfaces(fldIn);
45 n1=size(fldIn,1); n2=size(fldIn,2);
46 fldIn=reshape(fldIn,n1*n2,n3*n4);
47
48 %set rac and hFacC according to method
49 if abs(method)==1;
50 rac=reshape(convert2gcmfaces(mygrid.RAC),n1*n2,1)*ones(1,n3*n4);
51 if n3==length(mygrid.RC);
52 hFacC=reshape(convert2gcmfaces(mygrid.hFacC),n1*n2,n3);
53 hFacC=repmat(hFacC,[1 n4]);
54 DRF=repmat(mygrid.DRF',[n1*n2 n4]);
55 else;
56 hFacC=reshape(convert2gcmfaces(mygrid.mskC(:,:,1)),n1*n2,1)*ones(1,n3*n4);
57 hFacC(isnan(hFacC))=0;
58 DRF=repmat(mygrid.DRF(1),[n1*n2 n3*n4]);
59 end;
60 weight=rac.*hFacC.*DRF;
61 else;
62 weight=mygrid.mskC(:,:,1).*mygrid.RAC;
63 weight=reshape(convert2gcmfaces(weight),n1*n2,1)*ones(1,n3*n4);
64 end;
65
66 %masked area only:
67 weight(isnan(fldIn))=0;
68 weight(isnan(weight))=0;
69 mask=weight; mask(weight~=0)=1;
70 fldIn(isnan(fldIn))=0;
71
72 ny=length(mygrid.LATS_MASKS);
73 for iy=1:ny;
74
75 if method>0;
76 %get list of points that form a zonal band:
77 mm=convert2gcmfaces(mygrid.LATS_MASKS(iy).mskCedge);
78 mm=find(~isnan(mm)&mm~=0);
79 else;
80 if iy>1&iy<ny;
81 tmpMin=0.5*(mygrid.LATS(iy-1)+mygrid.LATS(iy));
82 tmpMax=0.5*(mygrid.LATS(iy)+mygrid.LATS(iy+1));
83 elseif iy==1;
84 tmpMin=-Inf;
85 tmpMax=0.5*(mygrid.LATS(iy)+mygrid.LATS(iy+1));
86 elseif iy==ny;
87 tmpMin=0.5*(mygrid.LATS(iy-1)+mygrid.LATS(iy));
88 tmpMax=+Inf;
89 end;
90 mm=convert2gcmfaces(mygrid.YC>=tmpMin&mygrid.YC<tmpMax);
91 mm=find(~isnan(mm)&mm~=0);
92 end;
93
94 if strcmp(fldType,'intensive');
95 tmp1=nansum(fldIn(mm,:).*weight(mm,:),1)./nansum(weight(mm,:),1);
96 tmp2=nansum(weight(mm,:),1);
97 else;
98 tmp1=nansum(fldIn(mm,:).*mask(mm,:),1)./nansum(weight(mm,:),1);
99 tmp2=nansum(weight(mm,:),1);
100 end;
101
102 %store:
103 if ~isempty(mm);
104 fldOut(iy,:,:)=reshape(tmp1,n3,n4);
105 weightOut(iy,:,:)=reshape(tmp2,n3,n4);
106 end;
107
108 end;
109
110 X=[]; Y=[];
111 if size(fldOut,2)==length(mygrid.RC);
112 X=mygrid.LATS*ones(1,length(mygrid.RC));
113 Y=ones(length(mygrid.LATS),1)*(mygrid.RC');
114 elseif size(fldOut,2)==1;
115 X=mygrid.LATS;
116 Y=ones(length(mygrid.LATS),1);
117 end;
118

  ViewVC Help
Powered by ViewVC 1.1.22