0001 function [K, shift] = getLoadCorrection(d)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 date = d.array.frame.utc(1);
0016 nDims = size(d.antenna0.receiver.data,2);
0017 if(nDims==10)
0018 filename = 'constants/load_correction_values_10.txt';
0019 elseif(nDims==8)
0020 filename = 'constants/load_correction_values_8.txt';
0021 end
0022
0023 corrs = load(filename);
0024
0025 cDate = corrs(:,1);
0026 corrs(:,1) = [];
0027
0028
0029
0030 [cDateChron, sortOrder] = sort(cDate);
0031 cChron = corrs(sortOrder,:);
0032
0033
0034 cDate = cDateChron;
0035 corrs = cChron;
0036
0037
0038
0039 reps = find(diff(cDate)==0);
0040 cDate(reps,:) = [];
0041 corrs(reps,:) = [];
0042
0043
0044 dateDif = cDate - repmat(date, size(cDate));
0045 f = find(dateDif > 0);
0046 if(isempty(f))
0047 f = length(dateDif);
0048 else
0049 f = f-1;
0050 f = f(1);
0051 end
0052 if(f==0)
0053 f=1;
0054 end
0055
0056 corrValue = corrs(f,:);
0057 finOrder = f;
0058
0059
0060 if(any(isnan(corrValue)))
0061 display(['getLoadCorrection:: Found some NaN values.']);
0062 display('getLoadCorrection:: Will find previous good data');
0063 fNan = find(isnan(corrValue));
0064
0065 for m=1:length(fNan)
0066 thisA = corrs(:,fNan(m));
0067 if(all(isnan(thisA)))
0068 display('getLoadCorrection:: CAN''T DO SHIT!!!');
0069 error(['getLoadCorrection:: ALL your load correction values are bad']);
0070 end
0071
0072
0073 newOrder = f;
0074 rVal = thisA(newOrder);
0075 while(isnan(rVal))
0076 newOrder = newOrder - 1;
0077 rVal = thisA(newOrder);
0078 end
0079 corrValue(fNan(m)) = rVal;
0080 end
0081 end
0082
0083 numEntries = length(corrValue);
0084 K = corrValue(1:numEntries/2);
0085 shift = corrValue(numEntries/2+1:numEntries);
0086
0087 return;
0088