%BAOPLT10_month_loop
% Plot data from BAO data loggers
% Systems turned back on April 2007
% Not calibrated old sensors
% 10m
%ID,YR,YearDay,hhmm,T,RH,WS,WSvec,DIR,Dsig,VDC,P,Precip,Corrected Dir
%10,2007,099,1413,7.35,87.654,.305,.305,292.84,2.03,13.981,826.61,0,111.234

clear

pltflg = 1; %flag to plot the data: 1=yes, 0=no
pngflg = 1; %flag to make a png of the plot: 1=yes, 0=no

inpath = 'Z:\bao\Tower\Processed\monthly\';
outpath  = 'Z:\bao\Tower\Processed_Images\monthly\';

cd(inpath);

m=dir('BAO_010_200801.dat');
lm = length(m);
fprintf(1,'number of files to process %d\n', lm);

for ii = 1:lm
    clear data10 yday
    disp(['Reading ',m(ii).name]);
    data10 = load(m(ii).name);    %load 1 month of PSD mean logger data
    hhmm = data10(:,4);
    hh = fix(hhmm/100);
    mm = hhmm - (hh*100);
    data10(:,3) = data10(:,3) + (((mm/60.) + hh)/24); %Julian day
    clear hhmm hh mm

    jdb = fix(data10(1,3));
    jde = fix(data10(length(data10),3))+1;
    %CSD experiment
    %jdb = 208;
    %jde = 222;

    if pltflg % do plots if pltflg=1
        figure(1)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,5))
        %hold
        %subplot(2,1,1),plot(data10(:,3),data10(:,5),'r')
        %xlabel('Year Day')
        ylabel('T (C)')
        stitle=sprintf('BAO %d 10m', data10(1,2));
        title(stitle)
        axis([jdb,jde,-20,30])
        xlim([jdb,jde])
        legend('10m')
        %legend('10m','50m')
        subplot(2,1,2),plot(data10(:,3),data10(:,6))
        %hold
        %subplot(2,1,2),plot(data10(:,3),data10(:,6),'r')
        xlabel('Year Day')
        ylabel('Rh (%)')
        %axis([110,116,0,100])
        %legend('10m')
        %legend('10m','50m')
        ylim([0,109])
        xlim([jdb,jde])

        if pngflg
            print_buffer = [outpath m(ii).name(1:14) '_TRH.png'];
            print('-dpng ', print_buffer);
        end

        figure(2)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,7))
        %hold
        %subplot(2,1,1),plot(data10(:,3),data10(:,7),'r')
        stitle=sprintf('BAO %d 10m', data10(1,2));
        title(stitle)
        %xlabel('Year Day')
        ylabel('Spd (m/s)')
        %axis([110,116,0,30])
        %legend('10m')
        xlim([jdb,jde])
        %legend('10m','50m')
        subplot(2,1,2),plot(data10(:,3),data10(:,14))
        %hold
        %subplot(2,1,2),plot(data10(:,3),data10(:,8),'r')
        xlabel('Year Day')
        ylabel('Dir (true)')
        %axis([110,116,0,360])
        legend('10m')
        xlim([jdb,jde])
        if pngflg
            print_buffer = [outpath, m(ii).name(1:14) '_WS.png'];
            print('-dpng ', print_buffer);
        end

        dd = find(data10(:,3) >= 121);
        %Total precip
        tp = cumsum(data10(dd,13));
        tpin = tp/25.4;

        figure(3)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,12))
         stitle=sprintf('BAO %d 10m', data10(1,2));
        title(stitle)
       %xlabel('Year Day')
        ylabel('Pressure (mb)')
        xlim([jdb,jde])
        %axis([110,116,820,850])
        subplot(2,1,2),plot(data10(dd,3),tpin,'r.')
        xlabel('Year Day')
        ylabel('Precip (in)')
        xlim([jdb,jde])
        ylim([0 .5])
        %axis([110,116,0,.5])

        if pngflg
            print_buffer = [outpath m(ii).name(1:14) '_PP.png'];
            print('-dpng ', print_buffer);
        end
    end % if doing plots

end % loop through all files

