function [] = his_hk_plots(print_flag,filedate)
%
%       function [] = his_hk_plots(print_flag,filedate)
%
%   ....Creates plots of the HIS housekeeping data that are normally placed in the flight 
%       data log book.
%
%       Written by Von P. Walden
%                  15 May 1998
%

%
%   ....Sets hardwired directory structure.
%
direc = 'd:\fireiii\data\HIS\';    % This line is changed depending on the dir structure.
direc = [direc,'ac',num2str(filedate),'\'];

%
%   ....Reads data from BL2 housekeeping file.
%
[hdr1,BL1,hdr2,BL2,hdr3,BL3] = read_his_hk_files([direc,num2str(filedate)]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BL3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plot(BL3.record_number3,BL3.mirror_position)
axis([min(BL3.record_number3) max(BL3.record_number3) 0 8])
xlabel('record number3')
ylabel('Mirror position index')
title(['HIS mirror position: ',num2str(filedate)])
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'mirror_pos_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(BL3.record_number3,BL3.misalignment,'b',BL3.record_number3,BL3.overflow+0.5,'r')
axis([min(BL3.record_number3) max(BL3.record_number3) 0 1.5])
xlabel('record number3')
ylabel('Alignment State')
h = text(max(BL3.record_number3)*0.8,1.25,'Overflow');
set(h,'color','r');
h = text(max(BL3.record_number3)*0.15,1.10,'Misalignment');
set(h,'color','b')
title(['HIS Alignment and Overflow: ',num2str(filedate)])
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'misalignment_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BL1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
%   ....Matlab serial time
%
tmpstr = num2str(filedate);
YY = str2num(tmpstr(1:2));
MM = str2num(tmpstr(3:4));
DD = str2num(tmpstr(5:6));
bday = find(BL1.time >= BL1.time(1));
eday = find(BL1.time < BL1.time(1));
mtime = [datenum(YY+1900,MM,DD)+BL1.time(bday)/24 datenum(YY+1900,MM,DD+1)+BL1.time(eday)/24];

cbb_offset = 52;
plot(mtime,BL1.hot_BB_temperature,'r',mtime,BL1.cold_BB_temperature+cbb_offset,'b')
axis([min(get(gca,'Xtick')) max(get(gca,'Xtick')) 18 33])
datetick('x',13);
xlabel('time (hh:mm:ss)')
ylabel('Temperature (deg C)')
title(['Blackbody Temperatures: ',num2str(filedate)])
h = text(mtime(length(mtime)/2),27,'HBB Temp.');
set(h,'color','r');
h = text(mtime(length(mtime)/2),25,'CBB Temp.');
set(h,'color','b');
h = text(mtime(length(mtime)/2),24,'(+52 C Offset)');
set(h,'color','b');
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'BBplot2_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL1.hot_BB_temperature,'r',mtime,BL1.cold_BB_temperature,'b')
axis([min(get(gca,'Xtick')) max(get(gca,'Xtick')) -35 45])
datetick('x',13);
xlabel('time (hh:mm:ss)')
ylabel('Temperature (deg C)')
title(['Blackbody Temperatures: ',num2str(filedate)])
h = text(mtime(length(mtime)/2),mean(BL1.hot_BB_temperature)+2,'HBB Temp.');
set(h,'color','r');
h = text(mtime(length(mtime)/2),mean(BL1.cold_BB_temperature)+2,'CBB Temp.');
set(h,'color','b');
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'BBplot1_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BL2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
%   ....Matlab serial time
%
tmpstr = num2str(filedate);
YY = str2num(tmpstr(1:2));
MM = str2num(tmpstr(3:4));
DD = str2num(tmpstr(5:6));
bday = find(BL2.time2 >= BL2.time2(1));
eday = find(BL2.time2 < BL2.time2(1));
mtime = [datenum(YY+1900,MM,DD)+BL2.time2(bday)/24 datenum(YY+1900,MM,DD+1)+BL2.time2(eday)/24];

plot(mtime,BL2.laser_temperature,'r',mtime,BL2.scam_enclosure_temperature,'b',mtime,BL2.power_supply_temperature,'g',mtime,BL2.bomem_power_supply_temperature,'m',mtime,BL2.recorder_drive_temperature,'c')
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Temperature (K)')
title(['HIS Electronics Temperatures: ',num2str(filedate)]);
h = text(mtime(1),max(get(gca,'Ytick'))*0.975,'Laser');
set(h,'color','r');
h = text(mtime(1),max(get(gca,'Ytick'))*0.950,'SCAM');
set(h,'color','b');
h = text(mtime(1),max(get(gca,'Ytick'))*0.925,'UW Power');
set(h,'color','g');
h = text(mtime(1),max(get(gca,'Ytick'))*0.900,'Bomem Power');
set(h,'color','m');
h = text(mtime(1),max(get(gca,'Ytick'))*0.875,'Recorder Drive');
set(h,'color','c');
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'electronicsT_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL2.beamsplitter_temperature,'r',mtime,BL2.dewar_window_temperature,'b',mtime,BL2.pod_inside_air_temperature,'g',mtime,BL2.blackbody_heatsink_temperature,'m',mtime,BL2.optics_mirror_temperature,'c',mtime,BL2.optics_bench_temperature,'k')
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Temperature (K)')
title(['HIS Optics Temperatures: ',num2str(filedate)]);
h = text(mtime(1),max(get(gca,'Ytick'))*0.975,'Beamsplitter');
set(h,'color','r');
h = text(mtime(1),max(get(gca,'Ytick'))*0.95,'Dewar Window');
set(h,'color','b');
h = text(mtime(1),max(get(gca,'Ytick'))*0.925,'Pod Air');
set(h,'color','g');
h = text(mtime(1),max(get(gca,'Ytick'))*0.900,'BB heatsink');
set(h,'color','m');
h = text(mtime(1),max(get(gca,'Ytick'))*0.875,'Mirror');
set(h,'color','c');
h = text(mtime(1),max(get(gca,'Ytick'))*0.850,'Optics Bench');
set(h,'color','k');
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'opticsT_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL2.dewar1_temperature)
axis([min(get(gca,'Xtick')) max(get(gca,'Xtick')) 5 6])
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Temperature (K)')
title(['HIS Dewar Temperature: ',num2str(filedate)]);
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'dewarT_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL2.atmospheric_pressure)
axis([min(get(gca,'Xtick')) max(get(gca,'Xtick')) -25 2000])
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Pressure (mb)')
title(['HIS Atmospheric Pressure: ',num2str(filedate)]);
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'pressure_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL2.record_number2)
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Record Number')
title(['HIS Record Number: ',num2str(filedate),'  (Normal = 240 Recs./Min.)']);
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'recnum_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end

plot(mtime,BL2.detector1_output_DC_level,'r',mtime,BL2.detector2_output_DC_level,'g',mtime,BL2.detector3_output_DC_level,'b')
datetick('x',13);
xlabel('time2 (hh:mm:ss)')
ylabel('Voltage (volts)')
h = text(mtime(length(mtime)/2),mean(BL2.detector1_output_DC_level)-0.3,'Detector #1');
set(h,'color','r');
h = text(mtime(length(mtime)/2),mean(BL2.detector2_output_DC_level)-0.3,'Detector #2');
set(h,'color','g');
h = text(mtime(length(mtime)/2),mean(BL2.detector3_output_DC_level)-0.3,'Detector #3');
set(h,'color','b');
title(['HIS DC Detector Output Levels: ',num2str(filedate)])
set(gcf,'PaperPositionMode','auto');
eval(['print -djpeg ',direc,'DClevels_',num2str(filedate),'.jpg']);
if print_flag print -dwinc; end


