%BAOPLT07
% 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

outpath  = 's:\bao\Tower\Processed_Images\';

pltflg = 1;  % save data to jpg's flag  1= yes 0 = no

fn ='s:\bao\Tower\Processed\BAO_010_2007226.dat';
m=dir('s:\bao\Tower\Processed\BAO_010_*');
lm = length(m)

% 8/28/2007  59 = 234 65 days
for ii = 65:lm
clear bao300 year month day minute sec hour juld
    disp(['Reading ',m(ii).name]);
    flist=fopen(m(ii).name,'r');
    fn(24:42) = (m(ii).name);
    %load bao10.dat
    %jds = input('Input Julian day to plot    ','s');
    %jd = str2num(jds);

    %name ='s:\bao\reformed\BAO_010_2007226.dat';
    %name(29:31) = jds(1:3);  % reformed directory
    %name ='s:\bao\daily\BAO_010_2007226.dat';
    %name(26:28) = jds(1:3);  % daily directory
    data10 = load(fn);    %load 1 day of PSD mean logger data

    %data10 = load(name);

    %load c:\data\bao\BAO_CR10\bao10.dat
    %load f:\BAO_CR10\data\bao10.dat

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

    %10m prop vane was on the north boom until Aug 3 ~1600 UTC when it was moved to
    %the south boom
    % N is 154  to correct we add 206 and correct for > 360
    ld = length(data10);

    ct = 0;
    if 0
        for ll = 1:ld
            if data10(ll,3) > 215.814  % check for Year Day (UTC) prop was moved to south boom
                data10(ll,8) = data10(ll,8) + 206; % Prop on south boom correct by 206 degrees
                if data10(ll,8) > 360
                    data10(ll,8) = data10(ll,8) - 360;
                    data10(ll,8);
                end
                ct = ct + 1;
            end
            if data10(ll,3) <= 215.814  % Prop on north boom correct by 26 degrees
                % N is 324  to correct we subtract 26 degs and correct for < 0
                data10(ll,8) = data10(ll,8) - 26;
                if data10(ll,8) < 0
                    data10(ll,8) = data10(ll,8) + 360;
                    data10(ll,8);
                end
                %ll
            end
        end
    end % skip boom change test
    %Total precip
    tp = cumsum(data10(:,11));
    tpin = tp/25.4;
    stp = size(tpin);
    ttpin = tpin(stp(1,1));
    %save total daily precip in an array
    totprecip(ii,1) = data10(1,3);
    totprecip(ii,2) = ttpin;;
    ttpins = num2str(ttpin(1,1));

    if 1  %skip plots
        figure(1)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,5))
        %hold
        %subplot(2,1,1),plot(data50(:,3),data50(:,5),'r')
        %xlabel('Year Day (UTC)')
        ylabel('T (C)')
        title('BAO 2007 10m')
        %axis([110,116,-10,30])
        xlim([jd,jd+1])
        %legend('10m')
        %legend('10m','50m')
        subplot(2,1,2),plot(data10(:,3),data10(:,6))
        %hold
        %subplot(2,1,2),plot(data50(:,3),data50(:,6),'r')
        xlabel('Year Day (UTC)')
        ylabel('Rh (%)')
        %axis([110,116,0,100])
        %legend('10m')
        %legend('10m','50m')
        ylim([0,109])
        xlim([jd,jd+1])
        if pltflg
            print_buffer = [outpath, fn(24:38),'_TRH.jpg'];
            print('-djpeg90 ', print_buffer);
        end


        figure(2)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,7))
        %hold
        %subplot(2,1,1),plot(data50(:,3),data50(:,7),'r')
        xlabel('Year Day (UTC)')
        ylabel('Spd (m/s)')
        title('BAO 2007 10m')
        %axis([110,116,0,30])
        %legend('10m')
        xlim([jd,jd+1])
        %legend('10m','50m')
        subplot(2,1,2),plot(data10(:,3),data10(:,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([jd,jd+1])
        %legend('10m','50m')
        if pltflg
            print_buffer = [outpath, fn(24:38),'_WS.jpg'];
            print('-djpeg90 ', print_buffer);
        end

        figure(3)
        clf
        subplot(2,1,1),plot(data10(:,3),data10(:,10))
        %xlabel('Year Day (UTC)')
        ylabel('Pressure (mb)')
        title('BAO 2007 10m')
        xlim([jd,jd+1])
        %axis([110,116,820,850])
        subplot(2,1,2),plot(data10(:,3),tpin,'r.')
        xlabel('Year Day (UTC)')
        ylabel('Precip (in)')
        xlim([jd,jd+1])
        ylim([0 2.5])
        text(jd+.1,2,'Total (in) = ')
        text(jd+.3,2,ttpins)
        %axis([110,116,0,.5])
        if pltflg
            print_buffer = [outpath, fn(24:38),'_PP.jpg'];
            print('-djpeg90 ', print_buffer);
        end
    end  % skip plots

end % loop through all files
figure(4)
clf
plot(totprecip(:,1),totprecip(:,2),'k*')
hold
plot(totprecip(:,1),totprecip(:,2),'k')
title('BAO daily total precipitation (in)')
        xlabel('Year Day (UTC)')
        ylabel('Precip (in)')
        stot = size(totprecip);
xlim([min(totprecip(:,1)),max(totprecip(stot(1,1),1))])
        if pltflg
            print_buffer = [outpath, fn(24:38),'TP.jpg'];
            print('-djpeg90 ', print_buffer);
        end


save totprecip.dat  totprecip -ascii


