Home > constants > getNoiseTemps.m

getNoiseTemps

PURPOSE ^

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

SYNOPSIS ^

function [time tnoise] = getNoiseTemps(starttime, stoptime, filename, avgFlag)

DESCRIPTION ^

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

  function [time tnoise] = getNoiseTemps(starttime, stoptime, filename, avgFlag)

   function that reads an ASCII text file, given by filename, and finds the
   tau 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 [time tnoise] = getNoiseTemps(starttime, stoptime, filename, avgFlag)
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 %  function [time tnoise] = getNoiseTemps(starttime, stoptime, filename, avgFlag)
0005 %
0006 %   function that reads an ASCII text file, given by filename, and finds the
0007 %   tau correction values that should be applied to the data for the
0008 %   time given by date
0009 %
0010 %   sjcm
0011 %
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 
0014 if(nargin<3)
0015   filename = 'constants/noise_diode_values.txt';
0016   avgFlag  = 1;
0017 end
0018 
0019 if(nargin<4)
0020   avgFlag = 1;
0021 end
0022 
0023 
0024 tnoise = load(filename);
0025 tDate  = tnoise(:,1);
0026 tnoise(:,1:2) = [];  % second is the source, which we do not care about
0027 
0028 
0029 % first put things in chronological order
0030 [tDateChron, sortOrder] = sort(tDate);
0031 tChron     = tnoise(sortOrder,:);
0032 
0033 % redefine the variables
0034 tDate     = tDateChron;
0035 tnoise    = tChron;
0036 
0037 
0038 % let us get rid of the repeats - always trust the lastest one
0039 reps   = find(diff(tDate)==0);
0040 tDate(reps,:) = [];
0041 tnoise(reps,:) = [];
0042 
0043 % find the ones from before the time
0044 prevDate = tDate - starttime;
0045 f = find(prevDate<0);
0046 ff = find(prevDate(f) == max(prevDate(f)));
0047 mostRecentPrior = f(ff);
0048 
0049 % find the ones from after the time
0050 postDate = tDate - stoptime;
0051 f = find(postDate>0);
0052 ff = find(postDate(f) == min(postDate(f)));
0053 mostRecentPost = f(ff);
0054 
0055 if(avgFlag == 1)
0056   % Next we find the ones that are within an hour of each, and take an average
0057   f = find(tDate> (tDate(mostRecentPrior)-1/24) & tDate <= ...
0058       tDate(mostRecentPrior));
0059   if(length(f)>1)
0060     timePre  = mean(tDate(f));
0061     noisePre = nanmean(tnoise(f,:));
0062   elseif(length(f)==0)
0063    display('getNoiseTemps:: Fail:  No prior measure of noise diode temperature');
0064    display('getNoiseTemps:: Setting to default');
0065     timePre  = startime;
0066     noisePre = [2.1 2.1];
0067   else
0068     timePre = tDate(f);
0069     noisePre = tnoise(f,:);
0070   end
0071   
0072   f = find(tDate>= tDate(mostRecentPost) & tDate < ...
0073       tDate(mostRecentPost)+1/24);
0074   if(length(f)>1)
0075     timePost  = mean(tDate(f));
0076     noisePost = nanmean(tnoise(f,:));
0077   elseif(length(f)==0)
0078     display('getNoiseTemps:: Fail:  No post measure of noise diode temperature');
0079     display('getNoiseTemps:: Setting to default');
0080     timePre  = stoptime;
0081     noisePre = [2.1 2.1];
0082   else
0083     timePost = tDate(f);
0084     noisePost = tnoise(f,:);
0085   end
0086   
0087   time   = [timePre; timePost];
0088   tnoise = [noisePre; noisePost];
0089 
0090   % now we check for zeros, NaN, etc.
0091   f = find(isnan(tnoise) | tnoise==0);
0092   if(~isempty(f))
0093     display('getNoiseTemps:: Possible Fail:  noise temperature diode set to default');
0094     dispaly('getNoiseTemps:: value of 2.1K');
0095     tnoise(f) = 2.1;
0096   end
0097 else
0098   ind = tDate >= starttime & tDate <=stoptime;
0099   tnoise = tnoise(ind,:);
0100   time   = tDate(ind);
0101 end
0102 
0103 return;
0104

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