Home > reduc > plotting > packd.m

packd

PURPOSE ^

packd(dcal,dopt,caltype,type,plotparams,str, field, dcal0, maindir)

SYNOPSIS ^

function [dcal, flag]=packd(dcal,flag,caltype,type,plotparams, str, field, dcal0, maindir)

DESCRIPTION ^

 packd(dcal,dopt,caltype,type,plotparams,str, field, dcal0, maindir)

 dcal    - modified data structure
 flag    - the flag structure to be set witha different color
 caltype - type of calibrator data to plot  [NOT USED YET]
           'int'   - intensity calibrator
           'pol'   - polarization calibrator
           'both'  - both 
           'none'   - plot does not rely on a specific calibrator
 type    - type of application used
           'az_el'    - az and el of antenna
           'cold_load'- cold load
           'rx_temp'  - receiver temps
           'wx'       - weather data
           'cone_temp'- cone temperature
           'plot_sources' - plot sources
           'intent'   - plots what was done in the track (features)
           'deglitch' - deglitching flagging
           'positional' - positional flagging
           'rfi'      - rfi flagging
           'alpha'    - alpha correction flagging
           'tsys'     - system temperature flagging
           'gain'     - gain of the system
           'tau'      - opacity plotting
           'stokes' - r_factor calibration
           'astro'    - astronomical conversion to Jy
           'mainsSwitch' - mains hum removal off switched data
           'mainsReg'    - mains hum removal off regular data
           'load_cal' - cold load calibration
           'power_spec' - power spectrum plots
           'rms'        - rms plots
 str     - optional gtitle string (give title to matrix plot)
           only available for use in:

 field   - field looked at.  needed for getMainDir.m
 plotparams - parameters for plottign/saving
 dcal0   - priordata set with no correction (for load_cal)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [dcal, flag]=packd(dcal,flag,caltype,type,plotparams, str, field, dcal0, maindir)
