;pro form_dither_list_1rg
;
;PURPOSE:
;  To create a file that can be used with dither_slope_median_1rg.  This file
;  contains all of the filenames that will be included in the mosaic along with
;  an approximation of offsets of each of the files from the others
;
;KEYWORDS:
;  OBJECTDIR:
;	 The directory where the files are located.  The default is the current
;	 working directory
;  ELECTRONICS:
;	 0 - ASIC files
;	 1 - LEACH files
;CALLING SEQUENCE:
;	 form_dither_list_2RG, 'Orion*Ifilter_15_1_0*FlatFielded*','IDitheredSlopes.lst',electronics=1
;	 form_dither_list_2RG, 'Orion*Yfilter_30_1_0*FlatFielded*','YDitheredSlopes.lst',electronics=1
;
;NOTES:
;    Must be in directory containing the files in order for this to work
;
pro form_dither_list_2rg, ObjectText, OutName, ObjectDir = ObjectDir, $
	Electronics = Electronics

  If N_Elements(ObjectDir) 	 eq 0 then ObjectDir 	= '.'
  If N_Elements(Electronics) eq 0 then Electronics  = 0
  Path_Delim = Path_Sep()

  Common KeyParams, KeyStr

  ;Get all of the defaults for the keywords from the KeywordStruct file
  @KeywordStruct_2RG.pro

  ;Get the files that should be used in the dither
  DitherFiles = File_Search(ObjectDir+Path_Delim+ObjectText+'*', /fully_qualify_path)
  DitherFiles = DitherFiles(sort(DitherFiles))
  NumDitherFiles = N_Elements(DitherFiles)

  ;Get the file handle for the output file
  Get_Lun, OutFile
  OpenW, OutFile, ObjectDir+Path_Delim+OutName

  If Electronics eq 0 then begin

  EndIf Else Begin
    RAOffset   = [-20., -20., -20., 0., 0., 0., 20., 20., 20.]
    DECOffset  = [-20., 0.  , 20. , -20., 0, 20., -20., 0, 20.]
    RAMin	   = 20*(1./KeyStr.PlateScale)
    DECMin	   = 20*(1./KeyStr.PlateScale)
	RADECMatch = 0
    For FileNum = 0, NumDitherFiles -1 do begin
        RADECStr = Strtrim(Long(RAOffset(RADECMatch)),2)+'_'+$
        		   Strtrim(Long(DECOffset(RADECMatch)),2)+'_VSUB'
        If not stregex(DitherFiles(FileNum), RADECStr, /boolean) then RADECMatch+=1
        RAOff  = -((1./KeyStr.PlateScale)*RAOffset(RADECMatch)+RAMin)
        DECOff = -((1./KeyStr.PlateScale)*DECOffset(RADECMatch)+DECMin)
        printf, OutFile, DitherFiles(FileNum), DECOff, RAOff, format='(A, I, I)'
    EndFor
  EndElse

  ;Close the file and free the handle
  Close, OutFile
  Free_Lun, OutFile
  stop
end
