%BAOPLT100_month_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
% 10,2007,99,1413,7.3547,87.654,.30489,292.84,13.981,826.61,0

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_100_200801.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);

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

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

    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(data100(:,3),data100(:,5),'r')
        xlabel('Year Day')
        ylabel('T (C)')
        stitle=sprintf('BAO %d 100m', data100(1,3));
        title(stitle)
        %axis([110,116,-10,30])
        xlim([jdb,jde])
        ylim([-20,30])
        subplot(2,1,2),plot(data100(:,3),data100(:,6))
        %hold
        %subplot(2,1,2),plot(data100(:,3),data100(:,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

        if 0
            figure(2)
            clf
            subplot(2,1,1),plot(data100(:,3),data100(:,7))
            %hold
            %subplot(2,1,1),plot(data100(:,3),data100(:,7),'r')
            xlabel('Year Day')
            ylabel('Spd (m/s)')
            stitle=sprintf('BAO %d 100m', data100(1,3));
            title(stitle)
            %axis([110,116,0,30])
            %legend('10m')
            xlim([jdb,jde])
            %legend('10m','50m')
            subplot(2,1,2),plot(data100(:,3),data100(:,8))
            %hold
            %subplot(2,1,2),plot(data100(:,3),data100(:,8),'r')
            xlabel('Year Day')
            ylabel('Dir (true)')
            %axis([110,116,0,360])
            legend('100m')
            xlim([jdb,jde])
        end

    end % if doing plots

end % loop through all files


