1 |
gforget |
1.1 |
function [fldOut,area]=calc_mskmean_T(fldIn,mask,fldType); |
2 |
|
|
% CALC_MSKMEAN_T(budgIn,mask,fldType) |
3 |
|
|
% computes average over a region (mask) of fldIn (or its fields recursively). |
4 |
|
|
% If fldType is 'intensive' (default) then fldIn is mutliplies by RAC. |
5 |
|
|
|
6 |
|
|
gcmfaces_global; |
7 |
|
|
|
8 |
|
|
if isempty(who('fldType')); fldType='intensive'; end; |
9 |
|
|
|
10 |
|
|
if isa(fldIn,'struct'); |
11 |
|
|
list0=fieldnames(fldIn); |
12 |
|
|
fldOut=[]; |
13 |
|
|
for vv=1:length(list0); |
14 |
|
|
tmp1=getfield(fldIn,list0{vv}); |
15 |
|
|
if isa(tmp1,'gcmfaces'); |
16 |
|
|
[tmp2,area]=calc_mskmean_T(tmp1,mask,fldType); |
17 |
|
|
fldOut=setfield(fldOut,list0{vv},tmp2); |
18 |
|
|
end; |
19 |
|
|
end; |
20 |
|
|
return; |
21 |
|
|
end; |
22 |
|
|
|
23 |
|
|
nr=size(fldIn{1},3); |
24 |
|
|
nr2=size(mask{1},3); |
25 |
|
|
if nr2~=nr; mask=repmat(mask,[1 1 nr]); end; |
26 |
|
|
mask(mask==0)=NaN; mask(isnan(fldIn))=NaN; |
27 |
|
|
areaMask=repmat(mygrid.RAC,[1 1 nr]).*mask; |
28 |
|
|
if strcmp(fldType,'intensive'); |
29 |
|
|
fldOut=nansum(fldIn.*areaMask,0)./nansum(areaMask,0); |
30 |
|
|
area=nansum(areaMask,0); |
31 |
|
|
else; |
32 |
|
|
fldOut=nansum(fldIn.*mask,0)./nansum(areaMask,0); |
33 |
|
|
area=nansum(areaMask,0); |
34 |
|
|
end; |
35 |
|
|
|
36 |
|
|
|