Home > reduc > load > checkLoadDates.m

checkLoadDates

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function [startMJD, endMJD, startPlotMJD, endPlotMJD, estimateMJDs] =checkLoadDates(startMJD, endMJD, startPlotMJD, endPlotMJD,archiveDir, newEstimatesDir, templateMJDs)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 function [mjdVec numArray estimateArray] = checkLoadDates(archiveDir,newEstimatesDir)

   Finds out the last template estimate that exists, and the last entry 
   in the alpha database.  Uses these values to modify the user's 
   input dates.  Also, checks to make sure that plotting range vs.
   calculation range make sense.

   I/O:

   MAS -- 26-Nov-2012

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [startMJD, endMJD, startPlotMJD, endPlotMJD, estimateMJDs] = ...
0002     checkLoadDates(startMJD, endMJD, startPlotMJD, endPlotMJD, ...
0003     archiveDir, newEstimatesDir, templateMJDs)
0004 
0005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0006 %
0007 % function [mjdVec numArray estimateArray] = checkLoadDates(archiveDir,newEstimatesDir)
0008 %
0009 %   Finds out the last template estimate that exists, and the last entry
0010 %   in the alpha database.  Uses these values to modify the user's
0011 %   input dates.  Also, checks to make sure that plotting range vs.
0012 %   calculation range make sense.
0013 %
0014 %   I/O:
0015 %
0016 %   MAS -- 26-Nov-2012
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 
0021 % FIRST OFF.  NEED TO DETERMINE THE LAST TEMPLATE ESTIMATE THAT HAS BEEN
0022 % CALCULATED.
0023 % Note that the list of template estimate dates is produced as a byproduct.
0024 % This will be useful later.
0025 
0026 % Find the files.
0027 fileListArch = dir([archiveDir '*-*-*T*.bin']);
0028 fileListLocal = dir([newEstimatesDir '*-*-*T*.bin']);
0029 
0030 fileList = cat(1,fileListArch,fileListLocal);
0031 nFiles = length(fileList);
0032 
0033 
0034 % Convert the filenames to a vector of MJDs.
0035 estimateMJDs = zeros(1,nFiles);
0036 
0037 for k=1:nFiles
0038     
0039     fileDate = regexp(fileList(k).name, ...
0040         '(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})T(?<hour>[0-9]{2})', 'names');
0041 
0042 %     fileDate = regexp(fileList(k).name, ...
0043 %         '[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}', 'match');
0044     
0045     estimateMJDs(k) = date2mjd( ...
0046         str2double(fileDate.year),str2double(fileDate.month), ...
0047         str2double(fileDate.day),str2double(fileDate.hour));
0048     
0049 end
0050 
0051 maxEstimateMJD = max(estimateMJDs);
0052 
0053 
0054 
0055 % SECOND.  NEED TO DETERMINE THE LAST TIME IN THE ALPHA DATABASE.
0056 
0057 lastLoadMJD = lastAlphaValue();
0058 
0059 maxAlphaMJD = lastLoadMJD - 1.9 / 24;  % Need to leave two hour buffer before end of alpha database.
0060 
0061 
0062 
0063 disp(' Your input arguments have been modified/rounded as follows:');
0064 
0065 
0066 
0067 % THIRD.  SORT OUT THE START/STOP DATES FOR TEMPLATE ESTIMATE CALCULATION.
0068 if startMJD == -Inf
0069     startMJD = maxEstimateMJD + 1/12;
0070 else 
0071     startMJD = floor(startMJD * 12 + 0.1) / 12;
0072 end
0073 
0074 if endMJD > maxAlphaMJD
0075     endMJD = floor(maxAlphaMJD * 12) / 12;
0076 else 
0077     endMJD = floor(endMJD * 12 + 0.1) / 12;
0078 end
0079 
0080 disp(['  - Your calculation range is ' mjd2string(startMJD) ' to ' mjd2string(endMJD)]);
0081 
0082 if endMJD <= startMJD+0.1/12
0083     disp('WARNING:  Your endTime is not after your startTime.');
0084     disp('  You will not calculate any new estimates.');
0085 end
0086 
0087 
0088 % FOURTH.  ENLARGE THE PLOTTING RANGE TO INCLUDE ALL TEMPLATE PERIODS THAT
0089 % OVERLAP WITH CALCULATION PERIOD.
0090 % This requires reading in the template database...
0091 if min(startMJD,startPlotMJD) > min(templateMJDs)
0092     startPlotMJD = max(templateMJDs((min(startMJD,startPlotMJD) - templateMJDs) >= 0));
0093 else
0094     startPlotMJD = min(startMJD,min(estimateMJDs));
0095 end
0096 
0097 if endPlotMJD < Inf
0098     if endPlotMJD > max(templateMJDs) && endMJD > max(templateMJDs)
0099         endPlotMJD = endMJD;
0100     else    
0101         endPlotMJD = min(templateMJDs((templateMJDs - max(endMJD,endPlotMJD)) >= 0));    
0102     end
0103 else
0104     endPlotMJD = max(endMJD,templateMJDs(end));
0105 end
0106     
0107 disp(['  - Your plotting range is ' mjd2string(startPlotMJD) ' to ' mjd2string(endPlotMJD)]);
0108 
0109 if endPlotMJD <= startPlotMJD
0110     error('WARNING:  Your plotting range makes no sense.');
0111 end
0112 
0113 
0114 disp(' ');
0115 
0116 end

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005