function get_hk_info, times0, mnem0, range=range, list=list, $
	raw_value=raw_value, rec=rec, qstop=qstop, qdebug=qdebug, q2stop=q2stop, $
	timarr=timarr, every=every, nostring=nostring, cleanup=cleanup, $
	exp_pkt=exp_pkt, check_exp=check_exp
;+
;NAME:
;	get_hk_info
;PURPOSE:
;	To return information from the HK database given a time and
;	a mnemonic.  
;SAMPLE CALLING SEQUENCE:
;	info = get_hk_info(times, mnem, /list)
;	info = get_hk_info('16-mar-94 09:00', 'mtopts5')
;	info = get_hk_info(['16-mar-94 5:00', '16-mar-94 14:00'], 'mtopts5')
;	info = get_hk_info(['16-dec-94', '18-dec-94'], ['qtopts1n', 'qtopts2n'])
;	info = get_hk_info(['7-jun-95', '7-jun-95 23:00'], 'mksqref'+strtrim(indgen(6),2),/qdebug, /raw)
;INPUT:
;	times	- A list of the dates/times of interest
;	mnem	- A list of the memonics to return info for
;OPTIONAL KEYWORD INPUT:
;	list	- If set, then the "times" input are a list of times
;		  to find the discrete values for.  Default is a starting
;		  and ending time.
;	every	- Can specify to only return every N values.  This is
;		  useful when specifying a long time range.  It must be
;		  less than 1000.
;	nostring - If set, then do not make the output string type (ie:
;		  do not use lookup table for "mnemonic" -- just send the
;		  raw value).  This only applies to digital mnemonics.
;	cleanup	  - If set, then check the data for only good data (ie: remove
;		    data which is from when the DEP is off).
;OUTPUT:
;	info 	- A floating point array of dimensions
;		  NxM where N is the number of different times requested
;		  and M is the number of mnemoics.
;RESTRICTIONS:
;	* Do not mix mnemonic types unless you are using the /RAW_VALUE switch
;	  (since floating point and string type do not mix well)
;METHOD:
;	An ASCII text file contains the information on where to find the
;	various files.
;HISTORY:
;	Written 23-May-94 by M.Morrison
;	24-May-94 (MDM) - Continued to develop
;	25-May-94 (MDM) - Continued to develop
;	24-Aug-94 (MDM) - Corrected for error when no valid input files
;			  available for requested time
;	12-Jan-95 (MDM) - Added EVERY option
;			- Added access to SC1, SC2, and SC4 database files
;	16-Jan-95 (MDM) - Continued to add access to SC1, SC2 and SC4
;			- Changed to do 1000 records at a time
;	23-Jan-95 (MDM) - Broke into two routines:  GET_HK_INFO and
;			  GET1HK_INFO.  Made GET_HK_INFO derive which packet 
;			  the mnemonic comes from and derive the file names.
;	24-Jan-95 (MDM) - Corrected error in how MAP2PACK was being derived
;	 6-Feb-95 (MDM) - Added /NOSTRING option
;	 7-Jun-95 (MDM) - Added MDI_MDIHK_LOG_DIR to the list of directories
;			  to check for HK database files.
;	28-Jun-95 (MDM) - Patched a bug which was causing the schk database
;			  common variable to get clobbered.
;	29-Jun-95 (MDM) - Added /CLEANUP keyword
;	27-Jul-95 (MDM) - Finished the 28-Jun-95 patch (added correction for
;			  case where there is no data file)
;	 1-Aug-95 (MDM) - Added /NOMORE to debug PRSTR call
;       16-Nov-95 (MDM) - Modified to allow a workaround where the expected
;                         extensions were .schk1,2,3,4 and they were implemented
;                         as sc1,2,3,4
;	21-Nov-95 (MDM) - Modified to handle the fact that the SC HK data is
;			  in a different directory on the EOF system.
;	27-Nov-95 (MDM) - Added /EXP_PKT option to read the emergency experiment
;			  packet
;	 4-Dec-95 (MDM) - Added /CHECK_EXP option to allow concatenation of
;			  MDIHK packet information and EXP packet information
;	 5-Dec-95 (MDM) - Added call to HK_TIME_SORT
;	 9-Oct-96 (MDM) - Expanded to work with TRACE
;			   *********** Major Rewrite ***********************
;	13-Jan-98 (MDM)	- Modified to use the single ASCII file for database definition
;			  (rather than binary database files READ_HIST or RTDB)
;-
;
common hk_dbase_blk1, tlm, alg, dsc, cmd
;
if (n_elements(tlm) eq 0) then rd_egse_hk_txt, tlm, alg, dsc, cmd
;
times = anytim2ints(times0)
qlist = keyword_set(list) or (n_elements(times) ne 2)
;
;----- Derive file names
;
if (qlist) then begin
    days = ex2fid( anytim2ex( times ) )
    days = days(uniq(days))
    ndays = n_elements(days)
    days = fid2ex(days)
