Home > atmlab > deprecated > read_granule.m

read_granule

PURPOSE ^

read_granule Read any sat/sensor granule (levels 1 and 2)

SYNOPSIS ^

function M = read_granule(sat, sensor, datevec, remdouble, force)

DESCRIPTION ^

 read_granule Read any sat/sensor granule (levels 1 and 2)

 High-level function to read a particular granule for a
 satellite/sensor-pair, if one doesn't know what function is suitable to
 use to read it. It also gets rid of ballast.

 Uses datasets_config('read_SENSOR') to find out what function to use to
 read this particular data. Uses granule_first_line to find out the first
 scanline to use (e.g. the rest are doubles).

 Valid datasets are returned by <a href="matlab:help list_datasets">list_datasets</a>.

 FORMAT

   M = read_granule(sat, sensor, datevec, remdouble, force)

 IN

   sat         string      Satellite (noaa18, cloudsat, etc.)
   sensor      string      Sensor or dataset (mhs, hirs, cpr, hirscs, etc.)
   datevec     vector      Date-vector indicating the starting time.
   remdouble   logical     (optional) Remove doubles or not? Default true.
   force       logical     (optional) rather than throwing an error,
                           return [] in case of error. Default false.

 OUT

   M       struct      Contains at least lat, lon, time and one or more
                       data fields. Exact results depend on the particular
                       satellite/sensor-pair.

 $Id: read_granule.m 7564 2012-05-02 14:24:45Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

read_granule.m

SOURCE CODE ^

0001 function M = read_granule(sat, sensor, datevec, remdouble, force)
0002 
0003 % read_granule Read any sat/sensor granule (levels 1 and 2)
0004 %
0005 % High-level function to read a particular granule for a
0006 % satellite/sensor-pair, if one doesn't know what function is suitable to
0007 % use to read it. It also gets rid of ballast.
0008 %
0009 % Uses datasets_config('read_SENSOR') to find out what function to use to
0010 % read this particular data. Uses granule_first_line to find out the first
0011 % scanline to use (e.g. the rest are doubles).
0012 %
0013 % Valid datasets are returned by <a href="matlab:help list_datasets">list_datasets</a>.
0014 %
0015 % FORMAT
0016 %
0017 %   M = read_granule(sat, sensor, datevec, remdouble, force)
0018 %
0019 % IN
0020 %
0021 %   sat         string      Satellite (noaa18, cloudsat, etc.)
0022 %   sensor      string      Sensor or dataset (mhs, hirs, cpr, hirscs, etc.)
0023 %   datevec     vector      Date-vector indicating the starting time.
0024 %   remdouble   logical     (optional) Remove doubles or not? Default true.
0025 %   force       logical     (optional) rather than throwing an error,
0026 %                           return [] in case of error. Default false.
0027 %
0028 % OUT
0029 %
0030 %   M       struct      Contains at least lat, lon, time and one or more
0031 %                       data fields. Exact results depend on the particular
0032 %                       satellite/sensor-pair.
0033 %
0034 % $Id: read_granule.m 7564 2012-05-02 14:24:45Z gerrit $
0035 
0036 warning(['atmlab:' mfilename], 'old style function, being phased out, use OO way');
0037 
0038 if ~exist('remdouble', 'var')
0039     remdouble = true;
0040 end
0041 
0042 if ~exist('force', 'var')
0043     force = false;
0044 end
0045 
0046 % find datafile and function to read it
0047 datafile = find_datafile_by_date(datevec, sat, sensor);
0048 reader = datasets_constants(['read_' sensor]);
0049 
0050 % read datafile
0051 %logtext(colloc_config('stdout'), '%s(''%s'')\n', ...
0052 %    func2str(reader), datafile);
0053 try
0054     M = reader(datafile);
0055 catch ME
0056     if force
0057         switch ME.identifier
0058             case 'atmlab:invalid_data'
0059                 logtext(atmlab('ERR'), ...
0060                     'Unable to read HIRS-data: %s\n', ME.message);
0061                 M = [];
0062                 return
0063             otherwise
0064                 ME.rethrow();
0065         end
0066     else
0067         ME.rethrow();
0068     end
0069 end
0070 %logtext(colloc_config('stdout'), 'read %s\n', datafile);
0071 nlines = size(M.time, 1);
0072 
0073 if remdouble
0074     % read ballast
0075     firstline = granule_first_line(sat, sensor, datevec);
0076     % get rid of ballast
0077     for f = fieldnames(M)'
0078         fn = f{1};
0079         if isnumeric(M.(fn)) && size(M.(fn), 1) == nlines
0080             % magic in next lines explained at
0081             % http://www.mathworks.de/matlabcentral/newsreader/view_thread/290890
0082             sz = size(M.(fn));
0083             M.(fn) = reshape(M.(fn)(firstline:nlines, :), [nlines-firstline+1, sz(2:end)]);
0084         end
0085     end
0086 end
0087 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005