
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% PLOT CEILOMETER DAILY AND COMPOSITE TIME SERIES AND BACKSCATTER
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INTENSITY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
%pathdata = 'C:\NEAQS_2004\ETLceilometer\results\';
s='I:\STRATUS_2006\RHB\ceilometer\Processed\';
pathdata = [s '*06.txt'];

%eval(['cd ', pathdata]);

%a = dir('*.txt');
a = dir(pathdata);%a(1).name
k = length(a);


[num] = num2str(k);
disp('Number of ceilometer *.txt files : '); disp( [num]); 

st = 1;

st = 3
for w = st:k;

[numf] = num2str(w);
disp('# of *.txt file in process :'); disp ( [numf]); 

%%%%%%% k is the # of *.cdf files need to be processed. %%%%%%%%

%data = [a(w).name]
data = [s a(w).name]
scatter_data = [s 'backscatter_' a(w).name(1:12) '.mat'];
ceil_series = load(data);
load(scatter_data);
ceil_time = ceil_series(:,5)+ceil_series(:,6)/60+ceil_series(:,7)/3600;

figure(5)
set(gcf,'DefaultAxesFonts',12);
plot(ceil_time,ceil_series(:,2),'b.');
xlim([0 24]); set(gca,'xtick',[0:4:24]);ylim([0 4000]);
xlabel('Time (UTC)','FontName','times','FontSize',16);
ylabel('Height (m)','FontName','times','FontSize',12);
title(['STRATUS 2006 ' a(w).name(1:3) '/' a(w).name(5:6) '-' a(w).name(8:9) '-' a(w).name(11:12) ', Ceilometer Cloud Base'],'FontName','times','FontSize',12);
print_buffer = ['I:\STRATUS_2006\RHB\ceilometer\Processed_Images\STRATUS2006_ceilometer_' a(w).name(1:12) '_base.jpg'];
print('-djpeg90 ', print_buffer);

% test=sort(ceil_time,'ascend');
% imagesc(test,height*1000,log10(abs(ceil_b)));

figure(6)
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 4000]);
xlabel('Time (UTC)','FontName','times','FontSize',12);
ylabel('Height (m)','FontName','times','FontSize',12);
title(['STRATUS 2006 ' a(w).name(1:3) '/'  a(w).name(5:6) '-' a(w).name(8:9) '-' a(w).name(11:12) ', Ceilometer Backscatter'],'FontName','times','FontSize',12);
print_buffer = ['I:\STRATUS_2006\RHB\ceilometer\Processed_Images\STRATUS2006_ceilometer_' a(w).name(1:12) '_backscatter.jpg'];
print('-djpeg90 ', print_buffer);
%%% START WITH THE RADIOMETER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
%clear ceil_b ceil* 

end


%clear all


%%%%%% COMPOSITE OF CEILOMETER BACKSCATTER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


s='I:\STRATUS_2006\RHB\ceilometer\Processed\';
pathdata = [s '*06.txt'];

%pathdata = 'C:\NEAQS_2004\ETLceilometer\results\';

%eval(['cd ', pathdata]);

%a=dir('*.txt');
a = dir(pathdata);

k = length(a);


[num] = num2str(k);
disp('Number of ceilometer *.txt files : '); disp( [num]); 

st = 1;

for w = st:k;

[numf] = num2str(w);

disp('# of *.txt file in process :'); disp ( [numf]); 

%%%%%%% k is the # of *.cdf files need to be processed. %%%%%%%%

data = [s a(w).name]
scatter_data = [s 'backscatter_' a(w).name(1:12) '.mat'];
ceil_series = load(data);
load(scatter_data);
ceil_time = ceil_series(:,5)+ceil_series(:,6)/60+ceil_series(:,7)/3600;
ceil_hr=ceil_series(:,5);
ceil_mn=ceil_series(:,6);
ceil_sc=ceil_series(:,7);
jd=datenum(str2num(['20' a(w).name(11:12)]),str2num(a(w).name(5:6)),str2num(a(w).name(8:9)))-datenum(2005,12,31);
%ceil_time = str2num(data(1:2))+(ceil_hr+ceil_mn/60+ceil_sc/3600)/24;
ceil_time = jd+(ceil_hr+ceil_mn/60+ceil_sc/3600)/24;
if w == st

sf = length(ceil_time);
time_all = ceil_time;
height_all = height;
backscatter = ceil_b;
base        = ceil_series(:,2);
else
    
    gf = length(time_all);
    sf = length(ceil_time);
    time_all(gf+1:gf+sf)=ceil_time;
    backscatter(1:256,gf+1:gf+sf)=ceil_b;
    base(gf+1:gf+sf)=ceil_series(:,2);
end


end

figure(6)
set(gcf,'DefaultAxesFonts',12);
imagesc(time_all(1:3:length(time_all)),height(1:135)*1000,log10(abs(backscatter(1:135,1:3:length(time_all)))),[1 3.5]);
axis xy; colorbar;
ylim([0 4000]);
xlabel('Time (Julian Day)','FontName','times','FontSize',12);
ylabel('Height (m)','FontName','times','FontSize',12);
title('STRATUS 2006 Ceilometer Backscatter','FontName','times','FontSize',12);
%print_buffer = ['C:\NEAQS_2004\ETLceilometer\results\NEAQS2004_ceilometer_allexp_backscatter.jpg'];
print_buffer = ['I:\STRATUS_2006\RHB\ceilometer\Processed_Images\STRATUS2006_ceilometer_allexp_backscatter.jpg'];

print('-djpeg90 ', print_buffer);


figure(5)
set(gcf,'DefaultAxesFonts',12);
plot(time_all(1:3:length(time_all)),base(1:3:length(time_all)),'b.');
% xlim([min(time_all) max(time_all)]);ylim([0 4000]);
xlim([time_all(1) max(time_all)]);ylim([0 4000]);
xlabel('Time (UTC)','FontName','times','FontSize',16);
ylabel('Height (m)','FontName','times','FontSize',12);
title('STRATUS 2006, Ceilometer Cloud Base','FontName','times','FontSize',12);
%print_buffer = ['C:\NEAQS_2004\ETLceilometer\results\NEAQS2004_ceilometer_allexp_base.jpg'];
print_buffer = ['I:\STRATUS_2006\RHB\ceilometer\Processed_Images\STRATUS2006_ceilometer_allexp_base.jpg'];

print('-djpeg90 ', print_buffer);
