;+
; Name: lat_get_gtis
; 
; Purpose: Retrieve Good Time Intervals (GTI) from a LAT LC or spectrum file
; 
; Calling Sequence:
;   gtis = lat_get_gtis(file=file)
;    
; Input Keywords:
;   file - Name of spectrum file containing GTI information
;  
; Output Keywords:
;   None
; 
; Output: Returns the Good Time intervals as a [2,n] array of start/end times in sec. since 1979/1/1
;   
; Examples:
; gtis = lat_get_gtis(file=lat_spectrum_20120304_20120311.fits)
; ptim,gtis[*,0:5]  ; prints the first 6 start/end values in ASCII format
;  
; Kim Tolbert, 6-Nov-2012
; Modifications:
;   31-Jan-2014, Kim.  Find extension number for GTI so can use on LC as well as spectrum files
; 
;-

function lat_get_gtis, file=file_in

checkvar, file_in, '/data/fermi/lat/2012/03/07/lat_spectrum_20120307.fits'

file = file_in
nfile = n_elements(file)

if nfile gt 1 then file = file[sort(file)]
for i=0,nfile-1 do begin

  extno = get_fits_extno(file[i], 'GTI')

  gti = mrdfits(file[i],extno,/dscale)

  stimes = append_arr(stimes, fermi_met2tim(gti.start))
  etimes = append_arr(etimes, fermi_met2tim(gti.stop))  
  
endfor

gtis = transpose([[stimes],[etimes]])
return, gtis
end
