0
|
1 |
function prof = readnetcdf(filename)
|
|
2 |
|
|
3 |
% Usage: prof = readnetcdf(filename)
|
|
4 |
%
|
|
5 |
% Read variables from a netCDF file.
|
|
6 |
|
|
7 |
ncid = netcdf.open(filename, 'NOWRITE');
|
|
8 |
|
|
9 |
% get variables
|
|
10 |
[ndims,nvars,natts,unlimdimid] = netcdf.inq(ncid);
|
|
11 |
|
|
12 |
for varid=0:nvars-1
|
|
13 |
[varname,xtype,dimids,nvaratts] = netcdf.inqVar(ncid,varid);
|
|
14 |
cmd = sprintf('prof.%s = netcdf.getVar(ncid,varid);',varname);
|
|
15 |
eval(cmd);
|
|
16 |
end
|
|
17 |
|
|
18 |
gattvarid = netcdf.getConstant('NC_GLOBAL');
|
|
19 |
for gattid=0:natts-1
|
|
20 |
attname = netcdf.inqAttName(ncid,gattvarid,gattid);
|
|
21 |
cmd = sprintf('prof.%s = netcdf.getAtt(ncid,gattvarid,''%s'');',attname,attname);
|
|
22 |
eval(cmd);
|
|
23 |
end
|
|
24 |
|
|
25 |
netcdf.close(ncid)
|
|
26 |
|
|
27 |
|