1 |
gforget |
1.5 |
function [FLD]=calc_transports(fldU,fldV,SECTIONS_MASKS,list_factors); |
2 |
gforget |
1.2 |
%object: compute transports through pre-defined sections |
3 |
|
|
%inputs: fldU and fldV are the fields of grid point transport |
4 |
|
|
% SECTIONS_MASKS is the set of sections along |
5 |
|
|
% which transports will integrated (SECTIONS_MASKS should |
6 |
|
|
% have been produced by line_greatC_TUV_mask.m) |
7 |
gforget |
1.5 |
%optional: list_factors is the list of factors that need to |
8 |
|
|
% be applied to fldU,fldV. By default it is empty (i.e. {}). |
9 |
|
|
% The most complete list would be {'dh','dz','hfac'}. |
10 |
gforget |
1.2 |
%output: FLD is the array of transport profiles |
11 |
gforget |
1.1 |
|
12 |
|
|
global mygrid; |
13 |
|
|
|
14 |
|
|
%initialize output: |
15 |
|
|
n3=max(size(fldU.f1,3),1); n4=max(size(fldV.f1,4),1); |
16 |
|
|
FLD=NaN*squeeze(zeros(length(SECTIONS_MASKS),n3,n4)); |
17 |
|
|
|
18 |
|
|
%prepare fldU/fldV: |
19 |
|
|
fldU(isnan(fldU))=0; fldV(isnan(fldV))=0; |
20 |
|
|
|
21 |
gforget |
1.5 |
if isempty(who('list_factors')); list_factors={}; end; |
22 |
|
|
|
23 |
|
|
if sum(strcmp(list_factors,'dh'))>0; |
24 |
|
|
dxg=mk3D(mygrid.DXG,fldU); dyg=mk3D(mygrid.DYG,fldU); |
25 |
|
|
else; |
26 |
|
|
dxg=1; dyg=1; |
27 |
|
|
end; |
28 |
|
|
if sum(strcmp(list_factors,'dz'))>0; |
29 |
|
|
drf=mk3D(mygrid.DRF,fldU); |
30 |
|
|
else; |
31 |
|
|
drf=1; |
32 |
|
|
end; |
33 |
|
|
facW=1; facS=1; |
34 |
|
|
for ii=1:length(list_factors); |
35 |
|
|
tmp1=list_factors{ii}; |
36 |
|
|
if strcmp(tmp1,'dh'); facW=facW.*dyg; facS=facS.*dxg; |
37 |
|
|
elseif strcmp(tmp1,'dz'); facW=facW.*drf; facS=facS.*drf; |
38 |
|
|
elseif strcmp(tmp1,'hfac'); facW=facW.*mygrid.hFacW; facS=facS.*mygrid.hFacS; |
39 |
|
|
elseif isempty(tmp1); 1; |
40 |
|
|
else; fprintf('error in calc_UV_div: non supported factor\n'); return; |
41 |
|
|
end; |
42 |
|
|
end; |
43 |
|
|
|
44 |
gforget |
1.1 |
for k4=1:n4; |
45 |
gforget |
1.5 |
fldU(:,:,:,k4)=fldU(:,:,:,k4).*facW; |
46 |
|
|
fldV(:,:,:,k4)=fldV(:,:,:,k4).*facS; |
47 |
gforget |
1.1 |
end; |
48 |
|
|
|
49 |
|
|
%use array format to speed up computation below: |
50 |
|
|
fldU=convert2array(fldU); fldV=convert2array(fldV); |
51 |
|
|
|
52 |
|
|
for iy=1:length(SECTIONS_MASKS); |
53 |
|
|
|
54 |
|
|
%get list ofpoints that form a zonal band: |
55 |
gforget |
1.4 |
mskW=SECTIONS_MASKS(iy).mskWedge; |
56 |
|
|
vecW=gcmfaces_subset(mskW,fldU); |
57 |
|
|
mskS=SECTIONS_MASKS(iy).mskSedge; |
58 |
|
|
vecS=gcmfaces_subset(mskS,fldV); |
59 |
|
|
|
60 |
gforget |
1.1 |
%store: |
61 |
gforget |
1.4 |
FLD(iy,:)=nansum(vecW,1)+nansum(vecS,1); |
62 |
gforget |
1.1 |
|
63 |
|
|
end; |
64 |
|
|
|
65 |
|
|
|