0001 function r = updateLoadTemplates(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 disp('======================================================');
0039 disp(' Welcome to the 1.2Hz Template Updater!');
0040 disp('======================================================');
0041 disp(' ');
0042
0043
0044
0045 [startMJD, endMJD, startPlotMJD, endPlotMJD] = ...
0046 parseLoadArguments(varargin);
0047
0048
0049
0050 [oldMjdList oldTemplates] = readTemplateDatabase();
0051
0052
0053
0054 defaultDataDir = whichHost();
0055 archiveDir = [defaultDataDir(1:end-3) '/reduc/load/'];
0056
0057
0058
0059 [home installeddir] = where_am_i();
0060 newEstimatesDir = [home '/' installeddir '/reduc/load/estimates/'];
0061 if ~exist(newEstimatesDir,'dir')
0062 mkdir(newEstimatesDir);
0063 end
0064
0065
0066
0067 [startMJD, endMJD, startPlotMJD, endPlotMJD, estimateMJDs] = ...
0068 checkLoadDates(startMJD, endMJD, startPlotMJD, endPlotMJD, ...
0069 archiveDir, newEstimatesDir, oldMjdList);
0070
0071
0072
0073
0074
0075 [mjdVec numArray estimateArray] = ...
0076 readTemplateEstimates(startPlotMJD,endPlotMJD, ...
0077 archiveDir,newEstimatesDir,estimateMJDs);
0078 oldEndMJD = max(mjdVec)+1/12;
0079
0080
0081
0082 [mjdVec estimateRecalc numArray estimateArray] = ...
0083 createTemplateEstimates(mjdVec, numArray, estimateArray,startMJD,endMJD,newEstimatesDir);
0084
0085
0086
0087 copyTemplateEstimates(newEstimatesDir);
0088
0089
0090
0091
0092 [newMjdList changeList] = ...
0093 plotTemplateEstimates(mjdVec, estimateArray(1:8:end,:,[1 6 7 8]), oldMjdList);
0094
0095
0096
0097 unChangedList = find(changeList == 0);
0098 for j = 1:length(unChangedList)
0099 k = unChangedList(j);
0100 if k < length(changeList)
0101 estimateIndices = ...
0102 mjdVec >= newMjdList(k)-0.1/12 & ...
0103 mjdVec <= newMjdList(k+1)-0.5/12;
0104 else
0105 estimateIndices = ...
0106 mjdVec >= (newMjdList(k)-0.1/12);
0107 end
0108
0109 if sum(estimateRecalc(estimateIndices)) > 0
0110 changeList(k) = 3;
0111 end
0112 end
0113
0114
0115
0116 newEndMJD = max(mjdVec)+1/12;
0117 recalcList = ...
0118 idTemplateUpdates(oldMjdList,newMjdList,oldEndMJD,newEndMJD, ...
0119 changeList);
0120
0121
0122
0123 newTemplates = compileLoadTemplates(mjdVec, numArray, estimateArray, ...
0124 newMjdList, recalcList, oldMjdList, oldTemplates);
0125
0126
0127 writeTemplateDatabase(newMjdList,newTemplates);
0128
0129
0130 r = 1;
0131
0132 end
0133
0134
0135
0136
0137
0138
0139 function [startMJD, endMJD, startPlotMJD, endPlotMJD] = ...
0140 parseLoadArguments(inputCell)
0141
0142
0143 keyIndex = find(strcmpi(inputCell,'plotrange'),1,'first');
0144
0145 if length(keyIndex) == 1 && keyIndex < length(inputCell)
0146
0147
0148 if length(inputCell{keyIndex+1}) == 2
0149
0150
0151
0152 if iscell(inputCell{keyIndex+1})
0153
0154 startPlotMJD = tstr2mjd(inputCell{keyIndex+1}{1});
0155 endPlotMJD = tstr2mjd(inputCell{keyIndex+1}{2});
0156 else
0157
0158 startPlotMJD = inputCell{keyIndex+1}(1);
0159 endPlotMJD = inputCell{keyIndex+1}(2);
0160 end
0161
0162 else
0163
0164
0165
0166 if iscell(inputCell{keyIndex+1})
0167
0168
0169
0170 startPlotMJD = tstr2mjd(inputCell{keyIndex+1}{1});
0171
0172 elseif ischar(inputCell{keyIndex+1})
0173
0174
0175 startPlotMJD = tstr2mjd(inputCell{keyIndex+1});
0176
0177 else
0178
0179
0180 startPlotMJD = inputCell{keyIndex+1};
0181
0182 end
0183
0184
0185 endPlotMJD = Inf;
0186
0187 end
0188
0189
0190
0191
0192
0193 if keyIndex == 1
0194
0195
0196
0197
0198
0199
0200 startMJD = -Inf;
0201 endMJD = Inf;
0202
0203 elseif keyIndex == 2
0204
0205
0206 if ischar(inputCell{1})
0207 endMJD = tstr2mjd(inputCell{1});
0208 else
0209 endMJD = inputCell{1};
0210 end
0211
0212 startMJD = -Inf;
0213
0214 else
0215
0216
0217 if ischar(inputCell{1})
0218 startMJD = tstr2mjd(inputCell{1});
0219 else
0220 startMJD = inputCell{1};
0221 end
0222 if ischar(inputCell{2})
0223 endMJD = tstr2mjd(inputCell{2});
0224 else
0225 endMJD = inputCell{2};
0226 end
0227
0228 end
0229 else
0230
0231
0232 startPlotMJD = -Inf;
0233 endPlotMJD = Inf;
0234
0235
0236
0237
0238
0239 if isempty(inputCell)
0240
0241
0242
0243
0244
0245
0246 startMJD = -Inf;
0247 endMJD = Inf;
0248
0249 elseif length(inputCell) == 1
0250
0251
0252 if ischar(inputCell{1})
0253 endMJD = tstr2mjd(inputCell{1});
0254 else
0255 endMJD = inputCell{1};
0256 end
0257
0258 startMJD = -Inf;
0259
0260 else
0261
0262
0263 if ischar(inputCell{1})
0264 startMJD = tstr2mjd(inputCell{1});
0265 else
0266 startMJD = inputCell{1};
0267 end
0268 if ischar(inputCell{2})
0269 endMJD = tstr2mjd(inputCell{2});
0270 else
0271 endMJD = inputCell{2};
0272 end
0273
0274 end
0275
0276 end
0277
0278
0279 disp(' Your input arguments have been parsed as follows: ');
0280
0281 if (endMJD < Inf)
0282 disp([' - You will calculate template estimates up ' mjd2string(endMJD)]);
0283 else
0284 disp(' - You will calculate template estimates up to the present. ');
0285 end
0286
0287 if (startMJD > -Inf)
0288 disp([' - You will recalculate template estimates beginning ' mjd2string(startMJD)]);
0289 else
0290 disp(' - You will not recalculate earlier template estimates. ');
0291 end
0292
0293 if (startPlotMJD == -Inf)
0294 disp(' - You did not to provide a plotting range.');
0295 elseif (endPlotMJD == Inf)
0296 disp([' - You chose to plot estimates after ' mjd2string(startPlotMJD)]);
0297 else
0298 disp([' - Your chosen plotting range is ' mjd2string(startPlotMJD) ' to ' mjd2string(endPlotMJD)]);
0299 end
0300
0301
0302 end
0303