Home > constants > getCalTemps.m

getCalTemps

PURPOSE ^

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

SYNOPSIS ^

function [outTsys] = getCalTemps(date1, date2, filename, avgFlag)

DESCRIPTION ^

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

   function [outTsys] = getCalTemps(date1, date2, filename, avgFlag)

   function that reads an ASCII text file, given by filename, and finds the
   tsys and noise diode temps 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 [outTsys] = getCalTemps(date1, date2,  filename, avgFlag)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %   function [outTsys] = getCalTemps(date1, date2, filename, avgFlag)
0006 %
0007 %   function that reads an ASCII text file, given by filename, and finds the
0008 %   tsys and noise diode temps that should be applied to the data for the
0009 %   time given by date
0010 %
0011 %   sjcm
0012 %
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 % note.  this function will not work if we have too many values set to nan.
0016 % will work on a fix for this in the future.
0017 
0018 
0019 if(nargin<3)
0020   filename = 'constants/calibration_values.txt';
0021   avgFlag = 1;
0022 end
0023 
0024 if(nargin<4)
0025   avgFlag = 1;
0026 end
0027 
0028 tsys = load(filename);
0029 
0030 aDate  = tsys(:,1);
0031 
0032 % first put things in chronological order
0033 [aDateChron, sortOrder] = sort(aDate);
0034 aChron     = tsys(sortOrder,:);
0035 
0036 % redefine the variables
0037 aDate     = aDateChron;
0038 tsys    = aChron;
0039 
0040 
0041 % let's get rid of the repeats - always trust the lastest one
0042 reps   = find(diff(aDate)==0);
0043 aDate(reps,:) = [];
0044 tsys(reps,:) = [];
0045 
0046 if(avgFlag == 1)
0047   
0048   % find the prior good time.
0049   dateDif = aDate - repmat(date1, size(aDate));
0050   f = find(dateDif > 0);
0051   if(isempty(f))
0052     f = length(dateDif);
0053   else
0054     f = f-1;
0055     f = f(1);
0056   end
0057   if(f==0)
0058     f=1;
0059   end
0060   
0061   % look for how many values are from within an hour of that one.
0062   inPriorHour = find(aDate>(aDate(f)-1/24) & aDate<=aDate(f));
0063   tsysPrior = tsys(inPriorHour,:);
0064   
0065   % next we check for the post time.
0066   % find the prior good time.
0067   dateDif = aDate - repmat(date2, size(aDate));
0068   f = find(dateDif > 0);
0069   if(isempty(f))
0070     f = length(dateDif);
0071   else
0072     f = f;
0073     f = f(1);
0074   end
0075   if(f==0)
0076     f=1;
0077   end
0078   
0079   % look for how many values are from within an hour of that one.
0080   inPostHour = find(aDate<(aDate(f)+1/24) & aDate>=aDate(f));
0081   tsysPost   = tsys(inPostHour,:);
0082   
0083   
0084   % now we have all our data sets as:
0085   tsysVals = [tsysPrior; tsysPost];
0086   
0087   % next we check that all our values are not nan-ed.
0088   % check for nan's
0089   if(all(isnan(tsysVals(:,3))))
0090     display(['getCalTemps:: Found some NaN values.']);
0091     display('getCalTemps:: Will find next good data');
0092     stop = 0;
0093     m = last(inPostHour);
0094     while(stop==0)
0095       if(~isnan(tsys(m,3)))
0096     tsysVals = [tsysVals; tsys(m,:)];
0097     stop = 1;
0098       else
0099     m = m+1;
0100       end
0101       if(m==length(tsys))
0102     stop = 1;
0103       end
0104     end
0105   end
0106   
0107   if(all(isnan(tsysVals(:,3))))
0108     display(['getCalTemps:: Still many NaN values']);
0109     display('getCalTemps:: Will find previous good data');
0110     stop = 0;
0111     m = inPriorHour(1);
0112     while(stop==0)
0113       if(~isnan(tsys(m,3)))
0114     tsysVals = [tsysVals; tsys(m,:)];
0115     stop = 1;
0116       else
0117     m = m-1;
0118       end
0119       if(m==0)
0120     stop = 1;
0121     display('getCalTemps:: CAN''T DO SHIT!!!');
0122     error(['getCalTemps:: ALL your Tsys values for this channel are bad']);      
0123       end
0124     end
0125   end
0126   
0127   if(all(isnan(tsysVals(:,4))))
0128     display(['getCalTemps:: Found some NaN values.']);
0129     display('getCalTemps:: Will find next good data');
0130     stop = 0;
0131     m = last(inPostHour);
0132     while(stop==0)
0133       if(~isnan(tsys(m,4)))
0134     tsysVals = [tsysVals; tsys(m,:)];
0135     stop = 1;
0136       else
0137     m = m+1;
0138       end
0139       if(m==length(tsys))
0140     stop = 1;
0141       end
0142     end
0143   end
0144   
0145   if(all(isnan(tsysVals(:,4))))
0146     display(['getCalTemps:: Still many NaN values']);
0147     display('getCalTemps:: Will find previous good data');
0148     stop = 0;
0149     m = inPriorHour(1);
0150     while(stop==0)
0151       if(~isnan(tsys(m,4)))
0152     tsysVals = [tsysVals; tsys(m,:)];
0153     stop = 1;
0154       else
0155     m = m-1;
0156       end
0157       if(m==0)
0158     stop = 1;
0159     display('getCalTemps:: CAN''T DO SHIT!!!');
0160     error(['getCalTemps:: ALL your Tsys values for this channel are bad']);      
0161       end
0162     end
0163   end
0164   
0165 else
0166   % do no averaging
0167   ind = aDate >= date1 & aDate <= date2;
0168   tsysVals = tsys(ind,:);
0169 end
0170 
0171   
0172 outTsys.time   = tsysVals(:,1);
0173 outTsys.source = tsysVals(:,2);
0174 outTsys.val    = tsysVals(:,3:4);
0175 outTsys.flag   = isnan(tsysVals(:,3:4));
0176 outTsys.tnoise = tsysVals(:,5:6);
0177 outTsys.trx    = tsysVals(:,7:8);
0178 
0179 % that's it
0180 return;
0181

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