;+
; NAME:
;	HXT_PRESTORE
; PURPOSE:
;	Obtain time tags at the midpoint of HXT data accumulation intervals. 
;       See p.71 of SOLAR-A Jikken-Keikaku-Syo for a reference.
; CALLING SEQUENCE:
;       pre = hxt_prestore(index)
;       pre = hxt_prestore(index,/ser)
;		pre has the form of pre = fltarr(4,[No. of Major Frames])
; INPUT:
;       index   - HXT index
; OPTIONAL KEYWORD INPUT:
;       hxa     - If set, end time for HXA data accumulation is returned. 
;	ser	- If set, the output will be 
;		  pre = fltarr(4*[No. of Major Frames])
;	endtime - If set, end time of data accumulation is given. 
; OUTPUT:
;	Mid-time of HXT data accumulation, in units of second.
;	Note that data corresponds to the first quarter of index(0) was 
;	obtained pre(0,0) sec prior to the time shown by 
;	gt_time(index(0),/str). 
; RESTRICTIONS:
;       Not yet prepared for HXT CAL data.
; HISTORY:
;       Written by T.Sakao on 30 June 1993
;	version 1.1		93.12.29 (Wed)
;	  Time tag was changed so that it corresponds to the midpoint of data 
;	  accumulation interval.
;-
;
;
function hxt_prestore, index, endtime=endtime, hxa=hxa, ser=ser
  n_index = n_elements(index)
  off_arr = fltarr(4,n_index)

  high  = 4  &  medium =  2
  flare = 9  &  quiet  = 13

  rate = gt_dp_rate(index)
  mode = gt_dp_mode(index)

  if not keyword_set(hxa) then begin   ; Time tag for count data (i.e. not HXA)
    if keyword_set(endtime) then begin  
				    ; Time tag at the end of data accumulation.
      off_arr(*,*) = 4.5            ; Set QT-H value as default. 
      sbt4 = where(rate eq high and mode eq flare,count) 
       				    ; HXT CAL case not considered.
      if count gt 0 then off_arr(*,sbt4)  = 4.0

    endif else begin                           ; Default time tag.
      off_arr(*,*) = 5.5                       ; Set QT-H value as default.
      fl_h = where(rate eq high and mode eq flare,fl_h_count)     ; FL-H
      fl_m = where(rate eq medium and mode eq flare,fl_m_count)   ; FL-M
      dhk_m = where(rate eq medium and mode ne flare,dhk_m_count) ; QT-M
      if fl_h_count  gt 0 then off_arr(*,fl_h)  =  4.25
      if fl_m_count  gt 0 then off_arr(*,fl_m)  =  6.5
      if dhk_m_count gt 0 then off_arr(*,dhk_m) = 12.5
    endelse
  endif else begin
    off_arr(*,*) = 0.0
    hi  = where(rate eq high,hcount)
    med = where(rate eq medium,mcount)
    if hcount gt 0 then off_arr(*,hi)  = 1.0
    if mcount gt 0 then off_arr(*,med) = 8.0
  endelse

  if keyword_set(ser) then off_arr = frame2serial(off_arr)

  return, off_arr
end

