Home > reduc > plotting > get_calobs.m

get_calobs

PURPOSE ^

SYNOPSIS ^

function [sources usn] = get_calobs(date_start,date_end,sched_to_reduce)

DESCRIPTION ^

 
 Function to check which calibrators were observed when
 Produces a database of names and start/end times --> calibrator_list.txt
 
 Called by plot_calibrators.m
 A log of all the calibrators and dates is created/added to in
 /log/calibrator_list.log
 
 Example usage: 

 [sources unique_source_names] = ('01-Jul-2011','10-Jul-2011','scan_calibrators_2011.sch')
 Will find all obs for that day and check which sources were observed.
 

 Use the optional sched_to_reduce to specify only specific schedule names 
 to be reduced. 

 ACT 25/7/2011

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [sources usn] = get_calobs(date_start,date_end,sched_to_reduce)
0002 %
0003 % Function to check which calibrators were observed when
0004 % Produces a database of names and start/end times --> calibrator_list.txt
0005 %
0006 % Called by plot_calibrators.m
0007 % A log of all the calibrators and dates is created/added to in
0008 % /log/calibrator_list.log
0009 %
0010 % Example usage:
0011 %
0012 % [sources unique_source_names] = ('01-Jul-2011','10-Jul-2011','scan_calibrators_2011.sch')
0013 % Will find all obs for that day and check which sources were observed.
0014 %
0015 %
0016 % Use the optional sched_to_reduce to specify only specific schedule names
0017 % to be reduced.
0018 %
0019 % ACT 25/7/2011
0020 
0021 [home,installeddir] = where_am_i();
0022 
0023 start_date_num = datenum(date_start);
0024 end_date_num = datenum(date_end);
0025 n_source = 1;
0026 start_date = datestr(start_date_num);
0027 end_date = datestr(end_date_num);
0028 disp(['Will look at all the data from ',start_date, '--> ',end_date]);
0029 
0030 for j=0:(end_date_num - start_date_num)
0031     date = datestr(start_date_num + j);
0032     disp(['Will reduce ',date, ' for schedule ',sched_to_reduce]);
0033 
0034     file = 'log/obs_log.html';
0035     try
0036     [start_dates,end_dates,schedule] =get_days_obs(file,date);
0037     if strcmp(char(start_dates),'Error')
0038         continue;
0039     end;
0040     catch exception
0041         error_string= ['FAILED TO FIND ANY DATA ON ',char(date)];
0042         disp(error_string);
0043         continue;
0044     end; %endtry
0045     disp(['day_reduce: FOUND ',int2str(length(start_dates)),' observations...']);
0046 
0047     for i=1:length(start_dates)
0048         
0049         sched_bits = regexp(char(schedule(i)), '/', 'split');
0050         sched_name = char(sched_bits(length(sched_bits)));  
0051         % strip out possible open bracket if there is one.
0052         sched_name = strrep(sched_name, '(',''); 
0053         disp(['day_reduce: Schedule is ',sched_name]);
0054        
0055         if (exist('sched_to_reduce'))
0056             if (~strncmp(sched_name,sched_to_reduce,length(sched_to_reduce)))
0057                 disp(['day_reduce: Skipping this observation - does not match the requested schedule i.e. ',sched_to_reduce]);   
0058             continue;
0059             end;
0060         end;
0061  
0062         start_string =  remove_colon_datestring(char(start_dates(i)));
0063         end_string =  remove_colon_datestring(char(end_dates(i))); 
0064         start_num = datenum(start_string);
0065         end_num = datenum(end_string);
0066       
0067         obs_length_mins = (end_num-start_num)*24*60;
0068         
0069         if (obs_length_mins<180)
0070             
0071         try
0072             
0073           disp(['READING Obs No. ', int2str(i),' of ',int2str(length(start_dates)),' ->  ',char(start_dates(i)),' --- ',char(end_dates(i))]);   
0074           % Check for error state.
0075           if strcmp(char(start_dates(i)),'Error')  
0076            continue;
0077           end; %endif
0078           d=pipe_read(char(start_dates(i)),char(end_dates(i)));
0079         catch exception
0080            error_string= ['day_reduce: FAILED TO READ ', int2str(i),' of ',int2str(length(start_dates)), ' ->  ',char(start_dates(i)),' --- ',char(end_dates(i))];
0081            disp(error_string);
0082         %   rep = getReport(exception, 'basic');
0083         %   fprintf(errfile,'%s\n',error_string);
0084         %   fprintf(errfile,'%s\n',rep)
0085         continue;
0086         end; %endtry
0087           
0088           
0089           new_source = length(unique(d.antenna0.tracker.source));
0090           source_names = unique(d.antenna0.tracker.source);
0091               for k = 1:new_source;
0092                 sources{n_source+k-1,1} = source_names{k,1};
0093                 sources{n_source+k-1,2} = char(start_dates(i));
0094                 sources{n_source+k-1,3} = char(end_dates(i));
0095               end
0096          n_source = n_source+new_source;
0097         end;
0098     end;
0099 
0100 end;
0101 
0102 % Now plot the days found during this search
0103 % Use plot_calibrators to plot the whole database
0104 
0105 if(n_source>1) 
0106     %Save to a text file
0107     fid = fopen(([home,'/',installeddir,'/log/calibrator_list.log']),'a+')
0108     %fid=fopen([home,'/',installeddir,'/log/calibrator_list.log'],'a+');
0109     
0110     for i=1:length(sources);
0111       fprintf(fid,'%12s %20s %20s\n',sources{i,:});
0112     end
0113     fclose(fid);
0114      
0115     % To make sure 'NCP' and 'current' don't appear in the list of calibrators
0116     cd ([home,'/',installeddir,'/log'])
0117     system('grep -v "NCP" calibrator_list.log > c.txt');
0118     system('grep -v "current" c.txt > c.txt2');
0119     system('mv c.txt2 calibrator_list.log');
0120     system('rm c.txt');
0121     cd ([home,'/',installeddir,]);
0122     
0123     usn = unique(sources(:,1));
0124 %
0125 %    %Now plot the sources
0126 %     usn = unique(sources(:,1))
0127 %     sd = sources(:,2)
0128 %     start_numbers = datenum(sd,'dd-mmm-yyyy:HH:MM:SS')
0129 %     sn = sources(:,1)
0130 %     min_time = min(start_numbers);
0131 %     max_time = max(start_numbers);
0132 %     xticks = [min_time:1:max_time];
0133 %     for i=1:length(usn)
0134 %         temp_times(:,1) = start_numbers(strmatch(usn(i),sn))  %% find the startdates for all the source_names matching unique name 1,2,3..
0135 %         temp_times(:,2)=i
0136 %         h(i) = plot(temp_times(:,1),temp_times(:,2),'p')
0137 %         xlim([min_time,max_time])
0138 %         ylim([0,length(usn)+1])
0139 %         set(gca,'xtick',xticks);
0140 %         hold all
0141 %         clear temp_times
0142 %     end
0143 %
0144 %
0145 %     datetick('x','dd/mm','keeplimits','keepticks');
0146 %     set(gca,'xtick',xticks);
0147 %     h = gca;
0148 %     th=rotateticklabel(h,45);
0149 %     names  = [' ';usn];
0150 %     set(gca,'YTickLabel',names)  % Label the y-axis with the calibrator names
0151 %     grid on;
0152 %     title('Calibrator observations','fontsize',15);
0153     
0154     
0155       
0156 else
0157     disp(' ');
0158     disp('DID NOT FIND ANY CALIBRATORS DURING THIS TIME PERIOD')
0159     sources = 0;
0160     usn = 0;
0161 end
0162 
0163 function processed_string = remove_colon_datestring(date_string)
0164 splitline = regexp(char(date_string), ':', 'split');  
0165 processed_string=[char(splitline(1)),' ',char(splitline(2)),':',char(splitline(3)),':',char(splitline(4))];
0166 
0167 function processed_string = insert_colon_datestring(date_string)
0168 splitline = regexp(char(date_string), ' ', 'split');
0169 processed_string=[char(splitline(1)),':',char(splitline(2))];

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