0002 % packd(dcal,dopt,caltype,type,plotparams,str, field, dcal0, maindir)
0003 %
0004 % dcal    - modified data structure
0005 % flag    - the flag structure to be set witha different color
0006 % caltype - type of calibrator data to plot  [NOT USED YET]
0007 %           'int'   - intensity calibrator
0008 %           'pol'   - polarization calibrator
0009 %           'both'  - both
0010 %           'none'   - plot does not rely on a specific calibrator
0011 % type    - type of application used
0012 %           'az_el'    - az and el of antenna
0013 %           'cold_load'- cold load
0014 %           'rx_temp'  - receiver temps
0015 %           'wx'       - weather data
0016 %           'cone_temp'- cone temperature
0017 %           'plot_sources' - plot sources
0018 %           'intent'   - plots what was done in the track (features)
0019 %           'deglitch' - deglitching flagging
0020 %           'positional' - positional flagging
0021 %           'rfi'      - rfi flagging
0022 %           'alpha'    - alpha correction flagging
0023 %           'tsys'     - system temperature flagging
0024 %           'gain'     - gain of the system
0025 %           'tau'      - opacity plotting
0026 %           'stokes' - r_factor calibration
0027 %           'astro'    - astronomical conversion to Jy
0028 %           'mainsSwitch' - mains hum removal off switched data
0029 %           'mainsReg'    - mains hum removal off regular data
0030 %           'load_cal' - cold load calibration
0031 %           'power_spec' - power spectrum plots
0032 %           'rms'        - rms plots
0033 % str     - optional gtitle string (give title to matrix plot)
0034 %           only available for use in:
0035 %
0036 % field   - field looked at.  needed for getMainDir.m
0037 % plotparams - parameters for plottign/saving
0038 % dcal0   - priordata set with no correction (for load_cal)
0039 %
0040 
0041 % the plot will be dependant on the type you choose.
0042 %
0043 % Stephen Muchovej
0044 % 28/10/2010 - ACT added gen=3 flag so removal of spurious data
0045 %                   can be done without having to see the plots
0046 %
0047 % 07/01/2011 - MAS removed the stageNum parameter for purposes of two-stage
0048 %                   RFI flagging.
0049 % 29/03/2011 - SJCM:  removed gen==3, modified things so you can save plots
0050 % without plotting them up.
0051 %
0052 % 02/05/2012 - MAS: added support for plotparams=0.  Don't assume that the
0053 % flag structure has 'old' and 'new' fields.
0054 
0055 
0056 if(nargin < 9)
0057   maindir = [];
0058 end
0059 
0060 
0061 
0062 % MAS: Added this to properly handle matters if plotparams=0 is passed
0063 % (which it is in many of the wrapper scripts).
0064 if isstruct(plotparams)
0065     % if not interactive, we need to call a separate function
0066     if(plotparams.interactive==0 & plotparams.save==0)
0067       gen = 2;
0068     elseif(plotparams.interactive==0 & plotparams.save==1)
0069       gen = 1;
0070     else
0071       gen = 0;
0072     end
0073 
0074     if(plotparams.plot==1)
0075       printhelp;
0076     end
0077 else
0078     gen = 2;
0079 end
0080 
0081 if(~exist('field'))
0082   field = [];
0083 end
0084 
0085 if(~issubfield(dcal, 'antenna0', 'receiver', 'switchData'))
0086   noSwitch = 1;
0087 else
0088   noSwitch = 0;
0089 end
0090 
0091 %  SJCM:  FIRST THING WE DO IS PUT FLAG IN THE PROPER DIMENSIONS SO WE DON'T
0092 %  HAVE TO CHANGE ANYTHING ELSE.
0093 if(isstruct(flag))
0094     %  MAS: Just because flag is a structure doesn't mean that it has the
0095     %  expected fields...
0096     if(~isfield(flag,'old'))
0097       flag.old.bit = flag.bit;
0098     end
0099     if(~isfield(flag,'new'))
0100       flag.new.bit.fast = zeros(size(flag.old.bit.fast));
0101     end
0102     % if it's not a structure, we're doing tsys/tau/noise/gains flagging
0103     if(size(flag.old.bit.fast,2) == 3)
0104       flag.old = convertFlagToDataSize(flag.old, ...
0105       size(dcal.antenna0.receiver.data,2), noSwitch);
0106       flag.new = convertFlagToDataSize(flag.new, ...
0107       size(dcal.antenna0.receiver.data,2), noSwitch);
0108     end
0109 end
0110 
0111 
0112 
0113 
0114 mon = getmonth;
0115 
0116 switch caltype
0117   case 'int'
0118     ind = dcal.index.calibrator.fast;
0119     
0120   case 'pol'
0121     ind = dcal.index.calibrator.fast;
0122     
0123   case 'both'
0124     ind = dcal.index.calibrator.fast;
0125     
0126   case 'none'
0127     ind = logical(ones(size(dcal.index.calibrator.fast)));
0128     
0129   case 'daily'
0130     ind = logical(ones(size(dcal.array.frame.features)));
0131 
0132   otherwise
0133     error('Invalid ''caltype'' argument')
0134 end
0135     
0136 
0137 % convert time to hour
0138 start = mjd2date_v2(dcal.array.frame.utc(1));
0139 start.month = mon{start.month};
0140 j2hour = 24;
0141 dcalt = dcal.array.frame.utc*j2hour;
0142 dcaltslow = dcalt-dcalt(1);
0143 
0144 if(isfield(dcal.antenna0, 'receiver'))
0145   dcaltfast = dcal.antenna0.receiver.utc*j2hour;
0146   dcaltfast = dcaltfast - dcaltfast(1);
0147 else
0148   % it's a daily plot
0149   dcaltfast = dcal.array.frame.utc*j2hour;
0150   dcaltfast = dcaltfast - dcaltfast(1);
0151 end
0152 
0153 
0154 % split it up into half hour chunks
0155 numChunks = ceil(max(dcaltfast)/0.5);
0156 
0157 % no swapping
0158 p.swap = 0;
0159 % check for flag field
0160 if (~isfield(dcal, 'flags') & ~strcmp(type,'az_el') & ...
0161       ~strcmp(type,'cold_load') & ~strcmp(type,'rx_temp') & ~strcmp(type, ...
0162       'plot_sources') & ~strcmp(type, 'wx') & ~strcmp(type, 'cone_temp') & ...
0163       ~strcmp(caltype, 'daily'))
0164   disp('flags not found');
0165   disp('Please use flagData')
0166   return;
0167 end
0168 
0169 switch type
0170   %---------------------------------------------%
0171   case 'az_el'
0172     clf
0173     disp(' ')
0174     disp('Plotting Az and El of calibrator')
0175     disp(' ')
0176     pause(1)
0177     az = dcal.antenna0.servo.az;
0178     el = dcal.antenna0.servo.el;
0179     
0180     subplot(2,1,1)
0181     hold on
0182     h = plot(dcaltfast,az);
0183     xlabel('Time [hr]')
0184     ylabel('Az [deg]')
0185     subplot(2,1,2)
0186     hold on
0187     plot(dcaltfast,el)
0188     xlabel('Time [hr]')
0189     ylabel('El [deg]')
0190     
0191     str=sprintf('Az/El of Antenna \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0192     start.day, start.month, start.year, start.hour, ...
0193     start.minute, start.second);
0194     gtitle(str);
0195     if (gen==1)
0196       if(isempty(maindir))
0197     maindir=getMainDir(dcal, field);
0198       end
0199       dbclear if error
0200       set(gcf,'paperposition',[0 0 6.0 6.0])
0201       eval(sprintf('print -dpng -r200 %s/intro/fig1.png;', ... 
0202       maindir));  
0203       dbstop if error
0204     end
0205     hold off
0206     pause(1)
0207     
0208   %---------------------------------------------%
0209   case 'plot_sources'
0210     clf
0211     disp(' ')
0212     disp('Plotting Sources');
0213     disp(' ')
0214     
0215     plot_sources(dcal, 1);
0216     
0217     str=sprintf('Sources observed  \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0218     start.day, start.month, start.year, start.hour, ...
0219     start.minute, start.second);
0220     gtitle(str);
0221     if (gen==1)
0222       maindir=getMainDir(dcal, field);
0223       dbclear if error
0224       set(gcf,'paperposition',[0 0 6.0 6.0])
0225       eval(sprintf('print -dpng -r200 %s/intro/fig1.png;', ... 
0226       maindir));  
0227       dbstop if error
0228     end
0229     hold off
0230 
0231   %---------------------------------------------%
0232   case 'cold_load'
0233     clf
0234     disp(' ')
0235     disp('Plotting Temperature of Cold Load');
0236     disp(' ')
0237     pause(1)
0238     dcaltfast = dcal.antenna0.thermal.utc*j2hour;
0239     dcaltfast = dcaltfast - dcaltfast(1);
0240     temp = dcal.antenna0.thermal.ccTemperatureLoad;
0241     
0242     h = plot(dcaltfast,temp);
0243     xlabel('Time [hr]')
0244     ylabel('Load Temperature [K]')
0245     str=sprintf('Temperature Cold Load  \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0246     start.day, start.month, start.year, start.hour, ...
0247     start.minute, start.second);
0248     gtitle(str);
0249     if (gen==1)
0250       if(isempty(maindir))
0251     maindir=getMainDir(dcal, field);
0252       end
0253       dbclear if error
0254       set(gcf,'paperposition',[0 0 6.0 6.0])
0255       eval(sprintf('print -dpng -r200 %s/intro/fig2.png;', ... 
0256       maindir));  
0257       dbstop if error
0258     end
0259     hold off
0260     pause(1)
0261     
0262   %---------------------------------------------%
0263   case 'rx_temp'
0264     clf
0265     disp(' ')
0266     disp('Plotting Temperature inside Cryostat');
0267     disp(' ')
0268     pause(1)
0269     tempStage1 = dcal.antenna0.thermal.lsTemperatureSensors(:,1:6);
0270     tempStage2 = dcal.antenna0.thermal.lsTemperatureSensors(:,7);
0271 
0272     hold on
0273     subplot(2,1,1);
0274     h = plot(dcaltslow,tempStage1);
0275     xlabel('Time [hr]')
0276     ylabel('Receiver Temperature [K]')
0277     title('Stage 1');
0278     
0279     subplot(2,1,2)
0280     hold on
0281     plot(dcaltslow, tempStage2)
0282     xlabel('Time [hr]')
0283     ylabel('Receiver Temperature [K]')
0284     title('Stage 2');
0285     str=sprintf('RX Temperature \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0286     start.day, start.month, start.year, start.hour, ...
0287     start.minute, start.second);
0288     gtitle(str);
0289     if (gen==1)
0290       if(isempty(maindir))
0291     maindir=getMainDir(dcal, field);
0292       end
0293       dbclear if error
0294       set(gcf,'paperposition',[0 0 6.0 6.0])
0295       eval(sprintf('print -dpng -r200 %s/intro/fig3.png;', ... 
0296     maindir));  
0297       dbstop if error
0298     end
0299     hold off
0300     pause(1)
0301 
0302     
0303       %---------------------------------------------%
0304   case 'cone_temp'
0305     clf
0306     disp(' ')
0307     disp('Plotting Electronics box and Cone temperatures');
0308     disp(' ')
0309     pause(1)
0310     tempPol    = dcal.antenna0.thermal.dlpTemperatureSensors(:,1:2);
0311     tempCone   = dcal.antenna0.thermal.dlpTemperatureSensors(:,3:4);
0312     tempEbox   = dcal.antenna0.thermal.dlpTemperatureSensors(:,5:7);
0313     
0314     hold on
0315     subplot(3,1,1);
0316     plot(dcaltslow,tempPol);
0317     xlabel('Time [hr]')
0318     ylabel('Temperature [C]')
0319     legend('Polarimeter Amplifier Plate', 'Noise Diode');
0320     title('Polarimeter Temps');
0321     
0322     subplot(3,1,2)
0323     hold on
0324     plot(dcaltslow, tempCone);
0325     xlabel('Time [hr]')
0326     ylabel('Temperature [C]')
0327     legend('Top of Cryo', 'LNA PSU'); 
0328     title('Cone Temperatures');
0329     
0330     subplot(3,1,3)
0331     hold on
0332     plot(dcaltslow, tempEbox);
0333     xlabel('Time [hr]')
0334     ylabel('Temperature [C]')
0335     legend('CBASSDAQ', 'Metal Casing', 'Air');
0336     title('E-box Temperatures');
0337 
0338     str=sprintf('Cone and Ebox Temperature \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0339     start.day, start.month, start.year, start.hour, ...
0340     start.minute, start.second);
0341     gtitle(str);
0342     if (gen==1)
0343       if(isempty(maindir))
0344     maindir=getMainDir(dcal, field);
0345       end
0346       dbclear if error
0347       set(gcf,'paperposition',[0 0 6.0 6.0])
0348       eval(sprintf('print -dpng -r200 %s/intro/fig4.png;', ... 
0349     maindir));  
0350       dbstop if error
0351     end
0352     hold off
0353     pause(1)
0354     
0355       %---------------------------------------------%
0356   case 'wx'
0357     clf
0358     disp(' ')
0359     disp('Plotting Weather Station Data');
0360     disp(' ')
0361     pause(1)
0362 
0363     hold on
0364     subplot(3,1,1);
0365     plot(dcaltslow, dcal.array.weather.airTemperature);
0366     xlabel('Time [hr]')
0367     ylabel('Temperature [C]')
0368     title('Ambient Temperature');
0369     
0370     subplot(3,1,2)
0371     hold on
0372     plot(dcaltslow, dcal.array.weather.relativeHumidity);
0373     xlabel('Time [hr]')
0374     ylabel('PerCent')
0375     title('Relative Humidity');
0376     
0377     subplot(3,1,3)
0378     hold on
0379     plot(dcaltslow, dcal.array.weather.windSpeed);
0380     xlabel('Time [hr]')
0381     ylabel('speed [m/s]');
0382     title('Wind Speed');
0383 
0384     str=sprintf('Weather Data \n%02u-%s-%u:%02u:%02u:%4.2f', ...
0385     start.day, start.month, start.year, start.hour, ...
0386     start.minute, start.second);
0387     gtitle(str);
0388     if (gen==1)
0389       if(isempty(maindir))
0390     maindir=getMainDir(dcal, field);
0391       end
0392       dbclear if error
0393       set(gcf,'paperposition',[0 0 6.0 6.0])
0394       eval(sprintf('print -dpng -r200 %s/intro/fig5.png;', ... 
0395     maindir));  
0396       dbstop if error
0397     end
0398     hold off
0399     pause(1)    
0400 
0401   %---------------------------------------------%
0402     case 'deglitch'    
0403       
0404     % initialize plot axis names
0405     txt{1}={'Channel'};
0406     txt{2}={'time [hr]'};
0407     txt{3}={'Backend Unit'};
0408     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0409     start.month,  start.year, start.hour, start.minute, start.second);
0410     txt{4}={str};
0411     % antenna display
0412     p.style='flag';
0413     p.featflag=0;
0414 
0415     % we need to break up the data into half hour sections.
0416     if(isempty(flag))
0417       flag = convertFlagToDataSize(dcal.flags, size(dcal.antenna0.receiver.data,2));
0418     end
0419     for m=1:numChunks
0420       if(m==numChunks)
0421     ind = dcaltfast>=((m-1)*0.5);
0422       else
0423     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0424       end
0425       x{1,m} = dcaltfast(ind);
0426       x{2,m} = dcal.antenna0.receiver.data(ind,:);
0427       fflag{1,m} = flag.new.bit.fast(ind,:);
0428       fflag{2,m} = flag.old.bit.fast(ind,:);
0429     end
0430 
0431     % plot the data
0432     if(gen==1)
0433       genfig(dcal, fflag, x, txt, [], 'deglitch', p, field, 1);
0434       theseFlags = fflag;
0435       newflag = [];
0436     elseif(gen==2)
0437       genfig(dcal, fflag, x, txt, [], 'deglitch', p, field, 0);
0438       theseFlags = fflag;
0439       newflag = [];
0440     else
0441       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
0442       % update the flags
0443     end
0444 
0445     % next we set the flags
0446     flags = [];
0447     for m=1:size(theseFlags,2)
0448       flags = [flags; theseFlags{1,m}];
0449     end
0450     % if we do it this way, we also have to put in the old flags too.
0451     outFlags = convertDataFlagsToFlagSize(flags);
0452     flag.new.out = outFlags;
0453     %dcal.flags.bit.fast = bitor(dcal.flags.bit.fast, resizedFlags);
0454     %dcal.flags.fast = dcal.flags.bit.fast>0;
0455     
0456   %---------------------------------------------%
0457    case 'positional'
0458     
0459     % initialize plot axis names
0460     txt{1}={'Channel'};
0461     txt{2}={'time [hr]'};
0462     txt{3}={'Backend Unit'};
0463     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0464     start.month,  start.year, start.hour, start.minute, start.second);
0465     txt{4}={str};
0466     % antenna display
0467     p.style='flag';
0468     p.featflag=0;
0469 
0470     if(size(dcal.antenna0.receiver.data,2)==8)
0471       plotIndices = [1:5 8];
0472     else
0473       plotIndices = 1:size(dcal.antenna0.receiver.data,2);
0474     end
0475     
0476     % we need to break up the data into half hour sections.
0477     if(isempty(flag))
0478       flag = convertFlagToDataSize(dcal.flags, ...
0479       size(dcal.antenna0.receiver.data,2));
0480     end
0481     for m=1:numChunks
0482       if(m==numChunks)
0483     ind = dcaltfast>=((m-1)*0.5);
0484       else
0485     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0486       end
0487       x{1,m} = dcaltfast(ind);
0488       if(isfield(dcal.antenna0.receiver, 'dataT'))
0489     x{2,m} = dcal.antenna0.receiver.dataT(ind,:);
0490       else
0491     x{2,m} = dcal.antenna0.receiver.data(ind,plotIndices);
0492       end
0493       
0494       
0495       % we need the corresponding indices.
0496       fa = fieldnames(dcal.index);
0497       for mm=1:length(fa)
0498     eval(sprintf('indices.%s = dcal.index.%s.fast(ind);', fa{mm}, ...
0499         fa{mm}));
0500       end
0501       x{3,m} = indices;
0502       fflag{1,m} = flag.new.bit.fast(ind,:);
0503       fflag{2,m} = flag.old.bit.fast(ind,:);
0504     end
0505 
0506     % plot the data
0507     if(gen==1)
0508       genfig(dcal, fflag, x, txt, [], 'positional', p, field, 1);
0509       theseFlags = fflag;      
0510     elseif(gen==2)
0511       genfig(dcal, fflag, x, txt, [], 'positional', p, field, 0);
0512       theseFlags = fflag;            
0513     else
0514       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
0515       % update the flags
0516     end
0517     
0518     % next we set the flags
0519     flags = [];
0520     for m=1:size(theseFlags,2)
0521       flags = [flags; theseFlags{1,m}];
0522     end
0523     % if we do it this way, we also have to put in the old flags too.
0524     outFlags = convertDataFlagsToFlagSize(flags);
0525     flag.new.out = outFlags;
0526 
0527   %---------------------------------------------%
0528    case 'rfi'
0529     
0530     % initialize plot axis names
0531     txt{1}={'I1', 'Q', 'U', 'Q', 'U', 'I2'};
0532     txt{2}={'time [hr]'};
0533     txt{3}={'Backend Unit'};
0534     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0535     start.month,  start.year, start.hour, start.minute, start.second);
0536     txt{4}={str};
0537     % antenna display
0538     p.style='flag';
0539     p.featflag=0;
0540     
0541     
0542     if(size(dcal.antenna0.receiver.data,2)==8)
0543       plotIndices = [1:5 8];
0544     else
0545       plotIndices = 1:size(dcal.antenna0.receiver.data,2);
0546     end    
0547     
0548 
0549     % we need to break up the data into half hour sections.
0550     if(isempty(flag))
0551       flag = convertFlagToDataSize(dcal.flags, ...
0552       size(dcal.antenna0.receiver.data,2));
0553     end
0554     index = 1;
0555     for m=1:numChunks
0556       if(m==numChunks)
0557     ind = dcaltfast>=((m-1)*0.5);
0558       else
0559     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0560       end
0561       if(~isempty(find(ind)))
0562     x{1,index} = dcaltfast(ind);
0563     if(isfield(dcal.antenna0.receiver, 'dataT'))
0564       x{2,index} = dcal.antenna0.receiver.dataT(ind,:);
0565     else
0566       x{2,index} = dcal.antenna0.receiver.data(ind,plotIndices);
0567     end
0568     
0569     
0570     % we need the corresponding indices.
0571     fa = fieldnames(dcal.index);
0572     for mm=1:length(fa)
0573       eval(sprintf('indices.%s = dcal.index.%s.fast(ind);', fa{mm}, ...
0574           fa{mm}));
0575     end
0576     x{3,index} = indices;
0577     fflag{1,index} = flag.new.bit.fast(ind,:);
0578     fflag{2,index} = flag.old.bit.fast(ind,:);
0579     index = index+1;
0580       end
0581     end
0582       
0583     clear dcaltfast;
0584     clear dcaltslow;
0585     clear dcalt;
0586     
0587     % plot the data
0588     if(gen==1)
0589       genfig(dcal, fflag, x, txt, [], 'rfi', p, field, 1);
0590       theseFlags = fflag;      
0591     elseif(gen==2)
0592       genfig(dcal, fflag, x, txt, [], 'rfi', p, field, 0);
0593       theseFlags = fflag;            
0594     else
0595       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
0596       % update the flags
0597     end
0598     clear fflag;
0599     clear x;
0600     
0601     
0602     % next we set the flags
0603     flags = [];
0604     for m=1:size(theseFlags,2)
0605       flags = [flags; theseFlags{1,m}];
0606     end
0607     % if we do it this way, we also have to put in the old flags too.
0608     outFlags = convertDataFlagsToFlagSize(flags);
0609     flag.new.out = outFlags;
0610     
0611       %---------------------------------------------%
0612       
0613   %---------------------------------------------%
0614    case 'rfi2'
0615     
0616     % initialize plot axis names
0617     txt{1}={'I1+I2', 'sqrt(Q^2+U^2)'};
0618     txt{2}={'time [hr]'};
0619     txt{3}={'Backend Unit'};
0620     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0621     start.month,  start.year, start.hour, start.minute, start.second);
0622     txt{4}={str};
0623     % antenna display
0624     p.style='feature';
0625     p.featflag=0;
0626     p.type = 'feature';
0627     
0628     % we need to break up the data into two hour sections.
0629     if(isempty(flag))
0630       flag = convertFlagToDataSize(dcal.flags, ...
0631       size(dcal.antenna0.receiver.data,2));
0632     end
0633 
0634     index = 1;
0635     for m=1:numChunks
0636       if(m==numChunks)
0637     ind = dcaltfast>=((m-1)*0.5);
0638       else
0639     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0640       end
0641       if(isempty(find(ind)))
0642     badChunks(m) = 1;
0643       else
0644     badChunks(m) = 0;
0645       end
0646       if(~isempty(find(ind)))
0647     x{1,index} = dcaltfast(ind);
0648     if(size(dcal.antenna0.receiver.data,2)==8)
0649       d1 = dcal.antenna0.receiver.data(ind,1) + ...
0650           dcal.antenna0.receiver.data(ind,8);
0651       d2 = dcal.antenna0.receiver.data(ind,6).^2 + ...
0652           dcal.antenna0.receiver.data(ind,7).^2;
0653     else
0654       d1 = dcal.antenna0.receiver.data(ind,1) + ...
0655           dcal.antenna0.receiver.data(ind,6);
0656       d2 = dcal.antenna0.receiver.data(ind,2).^2 + ...
0657           dcal.antenna0.receiver.data(ind,3).^2;
0658     end    
0659     dd = [d1 sqrt(d2)];
0660     x{2,index} = dd;
0661     clear d1;
0662     clear d2;
0663     clear dd;
0664 
0665     % we need the corresponding indices.
0666     fa = fieldnames(dcal.flags.rfi);
0667     for mm=1:length(fa)
0668       eval(sprintf('indices.%s = dcal.flags.rfi.%s.fast(ind);', fa{mm}, ...
0669           fa{mm}));
0670     end
0671     x{3,index} = indices;
0672     fflag{1,index} = logical(zeros(size(x{2,index})));
0673     fflag{2,index} = logical(zeros(size(x{2,index})));    
0674     index = index+1;
0675       end
0676     end
0677       
0678     clear dcaltfast;
0679     clear dcaltslow;
0680     clear dcalt;
0681 
0682     x = x(:,~badChunks);
0683     fflag = fflag(:,~badChunks);
0684 
0685     % plot the data
0686     if(gen==1)
0687       genfig(dcal, fflag, x, txt, [], 'rfi', p, field, 1);
0688       theseFlags = fflag;      
0689     elseif(gen==2)
0690       genfig(dcal, fflag, x, txt, [], 'rfi', p, field, 0);
0691       theseFlags = fflag;            
0692     else
0693       plotdnoflag(dcal, fflag, x, txt, [],p);
0694       % [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
0695     end
0696 
0697     %% sjcm, 2014, Feb 25:  I could work on making these flags work out, ...
0698     %%but at the end of the day, noone's looking at data interactively, ...
0699     %%so why bother?
0700       
0701       %---------------------------------------------%
0702    case 'intent'
0703      % initialize plot axis names
0704     txt{1}={'Channel'};
0705     txt{2}={'time [hr]'};
0706     txt{3}={'Backend Unit'};
0707     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0708     start.month,  start.year, start.hour, start.minute, start.second);
0709     txt{4}={str};
0710     % antenna display
0711     p.style='feature';
0712     p.featflag=0;
0713     p.type = 'feature';
0714     
0715     for m=1:numChunks
0716       if(m==numChunks)
0717     ind = dcaltfast>=((m-1)*0.5);
0718       else
0719     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0720       end
0721       if(isempty(find(ind)))
0722     badChunks(m) = 1;
0723       else
0724     badChunks(m) = 0;
0725       end
0726       x{1,m} = dcaltfast(ind);
0727       if(isfield(dcal.antenna0.receiver, 'dataT'))
0728     x{2,m} = dcal.antenna0.receiver.dataT(ind,:);
0729       else
0730     x{2,m} = dcal.antenna0.receiver.data(ind,:);
0731       end
0732       
0733       % we need the corresponding indices.
0734       fa = fieldnames(dcal.index);
0735       for mm=1:length(fa)
0736     eval(sprintf('indices.%s = dcal.index.%s.fast(ind);', fa{mm}, ...
0737         fa{mm}));
0738       end
0739       x{3,m} = indices;
0740       fflag{1,m} = logical(zeros(size(x{2,m})));
0741       fflag{2,m} = logical(zeros(size(x{2,m})));
0742     end
0743     clear dcaltfast;
0744     clear dcaltslow;
0745     clear dcalt;
0746 
0747     x = x(:,~badChunks);
0748     fflag = fflag(:,~badChunks);
0749     
0750     % plot the data
0751     if(gen==1)
0752       genfig(dcal, fflag, x, txt, [], 'intent', p, field, 1);
0753       theseFlags = fflag;      
0754     elseif(gen==2)
0755       genfig(dcal, fflag, x, txt, [], 'intent', p, field, 0);
0756       theseFlags = fflag;            
0757     else
0758       plotdnoflag(dcal, fflag, x, txt, [],p);
0759     end
0760     
0761           %---------------------------------------------%
0762    case 'summary'
0763     % initialize plot axis names
0764     txt{1}={'Channel'};
0765     txt{2}={'time [hr]'};
0766     txt{3}={'Jy-ish'};
0767     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0768     start.month,  start.year, start.hour, start.minute, start.second);
0769     txt{4}={str};
0770     % antenna display
0771     p.style='feature';
0772     p.featflag=0;
0773     p.type = 'allflags';
0774     
0775     % ignore the mean Q,U channels
0776     if(size(dcal.antenna0.receiver.data,2)==10)
0777       plotIndices = [1 3 4 5 6 9];
0778     elseif(size(dcal.antenna0.receiver.data,2)==8)
0779       plotIndices = [1 2 3 4 5 8];
0780     end
0781     
0782     % get our flag indices in a parseable form
0783     fa = getFlagNames();
0784     prevSet = zeros(size(dcal.flags.fast));
0785     for mm=1:length(fa)
0786       thisIndex = uint32(zeros(size(dcal.flags.fast)));
0787       [aa bb bitNum] = setNewFlag([],[],fa{mm});
0788       thisIndex = bitset(thisIndex, bitNum);
0789       isSet = bitand(thisIndex, dcal.flags.bit.fast) >0;
0790       
0791       thisSet = isSet - prevSet > 0;
0792       
0793       % make them the right size:
0794       numDims = size(dcal.antenna0.receiver.data,2);
0795       thisSetAll = convertFlagToDataSize(thisSet, numDims);
0796       
0797       eval(sprintf('bitflags.%s = thisSetAll(:,plotIndices);', fa{mm}));
0798     end
0799 
0800     for m=1:numChunks
0801       if(m==numChunks)
0802     ind = dcaltfast>=((m-1)*0.5);
0803       else
0804     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0805       end
0806       x{1,m} = dcaltfast(ind);
0807       x{2,m} = dcal.antenna0.receiver.data(ind,plotIndices);
0808       x{3,m} = structcut(bitflags, ind);
0809       fflag{1,m} = zeros(size(x{2,m}));
0810       fflag{2,m} = zeros(size(x{2,m}));
0811     end
0812 
0813     % plot the data
0814     if(gen==1)
0815       genfig(dcal, fflag, x, txt, [], 'summary', p, field, 1);
0816       theseFlags = fflag;      
0817     elseif(gen==2)
0818       genfig(dcal, fflag, x, txt, [], 'summary', p, field, 0);
0819       theseFlags = fflag;            
0820     else
0821       plotdnoflag(dcal, fflag, x, txt, [],p);
0822     end
0823     
0824   %---------------------------------------------%
0825   case 'alpha'
0826     % ONLY PLOT FOR OLD SCHEME.
0827     
0828     % initialize plot axis names
0829     txt{1}={'Noise Event'};
0830     txt{2}={'time [hr]'};
0831     txt{3}={'Backend Unit'};
0832     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0833     start.month,  start.year, start.hour, start.minute, start.second);
0834     txt{4}={str};
0835     % antenna display
0836     p.style='flag';
0837     p.featflag=0;
0838 
0839     % in this case we only care about the noise diode events
0840     % Noise diode off and on:
0841     ind_noise_event = dcal.index.noise_event.fast;
0842     dataLength = length(ind_noise_event);
0843     
0844     % noise diode event start/stop
0845     si = dcal.correction.alpha.indices(:,1);
0846     ei = dcal.correction.alpha.indices(:,3);
0847     numEvents = length(si);
0848 
0849     for m=1:numEvents
0850       % we know the indices of the noise diode events
0851       x{1,m} = dcaltfast(si(m):ei(m));
0852       x{1,numEvents+m} = dcaltfast(si(m):ei(m));
0853       x{2,m} = dcal.antenna0.receiver.data(si(m):ei(m),[1:2]);
0854       x{2,numEvents+m} = dcal.antenna0.receiver.data(si(m):ei(m),[9:10]);
0855       fflag{1,m} = flag.new.bit.fast(si(m):ei(m),[1:2]);
0856       fflag{1,numEvents+m} = flag.new.bit.fast(si(m):ei(m),[9:10]);
0857       fflag{2,m} = flag.old.bit.fast(si(m):ei(m),[1:2]);
0858       fflag{2,numEvents+m} = flag.old.bit.fast(si(m):ei(m),[9:10]);
0859     end
0860     % plot the data
0861     if(gen==1)
0862       genfigAlpha(dcal, fflag, x, txt, [], 'alpha', p, field,1);
0863       finalFlags = zeros(size(fflag));
0864     elseif(gen==2)
0865       genfigAlpha(dcal, fflag, x, txt, [], 'alpha', p, field,0);
0866       finalFlags = zeros(size(fflag));      
0867     else
0868       [theseFlags, finalFlags] = plot_alpha(dcal, fflag, x, txt, [],p);
0869       % update the flags
0870     end
0871 
0872     % next we set the flags
0873     ff = find(finalFlags);
0874     for m=1:length(ff)
0875       flag.new.bit.fast(si(ff(m)):ei(ff(m)),:) = 1;
0876     end
0877     outFlags = convertDataFlagsToFlagSize(flag.new.bit.fast);
0878     flag.new.out = outFlags;
0879   
0880   %---------------------------------------------%
0881   case 'stokes'
0882     % initialize plot axis names
0883     txt{1}={'Channel'};
0884     txt{2}={'time [hr]'};
0885     txt{3}={'Backend Unit (?) '};
0886     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0887     start.month,  start.year, start.hour, start.minute, start.second);
0888     txt{4}={str};
0889     % antenna display
0890     p.style='flag';
0891     p.featflag=0;
0892     
0893     % calculate the second thing to plot
0894     if(isfield(dcal.antenna0.receiver, 'switchData'))
0895       for m=1:6
0896     aa(:,m) = 0.5*sum(dcal.antenna0.receiver.switchData(:,[(m-1)*4+2 (m-1)*4+3]) - dcal.antenna0.receiver.switchData(:,[(m-1)*4+1 (m)*4]), 2);
0897       end
0898     else
0899       aa = zeros(size(dcal.antenna0.receiver.data,1), 6);
0900     end
0901 
0902     % ignore the mean Q,U channels
0903     if(size(dcal.antenna0.receiver.data,2)==10)
0904       plotIndices = [1 3 4 5 6 9];
0905     elseif(size(dcal.antenna0.receiver.data,2)==8)
0906       plotIndices = [1 2 3 4 5 8];
0907     elseif(size(dcal.antenna0.receiver.data,2)==6)
0908       plotIndices = 1:6;
0909     end
0910     
0911     index = 1;
0912     for m=1:numChunks
0913       if(m==numChunks)
0914     ind = dcaltfast>=((m-1)*0.5);
0915       else
0916     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
0917       end
0918       if(~isempty(find(ind)))
0919     % there was no gap in the trakc
0920     x{1,index} = dcaltfast(ind);
0921     x{2,index} = dcal.antenna0.receiver.data(ind,plotIndices );
0922     
0923     % we need the corresponding indices.
0924     fa = fieldnames(dcal.index);
0925     for mm=1:length(fa)
0926       eval(sprintf('indices.%s = dcal.index.%s.fast(ind);', fa{mm}, ...
0927           fa{mm}));
0928     end
0929     x{3,index} = indices;
0930     fflag{1,index} = flag.new.bit.fast(ind,plotIndices);
0931     fflag{2,index} = flag.old.bit.fast(ind,plotIndices);
0932     
0933     % next thing to overplot
0934     x{4,index} = aa(ind,:);
0935     index = index+1;
0936       end
0937     end
0938     clear aa;
0939     clear dcaltfast;
0940     clear dcaltslow;
0941     clear dcalt;
0942     
0943     % plot the data
0944     if(gen==1)
0945       genfig(dcal, fflag, x, txt, [], 'stokes', p, field,1);
0946       theseFlags = fflag;
0947     elseif(gen==2)
0948       genfig(dcal, fflag, x, txt, [], 'stokes', p, field,0);
0949       theseFlags = fflag;      
0950     else
0951       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
0952       % update the flags
0953     end
0954     clear fflag;
0955     clear x;
0956     
0957     % next we set the flags
0958     flags = [];
0959     for m=1:size(theseFlags,2)
0960       flags = [flags; theseFlags{1,m}];
0961       theseFlags{1,m} = [];
0962     end
0963     % if we do it this way, we also have to put in the old flags too.
0964     outFlags = convertDataFlagsToFlagSize(flags);
0965     flag.new.out = outFlags;
0966 
0967   %---------------------------------------------%
0968   case 'tau'
0969     
0970     % initialize plot axis names
0971     txt{1}={'Intensity Channel'};
0972     txt{2}={'time [hr]'};
0973     txt{3}={'Tau '};
0974     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
0975     start.month,  start.year, start.hour, start.minute, start.second);
0976     txt{4}={str};
0977     % antenna display
0978     p.style='flag';
0979     p.featflag=0;
0980 
0981     if(isempty(flag))
0982       flag = zeros(size(dcal.correction.tau.values,1),2);
0983     end    
0984 
0985     % this should be a super simple plot -- we should just have each plot be
0986     % of the tau values for each intensity channel, and we can flag as
0987     % normal
0988     time = (dcal.correction.tau.time(:,1) - dcal.antenna0.receiver.utc(1))*j2hour;
0989     x{1,1} = time;
0990     x{2,1} = dcal.correction.tau.values;
0991     fflag{1,1} = flag(:,1:2);
0992     fflag{2,1} = zeros(size(flag));
0993     
0994     % plot the data
0995     if(gen==1)
0996       genfig(dcal, fflag, x, txt, [], 'tau', p, field,1);
0997       theseFlags = fflag;
0998     elseif(gen==2)
0999       genfig(dcal, fflag, x, txt, [], 'tau', p, field,0);
1000       theseFlags = fflag;      
1001     else
1002       [theseFlags newflags] = plotd(dcal, fflag, x, txt, [],p);
1003       % update the flags
1004     end
1005     flag = theseFlags{1};
1006     
1007     %---------------------------------------------%
1008   case 'tsysOld'
1009     
1010     % initialize plot axis names
1011     txt{1}={'Intensity Channel'};
1012     txt{2}={'time [hr]'};
1013     txt{3}={'System Temperature '};
1014     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1015     start.month,  start.year, start.hour, start.minute, start.second);
1016     txt{4}={str};
1017     txt{5}= {'From Alpha Corrections', 'From Observations'};
1018     % antenna display
1019     p.style='flag';
1020     p.featflag=0;
1021     
1022     if(isempty(flag))
1023       flag = zeros(size(dcal.correction.tsys.flag));
1024     end    
1025 
1026     % this should be a super simple plot -- we should just have each plot be
1027     % of the tau values for each intensity channel, and we can flag as
1028     % normal
1029     time1 = (dcal.correction.tsys.time(:) - dcal.correction.tsys.time(1))*j2hour;
1030     x{1,1} = time1;
1031     x{2,1} = dcal.correction.tsys.val;
1032     fflag{1,1} = flag(:,1:2);
1033     fflag{2,1} = zeros(size(flag));
1034     time2 = (dcal.correction.tsys.time2 - dcal.correction.tsys.time(1))*j2hour;
1035     x{3,1} = time2;
1036     x{4,1} = dcal.correction.tsys.val2;
1037 
1038     % plot the data
1039     if(gen==1)
1040       genfig(dcal, fflag, x, txt, [], 'tsys', p, field,1);
1041       theseFlags = fflag;
1042     elseif(gen==2)
1043       genfig(dcal, fflag, x, txt, [], 'tsys', p, field,0);
1044       theseFlags = fflag;      
1045     else
1046       [theseFlags newFlag] = plotd(dcal, fflag, x, txt, [],p);
1047     end
1048     flag = theseFlags{1};
1049 
1050     
1051         %---------------------------------------------%
1052     case 'tsys'
1053     
1054     % initialize plot axis names
1055     txt{1}={'Intensity Channel'};
1056     txt{2}={'time [hr]'};
1057     txt{3}={'System Temperature '};
1058     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1059     start.month,  start.year, start.hour, start.minute, start.second);
1060     txt{4}={str};
1061     % antenna display
1062     p.style='flag';
1063     p.featflag=0;
1064     
1065     if(isempty(flag))
1066       flag = zeros(size(dcal.correction.tsys.flag));
1067     end    
1068 
1069     % this should be a super simple plot -- we should just have each plot be
1070     % of the tau values for each intensity channel, and we can flag as
1071     % normal
1072     time1 = (dcal.correction.tsys.time(:) - dcal.correction.tsys.time(1))*j2hour;
1073     x{1,1} = time1;
1074     x{2,1} = dcal.correction.tsys.val;
1075     fflag{1,1} = flag(:,1:2);
1076     fflag{2,1} = zeros(size(flag));
1077 
1078     % plot the data
1079     if(gen==1)
1080       genfig(dcal, fflag, x, txt, [], 'tsys', p, field,1);
1081       theseFlags = fflag;
1082     elseif(gen==2)
1083       genfig(dcal, fflag, x, txt, [], 'tsys', p, field,0);
1084       theseFlags = fflag;      
1085     else
1086       [theseFlags newFlag] = plotd(dcal, fflag, x, txt, [],p);
1087     end
1088     flag = theseFlags{1};
1089 
1090     %---------------------------------------------%
1091   case 'noise'
1092     
1093     % initialize plot axis names
1094     txt{1}={'Intensity Channel'};
1095     txt{2}={'time [hr]'};
1096     txt{3}={'Noise Diode Temperature '};
1097     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1098     start.month,  start.year, start.hour, start.minute, start.second);
1099     txt{4}={str};
1100     % antenna display
1101     p.style='flag';
1102     p.featflag=0;
1103 
1104     if(isempty(flag))
1105       flag = zeros(size(dcal.correction.tnoise.flags));
1106     end    
1107 
1108     % this should be a super simple plot -- we should just have each plot be
1109     % of the tau values for each intensity channel, and we can flag as
1110     % normal
1111     time1 = (dcal.correction.tnoise.time(:) - dcal.correction.tnoise.time(1))*j2hour;
1112     x{1,1} = time1;
1113     x{2,1} = dcal.correction.tnoise.Tnd; 
1114     fflag{1,1} = flag(:,1:2);
1115     fflag{2,1} = zeros(size(flag));
1116 
1117     % plot the data
1118     if(gen==1)
1119       genfig(dcal, fflag, x, txt, [], 'noise', p, field,1);
1120       theseFlags = fflag;
1121     elseif(gen==2)
1122       genfig(dcal, fflag, x, txt, [], 'noise', p, field,0);
1123       theseFlags = fflag;      
1124     else
1125       [theseFlags newFlags] = plotd(dcal, fflag, x, txt, [],p);
1126     end
1127 
1128     % update the flags
1129     flag(theseFlags{1}>0) = 1;
1130 
1131     %---------------------------------------------%
1132   case 'noiseInterp'
1133     
1134     % initialize plot axis names
1135     txt{1}={'TND1', 'TND2'};
1136     txt{2}={'time [hr]'};
1137     txt{3}={'Noise Diode Temp [K] '};
1138     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1139     start.month,  start.year, start.hour, start.minute, start.second);
1140     txt{4}={str};
1141     % antenna display
1142     p.style='flag';
1143     p.featflag=0;
1144 
1145     flag = zeros(size(dcal.antenna0.receiver.noise));
1146     % this should be a super simple plot -- we should just have each plot be
1147     % of the tau values for each intensity channel, and we can flag as
1148     % normal
1149     time1 = (dcal.antenna0.receiver.utc(:) - dcal.antenna0.receiver.utc(1))*j2hour;
1150     x{1,1} = time1;
1151     x{2,1} = dcal.antenna0.receiver.noise;
1152     fflag{1,1} = flag(:,1:2);
1153     fflag{2,1} = zeros(size(flag));
1154 
1155     % plot the data
1156     if(gen==1)
1157       genfig(dcal, fflag, x, txt, [], 'noiseInterp', p, field,1);
1158       theseFlags = fflag;
1159     elseif(gen==2)
1160       genfig(dcal, fflag, x, txt, [], 'noiseInterp', p, field,0);
1161       theseFlags = fflag;      
1162     else
1163       plotdnoflag(dcal, fflag, x, txt, [],p);
1164     end
1165 
1166     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1167   case 'tauInterp'
1168     
1169     % initialize plot axis names
1170     txt{1}={'Interpolated Opacity'};
1171     txt{2}={'time [hr]'};
1172     txt{3}={'tau'};
1173     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1174     start.month,  start.year, start.hour, start.minute, start.second);
1175     txt{4}={str};
1176     % antenna display
1177     p.style='flag';
1178     p.featflag=0;
1179 
1180     flag = zeros(size(dcal.antenna0.receiver.tau));
1181     % this should be a super simple plot -- we should just have each plot be
1182     % of the tau values for each intensity channel, and we can flag as
1183     % normal
1184     time1 = (dcal.antenna0.receiver.utc(:) - dcal.antenna0.receiver.utc(1))*j2hour;
1185     x{1,1} = time1;
1186     x{2,1} = dcal.antenna0.receiver.tau;
1187     fflag{1,1} = flag;
1188     fflag{2,1} = zeros(size(flag));
1189 
1190     % plot the data
1191     if(gen==1)
1192       genfig(dcal, fflag, x, txt, [], 'tauInterp', p, field,1);
1193       theseFlags = fflag;
1194     elseif(gen==2)
1195       genfig(dcal, fflag, x, txt, [], 'tauInterp', p, field,0);
1196       theseFlags = fflag;      
1197     else
1198       plotdnoflag(dcal, fflag, x, txt, [],p);
1199     end
1200     
1201     
1202     %---------------------------------------------%
1203   case 'gain'
1204     
1205     % initialize plot axis names
1206     txt{1}={'Intensity Channel'};
1207     txt{2}={'time [hr]'};
1208     txt{3}={'System Gain [dB]'};
1209     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1210     start.month,  start.year, start.hour, start.minute, start.second);
1211     txt{4}={str};
1212     % antenna display
1213     p.style='flag';
1214     p.featflag=0;
1215 
1216     % this should be a super simple plot -- we should just have each plot be
1217     % of the tau values for each intensity channel, and we can flag as
1218     % normal
1219     time1 = (dcal.correction.gain.time(:) - dcal.correction.gain.time(1))*j2hour;
1220     x{1,1} = time1;
1221     x{2,1} = dcal.correction.gain.val;
1222     fflag{1,1} = flag(:,1:2);
1223     fflag{2,1} = zeros(size(flag));
1224     
1225     % plot the data
1226     if(gen==1)
1227       genfig(dcal, fflag, x, txt, [], 'gain', p, field, 1);
1228       theseFlags = fflag;
1229     elseif(gen==2)
1230       genfig(dcal, fflag, x, txt, [], 'gain', p, field, 0);
1231       theseFlags = fflag;      
1232     else
1233       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
1234     end
1235 
1236     % update the flags
1237     flag(theseFlags{1}>0) = 1;
1238 
1239     %---------------------------------------------%
1240   case {'mainsSwitch'}
1241     
1242     % initialize plot axis names
1243     txt{1}={'Phase Switch State'};
1244     txt{2}={'Frequency (Hz)'};
1245     txt{3}={'Amplitude'};
1246     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1247     start.month,  start.year, start.hour, start.minute, start.second);
1248     txt{4}={str};
1249     % antenna display
1250     p.style='flag';
1251     p.featflag=0;
1252 
1253     % there should be 6 pages of 4 plots
1254     % each page should have the 4 phase switch states for that channel
1255     % there should just be stuff plotted on top of each other in each plot
1256     % plot the data
1257     % let's only plot the blanking data
1258     dcalcut = cutObs(dcal, 'blank', 'only');
1259     dcal0cut = cutObs(dcal0, 'blank', 'only');
1260     if(gen==1)
1261        genfigLoad(dcalcut, [], txt, [], p, dcal0cut, 'mains', field, 1, 1);
1262      elseif(gen==2)
1263        genfigLoad(dcalcut, [], txt, [], p, dcal0cut, 'mains', field, 1, 0);       
1264     else
1265         plotLoad(dcalcut, [], [], txt, [], p, dcal0cut, 1);
1266     end
1267     
1268     
1269     
1270     %---------------------------------------------%
1271   case {'mainsReg'}
1272     
1273     % initialize plot axis names
1274     txt{1}={'Channel Number'};
1275     txt{2}={'Frequency (Hz)'};
1276     txt{3}={'Amplitude'};
1277     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1278     start.month,  start.year, start.hour, start.minute, start.second);
1279     txt{4}={str};
1280     % antenna display
1281     p.style='flag';
1282     p.featflag=0;
1283 
1284     % there should be 1 page with 6 plots
1285     % one for reach channel
1286     % plot the data
1287     if(gen==1)
1288       genfigMainsReg(dcal, txt, [], 'mains', field,1);
1289     elseif(gen==2)
1290       genfigMainsReg(dcal, txt, [], 'mains', field,0);      
1291     else        
1292       thisData = plotMainsReg(dcal, [], [], txt, [], p);
1293     end
1294     
1295 
1296     % replace the current data
1297     dcal.antenna0.receiver.data = thisData;
1298     
1299         %---------------------------------------------%
1300   case 'load_cal'
1301     
1302     % initialize plot axis names
1303     txt{1}={'Channel Number'};
1304     txt{2}={'Frequency (Hz)'};
1305     txt{3}={'Amplitude'};
1306     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1307     start.month,  start.year, start.hour, start.minute, start.second);
1308     txt{4}={str};
1309     % antenna display
1310     p.style='flag';
1311     p.featflag=0;
1312 
1313     % there should be 1 page with 6 plots
1314     % one for reach channel
1315     % plot the data
1316     if(gen==1)
1317       genfigLoad(dcal, [], txt, [], p, dcal0, 'load', field, 0, 1);
1318     elseif(gen==2)
1319       genfigLoad(dcal, [], txt, [], p, dcal0, 'load', field, 0, 0);      
1320     else
1321       plotLoad(dcal, [], [], txt, [], p, dcal0, 0);
1322     end
1323 
1324     % check the result from the flagging if it worked.
1325     query = 1;
1326     %
1327     %display('Did it work?');
1328     if(query)
1329       dcal = dcal;
1330     else
1331       dcal = dcal0;
1332     end
1333     
1334         %---------------------------------------------%
1335   case 'power_spec'
1336     
1337     % initialize plot axis names
1338     txt{1}={'I1', 'Q', 'U', 'I2'};
1339     txt{2}={'Frequency (Hz)'};
1340     txt{3}={'Amplitude'};
1341     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1342     start.month,  start.year, start.hour, start.minute, start.second);
1343     txt{4}={str};
1344     % antenna display
1345     p.style='flag';
1346     p.featflag=0;
1347 
1348     % there should be 1 page with 6 plots
1349     % one for reach channel
1350     % plot the data
1351     if(gen==1)
1352       genfigPowerSpec(dcal, [], txt, [], p, 'power', field,1);
1353     elseif(gen==2)
1354       genfigPowerSpec(dcal, [], txt, [], p, 'power', field,0);      
1355     else
1356       plotPowerSpec(dcal, [], [], txt, [], p);
1357     end
1358 
1359     %---------------------------------------------%
1360   case 'astro'
1361     
1362     % initialize plot axis names
1363     txt{1}={'I1', 'Q', 'U', 'Q' 'U', 'I2'};
1364     txt{2}={'Time (hrs)'};
1365     txt{3}={'Temp (K)'};
1366     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1367     start.month,  start.year, start.hour, start.minute, start.second);
1368     txt{4}={str};
1369     % antenna display
1370     p.style='flag';
1371     p.featflag=0;
1372 
1373     if(size(dcal.antenna0.receiver.data,2)==8)
1374       plotIndices = [1:5 8];
1375     else
1376       plotIndices = 1:size(dcal.antenna0.receiver.data,2);
1377     end    
1378 
1379     % we need to break up the data into half hour sections.
1380     if(isempty(flag))
1381       flag = convertFlagToDataSize(dcal.flags, ...
1382       size(dcal.antenna0.receiver.data,2));
1383     end
1384     for m=1:numChunks
1385       if(m==numChunks)
1386     ind = dcaltfast>=((m-1)*0.5);
1387       else
1388     ind = dcaltfast>=((m-1)*0.5) & dcaltfast<( (m)*0.5);
1389       end
1390       x{1,m} = dcaltfast(ind);
1391       x{2,m} = dcal.antenna0.receiver.data(ind,plotIndices);
1392       % we need the corresponding indices.
1393       fa = fieldnames(dcal.index);
1394       for mm=1:length(fa)
1395     eval(sprintf('indices.%s = dcal.index.%s.fast(ind);', fa{mm}, ...
1396         fa{mm}));
1397       end
1398       x{3,m} = indices;
1399       fflag{1,m} = flag.new.bit.fast(ind,:);
1400       fflag{2,m} = flag.old.bit.fast(ind,:);
1401     end
1402     clear dcaltfast;
1403     clear dcaltslow;
1404     clear dcalt;
1405 
1406     % plot the data
1407     if(gen==1)
1408       genfig(dcal, fflag, x, txt, [], 'astro', p, field, 1);
1409       theseFlags = fflag;      
1410     elseif(gen==2)
1411       genfig(dcal, fflag, x, txt, [], 'astro', p, field, 0);
1412       theseFlags = fflag;            
1413     else
1414       [theseFlags newflag] = plotd(dcal, fflag, x, txt, [],p);
1415       % update the flags
1416     end
1417     clear fflag;
1418     clear x;
1419 
1420     % next we set the flags
1421     flags = [];
1422     for m=1:size(theseFlags,2)
1423       flags = [flags; theseFlags{1,m}];
1424     end
1425     % if we do it this way, we also have to put in the old flags too.
1426     outFlags = convertDataFlagsToFlagSize(flags);
1427     flag.new.out = outFlags;    
1428 
1429     % in addition, we just want to plot the interpolated noise diode and
1430     % opacity values.
1431     
1432     %---------------------------------------------%
1433   case 'rms'
1434      
1435     % initialize plot axis names
1436     txt{1}={'Channel Number'};
1437     txt{2}={'Integration time (s)'};
1438     txt{3}={'RMS'};
1439     str=sprintf('%s\n%02u-%s-%u:%02u:%02u:%4.2f', str, start.day, ...
1440     start.month,  start.year, start.hour, start.minute, start.second);
1441     txt{4}={str};
1442     % antenna display
1443     p.style='flag';
1444     p.featflag=0;
1445 
1446     % there should be 1 page with 6-8 plots
1447     % one for reach channel
1448     % plot the data
1449     if(gen==1)
1450       genfigRms(dcal, [], [], txt, [], p, 'rms', field,1);
1451     elseif(gen==2)
1452       genfigRms(dcal, [], [], txt, [], p, 'rms', field,0);      
1453     else
1454       plotRms(dcal, [], [], txt, [], p);
1455     end
1456 
1457     
1458     
1459   otherwise
1460     error('Invalid ''type'' argument')
1461 
1462 end
1463 
1464 
1465 %%%%%%%%%%%%%%%%%%%%%%%%%
1466 function printhelp()
1467 
1468 disp(' ')
1469 disp('*******************WARNING**********************')
1470 disp('Do not exit plot by manually killing the window.')
1471 disp('This will cause the program to crash!')
1472 disp('************************************************')
1473 pause(1)
1474 disp(' ')
1475 disp('For help with plots, type ''h''')
1476 disp(' ');
1477 pause(1);
1478

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