forked from SiqiLiOcean/HYCOM2FVCOM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hycom2fvcom_nesting_tide_TMD.m
81 lines (71 loc) · 2.58 KB
/
hycom2fvcom_nesting_tide_TMD.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
%==========================================================================
% HYCOM2FVCOM:
% Extract the tidal components for nesting boundary nodes and cells
% from OSU TPXO Tide Models with TMD
%
% input :
% fnesting --- fvcom nesting grid (mat, from hycom2fvcom_nesting_select.m)
% tide_name--- tide constituent names (string array)
% Model --- tide model control file required by TMD, download from
% https://www.esr.org/research/polar-tide-models/list-of-polar-tide-models/
% fout --- output tide coefficient file name and path (mat)
%
% output :
% nesting grid mat file
%
% Siqi Li, SMAST
% 2022-11-30
%
% Updates:
% 2023-02-28 Siqi Li Fixed the unit mismatch between TMD and HYCOM
%==========================================================================
addpath('~/tools/matFVCOM')
addpath('~/tools/TMD')
addpath('~/tools/t_tide')
clc
clear
%--------------------------------------------------------------------------
% Input
fnesting = './output/Japan_nesting_grid.mat';
tide_name = ["M2" "N2" "S2" "K2" "K1" "O1" "P1" "Q1"];
Model = '/hosts/hydra.smast.umassd.edu/data2/siqili/script/tools/TMD/DATA/Model_tpxo9';
fout = './output/Japan_nesting_tide.mat';
%--------------------------------------------------------------------------
% Load nesting grid
load(fnesting);
%--------------------------------------------------------------------------
% Extract the tide elevation components
[~, ~, ~, conList] = tmd_extract_HC(Model, fn.y(1), fn.x(1), 'z', []);
for j = 1 : length(tide_name)
k = find(ismember(upper(conList), tide_name{j}, 'rows'));
if isempty(k)
error(['Tide ' tide_name{j} ' is not included.'])
else
Cid(j) = k;
end
end
%--------------------------------------------------------------------------
% Extract tide
[amp, pha, depth] = tmd_extract_HC(Model, fn.y, fn.x, 'z', Cid);
amp = amp';
pha = pha';
% Create the tidestruc for t_tide
for i = 1 : fn.node
tide_zeta_struct(i,1) = create_tidestruc(tide_name, amp(i,:), pha(i,:));
end
clear amp pha
%--------------------------------------------------------------------------
% Extract the tide vector components
for j = 1 : length(tide_name)
[fmaj(:,j), fmin(:,j), pha(:,j), finc(:,j)] = tmd_ellipse(Model, fn.yc, fn.xc, tide_name{j});
end
% Convert unit from cm/s to m/s
fmaj = fmaj / 100;
fmin = fmin / 100;
% Create the tidestruc for t_tide
for i = 1 : fn.nele
tide_uv_struct(i,1) = create_tidestruc(tide_name, fmaj(i,:), fmin(i,:), finc(i,:), pha(i,:));
end
tide_uv_struct = repmat(tide_uv_struct, 1, fn.kbm1);
% Save out the file
save(fout, 'tide_zeta_struct', 'tide_uv_struct')