-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_restart_dye.m
60 lines (48 loc) · 1.47 KB
/
add_restart_dye.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
%==========================================================================
% Add dye in the restart file.
%
% Input : --- fin, original input nesting file
% --- fout, the new nesting file with center variables included
% --- dye, dye in (node, nsiglay, nt) (optional)
% Output : \
%
% Usage : add_restart_dye(fin, fout, dye);
%
% v1.0
%
% Siqi Li
% 2023-02-16
%
% Updates:
%
%==========================================================================
function add_restart_dye(fin, fout, varargin)
copyfile(fin, fout);
% Open the output NC file
ncid = netcdf.open(fout, 'NC_WRITE');
% Re-define mode
netcdf.reDef(ncid);
% Get the dimension id and length.
dimid_node = netcdf.inqDimID(ncid, 'node');
[~, node] = netcdf.inqDim(ncid, dimid_node);
dimid_nsiglay = netcdf.inqDimID(ncid, 'siglay');
[~, nsiglay] = netcdf.inqDim(ncid, dimid_nsiglay);
dimid_time = netcdf.inqDimID(ncid, 'time');
[~, nt] = netcdf.inqDim(ncid, dimid_time);
if isempty(varargin)
dye = zeros(node, nsiglay, nt);
else
dye = varargin{:};
end
% Define the dye variable.
varid_dye = netcdf.defVar(ncid, 'DYE', 'float', [dimid_node dimid_nsiglay dimid_time]);
netcdf.putAtt(ncid, varid_dye, 'long_name', 'DYE concentration');
netcdf.putAtt(ncid, varid_dye, 'units', '');
% End define mode
netcdf.endDef(ncid);
% Write data into the output NC file.
for it = 1 : nt
netcdf.putVar(ncid, varid_dye,[0 0 it-1],[node nsiglay 1],dye(:,:, it));
end
% Close the output NC file.
netcdf.close(ncid);