% ceilo_daily_plot_program
% NTAS 2009 :: 2009-06-12 :: LB
% Reads intermediate files \RHB\ceilometer\Processed\JJJ_MM_DD_YY.txt
% PLOT CEILOMETER DAILY AND COMPOSITE TIME SERIES AND BACKSCATTER INTENSITY

% read_parameters
% yyyy=year;
% year=sscanf(yyyy,'%4f');

pltflg = true; % flag to control whether plots are output to files or not.

sta=[way_proc_data_ceilo sprintf('cloudbase%04i%02i%02i_%03i.txt',year,month,monthday,yearday) ];
ceil_series=load(sta); %('%6i%6i%6i%6i%6i%6i%6i\n');% compact readable ascii format: [code height1 height2 height3 hour min sec]

ceil_time = ceil_series(:,5)+ceil_series(:,6)/60+ceil_series(:,7)/3600;
if ceil_time(end)==0
    step=diff(ceil_time);
    ceil_time(length(ceil_time))=ceil_time(length(ceil_time)-1)+step(1);
end;

figure()
set(gcf,'DefaultAxesFonts',12);
plot(ceil_time,ceil_series(:,2)/1e3,'b.','markersize',3);
xlim([0 24]); set(gca,'xtick',[0:4:24]);ylim([0 7]);
xlabel('Time (UTC)','FontName','times','FontSize',16);
ylabel('Height (km)','FontName','times','FontSize',12);
title([cruise ' ' yyyy '-' mm '-' dd ' day' ddd ', Ceilometer Cloud Base'],'FontName','times','FontSize',12);
if pltflg
    print_buffer=[way_images_ceilo sprintf('cloudbase%04i%02i%02i_%03i',year,month,monthday,yearday) ];
    print('-djpeg90 ', [print_buffer '.jpg']);
end

% load backscatter data
scatter_data=[way_proc_data_ceilo sprintf('backscatter%04i%02i%02i_%03i.mat',year,month,monthday,yearday) ];
ceil_b=load(scatter_data);
% dereference ceil_b structure
ceil_utc=ceil_b.ceil_utc;
ceil_range=ceil_b.ceil_range;
ceil_b=ceil_b.ceil_b;

a=sort(ceil_b(isfinite(ceil_b(:,ceil_range<=3)))); n=length(a);
climit=a(fix(n*[0.05 0.999])); % set color limit based on distribution of the backscatter
figure()
set(gcf,'DefaultAxesFonts',12);
imagesc(ceil_utc,ceil_range/1e3,ceil_b);
axis xy; colorbar; caxis(climit); 
xlim([0 24]); set(gca,'xtick',0:4:24);
ylim([0 7]);
xlabel('Time (UTC)','FontName','times','FontSize',12);
ylabel('Height (km)','FontName','times','FontSize',12);
title([cruise ' ' yyyy '-' num2str(month) '-' dd ' day' ddd ', ceilometer backscatter'],'FontName','times','FontSize',12);
if pltflg
    print_buffer=[way_images_ceilo sprintf('backscatter%04i%02i%02i_%03i',year,month,monthday,yearday) ];
    print('-djpeg90 ', [print_buffer '.jpg']);
end

figure()
set(gcf,'DefaultAxesFonts',12);
% imagesc(sort(ceil_utc),ceil_range,ceil_b);
imagesc(ceil_utc,ceil_range/1e3,log10(abs(ceil_b)));
axis xy; colorbar; % caxis(climit); 
xlim([0 24]); set(gca,'xtick',0:4:24);
ylim([0 7]);
xlabel('Time (UTC)','FontName','times','FontSize',12);
ylabel('Height (km)','FontName','times','FontSize',12);
title([cruise ' ' yyyy '-' num2str(month) '-' dd ' day' ddd ', ceilometer log_{10} backscatter'],'FontName','times','FontSize',12);
if pltflg
    print_buffer=[way_images_ceilo sprintf('backscatter_log10_%04i%02i%02i_%03i',year,month,monthday,yearday) ];
    print('-djpeg90 ', [print_buffer '.jpg']);
end