%BAOPLT100_loop
% Plot data from BAO data loggers
% Systems turned back on April 2007
% Not calibrated old sensors
% 10m
%ID  YR   Day  hhmm   T    RH     WS     DIR    VDC   P      Precip Corrected Dir
% 10,2007,99,1413,7.3547,87.654,.30489,292.84,13.981,826.61,0,111.234

%Prop-vane aligned along boom on N side pointing 324 subtract 26 to get
%true wind direction
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\daily\';
outpath  = 'z:\bao\Tower\Processed_Images\daily\';

cd(inpath);

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

for ii = 1:lm
    clear data100 yday
    disp(['Reading ',m(ii).name]);
    data100 = load(m(ii).name);    %load 1 day of PSD mean logger data

    hhmm = data100(:,4);
    hh = fix(hhmm/100);
    mm = hhmm - (hh*100);
    data100(:,3) = data100(:,3) + (((mm/60.) + hh)/24); %Year day
    yday = fix(data100(1,3));
    clear hhmm hh mm

    if pltflg  %do plots if pltflg=1
        figure(1)
        clf
        subplot(2,1,1),plot(data100(:,3),data100(:,5))
        %hold
        %subplot(2,1,1),plot(data50(:,3),data50(:,5),'r')
        %xlabel('Year Day (UTC)')
        ylabel('T (C)')
        stitle=sprintf('BAO %d 100m', data100(1,3));
        title(stitle)
        %axis([110,116,-10,30])
        xlim([yday,yday+1])
        subplot(2,1,2),plot(data100(:,3),data100(:,6))
        %hold
        xlabel('Year Day (UTC)')
        ylabel('Rh (%)')
        ylim([0,109])
        xlim([yday,yday+1])
        if pngflg
            print_buffer = [outpath, m(ii).name(1:15),'_TRH.png'];
            print('-dpng ', print_buffer);
            %print_buffer = [outpath, m(ii).name(1:15),'_TRH.png'];
            %print('-dpng', print_buffer);
            
        end
    end

    if 0 %skip this until we put up a prop vane DEW 9192007
        figure(2)
        clf
        subplot(2,1,1),plot(data100(:,3),data100(:,7))
        %hold
        %subplot(2,1,1),plot(data50(:,3),data50(:,7),'r')
        xlabel('Year Day (UTC)')
        ylabel('Spd (m/s)')
        stitle=sprintf('BAO %d 100m', data100(1,3));
        title(stitle)
        %axis([110,116,0,30])
        %legend('10m')
        xlim([yday,yday+1])
        %legend('10m','50m')
        subplot(2,1,2),plot(data100(:,3),data100(:,12))
        %hold
        %subplot(2,1,2),plot(data50(:,3),data50(:,8),'r')
        xlabel('Year Day (UTC)')
        ylabel('Dir (true)')
        %axis([110,116,0,360])
        %legend('10m')
        xlim([yday,yday+1])
        %legend('10m','50m')
        if pngflg
            print_buffer = [outpath, m(ii).name(1:15),'_WS.png'];
            print('-dpng ', print_buffer);
        end
    end
end % for looping through days
