-
Notifications
You must be signed in to change notification settings - Fork 0
/
nc_get_vars.m
40 lines (33 loc) · 860 Bytes
/
nc_get_vars.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_get_vars --- nc_toolbox
% Read all variables in an existing NetCDF file
%
% input :
% fin --- input NetCDF file path and name
%
% output :
% data --- varaible data
%
% Siqi Li, SMAST
% 2022-04-06
%
% Updates:
%
%==========================================================================
function data = nc_get_vars(fin)
ncid = nc_open(fin);
[~, nvars] = netcdf.inq(ncid);
for i = 1 : nvars
varid = i - 1;
data(i).name = netcdf.inqVar(ncid, varid);
data(i).value = netcdf.getVar(ncid, varid);
if isnumeric(data(i).value(1))
data(i).min = min(data(i).value(:));
data(i).max = max(data(i).value(:));
else
data(i).min = [];
data(i).max = [];
end
end
nc_close(ncid);
end