-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_coords.m
114 lines (90 loc) · 3.27 KB
/
do_coords.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
107
108
109
110
111
112
113
114
function [s_coords] = do_coords(s_cfg)
%function [s_coords] = do_coords(s_cfg)
%
%This function gets the horizontal and vertical coordinates
%
% s_coords = struct(...
% 'lat2d', lat2d, ...
% 'lon2d', lon2d, ...
% 'units', units, ...
% 'colorlim', colorlim, ...
% 'latlim', latlim, ...
% 'lonlim', lonlim, ...
% 'zsize', zsize, ...
% 'gregorian_time', gregorian_time, ...
% 'serial_time', serial_time);
disp('Loading coords from MOHID netcdf output file')
pack %optimize memory for getnc
if s_cfg.override_ll==true;
load lat_lon_override_file
lat = lat(:,1);
lon = lon(1,:);
%computes limits
iub = size(lat,1);
jub = size(lon,2);
else
switch (s_cfg.filetype)
case 'cdf'
lon = getnc(s_cfg.file,'lon', -1, -1, -1, -2, s_cfg.change_miss, s_cfg.new_miss);
lat = getnc(s_cfg.file,'lat', -1, -1, -1, -2, s_cfg.change_miss, s_cfg.new_miss);
case 'nc'
lon = nc_varget(s_cfg.file,'lon');
lat = nc_varget(s_cfg.file,'lat');
otherwise
end
%computes limits
iub = size(lat,1);
jub = size(lon,1);
end
switch (s_cfg.filetype)
case 'cdf'
zsize = getnc(s_cfg.file,'depth', -1, -1, -1, -2, s_cfg.change_miss, s_cfg.new_miss);
[gregorian_time, serial_time] = timenc(s_cfg.file);
case 'nc'
zsize = nc_varget(s_cfg.file,'depth');
serial_rel = nc_varget(s_cfg.file,'time');
serial_rel = serial_rel / 86400.;
time_units = nc_attget(s_cfg.file,'time','units');
[gregorian_base, rescale_serial_rel, serial_base_jd, serial_base] = do_parsetnc(time_units);
serial_time_jd = serial_rel + serial_base_jd;
if isempty(serial_time_jd)
gregorian_time = [];
serial_time = [];
else
gregorian_time = get_calendar_date(serial_time_jd);
serial_time = datenum(gregorian_time(:, 1), gregorian_time(:, 2), ...
gregorian_time(:, 3), gregorian_time(:, 4), ...
gregorian_time(:, 5), gregorian_time(:, 6));
end
otherwise
end
disp('Computing coordinates...');
if s_cfg.override_ll==true;
lat2d=lat;
lon2d=lon;
else
for i = 1:iub;
for j = 1:jub;
lat2d(i,j) = lat(i);
lon2d(i,j) = lon(j);
end
end
end
left = min(lon)+0.01;
right = max(lon)-0.01;
bottom = min(lat)+0.01;
top = max(lat)-0.01;
lonlim = [left right];
latlim = [bottom top];
disp('Started plotting...');
if s_cfg.save_coastline;
do_coastline;
end
s_coords = struct( ...
'lat2d', lat2d, ...
'lon2d', lon2d, ...
'latlim', latlim, ...
'lonlim', lonlim, ...
'zsize', zsize, ...
'gregorian_time', gregorian_time, ...
'serial_time', serial_time);