Home > reduc > support > gainWrapper.m

gainWrapper

PURPOSE ^

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

SYNOPSIS ^

function d = gainWrapper(d, plotparams, parm, field);

DESCRIPTION ^

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

  function d = gainWrapper(d, plotparams, parm, field);

    reduceData function that calls functions to calculate gain

    sjcm

  3/30/2011 sjcm:  saving plots without display
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function d = gainWrapper(d, plotparams, parm, field);
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function d = gainWrapper(d, plotparams, parm, field);
0006 %
0007 %    reduceData function that calls functions to calculate gain
0008 %
0009 %    sjcm
0010 %
0011 %  3/30/2011 sjcm:  saving plots without display
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 
0014 % by this point, we should already have the system temperature values.
0015 if(~issubfield(d, 'correction', 'tsys'))
0016   display('System temperatures not present');
0017   display('Assuming this is a survey track');
0018   d.correction.survey = 1;
0019 end
0020 
0021 if(d.correction.survey)
0022   % calculate gains should load up the latest value of the noise diode, and
0023   % calculate the gains based on that
0024   gains = calculateGains(d);
0025   d.correction.gain = gains;
0026   d.correction.gain.flag = zeros(size(gains.val));
0027 else
0028   tsysGains = d.correction.tsys.gaindB;
0029   time = [tsysGains(:,1); tsysGains(:,4)];
0030   val  = [tsysGains(:,2:3); tsysGains(:,5:6)];
0031   flag = [d.correction.tsys.flag; d.correction.tsys.flag];
0032 
0033   % next we put htem in time order.
0034   [time I] = sort(time);
0035   val = val(I,:);
0036   flag = flag(I,:);
0037   
0038   d.correction.gain.time = time;
0039   d.correction.gain.val  = val;
0040   d.correction.gain.flag = flag;
0041 end
0042 
0043 % first we flag the gains, if needed
0044 % next we flag
0045 parFlag = checkpar(parm, 'gain');
0046 if(parFlag)
0047   flagParams = [parm.gain.min parm.gain.max parm.gain.sigma];
0048 else
0049   display('Using Default Gain Flagging parameters');
0050   flagParams = [100 200 3];
0051 end
0052 [gainflag] = flagGain(d.correction.gain, flagParams);
0053 
0054 setPlotDisplay(plotparams.plot);
0055 % all flagging has already happened in the tsys step, so we just plot.
0056 display('Plotting data');
0057 [d gainflag] = packd(d, gainflag, 'none', 'gain', plotparams, 'Gain Plots', field);
0058 d.correction.gain.flag = gainflag;
0059   
0060 % next we write things to disk
0061 thisGain = d.correction.gain.val;
0062 thisGain(d.correction.gain.flag>0) = nan;
0063 thisGain = [d.correction.gain.time thisGain];
0064 
0065 if(all(d.correction.gain.flag(:)) | d.correction.tsys.allbad==1)
0066   display('ATTENTION --- ATTENTION --- ATTENTION');
0067   display('No good gain values in your data');
0068   display('This data set will not be used for calibration');
0069   d.correction.gain.allbad = 1;
0070 else
0071   d.correction.gain.allbad = 0;
0072 end
0073 
0074 
0075 [home,installeddir]=where_am_i();
0076 
0077 % make sure file is up-to-date
0078 parFlag = checkpar(parm, 'autosave');
0079 if(parFlag)
0080   if(parm.autosave.flag & d.correction.gain.allbad==0)
0081     %system('cvs update constants/gain_values.txt');
0082     allGain  = load('constants/gain_values.txt');
0083     allGain  = [allGain; thisGain];
0084     save([home,'/',installeddir,'/constants/gain_values.txt'],'allGain', '-ascii','-single');
0085     %system('cvs commit -m "update" constants/gain_values.txt');
0086   end
0087 end
0088 
0089 
0090 
0091 
0092 
0093 
0094 return;
0095 
0096

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