Home > atmlab > deprecated > find_scanline_overlaps.m

find_scanline_overlaps

PURPOSE ^

find_scanline_overlaps Create hashtable with scanline overlaps

SYNOPSIS ^

function find_scanline_overlaps(sat, sensor, startdate, enddate)

DESCRIPTION ^

 find_scanline_overlaps Create hashtable with scanline overlaps

 Creates a hashtable (such as used by granule_first_line) that maps for
 each sat/sensor granule the first scanline not occuring in the previous
 scanline.

 The resulting hashtable is written to a file according to
 datasets_config('firstline_data'), which is also where
 granule_first_line is looking for it.

 FORMAT

   find_scanline_overlaps(sat, sensor, startdate[, enddate])

 IN

   sat         string      Satellite
   sensor      string      sensor
   startdate   datevec     start here
   enddate     datevec     (optional) end here. Default: today
                           or end of data, whichever comes first

 OUT

   none, but writes a file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

find_scanline_overlaps.m

SOURCE CODE ^

0001 function find_scanline_overlaps(sat, sensor, startdate, enddate)
0002 
0003 % find_scanline_overlaps Create hashtable with scanline overlaps
0004 %
0005 % Creates a hashtable (such as used by granule_first_line) that maps for
0006 % each sat/sensor granule the first scanline not occuring in the previous
0007 % scanline.
0008 %
0009 % The resulting hashtable is written to a file according to
0010 % datasets_config('firstline_data'), which is also where
0011 % granule_first_line is looking for it.
0012 %
0013 % FORMAT
0014 %
0015 %   find_scanline_overlaps(sat, sensor, startdate[, enddate])
0016 %
0017 % IN
0018 %
0019 %   sat         string      Satellite
0020 %   sensor      string      sensor
0021 %   startdate   datevec     start here
0022 %   enddate     datevec     (optional) end here. Default: today
0023 %                           or end of data, whichever comes first
0024 %
0025 % OUT
0026 %
0027 %   none, but writes a file
0028 
0029 % Created by Gerrit Holl
0030 %
0031 % $Id: find_scanline_overlaps.m 7564 2012-05-02 14:24:45Z gerrit $
0032 
0033 warning(['atmlab:' mfilename ':deprecated'], ...
0034     'Deprecated, use SatDataset.find_granule_first_line instead');
0035 
0036 %colloc_config('stdout', fopen(fullfile('~/log', ['line_overlap_' sat '_' sensor '_out']), 'a'));
0037 %colloc_config('stderr', fopen(fullfile('~/log', ['line_overlap_' sat '_' sensor '_err']), 'a'));
0038 scanfile = datasets_config('firstline_data');
0039 scanfile = strrep(scanfile, '$SAT', sat);
0040 scanfile = strrep(scanfile, '$SENSOR', sensor);
0041 % read directly, not with read_granule, now I WANT the doubles
0042 reader = datasets_constants(['read_' sensor]);
0043 
0044 if ~exist('enddate', 'var')
0045     enddate = datevec(now);
0046 end
0047 
0048 logtext(atmlab('OUT'), 'Locating granules\n');
0049 allgrans = find_granules_for_period(startdate, enddate, sat, sensor);
0050 ngrans = size(allgrans, 1);
0051 logtext(atmlab('OUT'), 'Found %d granules\n', ngrans);
0052 
0053 if exist(scanfile, 'file')
0054     tm = load(scanfile);
0055     ht = tm.ht;
0056 else
0057     ht = java.util.Hashtable;
0058 end
0059 
0060 next = 0;
0061 for i = 1:ngrans-1
0062     logtext(atmlab('OUT'), 'granule %d/%d: %d-%02d-%02d %02d:%02d\n', i, ngrans-1, ...
0063             allgrans(i, 1), allgrans(i, 2), allgrans(i, 3), allgrans(i, 4), allgrans(i, 5));
0064     uni = date2unixsecs(allgrans(i+1, 1), allgrans(i+1, 2), allgrans(i+1, 3), allgrans(i+1, 4), allgrans(i+1, 5));
0065     if ht.containsKey(uint32(uni))
0066         logtext(atmlab('OUT'), 'Already exists (%d:%d)\n', uint32(uni), ht.get(uint32(uni)));
0067         continue
0068     end
0069     try
0070         couldreadcur = false;
0071         if isequal(next, 0)
0072             cur = reader(find_datafile_by_date(allgrans(i, :), sat, sensor));
0073         else
0074             cur = next;
0075         end
0076         couldreadcur = true;
0077         couldreadnext = false;
0078         next = reader(find_datafile_by_date(allgrans(i+1, :), sat, sensor));
0079         couldreadnext = true;
0080     catch ME
0081         switch ME.identifier
0082             case {'atmlab:find_datafile_by_date', 'atmlab:atovs_get_l1c:zamsu2l1c', 'atmlab:invalid_data'}
0083                 logtext(atmlab('ERR'), 'Problem: %s\n', ME.message);
0084             otherwise
0085                 ME.rethrow();
0086         end
0087     end
0088     %uni = date2unixsecs(allgrans(i+1, 1), allgrans(i+1, 2), allgrans(i+1, 3), allgrans(i+1, 4), allgrans(i+1, 5));
0089     if couldreadcur && couldreadnext
0090         t_cur = cur.epoch + cur.time;
0091         t_next = next.epoch + next.time;
0092         %[t_cur, t_next] = unify_time_axis(cur.time, next.time);
0093         firstline = find(t_next > t_cur(end), 1, 'first');
0094         if ~isempty(firstline)
0095             logtext(atmlab('OUT'), 'First line: %d\n', firstline);
0096             ht.put(uint32(uni), firstline);
0097         else
0098             logtext(atmlab('OUT'), 'No first line, setting to -2\n');
0099             ht.put(uint32(uni), -2);
0100         end
0101     elseif couldreadcur
0102         logtext(atmlab('OUT'), 'Could not read next, setting next to -3\n');
0103         ht.put(uint32(uni), -3);
0104     else
0105         logtext(atmlab('OUT'), 'Could not read current. setting to -4\n');
0106         ht.put(uint32(uni), -4);
0107     end
0108 end
0109 
0110 save(scanfile, 'ht');
0111 
0112 %if ~isempty(getenv('SGE_CWD_PATH')) % running inside queing system
0113 %    exit
0114 %end

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