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

%ceil_series = load(sta);
%load(stb);

%ceil_dn = ceil_series(:,5);
%nindx=find(isnan(ceil_dn));
%ceil_dn(nindx)=begdn+0.004167*nindx;
%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;

bdv=datevec(bdn);
edv=datevec(edn);
stitle =sprintf('BAO Ceilometer Backscatter/Cloud Base %4d-%02d-%02d to %4d-%02d-%02d Latest time %02d:%02d:%02d', ...
    bdv(1:3),edv(1:6));
dtindx=find(ceil_dn>=bdn & ceil_dn<=edn);

v1=find(cloudcode(dtindx) == 1);
v2=find(cloudcode(dtindx) == 2);
v3=find(cloudcode(dtindx) == 3);
v4=find(cloudcode(dtindx) == 4);
lenv1=length(v1);
lenv4=length(v4);

figure3 = figure('Position',[10 50 650 650]);
set(gcf,'DefaultAxesFonts',12);
imagesc(ceil_dn(dtindx),ceil_range*1000,log10(max(0,ceil_b(:,dtindx))),[-5.0 0.0]); % abs was goofy
axis xy;
colorbar;
xlim([bdn edn]);
set(gca,'xtick',bdn:(edn-bdn)/6.:edn);
datetick('x','HH:MM','keeplimits','keepticks');
ylim([0 7700]);
xlabel('Time (UTC)','FontName','times','FontSize',12);
ylabel('Height (m)','FontName','times','FontSize',12);
title(stitle);
hold
plot(ceil_dn(dtindx(v1)),cloud1(dtindx(v1)),'k.','MarkerSize',5);
if lenv4 > 0
    plot(ceil_dn(dtindx(v4)),cloud2(dtindx(v4)),'m.','MarkerSize',5);
end
plot(ceil_dn(dtindx(v2)),cloud2(dtindx(v2)),'k.','MarkerSize',5);
plot(ceil_dn(dtindx(v3)),cloud3(dtindx(v3)),'k.','MarkerSize',5);
if lenv1 > 0 && lenv4 > 0
    legend('Cloudbase','Visibility','Location','North','Orientation','Horizontal');
elseif lenv1 > 0
    legend('Cloudbase','Location','North','Orientation','Horizontal');
elseif lenv4 > 0
    legend('Visibility','Location','North','Orientation','Horizontal');
end
annotation(figure3,'textbox',[0.007154 0.01077 0.4498 0.02462],...
    'String',{'NOAA/ESRL/PSD/Weather & Climate Physics'},...
    'FontSize',8,'FitBoxToText','off','LineStyle','none');
if pltflg
    print_buffer=sprintf('%s%s_current_BCB.png',way_images_ceilo,cruise);
    set(gcf,'PaperPositionMode','auto');
    print('-dpng ', print_buffer);
end
