% ceilo_daily_plot_program
% CalNEX 2010 :: 2010-04-22 :: LB
% PLOT CEILOMETER DAILY AND COMPOSITE TIME SERIES AND BACKSCATTER INTENSITY

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

sta=[way_proc_data_ceilo sprintf('cloudbase_%04s_%02s_%02s_%03s.txt',yyyy,mon,dy,jds) ];
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;

if plotit
    figure()
    set(gcf,'DefaultAxesFonts',12);
    plot(ceil_time,ceil_series(:,2)/1000,'b.');
    xlim([0 24]); set(gca,'xtick',[0:4:24]);ylim([0 7.5]);
    xlabel('Time (UTC)','FontName','times','FontSize',12);
    ylabel('Height (km)','FontName','times','FontSize',12);
    title([cruise ' ' jds '/' yyyy(3:4) '-' mon '-' dy ', Ceilometer Cloud Base'],'FontName','times','FontSize',12,'Interpreter','none');
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit
        print_buffer = [way_images_ceilo, cruise, '_', ship, '_cloudbase_', yyyy, '_', mon, '_', dy, '_' jds, graphformat];
        print(graphdevice, print_buffer);
    end
end

% load backscatter data
scatter_data=[way_proc_data_ceilo sprintf('backscatter_%04s_%02s_%02s_%03i.mat',yyyy,mon,dy,jd) ];
ceil_b=load(scatter_data);
% dereference ceil_b structure
% ceil_utc=ceil_b.ceil_utc_cat;
% ceil_range=ceil_b.ceil_range;
% ceil_b=ceil_b.ceil_b_cat;
ceil_utc=ceil_b.ceil_utc;
ceil_range=ceil_b.ceil_range;
ceil_b=ceil_b.ceil_b;

ceil_utc_new=[];ceil_b_new=[];
ii=find(diff(ceil_utc)>1);  %to make imagesc plot the possible data gaps
if ~isempty(ii)
    for jj=1:length(ii)
        l=round(ceil_utc(ii(jj)+1)-ceil_utc(ii(jj)))*3600/15;
        ceil_b_new=[ceil_b_new ceil_b(:,1:ii(jj)) ones(length(ceil_range),l) ceil_b(:,ii(jj)+1:end)];
        ceil_utc_new=[ceil_utc_new; ceil_utc(1:ii); ones(l,1);ceil_utc(ii+1:end) ];
    end
else
    ceil_utc_new=ceil_utc;
    ceil_b_new=ceil_b;
end;

if plotit
    figure()
    set(gcf,'DefaultAxesFonts',12);
%     imagesc(ceil_time,ceil_range/1000,log10(max(0,ceil_b))); % abs was goofy
    imagesc(ceil_utc_new,ceil_range,log10(max(0,ceil_b_new))); % abs was goofy
    axis xy; colorbar;
    xlim([0 24]); set(gca,'xtick',[0:4:24]);ylim([0 7.5]);
    xlabel('Time (UTC)','FontName','times','FontSize',12);
    ylabel('Height (km)','FontName','times','FontSize',12);
    title([cruise ' ' jds '/' yyyy(3:4) '-' mon '-' dy ', Ceilometer Backscatter'],'FontName','times','FontSize',12,'Interpreter','none');
    annotation(gcf,'textbox',[0.007154 0.01077 0.4498 0.02462],'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},'FontSize',6,'FitBoxToText','off','LineStyle','none'); 
    if prtit
        print_buffer = [way_images_ceilo, cruise, '_', ship, '_ceilobackscatter_', yyyy, '_', mon, '_', dy, '_' jds, graphformat];
        print(graphdevice, print_buffer);
    end
end

dana_ceilo_process_SWERUS_2014