%BAOPLT10100300
% Plot daily combined data for levels 10, 100 and 300 meters.
% DEW2/13/2014 changed path so it will run on my desktop PC


function [retval] = baoozone_daily_func( by, bm, bd, ey, em, ed )
%clear

pltflg = 1;  % do the plot 1=yes 0=no
pngflg = 1;  % save data to png's flag  1= yes 0 = no

if ispc
    inpath = 'z:\Tower\Ozone\Processed\daily\';
    outpath  = 'z:\Tower\Ozone\Processed_Images\';
else
    inpath = '/archive/Tower/Ozone/Processed/';
    outpath  = '/archive/Tower/Ozone/Processed_Images/';
end

%cd(inpath);

if( nargin == 0 )
    bys = input('Input year to process (2007) ','s');
    bms = input('Input the month to process (1-12) ','s');
    bds = input('Input the beginning day to process (1-31) ','s');
    eys = input('Input year to process (2007) ','s');
    ems = input('Input the month to process (1-12) ','s');
    eds = input('Input end day to process (1-31) ','s');
    by = str2double( bys );
    bm = str2double( bms );
    bd = str2double( bds );
    ey = str2double( eys );
    em = str2double( ems );
    ed = str2double( eds );
end

bdn = datenum([by bm bd 0 0 0]);
edn = datenum([ey em ed 0 0 0]);

nmax = 3000;

for i = bdn:edn
    dv=datevec(i);
    if i == bdn && dv(4) > 0
        continue
    end
    yday = md2yd( dv(1), dv(2), dv(3) );
    %name10 = sprintf('%sBAO_010_%4d%03d.dat', inpath, dv(1), yday );
    %name100 = sprintf('%sBAO_100_%4d%03d.dat', inpath, dv(1), yday );
    name300 = sprintf('%sBAO_OZ3_%4d%03d.dat', inpath, dv(1), yday );
    
    fprintf(1,'*** Processing Ozone daily %d %d %d ***\n',dv(1),dv(2),dv(3));
       
    fid300 = fopen( name300 );
    if( fid300 > 0 )
        fclose( fid300 );
    else
        fprintf(1,'No 300m: %s\n',name300);
        continue;
    end
    
    [data300 dt n] = load300ozone( name300, nmax);

    jdb = fix(dt(1,7));
    jde = fix(dt(n,7))+1;
    
    if pltflg %skip plotting      
        figure1 = figure('Position',[100 50 650 650]);
        plot(dt(1:n,7),data300(1:n,1),'r')
        stitle=sprintf('BAO %4d-%02d-%02d Ozone', dv(1),dv(2),dv(3));
        title(stitle)
        %elim = max(data300(1:n,1))+5;
        %ylim([0 elim])
        ylim([0 120])
        xlim([jdb,jde])
        ylabel('O3 (PPB)')
        xlabel('Hour (UTC)')
        datetick('x','HH','keeplimits');     
        legend('300m','Location','NorthEast','Orientation','horizontal');
        legend('boxoff');
        grid on
        
        annotation(figure1,'textbox',[0.007154 0.01077 0.9498 0.02462],...
                  'String',{'These data have not been quality controlled and are not to be used without permission of NOAA/ESRL/GMD'},...
                  'FontSize',8,'FitBoxToText','off','LineStyle','none');
        if pngflg
            print_buffer = sprintf('%sBAO_10300_%4d%03d_Ozo.png',...
                                   outpath, dv(1), yday );
            set(gcf,'PaperPositionMode','auto');
            print('-dpng', print_buffer);
            %f=getframe(gcf);
            %imwrite(f.cdata,print_buffer,'png');
        end
        
    end % skip plotting
    
    clear data300 dt
    close all
    
end %loop through days

clear all

retval = 0;
