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

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/calc_mermean_T.m

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


Revision 1.3 - (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.2: +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_mermean_T(fldIn,method,fldType);
2 % CALC_MERMEAN_T(budgIn,method,fldType)
3 % computes meridional average of fldIn (or its fields recursively).
4 %
5 % If method is 1 (default) then mskCedge (from mygrid.LONS_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,'LONS_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_mermean_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.LONS_MASKS),n3,n4));
41 weightOut=NaN*squeeze(zeros(length(mygrid.LONS_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.LONS_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.LONS_MASKS(iy).mskCedge);
78 mm=find(~isnan(mm)&mm~=0);
79 else;
80 error('method < 0 remains to be implemented');
81 end;
82
83 if strcmp(fldType,'intensive');
84 tmp1=nansum(fldIn(mm,:).*weight(mm,:),1)./nansum(weight(mm,:),1);
85 tmp2=nansum(weight(mm,:),1);
86 else;
87 tmp1=nansum(fldIn(mm,:).*mask(mm,:),1)./nansum(weight(mm,:),1);
88 tmp2=nansum(weight(mm,:),1);
89 end;
90
91 %store:
92 if ~isempty(mm);
93 fldOut(iy,:,:)=reshape(tmp1,n3,n4);
94 weightOut(iy,:,:)=reshape(tmp2,n3,n4);
95 end;
96
97 end;
98
99 X=[]; Y=[];
100 if size(fldOut,2)==length(mygrid.RC);
101 X=mygrid.LONS*ones(1,length(mygrid.RC));
102 Y=ones(length(mygrid.LONS),1)*(mygrid.RC');
103 elseif size(fldOut,2)==1;
104 X=mygrid.LONS;
105 Y=ones(length(mygrid.LONS),1);
106 end;
107

  ViewVC Help
Powered by ViewVC 1.1.22