;+
; NAME: eis_hk1_temperatures.pro
;
; PURPOSE: To convert status hk1 parameters from telemetered values
;          to engineering values
;      
; CATEGORY:
;
; CALLING SEQUENCE: 
;
; INPUTS: 
;
; KEYWORD PARAMETERS: None
;
; OUTPUTS: 
;
; CALLS:
;
; COMMON BLOCKS: None
;
; PROCEDURE:
;
; RESTRICTIONS: Uses SolarSoft
;
; MODIFICATION HISTORY:
;	03/June/2006 v1.0 mcrw wrote
;       15/Nov/2006  v1.1 mcrw minor corrections
;
;-------------------------------------------------------------------------------------------------

pro icu_temps, files, output, end_time

    icu_1 = eis_convert_hk1_icu1_temp(eis_get_daily_data(files, 'HK1_EIS_ICU_1_TEMP', 4, 1, mx0, mn0, base_time, end_time))
    icu_2 = eis_convert_hk1_icu2_temp(eis_get_daily_data(files, 'HK1_EIS_ICU_2_TEMP', 5, 1, mx1, mn1))

    x = lindgen(n_elements(icu_1)) * 2

; Need to convert the min and max before doing this step
    minr = min([eis_convert_hk1_icu1_temp([mn0]), eis_convert_hk1_icu2_temp([mn1])])
    maxr = max([eis_convert_hk1_icu1_temp([mx0]), eis_convert_hk1_icu2_temp([mx1])])

    cs=1.6

;    window, /free, xsize=1024
;    !p.multi=0
;    utplot, x, htr_a_array, base_time, timerange=[base_time,end_time],yrange=[minr-1,maxr+1],xstyle=2,pstyle=4,title='Htr A', ytitl='Temp. (Deg C)',charsize=cs
;    outplot,x, htr_b_array,color='0000FF'x
;    outplot,x, htr_c_array,color='00FFFF'x

    set_plot,'ps'
    ; Could use encapsulated here
;;;    device,xoff=2.5,yoff=6,xs=16,ys=18,file='/tmp/eis_icu_temps.ps'
    device,xoff=2.5,yoff=6,xs=16,ys=18,file=output+'/eis_icu_temps.ps',/portrait
    !p.multi=[0,1,3]
    utplot, x, icu_1, base_time, timerange=[base_time,end_time],yrange=[minr-1,maxr+1],xstyle=2,pstyle=4, $
      title='ICU 1 Base Plate', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, icu_2, base_time, timerange=[base_time,end_time],yrange=[minr-1,maxr+1],xstyle=2,pstyle=4, $
      title='ICU 2 Top Plate', ytitl='Temp. (Deg C)',charsize=cs
    device,/close
    set_plot,'X'
end

pro sur_temps, files, output, end_time

    htr_a = eis_convert_hk1_htra_temp(eis_get_daily_data(files, 'HK1_EIS_A_HTR_TMP', 1, 1, mx0, mn0, base_time, end_time))
    htr_b = eis_convert_hk1_htrb_temp(eis_get_daily_data(files, 'HK1_EIS_B_HTR_TMP', 2, 1, mx1, mn1))
    htr_c = eis_convert_hk1_htrc_temp(eis_get_daily_data(files, 'HK1_EIS_C_HTR_TMP', 3, 1, mx2, mn2))

    x = lindgen(n_elements(htr_a)) * 2

;    minr = min([mn0, mn1, mn2])
;    maxr = max([mx0, mx1, mx2])

    cs=1.6

;    window, /free, xsize=1024
;    !p.multi=0
;    utplot, x, htr_a_array, base_time, timerange=[base_time,end_time],yrange=[minr-1,maxr+1],xstyle=2,pstyle=4,title='Htr A', ytitl='Temp. (Deg C)',charsize=cs
;    outplot,x, htr_b_array,color='0000FF'x
;    outplot,x, htr_c_array,color='00FFFF'x

    set_plot,'ps'
    ; Could use encapsulated here
