Home > atmlab > deprecated > collocate_date.m

collocate_date

PURPOSE ^

collocate_date Collect all collocations for given date

SYNOPSIS ^

function [overlap, data, meandata] = collocate_date(year, month, day, sat1, sensor1, sat2, sensor2)

DESCRIPTION ^

 collocate_date Collect all collocations for given date

 This m-file collects all collocations for the given date between the
 indicated sensor pairs and returns the result in a structure.

 FORMAT

   collocate_date(year, month, day, sat1, sensor1, sat2, sensor2)

 IN

   year    (numeric)   Year for which to find collocations
   month   (numeric)   Month for which to find collocations
   day     (numeric)   Day for which to find collocations
   sat1    string      Primary satellite
   sensor1 string      Sensor on sat1 to consider
   sat2    string      Secondary satellite: POES means many
   sensor2 string      Sensor on secondary satellite to consider

 OUT

   S       structure   S contains the collocations for all satellites for the
                       date of interest. Its fields are the satellite names
                       (only one if sat2 is not equal to poes). The values of
                       those fields are the collections of collocate_granule
                       for all granules of sat1/sensor1 for that date.
   data    structure   Similar to S but with data.

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

collocate_date.m

SOURCE CODE ^

0001 function [overlap, data, meandata] = collocate_date(year, month, day, sat1, sensor1, sat2, sensor2)
0002 
0003 % collocate_date Collect all collocations for given date
0004 %
0005 % This m-file collects all collocations for the given date between the
0006 % indicated sensor pairs and returns the result in a structure.
0007 %
0008 % FORMAT
0009 %
0010 %   collocate_date(year, month, day, sat1, sensor1, sat2, sensor2)
0011 %
0012 % IN
0013 %
0014 %   year    (numeric)   Year for which to find collocations
0015 %   month   (numeric)   Month for which to find collocations
0016 %   day     (numeric)   Day for which to find collocations
0017 %   sat1    string      Primary satellite
0018 %   sensor1 string      Sensor on sat1 to consider
0019 %   sat2    string      Secondary satellite: POES means many
0020 %   sensor2 string      Sensor on secondary satellite to consider
0021 %
0022 % OUT
0023 %
0024 %   S       structure   S contains the collocations for all satellites for the
0025 %                       date of interest. Its fields are the satellite names
0026 %                       (only one if sat2 is not equal to poes). The values of
0027 %                       those fields are the collections of collocate_granule
0028 %                       for all granules of sat1/sensor1 for that date.
0029 %   data    structure   Similar to S but with data.
0030 %
0031 % $Id$
0032 
0033 % FIXME: update to new-style
0034 warning(['atmlab:' mfilename], 'old style function, being phased out, use OO way');
0035 
0036 fid = atmlab('OUT');
0037 
0038 % find granules for primary dataset; if the length equals one day, do not
0039 % take the day before as it's already sorted per day
0040 grans = find_granules_by_date(year, month, day, sat1, sensor1, ...
0041     datasets_constants(['granule_duration_' sensor1])~=86400);
0042 if isempty(grans)
0043     logtext(atmlab('ERR'), 'no granules found %s/%s %d-%d-%d\n', ...
0044         sat1, sensor1, year, month, day);
0045 end
0046 ngrans = size(grans, 1);
0047 % initialise overlap structure
0048 empty = struct();
0049 switch lower(sat2)
0050     case 'poes'
0051         sats = datasets_constants('POES_satellite_names');
0052         for i = 1:length(sats)
0053             empty.(sats{i}) = []; % FIXME: get good width
0054         end
0055     otherwise
0056         empty.(sat2) = [];
0057 end
0058 overlap = empty;
0059 data = empty;
0060 meandata = empty;
0061 nout = max(nargout, 1);
0062 S = {empty, empty, empty};
0063 anysuccess = false;
0064 
0065 for i = 1:ngrans
0066     % keep track, because first granule is probably yesterday
0067     thisyear = grans(i, 1);
0068     thismonth = grans(i, 2);
0069     thisday = grans(i, 3);
0070     hour = grans(i, 4);
0071     minute = grans(i, 5);
0072     
0073     logtext(fid, 'Collocating %s %s %04d-%02d-%02d %02d:%02d with %s %s \n', ...
0074         sat1, sensor1, thisyear, thismonth, thisday, hour, minute, sat2, sensor2);
0075     
0076     if ~isequal([thisyear thismonth thisday], [year month day]);
0077         % only take collocations happening in part of granule occuring on
0078         % the day requested
0079         oneday = 2;
0080     else % take any collocations happening on the day requested
0081         oneday = 1;
0082     end
0083     
0084     try
0085         [S{1:nout}] = collocate_granule(sat1, sensor1, sat2, sensor2, ...
0086             [thisyear, thismonth, thisday, hour, minute], oneday);
0087         anysuccess = true;
0088     catch ME
0089         switch ME.identifier
0090             case 'atmlab:find_datafile_by_date'
0091                 logtext(atmlab('ERR'), 'Error in searching for datafile %4d-%02d-%02d %02d:%02d %s %s: %s. SKIPPING\n', ...
0092                     thisyear, thismonth, thisday, hour, minute, sat1, sensor1, ME.message);
0093                 continue
0094             case {'atmlab:collocate', 'atmlab:atovs_get_l1c:zamsu2l1c', 'atmlab:collocate_granule:noother'}
0095                 logtext(atmlab('ERR'), 'Error in collocating with datafile at %4d-%02d-%02d %02d:%02d %s %s: %s. SKIPPING\n', ...
0096                     thisyear, thismonth, thisday, hour, minute, sat1, sensor1, ME.message);
0097                 continue
0098             case {'MATLAB:hdfinfo:invalidFile'}
0099                 logtext(atmlab('ERR'), 'Cannot read datafile %s %s %4d-%02d-%02d %02d:%02d: %s. SKIPPING\n', ...
0100                     sat1, sensor1, thisyear, thismonth, thisday, hour, minute, ME.message);
0101                 continue
0102             otherwise
0103                 ME.rethrow();
0104         end
0105     end
0106     [overlap, data, meandata] = colloc_concatenate_colloc_data_mean(...
0107         overlap, S{1}, data, S{2}, meandata, S{3});
0108 end
0109 
0110 if ~anysuccess
0111     error('atmlab:collocate_date:nosource', 'no source data found at all');
0112 end
0113 end

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