% Function to read parameter names from a satellite HDF file.
% Copyright by Jasmine S Nahorniak, Oregon State University.
% june 14 00
% [name]=readMODISparams(pathfile,refnum);
% refnum : reference number for the parameter 
%         (eg 5 for level 3 data files,
%          6-22 for level 2 data files,
%          6-15 for geolocation data files)

function [name]=readMODISparams(pathfile,refnum);

SD_id = hdfsd('start',pathfile,'read');   % open HDF file

%[ndatasets,nglobal_attr,status1] = hdfsd('fileinfo',SD_id); % general info about file

% NOTE: to check which reference number is applicable, loop through this next
% command for 40 or so reference numbers, letting "name" from the
% IloadHDFdata routine print to the screen.  The ref number is the
% order that the desired quantity appears.
%for i=1:40, 
%[data, name]=IloadHDFdata(SD_id,i);
%i
%name
%end

[name]=IloadHDFparam(SD_id,refnum);

status5 = hdfsd('end',SD_id);   % close HDF file

% ***********************************************************************************

function [name]=IloadHDFparam(SD_id,ref);

sds_index = hdfsd('reftoindex',SD_id,ref);  % create an index number from the reference number

sds_id = hdfsd('select',SD_id,sds_index); % create an id number

[name,rank,dimsizes,data_type,nattrs,status2] = hdfsd('getinfo',sds_id); % info about data


return
