;+
; NAME:
;       BCS_TVEC
; PURPOSE:
;       Extracts start time of BCS spectra and returns times that correspond
;       to the mid time of the integration.
; CATEGORY:
; CALLING SEQUENCE:
;       time = tvec(item)
;       time = tvec(item,ista,istp)
; INPUTS:
;       item    Normal yodat produced item, or selected part thereof
; OPTIONAL INPUT PARAMETERS:
;       ista    start item in array if needed
;       istp    stop item in array if needed
; KEYWORD PARAMETERS:
;       rel     if present, output vector is relative to start time
; OUTPUTS:
;       Vector of time, corrected for bcs spectral integration time
; COMMON BLOCKS:
;       none
; SIDE EFFECTS:
; RESTRICTIONS:
; PROCEDURE:
; MODIFICATION HISTORY:
;       RDB  19-Oct-93  Written
;       RDB  25-Jan-94  Corrected error in flag name
;       RDB   2-Sep-94  Extract dgi according to structure type (Corr)
;-

function bcs_tvec,item,ista,istp,rel=rel


if n_params() eq 1 then begin
  ista = 0
  istp = n_elements(item)-1
endif


;       calculate the offset to mid point of the integration
tags = tag_names(item)
case tags(0) of
'GEN':  begin & dgi = item.bcs.dgi & end
else:   begin & dgi = item.dgi     & end
endcase
tvec_corr = dgi(ista:istp)*0.125/2.           ;mid point


if keyword_set(rel) then begin
;       need to derive a time vector for plot
  tt = anytim2ints(item)

  ttstart = tt(ista).time + (tt(ista).day - tt(0).day)*86400L*1000L
  ttime = tt.time + (tt.day - tt(0).day)*86400L*1000L

  tvec = (ttime(ista:istp) - ttstart)/1000.    ;secs
  tvec = tvec + tvec_corr
  ;;tvec = tvec + lsta

  return, tvec
endif


tvec = anytim2ints(item(ista:istp),offset=tvec_corr)
return,tvec

end
