%BAOPLT07
% Plot total precip data from BAO data loggers

clear
outpath  = 'Z:\bao\Tower\Processed_Images\';

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

inpath = 'Z:\bao\Tower\Processed\monthly\';
s1='Z:\bao\Tower\Processed\monthly\BAO.010.2007*.dat';
yy = input('Input the year to process (2007) ','s');
s1(40:43) = yy;
dr=dir(s1);
[n m]=size(dr);
mx=n;
bi = 1;
ei = 0;
for i=1:mx
    ss = [inpath dr(i).name]
    %1    2   3   4     5     6      7      8       9      10        11     12     13    14
    %ID  YR  YD  hhmm  T      RH     WSv   WSs     Dir    WDt       Bat    press  precip WDT
    %10,2007,165,1405,15.095,50.858,1.810,-999.000,238.61,-999.0000,13.515,843.01,0.000,212.610
    %10,2007,165,1406,15.115,50.448,1.692,-999.000,245.47,-999.0000,13.514,842.98,0.000,219.470

    data10 = load(ss);
    sd = size(data10);

    hhmm = data10(:,4);
    hh = fix(hhmm/100);
    mn = hhmm - (hh*100);
    data10(:,3) = data10(:,3) + (((mn/60.) + hh)/24); %Julian day
    clear hhmm hh mm
    sd = size(data10);
    ei = bi + sd(1) - 1;
    pp(bi:ei,:) = data10;
    bi = ei + 1;
    clear data10
end

%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(pp);
jdb = fix(pp(1,3));
jde = fix(pp(ld,3))+1;
%CSD experiment
%jdb = 208;
%jde = 222;
ct = 0;
if 0
    for ll = 1:ld
        if data10(ll,3) > 215.814  % check for Julian Day prop was moved to south boom
            data10(ll,12) = data10(ll,8) + 206; % Prop on south boom correct by 206 degrees
            if data10(ll,12) > 360
                data10(ll,12) = data10(ll,12) - 360;
                data10(ll,12);
            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,12) = data10(ll,8) - 26;
            if data10(ll,12) < 0
                data10(ll,12) = data10(ll,12) + 360;
                data10(ll,12);
            end
            %ll
        end
    end
end % skip boom change test

if 1 %skip plotting

    dd = find(pp(:,3) >= 121);

    %Total precip
    tp = cumsum(pp(dd,13));
    tpin = tp/25.4; % cinver to inches

    figure(1)
    clf
    subplot(2,1,1),plot(pp(:,3),pp(:,13)/25.4)
    title('BAO Precip 2007')
    ylabel('Precip (in)')
    xlim([jdb,jde])
    %axis([110,116,820,850])
    subplot(2,1,2),plot(pp(dd,3),tpin,'r')
    xlabel('Year Day')
    ylabel('Cumulative Precip (in)')
    xlim([jdb,jde])
    elim = max(tpin)+.05;
    ylim([0 elim])
    %axis([110,116,0,.5])
    if pltflg
        print_buffer = [outpath 'BAO_precip.jpg'];
        print('-djpeg90 ', print_buffer);
    end
    
    figure(2)
    clf
    subplot(2,1,1),plot(pp(:,3),pp(:,5))
    title('BAO T RH 2007')
    ylabel('Temp (C)')
    xlim([jdb,jde])
    %axis([110,116,820,850])
    subplot(2,1,2),plot(pp(dd,3),pp(:,6),'r')
    xlabel('Year Day')
    ylabel('RH (%)')
    xlim([jdb,jde])
    %elim = max(tpin)+.05;
    ylim([0 105])
    if pltflg
        print_buffer = [outpath 'BAO_TRH.jpg'];
        print('-djpeg90 ', print_buffer);
    end
    
    figure(3)
    clf
    subplot(2,1,1),plot(pp(:,3),pp(:,7))
    title('BAO Winds 2007')
    ylabel('Speed (m/s)')
    xlim([jdb,jde])
    %axis([110,116,820,850])
    subplot(2,1,2),plot(pp(dd,3),pp(:,14),'r')
    xlabel('Year Day')
    ylabel('Dir (True)')
    xlim([jdb,jde])
    %elim = max(tpin)+.05;
    ylim([0 360])
    %axis([110,116,0,.5])
    if pltflg
        print_buffer = [outpath 'BAO_Wind.jpg'];
        print('-djpeg90 ', print_buffer);
    end
    
    figure(4)
    clf
    plot(pp(:,3),pp(:,12))
    title('BAO Pressure 2007')
    ylabel('Press (mb)')
    xlim([jdb,jde])
    ylim([820 860])
   
    if pltflg
        print_buffer = [outpath 'BAO_Press.jpg'];
        print('-djpeg90 ', print_buffer);
    end
    
end % skip plotting

%save bao10.dat data10 -ascii


