Home > constants > getLoadCorrection.m

getLoadCorrection

PURPOSE ^

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

SYNOPSIS ^

function [K, shift] = getLoadCorrection(d)

DESCRIPTION ^

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

   function [K, shift] = getLoadCorrection(d)

   function that reads an ASCII text file, given by filename, and finds the
   load correction values that should be applied to the data for the
   time given by date

   sjcm

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [K, shift] = getLoadCorrection(d)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %   function [K, shift] = getLoadCorrection(d)
0006 %
0007 %   function that reads an ASCII text file, given by filename, and finds the
0008 %   load correction values that should be applied to the data for the
0009 %   time given by date
0010 %
0011 %   sjcm
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 % first put things in chronological order
0030 [cDateChron, sortOrder] = sort(cDate);
0031 cChron     = corrs(sortOrder,:);
0032 
0033 % redefine the variables
0034 cDate     = cDateChron;
0035 corrs    = cChron;
0036 
0037 
0038 % let us  get rid of the repeats - always trust the lastest one
0039 reps   = find(diff(cDate)==0);
0040 cDate(reps,:) = [];
0041 corrs(reps,:) = [];
0042 
0043 % find the closest value to our desired date
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 % check for nans
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         % since we have already cut the repeats, we can just use f as
0072         % our index to remove..
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

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