%BAOPLT07
% Plot monthly precip data from BAO data loggers

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

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

name = 'Z:\bao\Tower\Processed\monthly\BAO.010.200706.dat';
ym = input('Input year month to process (200710) ','s');
name(40:45) = ym;


%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(name);
    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

%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);
jdb = fix(data10(1,3));
jde = fix(data10(ld,3))+1;
%CSD experiment
%jdb = 208;
%jde = 222;
db = data10;
ct = 0;
if 1
    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
da = data10;
if 1 %skip plotting

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

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


    figure(1)
    clf
    subplot(2,1,1),plot(data10(:,3),data10(:,13)/25.4)
    title(name(32:45))
    ylabel('Precip (in)')
    xlim([jdb,jde])
    %axis([110,116,820,850])
    subplot(2,1,2),plot(data10(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 'BAO10_precip_' ym '.jpg'];
        print('-djpeg90 ', print_buffer);
    end
end % skip plotting

%save bao10.dat data10 -ascii


