pro ads2att, infil, week=week, run_time=run_time, qdebug=qdebug
;
;+
;NAME:
;	ads2att
;PURPOSE:
;	Driver to call ads_into_att for each input file
;SAMPLE CALLING SEQUENCE:
;	ads2att, week=week
;	ads2att, adsfiles
;OPTIONAL INPUT:
;	infil	- The list of input ADS files
;OPTIONAL KEYWORD INPUT:
;	week	- The week number to process
;OPTIONAL KEYWORD OUTPUT:
;      run_time - Approximate run time of this module in minutes
;HISTORY:
;	Written 11-Aug-93 by M.Morrison (using DO_AIT as starting point)
;	31-Mar-94 (MDM) - Modified logic slightly on finding if there
;			  are ADS files available (because /yd19 has
;			  NFS mount problems a bunch)
;-
;
if (n_elements(infil) eq 0) then begin
    ;week needs to have been passed

    adsdir=adsdirs(week_str=week, /actual, /all)             ; get ads directory for week
    infil = file_list(adsdir, '*')
end
;
run_time = 0.
start_time = systime(1)
;
if n_elements(infil) eq 0 then begin
    print, 'No input files'
    return
end

; determine ads files to process
adsfils=infil
break_file,infil,log,path,adsnames,version
adschk = strtrim(adsnames(0),2)
qcompress = 0
if strpos(adschk,'PSK') ne 0 then begin			; directory passed
    ;zadsfils = findfile(concat_dir(adsfils,'PSK239*Z'))	;MDM added 17-May-93
    zadsfils = file_list(adsfils,'PSK239*Z')			;MDM modified 31-Mar-94
    if (zadsfils(0) ne '') then begin
	qcompress = 1
	print, 'Decompressing ADS files'
	for i=0,n_elements(zadsfils)-1 do spawn, 'uncompress "' + zadsfils(i) + '"'
    end
    
    ;adsfils=findfile(concat_dir(adsfils,'PSK239*'))
    adsfils = file_list(adsfils,'PSK239*')			;MDM modified 31-Mar-94
end

if adsfils(0) eq '' then begin
   message,/info,'No infil available, returning...
endif else begin
   for i=0,n_elements(adsfils)-1 do begin
      message,/info,'Now Processing ADS file:' + adsfils(i)

      ads_into_att, adsfils(i), run_time=run_time0, match_week=week, qdebug=qdebug

      openu, lun, '$DIR_GEN_ADS/do_ads.log', /append, /get_lun    
      printf, lun, i, adsfils(i), '         ' , run_time0, !stime, $
	  format='(1x, i5, a30, 1x, a, 3x, f7.2, 3x, a)'
      free_lun,lun
   endfor
endelse
   
if (qcompress) then for i=0,n_elements(adsfils)-1 do spawn, 'compress "' + adsfils(i) + '"'
end_time = systime(1)
run_time = (end_time-start_time)/60.
print, 'ADS2ATT took ', run_time, ' minutes (for one week?)'
return
end
