
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% PLOT CEILOMETER DAILY AND COMPOSITE TIME SERIES AND BACKSCATTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INTENSITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pltflg = 1; % flag to control whether plots are made or not.

way_images_ceilo = 'c:\data\ICEALOT\data\ceilometer\Raw_Images\';
way_proc_data_ceilo = 'c:\data\ICEALOT\data\ceilometer\';
if fname(1) == 'K'
    data = [way_proc_data_ceilo jdn '_' fn '.txt'];
    scatter_data = [way_proc_data_ceilo  'backscatter_' jdn '_' fn '.mat'];end
if fname(1) == 'S'
    data = [way_proc_data_ceilo jdn '_' fn 'S.txt'];
    scatter_data = [way_proc_data_ceilo  'backscatter_' jdn '_' fn 'S.mat'];end

ceil_series = load(data);
load(scatter_data);

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


figure(1)
set(gcf,'DefaultAxesFonts',12);
plot(ceil_time,ceil_series(:,2),'b.');
xlim([0 24]); set(gca,'xtick',[0:4:24]);ylim([0 7700]);
xlabel('Time (UTC)','FontName','times','FontSize',16);
ylabel('Height (m)','FontName','times','FontSize',12);

if pltflg
    if fname(1) == 'K'
        title([cruise year '-' fn(1:2) '-' fn(4:5) '-' fn(7:8) ', Ceilometer Cloud Base'],'FontName','times','FontSize',12);
        print_buffer = [way_images_ceilo, cruise, jdn '_' fn, '_base.png'];
        print('-dpng', print_buffer);
    end
    if fname(1) == 'S'
        title([cruise year '-' fn(1:2) '-' fn(4:5) '-' fn(7:8) ', Ceilometer Cloud Base 2nd'],'FontName','times','FontSize',12);
        print_buffer = [way_images_ceilo, cruise, jdn '_' fn, 'S_base.png'];
        print('-dpng', print_buffer);
    end
end

figure(2)
set(gcf,'DefaultAxesFonts',12);
imagesc(ceil_time,height*1000,log10(abs(ceil_b)));
axis xy; colorbar;
xlim([0 24]); set(gca,'xtick',[0:4:24]);%ylim([0 7700]);
xlabel('Time (UTC)','FontName','times','FontSize',12);
ylabel('Height (m)','FontName','times','FontSize',12);
if pltflg
    if fname(1) == 'K'
        title([cruise year '-' fn(1:2) '-' fn(4:5) '-' fn(7:8) ', Ceilometer Backscatter'],'FontName','times','FontSize',12);
        print_buffer = [way_images_ceilo, cruise, jdn '_' fn, '_backscatter.png'];
        print('-dpng', print_buffer);
    end
    if fname(1) == 'S'
        title([cruise year '-' fn(1:2) '-' fn(4:5) '-' fn(7:8) ', Ceilometer Backscatter 2nd'],'FontName','times','FontSize',12);
        print_buffer = [way_images_ceilo, cruise, jdn '_' fn, 'S_backscatter.png'];
        print('-dpng', print_buffer);
    end
end
