Home > comms > scanForNDEvents_DD.m

scanForNDEvents_DD

PURPOSE ^

This script searches the data archive for noise diode events between

SYNOPSIS ^

function [t,A,G,T,r,H,E,Temp] = scanForNDEvents_DD(start,finish,fname)

DESCRIPTION ^

 This script searches the data archive for noise diode events between
 start and finish, and calculates the Alpha, Gain, and r-factor values
 therein. They are appended to the text file called fname.

 The nominal start time is start, and end time is finish. These have the
 format that pipe_read would accept, for instance.

 ogk, 3 December 2010

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [t,A,G,T,r,H,E,Temp] = scanForNDEvents_DD(start,finish,fname)
0002 % This script searches the data archive for noise diode events between
0003 % start and finish, and calculates the Alpha, Gain, and r-factor values
0004 % therein. They are appended to the text file called fname.
0005 %
0006 % The nominal start time is start, and end time is finish. These have the
0007 % format that pipe_read would accept, for instance.
0008 %
0009 % ogk, 3 December 2010
0010 
0011 % Parse start and finish:
0012 mjdstart = tstr2mjd(start);
0013 mjdstop  = tstr2mjd(finish);
0014 % to convert mjd to string: mjd2string(mjdtime)
0015 
0016 % Take the data in tscans hour segments:
0017 Tscans = 2;
0018 N = floor((mjdstop-mjdstart)*24/Tscans);
0019 
0020 fprintf('Number of %2.1f hour segments to scan: %d\n',Tscans,N)
0021 
0022 % A possibly necessary offset, in case we start or end in a noise diode
0023 % event:
0024 offset = 0;
0025 t = [];
0026 A = [];
0027 G = [];
0028 T = [];
0029 r = [];
0030 Temp = [];
0031 H = [];
0032 E = [];
0033 
0034 tfile = fopen(fname,'a+');
0035 fprintf(tfile,'# C-BASS alpha values\n');
0036 fprintf(tfile,'# 24 columns:\n');
0037 fprintf(tfile,'# MJD, 5 x alpha, 5 x G, 2 x r, 2 x Tsys/TND, 2 x horiz, 2 x equa, 7 x temp \n');
0038 fprintf(tfile,'#\n');
0039 
0040 for k=1:N
0041     stime = mjdstart + (k-1)*Tscans/24 + offset;
0042     offset = 0;
0043     if k == N
0044         ftime = mjdstop;
0045     else
0046         ftime = mjdstart + k*Tscans/24;
0047     end
0048     fprintf('***** Reading scan %d of %d:\n',k,N)
0049     disp(['      Start:  ' mjd2string(stime)])
0050     disp(['      Finish: ' mjd2string(ftime)])
0051      
0052     % Read in the data:
0053     try
0054         d = pipe_read(mjd2string(stime),mjd2string(ftime));   
0055         % Do we end in a noise diode event?
0056         while d.index.noise_event.fast(end)
0057             disp('***** Ended during a noise diode event, adjusting time accordingly')
0058             offset = offset + 2/24/60; % Add 2 minutes to the start time
0059             ftime = mjdstart + k*Tscans/24 + offset;
0060             d = pipe_read(mjd2string(stime),mjd2string(ftime));
0061         end
0062    
0063         % Calculate alpha:
0064         d = assembleAlphaStreams_DD(d);
0065         [td,Ad,Gd,Td,rd,horz,equa,offStPos,onEndPos, offEndPos, onStPos] = calculateAlpha_DD(d);
0066         
0067         % Interpolate the temperature data
0068         d.antenna0.thermal.dlpTemperatureSensors = interp1(d.array.frame.utc,d.antenna0.thermal.dlpTemperatureSensors,d.antenna0.receiver.utc,'linear');
0069         
0070         if ~isempty(td)
0071             tTemp = [];
0072             for m=1:size(onStPos,2)
0073                 tTemp = [tTemp; mean(d.antenna0.thermal.dlpTemperatureSensors(onStPos(m):onEndPos(m),1:7),1)];
0074             end
0075             t = [t; td];
0076             Temp = [Temp; tTemp];
0077             A = [A; Ad];
0078             G = [G; Gd];
0079             T = [T; Td];
0080             r = [r; rd];
0081             H = [H; horz*pi/180];
0082             E = [E; equa];
0083             fprintf(tfile,...
0084                 '%7.6f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %5.4f %4.3f %4.3f %4.2f %4.2f %5.4f %5.4f %5.4f %5.4f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n',...
0085                 [td Ad Gd rd Td horz*pi/180 equa tTemp]');
0086         end
0087         
0088     catch
0089         disp('***** BAD DATA; SKIPPING TO NEXT SET')
0090     end
0091 end
0092 
0093 fclose(tfile);
0094 
0095 end

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