pro pr_hk_info, outfil, qdebug=qdebug, infil=infil, insim=insim, long=long, $
		summary_type=summary_type, format_sample=format_sample, $
		noheader=noheader
;+
;NAME:
;	pr_hk_info
;PURPOSE:
;	To display information on the MDI Housekeeping mnemonics
;SAMPLE CALLING SEQUENCE:
;	pr_hk_info
;	pr_hk_info, 'pr_hk_info.txt'
;	pr_hk_info, outfil
;INPUT:
;	outfil	- Optional output file to write to
;HISTORY:
; V1.0	Feb-94 by M.Morrison
; V2.0	15-Jul-94 (MDM) - Added information on mnemonic type (A, D, or R)
;			- Added info on total number of bits of data
;			- Added info on which HK summary file the info goes in
; V2.1	16-Jan-95 (MDM) - Added INFIL option
; V3.0	24-Jan-95 (MDM) - Added INSIM and LONG option
; V3.1	 6-Feb-95 (MDM) - Modified LONG option output format
; V4.0	 9-Oct-96 (MDM) - Modified to work with TRACE
; V4.1	13-Nov-96 (MDM) - Modified to work with TRACE or MDI
;			- Made summary type optional
;			- Added /format_sample (for TRACE)
; V4.2	21-Nov-96 (MDM) - Added /NOHEADER
; V4.3	14-Mar-97 (MDM) - Added two more packet types ('SC0A', 'SC0B')
; V5.0	 6-Jan-99 (MDM) - Scapped and modified to use SMEX ascii database
;			  definition file (rd_egse_hk_txt) rather than
;			  RTDB binary file (convert_hk)
;			- Changed the name length format to be 12 (instead of 10)
;-
;
common hk_dbase_blk1, tlm, alg, dsc, cmd
;
if (n_elements(tlm) eq 0) then rd_egse_hk_txt, tlm, alg, dsc, cmd
;
;;ss = where(is_number(tlm.apid(0)))	;exclude IPB and FDB and DPH
;;tlm = tlm(ss)
;
qoutfil = 0
if (n_elements(outfil) ne 0) then begin
    qoutfil = 1
    openw, lun, outfil, /get_lun
    if (not keyword_set(noheader)) then begin
	printf, lun, 'PR_HK_INFO.PRO   Ver 5.0
	printf, lun, ' '
    end
end
;            0    1    2    3    4    5    6    7    8]
;type_arr =['?', 'A', 'D', '?', '?', '?', '?', '?', 'R']
type_arr = ['?', '?', '?', '?', '?', '?', '?', '?', '?']
nam = tlm.name
descr = tlm.descr
hk_sum_num = '???'
sum_type = '????'
;
for i=0,n_elements(nam)-1 do begin
    nam0 = nam(i)
    type = '-'

    conv = tlm(i).conv
    conv_code = tlm(i).conv_code

    which = strtrim(tlm(i).apid(0))
    ;
    nbit = tlm(i).nbit
    stbit = tlm(i).stbyte(0)
    maskp = 2L^nbit-1
    if (tlm(i).stbit ne 0) then maskp = ishft(maskp, tlm(i).stbit)
    maskp = maskp<255
    ;
    fmt = '(1x, a12, 1x, a1, 1x, a36, a7, i5, "/", z2.2, i4, 2x)
    str = string(nam0+'         ', type, descr(i), which, stbit, maskp, $
			nbit, format=fmt)
    if (keyword_set(summary_type)) then str = str + string(sum_type(i), format='(a14)')
    if (keyword_set(format_sample)) then begin
	if (n_elements(rec) eq 0) then rec = bytarr(1500)
	val = gtt_mnem(rec, nam0, 'HK')
	case (data_type(val)) of
	    7:    str = str + '  (a8)'
	    4:    str = str + '  (f7.2)'
	    5:    str = str + '  (f7.2)'
	    else: str = str + '  (i5)'
	endcase
    end
    if (keyword_set(long)) then begin
	;no longer available after 6-Jan-99
    end
    if (keyword_set(qdebug)) then str = string(i, format='(i4)') + str
    print, str
    if (qoutfil) then printf, lun, str
end
;
if (qoutfil) then free_lun, lun
end