end else begin
    ndays = times(1).day - times(0).day + 1
    if (ndays eq 1) then begin
	days = times(0)
	days.time = 0
    end else begin
	days = replicate( anytim2ints([0,0]), ndays )
	days.day = indgen(ndays) + times(0).day
    end
end
;
fids = ex2fid( anytim2ex(days) )
months = strmid(fids, 0, 4)		;YYMM
umonths = months(uniq(months))
fids = strmid(fids, 0, 6)
;
;---- Check mnemonic names out
;
n = n_elements(mnem0)
if (n eq 0) then return, -1
mnem = strlowcase(strtrim(mnem0,2))
ss = where_arr(mnem, tlm.name, /map_ss)
ss2 = where(ss eq -1, nss2)
if (nss2 ne 0) then begin
    print, 'GET_HK_INFO: Unrecognized mnemonic... ' + mnem0(ss2)
    print, '             Full list was: ' + mnem0
    return, [-1]
end
apids = tlm(ss).apid(0)
uapids = apids(uniq(apids, sort(apids)))
;
;---- Read the HK "mapping" file
;
hkmapfil = '$db/trace.hk'			;TODO - generalize
map = rd_tfile(hkmapfil, 6, nocomment='#')
;
;---- Read the HK files
;
str_cmd = '{dummy '
last_dirstr = ''
for iapid=0,n_elements(uapids)-1 do begin
    ss = where(apids eq uapids(iapid))
    mnem2 = mnem(ss)			;the mnemonics which are in the current APID

    ;--- Find out what file to get that data out of

    ss = where(map(0,*) eq uapids(iapid), nss)
    if (nss eq 0) then begin
	print, 'GET_HK_INFO: APID in HK database is not in the HK "mapping" file ' + hkmapfil
	print, '             APID was: ' + uapids(iapid)
	return, -1
    end
    dirstr 	= map(3,ss(0))
    ext 	= map(2,ss(0))
    prefix	= map(1,ss(0))
    if (dirstr ne last_dirstr) then begin
	sdir = str2arr(dirstr)
	for i=0,n_elements(sdir)-1 do if (strmid(sdir(i),0,1) eq '$') then sdir(i) = getenv(strmid(sdir(i),1,99))
	dirs = get_subdirs(sdir(0))
	for i=1,n_elements(sdir)-1 do dirs = [dirs, get_subdirs(sdir(i))]
	last_dirstr = dirstr
    end
    ;
    infil_arr = file_list2(dirs, fids+ext)
    if (infil_arr(0) eq '') then begin
	    print, 'GET_HK_INFO: Cannot find input files: ', fids+ext
	    print, '             In directories: ', dirs
	    cmd = prefix + 'hkv = 0b'
	    stat = execute(cmd)
    end else begin
	    cmd = prefix + 'hkv = get1hk_info(infil_arr, times, mnem2, ' + $
			'list=qlist, every=every, raw_value=raw_value, ' + $
			'qdebug=qdebug, insim=qinsim, err=err, nostring=nostring, ' + $
			'cleanup=cleanup, exp_pkt=exp_pkt, hkmapfil=hkmapfil)'
	    if (keyword_set(qdebug)) then print, cmd
	    stat = execute(cmd)

	    if (err eq 0) then begin
		cmd = 'str_name = tag_names(' + prefix + 'hkv, /structure)'
		stat = execute(cmd) 
		str_cmd = str_cmd + ',' + prefix + ':{' + str_name + '}'
	    end
    end
end
str_cmd = str_cmd + '}'
;
;---- Build the full up output structure
;
out = -1
if (strpos(str_cmd, ':') ne -1) then begin
    out = make_str(str_cmd)
    ii = 0
    tags = tag_names(out)
    for i=0,n_elements(tags)-1 do begin
	cmd = 'out.' + tags(i)  + ' = ' + tags(i) + 'hkv'
	stat = execute(cmd)
	out.(i).code = out.(i).code + ii
	ii = ii + n_elements(out.(i).code)
    end
end
;
if (data_type(out) eq 8) then hk_time_sort, out		;MDM added 5-Dec-95
;
if (keyword_set(qstop)) then stop
return, out
end

