1 |
function [FLD]=calc_zonmedian_T(fld); |
2 |
%object: compute zonal median |
3 |
%inputs: fld is the field of interest |
4 |
%output: FLD is the zonal median field |
5 |
% |
6 |
%notes: mygrid.LATS_MASKS is the set of quasi longitudinal lines along which |
7 |
% medians will be computed, as computed in gcmfaces_lines_zonal |
8 |
|
9 |
gcmfaces_global; |
10 |
|
11 |
%check that LATS_MASKS has already been defined: |
12 |
if ~isfield(mygrid,'LATS_MASKS'); |
13 |
fprintf('one-time initialization of gcmfaces_lines_zonal: begin\n'); |
14 |
gcmfaces_lines_zonal; |
15 |
fprintf('one-time initialization of gcmfaces_lines_zonal: end\n'); |
16 |
end; |
17 |
|
18 |
%initialize output: |
19 |
n3=max(size(fld.f1,3),1); n4=max(size(fld.f1,4),1); |
20 |
FLD=NaN*squeeze(zeros(length(mygrid.LATS_MASKS),n3,n4)); |
21 |
|
22 |
%apply mask: |
23 |
nr=size(mygrid.mskC.f1,3); |
24 |
if n3==nr; |
25 |
for i4=1:n4; fld(:,:,:,i4)=fld(:,:,:,i4).*mygrid.mskC; end; |
26 |
else; |
27 |
for i3=1:n3; for i4=1:n4; fld(:,:,i3,i4)=fld(:,:,i3,i4).*mygrid.mskC(:,:,1); end; end; |
28 |
end; |
29 |
|
30 |
%use array format to speed up computation below: |
31 |
fld=convert2array(fld); |
32 |
n1=size(fld,1); n2=size(fld,2); |
33 |
fld=reshape(fld,n1*n2,n3*n4); |
34 |
|
35 |
for iy=1:length(mygrid.LATS_MASKS); |
36 |
|
37 |
%get list ofpoints that form a zonal band: |
38 |
mm=convert2array(mygrid.LATS_MASKS(iy).mskCedge); |
39 |
mm=find(~isnan(mm)&mm~=0); |
40 |
|
41 |
%do the median along this band: |
42 |
tmp1=nanmedian(fld(mm,:),1); |
43 |
|
44 |
%store: |
45 |
if ~isempty(mm); |
46 |
FLD(iy,:,:)=reshape(tmp1,n3,n4); |
47 |
end; |
48 |
|
49 |
end; |
50 |
|
51 |
|