-
Notifications
You must be signed in to change notification settings - Fork 1
/
write_hycom.m
119 lines (111 loc) · 3.34 KB
/
write_hycom.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
115
116
117
118
119
function write_hycom(OGCM_dir, OGCM_prefix, raw_hycom_name, vars, time, thedatemonth, Yorig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Convert HYCOM data to a format compatible with CROCOTOOLS
%
% Further Information:
% http://www.croco-ocean.org
%
% This file is part of CROCOTOOLS
%
% CROCOTOOLS is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation; either version 2 of the License,
% or (at your option) any later version.
%
% CROCOTOOLS is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston,
% MA 02111-1307 USA
%
% Copyright (c) 2006 by Pierrick Penven
% e-mail:[email protected]
%
% Updated 9-Sep-2006 by Pierrick Penven
% Updated 19-May-2011 by Andres Sepulveda & Gildas Cambon
% Updated 12-Feb-2016 by P. Marchesiello
% Updated 4-Jun-2024 by [Your Name]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fname_z = [raw_hycom_name(1:end-3), '_z.nc'];
fname_u = [raw_hycom_name(1:end-3), '_u.nc'];
fname_t = [raw_hycom_name(1:end-3), '_t.nc'];
fname_s = [raw_hycom_name(1:end-3), '_s.nc'];
% Get grid and time frame
nc = netcdf(fname_t);
lon = nc{'lon'}(:);
lat = nc{'lat'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(2000,1,1) - datenum(Yorig,1,1);
close(nc)
% Get SSH
disp(' ...SSH')
nc = netcdf(fname_z,'r');
vname = sprintf('%s', vars{1});
ncc = nc{vname};
ssh = ncc(:);
missval = ncc.FillValue_(:);
scale_factor = 1;
add_offset = 0;
ssh(ssh >= missval) = NaN;
ssh = ssh .* scale_factor + add_offset;
close(nc)
% Get U
disp(' ...U')
nc = netcdf(fname_u,'r');
vname = sprintf('%s', vars{2});
ncc = nc{vname};
u = ncc(:);
missval = ncc.FillValue_(:);
scale_factor = 1;
add_offset = 0;
u(u >= missval) = NaN;
u = u .* scale_factor + add_offset;
close(nc)
% Get V
disp(' ...V')
nc = netcdf(fname_u,'r');
vname = sprintf('%s', vars{3});
ncc = nc{vname};
v = ncc(:);
missval = ncc.FillValue_(:);
scale_factor = 1;
add_offset = 0;
v(v >= missval) = NaN;
v = v .* scale_factor + add_offset;
close(nc)
% Get TEMP
disp(' ...TEMP')
nc = netcdf(fname_t,'r');
vname = sprintf('%s', vars{4});
ncc = nc{vname};
temp = ncc(:);
missval = ncc.FillValue_(:);
scale_factor = 1;
add_offset = 0;
temp(temp >= missval) = NaN;
temp = temp .* scale_factor + add_offset;
close(nc)
% Get SALT
disp(' ...SALT')
nc = netcdf(fname_s,'r');
vname = sprintf('%s', vars{5});
ncc = nc{vname};
salt = ncc(:);
missval = ncc.FillValue_(:);
scale_factor = 1;
add_offset = 0;
salt(salt >= missval) = NaN;
salt = salt .* scale_factor + add_offset;
close(nc)
% Create the HYCOM file
create_OGCM([OGCM_dir, OGCM_prefix, thedatemonth, '.nc'],...
lon, lat, lon, lat, lon, lat, depth, time,...
squeeze(temp), squeeze(salt), squeeze(u),...
squeeze(v), squeeze(ssh), Yorig)
end