function get_subarr2,start_tim,end_tim,ref_tim,ys=ys,zs=zs, $
  dirs=dirs,pdata=pdata,outfil=outfil

start_time = systime(1)
run_time = 0.
progVerNo = 1.000*1000
progName = 'GET_SUBARR2.PRO'

; Diagnostic variables:
qprint = 1
qdebug = 1

if n_elements(dirs) eq 0 then dirs = data_paths()
if keyword_set(outfil) eq 0 then outfil = 'sar.dat'

; Determine names of needed SFD files:
weeks = week_loop(start_tim, end_tim)
;infil = dirs + '/' + 'sfd' + string(weeks.year,format='(i2.2)') + $
;        '_' + string(weeks.week,format='(i2.2)') + 'a.01'
;infil = ['/yd4/sfd/sfd92_06a.02', $
;    '/yd4/sfd/sfd92_07a.03', $
;    '/yd4/sfd/sfd92_08a.03']
infil = ['/yd4/sfd/sfw92_06a.02', $
     '/yd4/sfd/sfw92_07a.03', $
     '/yd4/sfd/sfw92_08a.03']

;ss_exist = where(file_exist(infil))
;if (ss_exist(0) eq -1) then stop, ' No files for times selected.'
;infil = infil(ss_exist)

; Read roadmap for all files specified by INFIL:
rd_roadmap,infil,roadmap,nimg_each_file
nimg = long(total(nimg_each_file))
tim2orbit, roadmap, saa=saa

; Get indices of Al 1200 A images:
;ss = where((gt_filta(roadmap) eq 1) and $
;           (gt_filtb(roadmap) eq 2) and $
;      (gt_res(roadmap) eq 1) and $
;           (not saa))
ss = where((gt_res(roadmap) eq 1) and $
           (not saa))
if ((ss(0) eq -1) or (n_elements(ss) lt 2)) then $
  stop,' No images satisfying imposed conditions.'

; Get image times:
t_ex = anytim2ex(roadmap(ss))
t_sec = int2secarr(anytim2ints(roadmap(ss)),ref_tim)
min_diff = min(abs(t_sec),ref_num)

rd_xda,infil,ss(ref_num),index_ref,data_ref,roadmap
window,0,xs=512
tvscl,data_ref
; Select subarray center:
cursor,y0,z0,/dev,/down
wait,.5
; If subarray size not specified on input then select
;   subarray lower left corner:
if keyword_set(ys) eq 0 then begin
  cursor,y1,z1,/dev,/down
  ys = 2*abs(y0-y1)
  zs = 2*abs(z0-z1)
endif

ysh = ys/2 & zsh = zs/2
subdata = bytarr(ys,zs,n_elements(ss))

yz = rot_pix2(roadmap(ss),y0,z0,ref_num,pdata=pdata)

; Extract sub_array
for i=0,n_elements(ss)-1 do begin
  rd_xda,infil,ss(i),index,data,roadmap
  sz_data = size(data)
  subdata0 = data(((yz(0,i)-ysh+1)>0):(yz(0,i)+ysh)<(sz_data(1)-1), $
    ((yz(1,i)-zsh+1)>0):(yz(1,i)+zsh)<(sz_data(2)-1))
  subdata((-(yz(0,i)-ysh+1))>0,(-(yz(1,i)-zsh+1))>0,i) = subdata0
  sav_sda, outfil, index, subdata0, append=(i ne 0), $
    skipmap=(i ne n_elements(ss)-1), progName=progName, progVerNo=progVerNo
endfor

return, subdata

end