Home > atmlab > deprecated > find_granules_by_date.m

find_granules_by_date

PURPOSE ^

find_granules_by_date Find all granule start times for date/sat/dataset

SYNOPSIS ^

function [M, paths] = find_granules_by_date(year, month, day, sat, dataset,with_yesterday)

DESCRIPTION ^

 find_granules_by_date Find all granule start times for date/sat/dataset

 This function finds all granule start times for granules with any coverage
 for the the indicated for the indicated satellite/dataset pair. This
 includes the last granule of the date before, unless this is explicitly
 prohibited. Note that the last granule of the date before may or may not
 actually contain information for the day requested. Also note that there may
 also be more than one granule on the date before containing information
 for the day requested. This is not currently taken into account.

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

 FORMAT

   [M, paths] = find_granules_by_date(year, month, day, sat, dataset, with_yesterday)

 OUT

   M     N x m matrix     where each row corresponds to one granule and is
                          a datevec.
   paths cell strings     Cell array of strings, corresponding full paths

 IN

  year             (numeric)  Year for which to find the times.
  month            (numeric)  Month for which to find the times.
  day              (numeric)  Day for which to find the times.
  sat              string     Describing the satellite.
  dataset          string     Describing the dataset.
  with_yesterday   bool       Include last of yesterday (defaults to true)

 For POES satellites (NOAA-15 -- NOAA-19 and MetOp-A), AMSU, MHS, HIRS and
 AVHRR have the same granule times.

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

find_granules_by_date.m

SOURCE CODE ^

0001 function [M, paths] = find_granules_by_date(year, month, day, sat, dataset, ...
0002     with_yesterday)
0003 
0004 % find_granules_by_date Find all granule start times for date/sat/dataset
0005 %
0006 % This function finds all granule start times for granules with any coverage
0007 % for the the indicated for the indicated satellite/dataset pair. This
0008 % includes the last granule of the date before, unless this is explicitly
0009 % prohibited. Note that the last granule of the date before may or may not
0010 % actually contain information for the day requested. Also note that there may
0011 % also be more than one granule on the date before containing information
0012 % for the day requested. This is not currently taken into account.
0013 %
0014 % Valid datasets are shown by <a href="matlab:help list_datasets">list_datasets</a>
0015 %
0016 % FORMAT
0017 %
0018 %   [M, paths] = find_granules_by_date(year, month, day, sat, dataset, with_yesterday)
0019 %
0020 % OUT
0021 %
0022 %   M     N x m matrix     where each row corresponds to one granule and is
0023 %                          a datevec.
0024 %   paths cell strings     Cell array of strings, corresponding full paths
0025 %
0026 % IN
0027 %
0028 %  year             (numeric)  Year for which to find the times.
0029 %  month            (numeric)  Month for which to find the times.
0030 %  day              (numeric)  Day for which to find the times.
0031 %  sat              string     Describing the satellite.
0032 %  dataset          string     Describing the dataset.
0033 %  with_yesterday   bool       Include last of yesterday (defaults to true)
0034 %
0035 % For POES satellites (NOAA-15 -- NOAA-19 and MetOp-A), AMSU, MHS, HIRS and
0036 % AVHRR have the same granule times.
0037 %
0038 % $Id$
0039 
0040 % errid = 'atmlab:find_granules_by_date';
0041 
0042 warning(['atmlab:' mfilename], 'old style function, being phased out, use OO way');
0043 
0044 if ~exist('with_yesterday', 'var')
0045     with_yesterday = true;
0046 end
0047 
0048 datadir = find_datadir_by_date([year month day], sat, dataset);
0049 yearstr = num2str(year, '%04d'); % for comparing easily with 2digit years
0050 
0051 matchy = datasets_config([dataset '_regexp']);
0052 if isnan(matchy)
0053     matchy = datasets_config([dataset '_filename']); % exact match only
0054 end
0055 matchy = strrep_variables(matchy, sat, [year month day]);
0056 files = dir(datadir);
0057 nfiles = length(files);
0058 M = zeros(nfiles, 5);
0059 for i = 1:nfiles
0060     fname = files(i).name;
0061     nam = regexp(fname, matchy, 'names');
0062     if ~isempty(nam)
0063         % if present, year/month/day should be the same
0064         if (isfield(nam, 'year02') && ~isempty(nam.year02) && ~strcmp(nam.year02, yearstr(3:4))) || ...
0065             (isfield(nam, 'year04') && ~isempty(nam.year04) && str2double(nam.year04)~=year) || ...
0066             (isfield(nam, 'year') && ~isempty(nam.year) && str2double(nam.year)~=year) || ...
0067             (isfield(nam, 'month') && ~isempty(nam.month) && str2double(nam.month)~=month) || ...
0068             (isfield(nam, 'day') && ~isempty(nam.day) && str2double(nam.day)~=day) || ...
0069             (isfield(nam, 'doy') && ~isempty(nam.doy) && str2double(nam.doy)~=dayofyear(year, month, day));
0070            continue;
0071         end
0072             
0073         M(i, 1:3) = [year month day];
0074         if isfield(nam, 'hour')
0075             M(i, 4) = str2double(nam.hour);
0076         end
0077         if isfield(nam, 'minute')
0078             M(i, 5) = str2double(nam.minute);
0079         end
0080     end
0081 end
0082 % all paths
0083 paths = cellfun(@(f) fullfile(datadir, f), {files.name}, 'UniformOutput', false);
0084 % remove lines with zeroes (those are not granules)
0085 nogran = M(:, 1)==0;
0086 M(nogran, :) = [];
0087 paths(nogran) = [];
0088 % sort
0089 [M, I] = sortrows(M);
0090 paths = paths(I);
0091 % add yesterday
0092 if with_yesterday
0093     yesterday = datevec(datenum([year month day])-1);
0094     [M_yesterday, paths_yesterday] = find_granules_by_date(...
0095         yesterday(1), yesterday(2), yesterday(3), sat, dataset, false);
0096     if ~isempty(M_yesterday) % maybe today is genesis/big bang/epoch/birth/1970-01-01
0097         M = [M_yesterday(end, :); M];
0098         paths = [paths_yesterday(end) paths];
0099     end
0100 end

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