##^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009
##ReturnFileList_HxRG.py
## 
##PURPOSE: 
##  To return a list of the files that match up with a combination o f
##  keywords for the data taken from the HxRGs.
##
##INPUTS: 
##      DetStr       - 'H1RG-022','H2RG-32-147', or 'H4RG-10-007' 
##      ElecSt       - 'ASIC' or 'LEACH'
##      Date         - A string containing the date in the path (ex. '07Nov16')
##      ObjectName   - A string containing the name of the object under study
##      Filter       - A string designating the filter used: 'G,I,Y'
##      NReads       - A string with the number of reads in the dark images
##
##KEYWORDS:
##      FirstFile: int 
##          The index of the first read to be plotted (starting at zero)
##      LastFile: int
##          The index of the last read to be plotted
##
##EXAMPLE CALLING SEQUENCE:
##  import ReturnFileList_HxRG; reload(ReturnFileList_HxRG); from ReturnFileList_HxRG import *
##
##
from HxRG_Class import *
from strip_scf import *
import pdb

def ReturnFileList_HxRG(DetStr, ElecStr, Date, ObjectName, Filter, NReads, \
                   FirstFile=0, LastFile=0):

  #Form the class that will contain the necessary info
  HxRG = HxRG_C(DetStr=DetStr, ElecStr=ElecStr, ObjectName=ObjectName, \
                Filter=Filter, Date=Date, NReads=NReads)

  ##FIND THE FILES THAT MATCH THE SEQUENCE IN MIND AND ORDER THEM BY TIME
  if HxRG.DetStr != 'H4RG-10-007':
    SearchStr    = HxRG.RawObjectDir+HxRG.ObjectName+'*_'\
                   +HxRG.Filter+'_*'+str(NReads)+'_Reads_*.fits'
    FitsFiles    = sort_files_by_date(HxRG.RawObjectDir+HxRG.ObjectName+'*_'\
                                +HxRG.Filter+'_*'+str(NReads)+'_Reads_*.fits')
  else:
    SearchStr    = HxRG.RawObjectDir+HxRG.ObjectName+'*_'\
                   +str(NReads)+'_Reads_*.fits'
    FitsFiles    = sort_files_by_date(HxRG.RawObjectDir+HxRG.ObjectName+'*_'\
                                  +str(NReads)+'_Reads_*.fits')

  pdb.set_trace()
  ##SELECT ONLY THE ONES NEEDED
  if LastFile  == 0 : LastFile = len(FitsFiles)
  FitsFiles    = SortFilesByTime(FitsFiles)
  NumFitsFiles = LastFile-FirstFile
  FitsFiles    = FitsFiles[FirstFile:LastFile]

  return FitsFiles



