
% Reads in raw ceilometer .DAT files as written by the Vaisala logging program
%Writes out the old stye cloud base height file and the backscatter file
% This version is looking for data on  E:\
%It ignores files smaller than 8k to avoid the log files
%Uses LCload_1 adapted from Pavlos Kollias on Stratus 03 Revelle cruise
%Uses LCload_CL31_2007.m adapted from Ludovic Bariteau for the new
%ceilometer CL31.

% program written by C. Fairall.  
% on 8 Aug 2004.  

disp('Reading ceilo files')

s=[raw_data_path fname];
dr=dir(s);			%lists all files in directory
[n m]=size(dr);
nx=n;				%# of files in data directory (includes . and ..)     


%******************  setup read data loop  **********
ss=raw_data_path;
wrtit=1;

jamx=1;
for ibg = 1:n 			%major read loop
    if dr(ibg).bytes>8000
               
        ff=dr(ibg).name;		 		%names of files
        ceil_filename=[ss ff];
        mon=ff(3:4);	%get month
        month=str2num(mon);	%get month
        dy=ff(5:6);		%get day
        day=str2num(dy);		%get day
        yr=['0' ff(2)];	
        year=str2num(yr);
        data=[year month day];%get year
        jd=datenum(str2num(['20' yr]),month,day)-datenum(str2num(['20' yr])-1,12,31);
        jdn=num2str(jd);
        if length(jdn)==2
            jdn=['0' jdn];
        end;
        
        LCload_CL31_stratus07a; 
       %LCload_CL31_2007; 
         if wrtit
             fn=[mon '_' dy '_' yr];
             sta=[processed_data_path jdn '_' fn '.txt'];
             save( sta, 'ceilo_30_sec', '-ascii','-tabs')
             
             stb=[processed_data_path 'backscatter_' jdn '_' fn '.mat'];
             %save(stb,'ceil_utc','ceil_b','-ascii','-tabs');
             save(stb,'ceil_utc','height','ceil_b');
        end;
    end;%end if
    
end; %  data line loop