1 | function mask=get_embeddedmask(mask_parent,h,refinecoeff,newtopo) |
---|
2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3 | % |
---|
4 | % Compute the mask for the child grid |
---|
5 | % |
---|
6 | % Further Information: |
---|
7 | % http://www.brest.ird.fr/Roms_tools/ |
---|
8 | % |
---|
9 | % This file is part of ROMSTOOLS |
---|
10 | % |
---|
11 | % ROMSTOOLS is free software; you can redistribute it and/or modify |
---|
12 | % it under the terms of the GNU General Public License as published |
---|
13 | % by the Free Software Foundation; either version 2 of the License, |
---|
14 | % or (at your option) any later version. |
---|
15 | % |
---|
16 | % ROMSTOOLS is distributed in the hope that it will be useful, but |
---|
17 | % WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | % GNU General Public License for more details. |
---|
20 | % |
---|
21 | % You should have received a copy of the GNU General Public License |
---|
22 | % along with this program; if not, write to the Free Software |
---|
23 | % Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
---|
24 | % MA 02111-1307 USA |
---|
25 | % |
---|
26 | % Copyright (c) 2004-2006 by Pierrick Penven and Laurent Debreu |
---|
27 | % e-mail:Pierrick.Penven@ird.fr |
---|
28 | % |
---|
29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
30 | if newtopo==1 |
---|
31 | mask=h>0; |
---|
32 | [M,L]=size(mask); |
---|
33 | % |
---|
34 | mask(1,:)=mask_parent(1,:); |
---|
35 | mask(end,:)=mask_parent(end,:); |
---|
36 | mask(:,1)=mask_parent(:,1); |
---|
37 | mask(:,end)=mask_parent(:,end); |
---|
38 | % |
---|
39 | [imat,jmat]=meshgrid((1:L),(1:M)); |
---|
40 | dist=0*mask+inf; |
---|
41 | for j=1:M |
---|
42 | if mask(j,1)==1 |
---|
43 | dist=min(cat(3,dist,sqrt((imat-1).^2+(jmat-j).^2)),[],3); |
---|
44 | end |
---|
45 | if mask(j,L)==1 |
---|
46 | dist=min(cat(3,dist,sqrt((imat-L).^2+(jmat-j).^2)),[],3); |
---|
47 | end |
---|
48 | end |
---|
49 | for i=1:L |
---|
50 | if mask(1,i)==1 |
---|
51 | dist=min(cat(3,dist,sqrt((imat-i).^2+(jmat-1).^2)),[],3); |
---|
52 | end |
---|
53 | if mask(M,i)==1 |
---|
54 | dist=min(cat(3,dist,sqrt((imat-i).^2+(jmat-M).^2)),[],3); |
---|
55 | end |
---|
56 | end |
---|
57 | % |
---|
58 | % Put the parent mask close to the boundaries |
---|
59 | % |
---|
60 | nmsk=1+2*refinecoeff; |
---|
61 | mask(dist<=nmsk)=mask_parent(dist<=nmsk); |
---|
62 | else |
---|
63 | mask=mask_parent; |
---|
64 | end |
---|
65 | % |
---|
66 | % Process the mask to check for points bays, et... |
---|
67 | % |
---|
68 | mask=process_mask(mask); |
---|
69 | % |
---|
70 | % in some cases the child mask can't be the same to the parent |
---|
71 | % at the boundary: |
---|
72 | % |
---|
73 | if sum(mask(1,:)~=mask_parent(1,:))~=0 |
---|
74 | disp(' ') |
---|
75 | disp(' Warning: the parent mask is not matching') |
---|
76 | disp(' the child mask at the SOUTH boundary') |
---|
77 | disp(' You might want to deplace this boundary') |
---|
78 | disp(' ') |
---|
79 | end |
---|
80 | if sum(mask(end,:)~=mask_parent(end,:))~=0 |
---|
81 | disp(' ') |
---|
82 | disp(' Warning: the parent mask is not matching') |
---|
83 | disp(' the child mask at the NORTH boundary') |
---|
84 | disp(' You might want to deplace this boundary') |
---|
85 | disp(' ') |
---|
86 | end |
---|
87 | if sum(mask(:,end)~=mask_parent(:,end))~=0 |
---|
88 | disp(' ') |
---|
89 | disp(' Warning: the parent mask is not matching') |
---|
90 | disp(' the child mask at the EAST boundary') |
---|
91 | disp(' You might want to deplace this boundary') |
---|
92 | disp(' ') |
---|
93 | end |
---|
94 | if sum(mask(:,1)~=mask_parent(:,1))~=0 |
---|
95 | disp(' ') |
---|
96 | disp(' Warning: the parent mask is not matching') |
---|
97 | disp(' the child mask at the WEST boundary') |
---|
98 | disp(' You might want to deplace this boundary') |
---|
99 | disp(' ') |
---|
100 | end |
---|
101 | return |
---|