Home > constants > getAlpha.m

getAlpha

PURPOSE ^

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

SYNOPSIS ^

function [alpha, gain, tsys horiz equa] = getAlpha(date, filename)

DESCRIPTION ^

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

   function [alpha, gain, tsys] = getAlpha(date, filename)

   function that reads an ASCII text file, given by filename, and finds the
   alpha 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 [alpha, gain, tsys horiz equa] = getAlpha(date, filename)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %   function [alpha, gain, tsys] = getAlpha(date, filename)
0006 %
0007 %   function that reads an ASCII text file, given by filename, and finds the
0008 %   alpha correction values that should be applied to the data for the
0009 %   time given by date
0010 %
0011 %   sjcm
0012 %
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 if(nargin<2)
0016   filename = 'constants/alpha_values.txt';
0017 end
0018 
0019 alphas = load(filename);
0020 
0021 aDate  = alphas(:,1);
0022 alphas(:,1) = [];
0023 
0024 
0025 % first put things in chronological order
0026 [aDateChron, sortOrder] = sort(aDate);
0027 aChron     = alphas(sortOrder,:);
0028 
0029 % redefine the variables
0030 aDate     = aDateChron;
0031 alphas    = aChron;
0032 
0033 
0034 % let's get rid of the repeats - always trust the lastest one
0035 reps   = find(diff(aDate)==0);
0036 aDate(reps,:) = [];
0037 alphas(reps,:) = [];
0038 
0039 % find the closest value to our desired date
0040 dateDif = aDate - repmat(date, size(aDate));
0041 f = find(dateDif > 0);
0042 if(isempty(f))
0043   f = length(dateDif);
0044 else
0045   f = f-1;
0046   f = f(1);
0047 end
0048 if(f==0)
0049   f=1;
0050 end
0051 
0052 alpha = alphas(f,:);
0053 finOrder = f;
0054 
0055 % check for nan's
0056 if(any(isnan(alpha)))
0057     display(['getAlpha:: Found some NaN values.']);
0058     display('getAlpha:: Will find previous good data');
0059     fNan = find(isnan(alpha));
0060 
0061     for m=1:length(fNan)
0062         thisA = alphas(:,fNan(m));
0063         if(all(isnan(thisA)))
0064             display('getAlpha:: CAN''T DO SHIT!!!');
0065             error(['getAlpha:: ALL your R-factor corrections for this channel are bad']);
0066         end
0067         % since we've already cut the repeats, we can just use f as
0068         % our index to remove..
0069         newOrder = f;
0070         rVal = thisA(newOrder);
0071         while(isnan(rVal))
0072             newOrder = newOrder - 1;
0073             rVal = thisA(newOrder);
0074         end
0075         alpha(fNan(m)) = rVal;
0076     end
0077 end
0078 
0079 % that's it
0080 gain = alpha(9:16);
0081 tsys = alpha(17:20);
0082 horiz= alpha(21:22);
0083 equa = alpha(23:24);
0084 alpha= alpha(1:8);
0085 
0086 return;
0087

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