Merge branch 'femwind' of github.com:janmandel/wrf-fire-matlab into femwind
[wrf-fire-matlab.git] / netcdf / nclist.m
blob4989145e1f6c804ab8e271fee61434a06451a00f
1 function var=nclist(filename,q) 
2 % var=nclist(filename)
3 % var=nclist(filename,'q')  
4 %  return structure array with info on each netcdf variable in the file
5 %  'q' = quiet
7 quiet=exist('q','var');
8 fprintf('ncdump: file %s\n',filename);
9 ncid = netcdf.open(filename,'NC_NOWRITE');
10 [ndims,nvars,ngatts,unlimdim] = netcdf.inq(ncid);
11 for varid=1:nvars, % one variable at a time
12     varinfo = ncvarinfo(ncid,varid-1);
13     field_names = fieldnames(varinfo);
14     for i=1:numel(field_names)
15         field = field_names{i};
16         var(varid).(field)=varinfo.(field);
17     end
18     if ~quiet,
19         fprintf('%i ',varid);
20         dispvarinfo(var(varid));
21     end
22 end
23 for i=1:nvars % save the native netcdf variable order
24     var(i).varid=i-1;
25 end
26 [~,ix]=sort({var.varname});
27 var=var(ix);
28 netcdf.close(ncid);
29 end