1 |
% [BN BS BW BE BT BB] = getVOLbounds(PII) |
2 |
% |
3 |
% Given a 1/0 3D matrix PII, determine faces bounding the volume |
4 |
% |
5 |
% INPUT: |
6 |
% PII is of dimensions: PII(NDPT,NLAT,NLON) |
7 |
% with: |
8 |
% DPT downward |
9 |
% LAT northward |
10 |
% LON eastward |
11 |
% |
12 |
% OUTPUT: |
13 |
% BN,BS, BW,BE, BT,BB are 3D matrices like PII, filled with 0 or 1. |
14 |
% 1 indicates a surface bounding the volume |
15 |
% |
16 |
% BN stands for northern bound |
17 |
% BS stands for southern bound |
18 |
% BW stands for western bound |
19 |
% BE stands for eastern bound |
20 |
% BT stands for top bound |
21 |
% BB stands for bottom bound |
22 |
% |
23 |
% gmaze@mit.edu 2007/07/19 |
24 |
% |
25 |
|
26 |
function varargout = getVOLbounds(varargin) |
27 |
|
28 |
|
29 |
pii = varargin{1}; |
30 |
ndpt = size(pii,1); |
31 |
nlat = size(pii,2); |
32 |
nlon = size(pii,3); |
33 |
|
34 |
|
35 |
bounds_W = zeros(ndpt,nlat,nlon); |
36 |
bounds_E = zeros(ndpt,nlat,nlon); |
37 |
bounds_S = zeros(ndpt,nlat,nlon); |
38 |
bounds_N = zeros(ndpt,nlat,nlon); |
39 |
bounds_T = zeros(ndpt,nlat,nlon); |
40 |
bounds_B = zeros(ndpt,nlat,nlon); |
41 |
|
42 |
for iz = 1 : ndpt |
43 |
for iy = 1 : nlat |
44 |
for ix = 1 : nlon |
45 |
if pii(iz,iy,ix) == 1 |
46 |
|
47 |
% Is it a western boundary ? |
48 |
if ix-1 <= 0 % Reach the western domain limit |
49 |
bounds_W(iz,iy,ix) = 1; |
50 |
elseif pii(iz,iy,ix-1) == 0 % Reach the western volume limit |
51 |
bounds_W(iz,iy,ix) = 1; |
52 |
end |
53 |
% Is it a eastern boundary ? |
54 |
if ix+1 >= nlon % Reach the domain limit |
55 |
bounds_E(iz,iy,ix) = 1; |
56 |
elseif pii(iz,iy,ix+1) == 0 |
57 |
bounds_E(iz,iy,ix) = 1; |
58 |
end |
59 |
|
60 |
% Is it a southern boundary ? |
61 |
if iy-1 <= 0 % Reach the domain limit |
62 |
bounds_S(iz,iy,ix) = 1; |
63 |
elseif pii(iz,iy-1,ix) == 0 |
64 |
bounds_S(iz,iy,ix) = 1; |
65 |
end |
66 |
% Is it a northern boundary ? |
67 |
if iy+1 >= nlat % Reach the domain limit |
68 |
bounds_N(iz,iy,ix) = 1; |
69 |
elseif pii(iz,iy+1,ix) == 0 |
70 |
bounds_N(iz,iy,ix) = 1; |
71 |
end |
72 |
|
73 |
% Is it a top boundary ? |
74 |
if iz-1 <= 0 % Reach the domain limit |
75 |
bounds_T(iz,iy,ix) = 1; |
76 |
elseif pii(iz-1,iy,ix) == 0 |
77 |
bounds_T(iz,iy,ix) = 1; |
78 |
end |
79 |
% Is it a bottom boundary ? |
80 |
if iz+1 >= ndpt % Reach the domain limit |
81 |
bounds_B(iz,iy,ix) = 1; |
82 |
elseif pii(iz+1,iy,ix) == 0 |
83 |
bounds_B(iz,iy,ix) = 1; |
84 |
end |
85 |
|
86 |
end % if |
87 |
end %for ix |
88 |
end % for iy |
89 |
end % for iz |
90 |
|
91 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OUTPUTS |
92 |
switch nargout |
93 |
|
94 |
case 1 |
95 |
varargout(1) = {bounds_N}; |
96 |
case 2 |
97 |
varargout(1) = {bounds_N}; |
98 |
varargout(2) = {bounds_S}; |
99 |
case 3 |
100 |
varargout(1) = {bounds_N}; |
101 |
varargout(2) = {bounds_S}; |
102 |
varargout(3) = {bounds_W}; |
103 |
case 4 |
104 |
varargout(1) = {bounds_N}; |
105 |
varargout(2) = {bounds_S}; |
106 |
varargout(3) = {bounds_W}; |
107 |
varargout(4) = {bounds_E}; |
108 |
case 5 |
109 |
varargout(1) = {bounds_N}; |
110 |
varargout(2) = {bounds_S}; |
111 |
varargout(3) = {bounds_W}; |
112 |
varargout(4) = {bounds_E}; |
113 |
varargout(5) = {bounds_T}; |
114 |
case 6 |
115 |
varargout(1) = {bounds_N}; |
116 |
varargout(2) = {bounds_S}; |
117 |
varargout(3) = {bounds_W}; |
118 |
varargout(4) = {bounds_E}; |
119 |
varargout(5) = {bounds_T}; |
120 |
varargout(6) = {bounds_B}; |
121 |
|
122 |
end %switch |