function sel_qs, struct, intim
;
;+
;Name:
;	Sel_QS
;Purpose:
;	Given a time, return the indicie for the QS that was valid
;	for that time.
;Input:
;	struct	- The QS structure to find the valid time for
;	intim   - A structure that has .TIME and .DAY fields
;Output:
;	Subscript of the QS record that should be used.  If there
;	is no record with a valid time range, a -1 is returned.
;Example:
;	ss = sel_qs(qs.instr, index(10).gen)
;	ss = sel_qs(qs.instr, roadmap(1000))
;	ss = sel_qs(qs.general1, roadmap)
;History:
;	Written Fall '91 by M.Morrison
;-
;
qdebug = 0
s_day = 86400
n = n_elements(struct)
nn = n_elements(intim)
out = intarr(nn)-1
;
for j=0,nn-1 do begin
    for i=0,n-1 do begin
        ;diff is positive if STRUCT time is LATER than input time
        diff1 = (struct(i).st_day - intim(j).day)*s_day + (struct(i).st_time - intim(j).time)/1000
        ;---- want diff1 to be negative (start time BEFORE input time)
        diff2 = (struct(i).en_day - intim(j).day)*s_day + (struct(i).en_time - intim(j).time)/1000
        ;---- want diff2 to be positive (end time AFTER input time)
        ;
        if ((diff1 le 0) and (diff2 ge 0)) then out(j) = i
        if (qdebug) then print, diff1, diff2
        if (qdebug) then print, intim.time, intim.day
    end
end
;TODO - change to "vectorize"
;
if (nn eq 1) then out=out(0)	;convert to scaler
return, out
;
end
