Home > atmlab > deprecated > find_datafile_by_date.m

find_datafile_by_date

PURPOSE ^

find_datafile_by_date Return full path of datafile by date/time

SYNOPSIS ^

function datafile = find_datafile_by_date(datevec, satname, sensor,tol)

DESCRIPTION ^

 find_datafile_by_date Return full path of datafile by date/time

 Returns the full path of the datafile corresponding to the input
 arguments. There are two modes:

   - If datasets_config('DATASET_filename') is defined, the path is
     calculated directly from datasets_config settings and the arguments
     passed on. The file may or may not actually exist, so in this case,
     you can use it to calculate the path when planning to create it.

   - If this is not defined, then datasets_config('DATASET_regexp') has to
     be defined. It will search the filesystem for a file matching the
     regular expression and the indicated datevec/satname/dataset. In this
     case, one can apply a tolerance in seconds.

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

 FORMAT

   datafile = find_datafile_by_date(datevec, sat, dataset[, tol])

 IN

   datevec     vector  Date/time to find datafile for
   satname     string/ Name of satellite. For datasets belonging to one
               cellstr satellite, a simple string. For datasets belonging
                       to two satellites (such as collocations), a cell
                       array of two strings.
   dataset     string  Name of dataset
   tol         number  Optional: tolerance in seconds. Sometimes, MSPPS
                       doesn't start the same minute as AMSU :(.

 OUT

   datafile    string     Path to the looked-for datafile.


 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

find_datafile_by_date.m

SOURCE CODE ^

0001 function datafile = find_datafile_by_date(datevec, satname, sensor, ...
0002     tol)
0003 
0004 % find_datafile_by_date Return full path of datafile by date/time
0005 %
0006 % Returns the full path of the datafile corresponding to the input
0007 % arguments. There are two modes:
0008 %
0009 %   - If datasets_config('DATASET_filename') is defined, the path is
0010 %     calculated directly from datasets_config settings and the arguments
0011 %     passed on. The file may or may not actually exist, so in this case,
0012 %     you can use it to calculate the path when planning to create it.
0013 %
0014 %   - If this is not defined, then datasets_config('DATASET_regexp') has to
0015 %     be defined. It will search the filesystem for a file matching the
0016 %     regular expression and the indicated datevec/satname/dataset. In this
0017 %     case, one can apply a tolerance in seconds.
0018 %
0019 % Valid datasets are returned by <a href="matlab:help list_datasets">list_datasets</a>.
0020 %
0021 % FORMAT
0022 %
0023 %   datafile = find_datafile_by_date(datevec, sat, dataset[, tol])
0024 %
0025 % IN
0026 %
0027 %   datevec     vector  Date/time to find datafile for
0028 %   satname     string/ Name of satellite. For datasets belonging to one
0029 %               cellstr satellite, a simple string. For datasets belonging
0030 %                       to two satellites (such as collocations), a cell
0031 %                       array of two strings.
0032 %   dataset     string  Name of dataset
0033 %   tol         number  Optional: tolerance in seconds. Sometimes, MSPPS
0034 %                       doesn't start the same minute as AMSU :(.
0035 %
0036 % OUT
0037 %
0038 %   datafile    string     Path to the looked-for datafile.
0039 %
0040 %
0041 % $Id$
0042 
0043 errid = 'atmlab:find_datafile_by_date';
0044 
0045 % implementation:
0046 % 1. find the directory containing the files from basedir/subdir
0047 % 2. if possible, calculate the filename directly
0048 % 3. otherwise, list all files and match with regexp+tolerance
0049 
0050 fulldir = find_datadir_by_date(datevec, satname, sensor);
0051 
0052 if ~isnan(datasets_config([sensor '_filename'])) % calculate directly
0053     fn = datasets_config([sensor '_filename']);
0054     fn = strrep_variables(fn, satname, datevec);
0055     datafile = fullfile(fulldir, fn);
0056 else % will search through all granules with find_granules_by_date
0057     [granules, paths] = find_granules_by_date(datevec(1), datevec(2), datevec(3), satname, sensor, false);
0058     if exist('tol', 'var') % use tolerance
0059         g = mat2cell(granules, size(granules, 1), [1 1 1 1 1]);
0060         grans_unisecs = date2unixsecs(g{:});
0061         dv_unisecs = date2unixsecs(datevec(1), datevec(2), datevec(3), datevec(4), datevec(5));
0062         found = abs(grans_unisecs - dv_unisecs) < tol;
0063     else
0064         found = granules(:, 4)==datevec(4) & granules(:, 5)==datevec(5);
0065     end
0066     
0067     nfound = sum(found);
0068     if nfound==0
0069         error(errid, 'No datafile found for %s %s [%s]', satname, sensor, num2str(datevec));
0070     elseif nfound > 1
0071         error(errid, 'Multiple datefiles found for %s %s', satname, sensor);
0072     else
0073         datafile = paths{found};
0074     end
0075     
0076 end
0077 
0078 end

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