;;;    device,xoff=2.5,yoff=6,xs=16,ys=18,file='/tmp/eis_sur_temps.ps'
    device,xoff=2.5,yoff=6,xs=16,ys=18,file=output+'/eis_sur_temps.ps'
    !p.multi=[0,1,3]
    utplot, x, htr_a, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='SUS A MIR', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, htr_b, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='SUS B GRA', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, htr_c, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='SUS C MIR', ytitl='Temp. (Deg C)',charsize=cs
    device,/close
    set_plot,'X'
end

pro str_temps, files, output, end_time

    str_1 = eis_convert_hk1_str1_temp(eis_get_daily_data(files, 'HK1_EIS_STR_1_TEMP',  6, 1, mx0, mn0, base_time, end_time))
    str_2 = eis_convert_hk1_str2_temp(eis_get_daily_data(files, 'HK1_EIS_STR_2_TEMP',  7, 1, mx1, mn1))
    str_3 = eis_convert_hk1_str3_temp(eis_get_daily_data(files, 'HK1_EIS_STR_3_TEMP',  8, 1, mx2, mn2))
    str_4 = eis_convert_hk1_str4_temp(eis_get_daily_data(files, 'HK1_EIS_STR_4_TEMP',  9, 1, mx3, mn3))
    str_5 = eis_convert_hk1_str5_temp(eis_get_daily_data(files, 'HK1_EIS_STR_5_TEMP', 10, 1, mx4, mn4))
    str_6 = eis_convert_hk1_str6_temp(eis_get_daily_data(files, 'HK1_EIS_STR_6_TEMP', 11, 1, mx5, mn5))
    str_7 = eis_convert_hk1_str7_temp(eis_get_daily_data(files, 'HK1_EIS_STR_7_TEMP', 12, 1, mx6, mn6))

    x = lindgen(n_elements(str_1)) * 2

    minr = min([mn0, mn1, mn2,mn3,mn4,mn5,mn6])
    maxr = max([mx0, mx1, mx2,mx3,mx4,mx5,mx6])

    cs=1.6

;    window, /free, xsize=1024
;    !p.multi=0
;    utplot, x, htr_a_array, base_time, timerange=[base_time,end_time],yrange=[minr-1,maxr+1],xstyle=2,pstyle=4,title='Htr A', ytitl='Temp. (Deg C)',charsize=cs
;    outplot,x, htr_b_array,color='0000FF'x
;    outplot,x, htr_c_array,color='00FFFF'x

    set_plot,'ps'
    ; Could use encapsulated here
;;;    device,xoff=2.5,yoff=6,xs=16,ys=18,file='/tmp/eis_str_temps.ps'
    device,xoff=2.5,yoff=6,xs=16,ys=18,file=output+'/eis_str_temps.ps'
    !p.multi=[0,1,3]
    utplot, x, str_1, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 1 Outer Door HOPS', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_2, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 2 Inner Door HOPS', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_3, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 3 Door Front', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_4, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 4 Particle Shield', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_5, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 5 ROE Thermal Shield', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_6, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 6 ROE Box', ytitl='Temp. (Deg C)',charsize=cs
    utplot, x, str_7, base_time, timerange=[base_time,end_time],xstyle=2,pstyle=4, $
      title='Str 7 MHC Ref Foot', ytitl='Temp. (Deg C)',charsize=cs

    device,/close
    set_plot,'X'

end


pro eis_hk1_temperatures, dir, output, end_time

    ;dir = '/tmp/'
    files = findfile(dir + 'eis_hk1_*fits', count=count)
    if count eq 0 then begin
        print, 'No files'
        return
    endif
    
    icu_temps, files, output, end_time
    sur_temps, files, output, end_time
    str_temps, files, output, end_time
    
    !p.multi=0
end
