;pro return_slope_params
;
;PURPOSE:
;	To return the parameters necessary to do a slope fit.  These consist
;	of the time at each read, the number of reads, the number of drop, etc.
;
;INPUTS:
;	FitsHeader - The header that contains the keywords for the given slope
;
;OUTPUTS:
;       ct - A structure that contains the following
;
;	Filter   = The filter used for the exposure
;	NumReads = The number of groups in the ramp
;	SamplesPerRead = The number of reads per group
;	NDrops	   = The number of frames dropped between groups
;	ExposureTime   = The total exposure time
;	GroupFactor	   = The total number of ramps (default 1)
;	NumFrames	   = The total number of reads in the ramp
;	NumGroups	   = The total number of reads in all ramps
;	GroupEnds	   = The ending value for each group
;	ReadTimes	   = The time at which each frame started
;	OverTimes 	   = NaN if read time is greater than exposure time
;	GroupTimes	   = The mean value of the time for a given read

function Return_Slope_Params_1RG, FitsHeader

  ;Get axes and keywords related to the ramp sequence
  Naxis1           =  long(SxPar(FitsHeader, 'NAXIS1'))
  Naxis2           =  long(SxPar(FitsHeader, 'NAXIS2'))
  TotalReads       =  long(SxPar(FitsHeader, 'NAXIS3'))
  Filter           =       SxPar(FitsHeader, 'FILTER')
  NumReads         =   Fix(Sxpar(FitsHeader, 'NREADS'))
  NumGroups	   =   Fix(Sxpar(FitsHeader, 'NGROUPS'))
  Numdrops         =   Fix(Sxpar(FitsHeader, 'NDROPS'))
  DetTemp          = float(Sxpar(FitsHeader, 'MOLYTABL'))
  
  ; Measured on the oscilloscope and with the counter implementation
  FrameTime = 0.71
  ExposureTime     = FrameTime*((NumDrops+NumReads)*NumGroups-NumDrops)

  ; Find out how many frame groups there are
  NumFrames = Numreads * NumGroups
  
  ; Create an array containing the time for each group of reads
  ReadTimes = FrameTime*(Indgen(NumReads*NumGroups) + $
              (Indgen(NumReads*NumGroups)/NumReads * NumDrops))
 
  ; If groupfactor > 1 and the last group isn't completely filled
  ; (i.e., the number of reads in the exposure is not evenly
  ; divisible by the groupfactor), the readtimes array will contain
  ; exposure times for reads that aren't present because it assumes that
  ; all groups contain the same number of reads.  Mark these invalid
  ; exposure times as NaN so they can be ignored in processing.
  Overtimes = where(Readtimes gt ExposureTime)
  if (Overtimes[0] ne -1) then $
	ReadTimes[OverTimes] = !values.f_nan

  ; Make an array to hold the exposure times for each group.  Each
  ; element is the mean value of the exposure times of the reads
  ; contained in the group.
  Grouptimes = fltarr(NumFrames)
  For GroupNum = 0, NumFrames - 1 do begin
        GroupTimes[GroupNum] = ReadTimes(GroupNum)
  EndFor

  ;The structure that will be returned
  SlopeStr  = { $
            Filter: 		Filter,       $
	    FrameTime:		FrameTime,    $
            NumReads: 		NumReads,     $
            NumDrops: 		NumDrops,     $
            DetTemp: 		DetTemp,      $
            ExposureTime: 	ExposureTime, $
            NumFrames: 		NumFrames,    $
            NumGroups: 		NumGroups,    $
            ReadTimes: 		ReadTimes,    $
            OverTimes: 		OverTimes,    $
            GroupTimes: 	GroupTimes    $
           }
 
  return, SlopeStr

End
