%rd_lights
% Plot light status file from BAO

clear
close all

dt=input('Input yearmonthday (ex:20090128) ', 's');


outpath  = 'Z:\bao\Tower\Lights\images\';

doplot = 1;  % do the plot 1=yes 0=no
pngflg = 1;  % save data to png's flag  1= yes 0 = no

%Z:\bao\Tower\Lights\Data\tower_lights.20090128.dat
nameL =   ['Z:\bao\Tower\Raw\' dt '\tower_lights_' dt '.dat'];


ii = 0;

%1    2   3   4     5     6    7   8     9     10     11    12    13    14
%ID  YR  YD  hhmm  L1   L2    L3   L4    L5    L6     L7    L8    L9   Bat
%12,2009,8,1731,-.413,-.446,-.392,-.432,-.398,-.453,-.389,-.451,-.361,13.7
%12,2009,8,1741,-.413,-.446,-.392,-.433,-.397,-.453,-.389,-.451,-.361,13.66
%12,2009,8,1751,-.413,-.446,-.391,-.433,-.397,-.453,-.388,-.452,-.36,13.63

fid100 = fopen( nameL );
data100 = load(nameL);


fprintf(1,'%s\n',nameL);

nmax = 2880;
year = zeros(1,nmax);
month = zeros(1,nmax);
day = zeros(1,nmax);
hour = zeros(1,nmax);
minute = zeros(1,nmax);
sec = zeros(1,nmax);
yday = zeros(1,nmax);
bao100 = zeros( nmax, 15);


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

ld = length(data100);
jdb = fix(data100(1,3));
jde = fix(data100(ld,3))+1;

if doplot %skip plotting

    figure(1)
    clf
    subplot(3,1,1),plot(data100(:,3),data100(:,5:7))
    ylim([-2 2])
    %xlim([16,21])
    ylabel('Volts')
    title('BAO Tower Lights Status');

    legend('1','2','3','Location','BestOutside');
    subplot(3,1,2),plot(data100(:,3),data100(:,8:10))
    ylim([-2 2])
    ylabel('Volts')
    %xlim([16,21])
    legend('4','5','6','Location','BestOutside');
    subplot(3,1,3),plot(data100(:,3),data100(:,11:13))
    ylim([-2 2])
    ylabel('Volts')
    xlabel('Year Day (UTC)');
    %xlim([16,21])
    legend('7','8','9','Location','BestOutside');
    ll = length(data100);
    jd =  fix(data100(ll,3));
    jds = num2str(jd);
    if pngflg
        print_buffer = [outpath 'Lights_' dt '_WS.png'];
        print('-dpng ', print_buffer);
    end

end % skip plotting

