-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_grid_border_mask.m
68 lines (65 loc) · 2.25 KB
/
make_grid_border_mask.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function [] = make_grid_border_mask(PK1,PDIAG,PDEPTH)
%
%%
% *********************************************************************** %
% *** CREATE BORDER MASK ************************************************ %
% *********************************************************************** %
%
% *** initialize ******************************************************** %
%
% copy passed parameters
str_k1 = PK1;
opt_diag = PDIAG;
n_depth = PDEPTH;
% set default paths
str_dirin = pwd;
str_dirout = pwd;
% set filename
str_date = [datestr(date,11), datestr(date,5), datestr(date,7)];
if opt_diag,
str_nameout = [str_k1 '.ndepth' num2str(n_depth) '.diag'];
else
str_nameout = [str_k1 '.ndepth' num2str(n_depth)];
end
% load k1 and process file
[grid_k1,grid_mask,imax,jmax] = fun_read_k1(pwd,str_k1,'k1');
% icreate & nitialzie borders array
grid_bdrs = zeros(jmax,imax);
%
% *** iterate through search depth ************************************** %
%
for n = 1:n_depth
% search across grid
for i = 1:imax
for j = 1:jmax
% test for cell being land
if ~grid_mask(j,i),
% look for ocean cells and mark borders
[grid_bdrs] = fun_grid_cell_neighbour_search(j,i,grid_mask,grid_bdrs,opt_diag);
end
end
end
% update mask
% => make border cell as 'land'
grid_mask = grid_mask & ~grid_bdrs;
end
% convert from logical to real and replace mask with borders
grid_mask = double(grid_bdrs);
%
% *** plot & save mask ************************************************** %
%
% plot orignal k1 grid
plot_2dgridded(flipud(grid_k1),9999,'',[str_nameout '.originalk1'],['original grid']);
% plot borders mask
plot_2dgridded(flipud(grid_mask),9999,'',[str_nameout '.bordersmask'],['mask']);
% save borders mask
fprint_2DM(grid_mask(:,:),[],[str_nameout, '.', str_date, '.bordersmask.dat'],'%4.1f','%4i',true,false);
%
% *********************************************************************** %
% *********************************************************************** %
% *** END *************************************************************** %
% *********************************************************************** %
%
%%%
%
% *********************************************************************** %