function COUNTS = hdf2mat(pathname)
% pathname must be the fully qualified name (FQDN) of the file:
% e.g. c:\data\AIRS\hdf\AIRS.2004.03.02.009.L1A.AIRS_Scene.v3.2.7.0.N04061220338.hdf
% path = 'c:\data\AIRS\hdf\';
% file = 'AIRS.2004.03.02.009.L1A.AIRS_Scene.v3.2.7.0.N04061220338.hdf'
% FQDN = path . file;
swathname = 'L1A_AIRS_Science';
variable = 'COUNTS';
fileid = hdfsw('open',pathname,'read');
swathid = hdfsw('attach',fileid,swathname);
COUNTS = zeros(2378,135*90);
[DATA,STATUS] = hdfsw('readfield',swathid,'counts',[],[],[]);
   for i=1:2378
      for j=1:135
         for k=1:90
            COUNTS(i,(j-1)*90+k) = DATA(i,k,j);
         end
      end
   end
hdfsw('detach',swathid);
hdfsw('close',fileid);
