-
Notifications
You must be signed in to change notification settings - Fork 0
/
nc_get_var.m
47 lines (38 loc) · 1.06 KB
/
nc_get_var.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
%==========================================================================
% nc_get_var --- nc_toolbox
% Read a variable in an existing NetCDF file
%
% input :
% fin --- input NetCDF file path and name
% var_name --- varaible name
% start --- (optional)
% count --- (optional)
% stride --- (optional)
%
% output :
% data --- varaible data
%
% Siqi Li, SMAST
% 2022-04-06
%
% Updates:
%
%==========================================================================
function data = nc_get_var(fin, var_name, start, count, stride)
ncid = nc_open(fin);
% Get variable ID
varid = netcdf.inqVarID(ncid, var_name);
if exist('start', 'var')
if exist('count', 'var')
if exist('stride', 'var')
data = netcdf.getVar(ncid, varid, start, count, stride);
else
data = netcdf.getVar(ncid, varid, start, count);
end
else
data = netcdf.getVar(ncid, varid, start);
end
else
data = netcdf.getVar(ncid, varid);
end
nc_close(ncid);