-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnc_put_att.m
39 lines (33 loc) · 854 Bytes
/
nc_put_att.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
%==========================================================================
% nc_put_att --- nc_toolbox
% Put an attribute to an existing NetCDF file
%
% input :
% fin --- input NetCDF file path and name
% var_name --- varaible name ([] for global)
% att_name --- attribute name
% att_value --- attribute value
%
% output :
%
%
% Siqi Li, SMAST
% 2023-03-15
%
% Updates:
%
%==========================================================================
function nc_put_att(fin, var_name, att_name, att_value)
ncid = nc_open(fin, 1);
% Re-define mode
nc_redef(ncid);
% Get variable ID
if isempty(var_name)
varid = netcdf.getConstant('GLOBAL');
else
varid = netcdf.inqVarID(ncid, var_name);
end
netcdf.putAtt(ncid, varid, att_name, att_value)
% End define mode
nc_enddef(ncid);
nc_close(ncid);