pro sft2sfc, img_times, online=online, sftdir=sftdir, sfcdir=sfcdir, $
   noconfirm=noconfirm
;
;+
;   Name: sft2sfc
;
;   Purpose: convert one or more SFT files to SFC files (via sfc_prep)
;
;   History:
;      15-mar-1995 (SLF)
;       7-Aug-97  :  NN, change the index to be saved - should reflect
;            the new version of sfc_prep, which keeps the index from dark_sub
;-

if keyword_set(online) then begin
   sfcdir=get_logenv('DIR_SXT_SFC')
   sftdir=get_logenv('DIR_SXT_SFT')
endif

sfcdir='/1d1/yohkoh_b/MOjob/sfc_new'		;****** temporary ***
sftdir='/1d1/yohkoh_b/MOjob/sft_new'		;********************

if not keyword_set(sfcdir) then begin
   tbeep
   message,/info,"please specify SFC output directory (or use /online)
   return   
endif

if not keyword_set(sftdir) then begin
   tbeep
   message,/info,"please specify SFC output directory (or use /online)
   return
endif

resp=''
if not keyword_set(noconfirm) then begin
   prstr,['Using directories...','   Input  (SFT): ' + sftdir,	$
				 '   Output (SFC): ' + sfcdir,'']
   read,"Enter <ok> to continue, anything else to quit: " ,resp
   if strupcase(resp) ne 'OK' then message,"Aborting on request..."
endif else $
   prstr,['Using directories...','   Input  (SFT): ' + sftdir,	$
			         '   Output (SFC): ' + sfcdir,'']

sfts=file_list(sftdir,'sft??_??.??')
if sfts(0) eq '' then message,/info,"NO sft files found..."

rd_roadmap, sfts, rmap, ndset

if n_elements(img_times) eq 0 then img_times=rmap
   
match=tim2dset(rmap,img_times,delt=delt)

ss=where(delt eq 0,gcnt)
bad=where(delt ne 0,bcnt)

if bcnt gt 0 then $
   message,/info,"Number of mis-matched image times: " + strtrim(bcnt,2)

for i=0,gcnt-1 do begin		; image loop
   rd_sda,sfts,match(ss(i)),index,data,rmap
   prstr,'sfc_prep >> ' + fmt_tim(index) + ' ' + $
      gt_filta(index,/string) + '/' + gt_filtb(index,/string)

;   sfc=sfc_prep(index,data)
   sfc=sfc_prep(index,data, index_out=index_out)  ; by NN 7-Aug-97
   outsfc=concat_dir(sfcdir,'sfc' + (ex2fid(anytim2ex(index)))(0))
   prstr,'sav_sda >> ' + outsfc 
;   sav_sda,outsfc,index,sfc
   sav_sda,outsfc,index_out,sfc      ; by NN 7-Aug-97

endfor


return
end
