function y = CPR_L1B_rdr(filelist,fieldlist) % CPR L1B HDF-EOS reader % % VER: BETA 1 % % INPUT % filelist is a struct array generated by the dir command % fieldlist is a cell array with each element matching one of the CPR L1B HDF-EOS fields % (omit to select all fields) % Exception: the 'Sigma-Zero' field is renamed in output as 's0' % % OUTPUT % y is a struct array with as many elements as the number of files in the filelist % and the (selected) fields from the HDF-EOS file % % Example: % filelist = dir('*.hdf'); % y = CPR_L1B_rdr(filelist(1:2),{'TAI_start','Latitude','Longitude'}); % % will generate % % y = 1x2 struct array with fields: % TAI_start % Latitude % Longitude % % Coefficients and formats % BETA 0 % 1) Converts all fields into double precision variables % 2) 'Sigma-Zero' field is renamed in output as 's0' % BETA 1 % 1 - 2) as in BETA 0 % 3) Applies 0.01 coeff to Sigma-Zero to obtain value in dB % 4) Applies 1000 coeff to Spacecraft_Altitude to convert km in m if nargin < 2 fieldlist = []; end for ifile = 1:length(filelist) file = filelist(ifile).name; fileinfo = hdfinfo(file,'eos'); NDataFields = length(fileinfo.Swath.DataFields); NGeoFields = length(fileinfo.Swath.GeolocationFields); if ifile == 1 y = struct('dummyfield',[]); for i = 1:NDataFields if isempty(fieldlist) | any(strcmp(fieldlist,fileinfo.Swath.DataFields(i).Name)) if strcmp(fileinfo.Swath.DataFields(i).Name,'Sigma-Zero') out = 's0'; else out = fileinfo.Swath.DataFields(i).Name; end y = setfield(y,out,[]); end end for i = 1:NGeoFields if isempty(fieldlist) | any(strcmp(fieldlist,fileinfo.Swath.GeolocationFields(i).Name)) y = setfield(y,fileinfo.Swath.GeolocationFields(i).Name,[]); end end y = repmat(y,[1,length(filelist)]); y = rmfield(y,'dummyfield'); end for i = 1:NDataFields if isempty(fieldlist) | any(strcmp(fieldlist,fileinfo.Swath.DataFields(i).Name)) if strcmp(fileinfo.Swath.DataFields(i).Name,'Sigma-Zero') out = 's0'; coeff = 1/100; else out = fileinfo.Swath.DataFields(i).Name; coeff = 1; end dummy = hdfread(fileinfo.Filename,fileinfo.Swath.DataFields(i).Name); if iscell(dummy), dummy = dummy{1}; end dummy = double(dummy) * coeff; eval(['y(ifile).' out ' = dummy;']) end end for j = 1:NGeoFields if isempty(fieldlist) | any(strcmp(fieldlist,fileinfo.Swath.GeolocationFields(j).Name)) dummy = hdfread(fileinfo.Filename,fileinfo.Swath.GeolocationFields(j).Name); if iscell(dummy), dummy = dummy{1}; end if strcmp(fileinfo.Swath.GeolocationFields(j).Name,'Spacecraft_altitude') coeff = 1000; else coeff = 1; end dummy = double(dummy) * coeff; eval(['y(ifile).' fileinfo.Swath.GeolocationFields(j).Name ' = dummy;']) end end end