-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_var.m
106 lines (93 loc) · 3.79 KB
/
get_var.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function [var2d mask batim] = get_var(s_cfg, s_at, bl_corner, tr_corner, ...
m_bl_corner, m_tr_corner,...
bat_bl_corner, bat_tr_corner)
%function var2d = get_var(s_cfg, s_at, bl_corner, tr_corner, ...
% m_bl_corner, m_tr_corner,...
% bat_bl_corner, bat_tr_corner)
%
% Extracts the MOHID netcdf data with the landmask
%
switch (s_cfg.filetype)
case 'mat'
var2d = getmat(s_cfg.matfile, ...
s_at.varname, ...
m_bl_corner, ...
m_tr_corner, ...
1 ... %stride
);
mask = getmat(s_cfg.matfile, ...
'matmask', ...
m_bl_corner, ...
m_tr_corner, ...
1 ... %stride
);
batim = getmat(s_cfg.matfile, ...
'matbatim', ...
bat_bl_corner, ...
bat_tr_corner, ...
1 ... %stride
);
case 'nc'
start_nc = bl_corner - ones(size(bl_corner));
count_nc = tr_corner - start_nc;
var2d = nc_varget(s_cfg.file, ...
s_at.varname, ...
start_nc, ... % bl_corner
count_nc ...
);
m_start_nc = m_bl_corner - ones(size(m_bl_corner));
m_count_nc = m_tr_corner - m_start_nc;
mask = nc_varget(s_cfg.file, ...
'mask', ...
m_start_nc, ... % bl_corner (tzxy)
m_count_nc ...
);
bat_start_nc = bat_bl_corner - ones(size(bat_bl_corner));
bat_count_nc = bat_tr_corner - bat_start_nc;
batim = nc_varget(s_cfg.file, ...
'bathymetry', ...
bat_start_nc, ... % bl_corner (xy)
bat_count_nc ...
);
case 'cdf'
var2d = getnc(s_cfg.file, ...
s_at.varname, ...
bl_corner, ... % bl_corner
tr_corner ... %tr_corner
);
mask = getnc(s_cfg.file, ...
'mask', ...
m_bl_corner, ... % bl_corner (tzxy)
m_tr_corner ... %tr_corner (tzxy)
);
batim = getnc(s_cfg.file, ...
'bathymetry', ...
bat_bl_corner, ... % bl_corner (tzxy)
bat_tr_corner ... %tr_corner (tzxy)
);
case 'hdf5'
var2d = gethdf5_2d(s_cfg.file, ...
s_at.varname, ...
bl_corner, ...
tr_corner, ...
1 ... %stride
);
mask = gethdf5_2d(s_cfg.file, ...
'/Grid/WaterPoints3D', ...
bl_corner, ...
tr_corner, ...
1 ... %stride
);
batim = gethdf5_2d(s_cfg.file, ...
'/Grid/Bathymetry', ...
bat_bl_corner, ...
bat_tr_corner, ...
1 ... %stride
);
otherwise
disp ('Error: wrong filetype defined! mat, cdf or hdf5 only!');
end
nn = find(mask == 0); % Find land
mask(nn) = NaN; % and NaN it...
%pass the mask out and work with it!
%var2d = var2d .* mask; % Apply the landmask to our data.