-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_met_xy.m
52 lines (41 loc) · 1.38 KB
/
add_met_xy.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
%==========================================================================
% Add the xy coordinate variables in the meteorological forcing file
%
% Input : --- fin, original meteorological forcing
% --- xx, x-coordinate matrix
% --- yy, y-coordinate matrix
% --- fout, the new meteorological forcing file (optional)
%
% Output : \
%
% Usage : add_nesting_center(fin, fout);
%
% v1.0
%
% Siqi Li
% 2023-09-14
%
% Updates:
%==========================================================================
function add_met_xy(fin, xx, yy, fout)
if exist('fout', 'var')
copyfile(fin, fout);
else
fout = fin;
end
ncid = netcdf.open(fout, 'NC_WRITE');
netcdf.reDef(ncid);
xx_dimid = netcdf.inqDimID(ncid, 'west_east');
yy_dimid = netcdf.inqDimID(ncid, 'south_north');
xx_varid = netcdf.defVar(ncid, 'xx', 'float', [xx_dimid yy_dimid]);
netcdf.putAtt(ncid, xx_varid, 'description', 'Cartesian Coordinate X');
netcdf.putAtt(ncid, xx_varid, 'units', 'm');
netcdf.putAtt(ncid, xx_varid, 'coordinates', 'XLONG XLAT');
yy_varid = netcdf.defVar(ncid, 'yy', 'float', [xx_dimid yy_dimid]);
netcdf.putAtt(ncid, yy_varid, 'description', 'Cartesian Coordinate X');
netcdf.putAtt(ncid, yy_varid, 'units', 'm');
netcdf.putAtt(ncid, yy_varid, 'coordinates', 'XLONG XLAT');
netcdf.endDef(ncid);
netcdf.putVar(ncid, xx_varid, xx);
netcdf.putVar(ncid, yy_varid, yy);
netcdf.close(ncid);