Home > reduc > load > readTemplateEstimates.m

readTemplateEstimates

PURPOSE ^

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

SYNOPSIS ^

function [mjdVec numArray estimateArray] =readTemplateEstimates(startMJD,endMJD,archiveDir,newEstimatesDir,estimateMJDs)

DESCRIPTION ^

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

 function [mjdVec numArray estimateArray] = ...
       readTemplateEstimates(startMJD,endMJD,archiveDir, ...
       newEstimatesDir,estimateMJDs)

   Reads in the 2-hour cold-load template estimates from the archive.   


   I/O:

   MAS -- 20-April-2012

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mjdVec numArray estimateArray] = ...
0002     readTemplateEstimates(startMJD,endMJD, ...
0003     archiveDir,newEstimatesDir,estimateMJDs)
0004 
0005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0006 %
0007 % function [mjdVec numArray estimateArray] = ...
0008 %       readTemplateEstimates(startMJD,endMJD,archiveDir, ...
0009 %       newEstimatesDir,estimateMJDs)
0010 %
0011 %   Reads in the 2-hour cold-load template estimates from the archive.
0012 %
0013 %
0014 %   I/O:
0015 %
0016 %   MAS -- 20-April-2012
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 
0021 fprintf(['\nReading in the existing template estimates.  \n' ...
0022         'This will take a minute or so.  \n\n' ...
0023         'Make yourself comfortable.\n\n']);
0024 
0025 
0026 % % Find the files.
0027 % fileListArch = dir([archiveDir '*.bin']);
0028 % nFilesArch = length(fileListArch);
0029 % fileListLocal = dir([newEstimatesDir '*.bin']);
0030 % nFilesLocal = length(fileListLocal);
0031 %
0032 % nFiles = nFilesArch + nFilesLocal;
0033 
0034 
0035 % Create the list of files to be read:
0036 % File format (updated 26-Nov-2012): yyyy-mm-ddThh.bin
0037 mjdVec = unique( ...
0038     estimateMJDs(estimateMJDs > startMJD-0.1/12 & ...
0039     estimateMJDs < endMJD-0.1/12));
0040 
0041 nFiles = length(mjdVec);
0042 
0043 fileList = cell(1,nFiles);
0044 for k=1:length(mjdVec)
0045 
0046     [year, month, day, hour, minute, second] = mjd2date(mjdVec(k));
0047 
0048     if (minute > 30)
0049         [year, month, day, hour, minute, second] = mjd2date(mjdVec(k)+0.1/12);
0050     end
0051     
0052     fileList{k} = sprintf('%04d-%02d-%02dT%02d.bin', ...
0053         year, month, day, hour);
0054 
0055 end
0056 
0057 
0058 % Do the first file.
0059 fileName_arch = [archiveDir fileList{1}];
0060 fileName_new = [newEstimatesDir fileList{1}];
0061 
0062 if ~exist(fileName_arch,'file')
0063     % Read it in from the new estimate directory if it's not in the
0064     % archive.
0065     fid = fopen(fileName_new, 'rb');
0066 else
0067     % Read it in from the archive if it's there.
0068     fid = fopen(fileName_arch, 'rb');
0069     if exist(fileName_new,'file')
0070         % If it's also in the new estimate directory, then delete that
0071         % copy.
0072         delete(fileName_new);
0073     end
0074 end
0075     
0076 
0077 templateEstimates = fread(fid,'float');
0078 fclose(fid);
0079 
0080 n_phase = length(templateEstimates) / 21;
0081 
0082 templateEstimates = reshape(templateEstimates,n_phase,21);
0083 
0084 
0085 % When keeping the data from this first file, also prepare the output
0086 % arrays.  We do this at this point because we don't want to assume how
0087 % many phase bins there are.
0088 
0089 numArray = zeros(n_phase,nFiles);
0090 numArray(:,1) = templateEstimates(:,1);
0091 
0092 estimateArray = zeros(n_phase,nFiles,20);
0093 estimateArray(:,1,:) = templateEstimates(:,2:21);
0094 
0095 
0096 % Loop over and read in the files.
0097 for k=2:nFiles
0098 
0099     % Possible file names.
0100     fileName_arch = [archiveDir fileList{k}];
0101     fileName_new = [newEstimatesDir fileList{k}];
0102 
0103     if ~exist(fileName_arch,'file')
0104         % Read it in from the new estimate directory if it's not in the
0105         % archive.
0106         fid = fopen(fileName_new, 'rb');
0107     else
0108         % Read it in from the archive if it's there.
0109         fid = fopen(fileName_arch, 'rb');
0110         if exist(fileName_new,'file')
0111             % If it's also in the new estimate directory, then delete that
0112             % copy.
0113             delete(fileName_new);
0114         end
0115     end
0116     
0117         
0118     
0119     templateEstimates = fread(fid,'float');
0120     fclose(fid);
0121 
0122     templateEstimates = reshape(templateEstimates,n_phase,21);
0123     
0124 
0125     numArray(:,k) = templateEstimates(:,1);
0126 
0127     estimateArray(:,k,:) = templateEstimates(:,2:21);
0128 end
0129 
0130 
0131 % % Next, if we have any files in the local directory, then read those in,
0132 % % too.  Delete any that are in the archive.
0133 % for k=1:nFilesLocal
0134 %
0135 %     fileName = [newEstimatesDir fileListLocal(k).name];
0136 %
0137 %     inputDate = regexp(fileName, ...
0138 %         '[0-9]+-[A-Za-z]+-[0-9]{4}:[0-9]{2}:[0-9]{2}:[0-9]{2}','match');
0139 %
0140 %
0141 %     if min(abs(mjdVec - tstr2mjd(char(inputDate)))) < (1 / 1440)
0142 %         % This file is already in the archive.
0143 %         delete(fileName);
0144 %         continue;
0145 %     end
0146 %
0147 %     fid = fopen(fileName, 'rb');
0148 %     templateEstimates = fread(fid,'float');
0149 %     fclose(fid);
0150 %
0151 %     templateEstimates = reshape(templateEstimates,n_phase,21);
0152 %
0153 %
0154 %     mjdVec(nFilesArch+k) = tstr2mjd(char(inputDate));
0155 %
0156 %     numArray(:,nFilesArch+k) = templateEstimates(:,1);
0157 %
0158 %     estimateArray(:,nFilesArch+k,:) = templateEstimates(:,2:21);
0159 % end
0160 
0161 
0162 
0163 % % Get rid of nondata elements.
0164 % numArray = numArray(:,mjdVec~=0);
0165 % estimateArray = estimateArray(:,mjdVec~=0,:);
0166 % mjdVec = mjdVec(mjdVec~=0);
0167 %
0168 %
0169 % % Sort the arrays...
0170 % [mjdVecM mjdI] = unique(round(mjdVec*12));
0171 % mjdVec = mjdVecM / 12;
0172 % numArray = numArray(:,mjdI);
0173 % estimateArray = estimateArray(:,mjdI,:);
0174 %
0175 %
0176 % % Insert zero vectors for missing data.
0177 % dt = round(12*diff(mjdVec));
0178 % for k=sort(find(dt > 1),2,'descend')
0179 %     mjdVec = [mjdVec(1:k) mjdVec(k)+(1:dt(k)-1)/12 mjdVec(k+1:end)];
0180 %     numArray = [numArray(:,1:k) zeros(n_phase, dt(k)-1) numArray(:,k+1:end)];
0181 %     estimateArray = [estimateArray(:,1:k,:) zeros(n_phase, dt(k)-1, 20) estimateArray(:,k+1:end,:)];
0182 % end
0183 
0184 end

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