@jitter_subs
;
; Monitor for new TLM files and to FTP them to MDIBBS
;
if (n_elements(dir) eq 0) then dir = getenv('MDI_SCI160K_LOG_DIR')
;
node = 'mdibbs'
outdir = '/md65/eof/log/sci160k/'
input, 'Enter output directory name on MDIBBS', outdir, outdir
;
ff2 = file_list(dir, '*.tfr', /cd)
break_file, ff2, dsk_log, dir0, filnam, ext
print, filnam
n = n_elements(filnam)
input, 'Enter last file successfully copied', last_fid, filnam(n-1)
;
qdone = 0
while not qdone do begin
    print, '----- Checking for new telemetry files ----- (' + !stime + ')'
    ;
    ff2 = file_list(dir, '*.tfr', /cd)
    ;
    break_file, ff2, dsk_log, dir0, filnam, ext
    ss = where(filnam gt last_fid, nss)
    ff_todo = ''
    for ifil=0,nss-1 do begin
	ff_todo = ff2(ss(ifil))
	if (ifil eq nss-1) then begin		;the last telem file there
	    nnn = file_info2(ff_todo, finfo)
	    del = int2secarr(!stime, finfo)
	    if (abs(del) gt 600) then begin
		print, ff_todo, ' has not been writen to in ', del/60, ' minutes'
		print, 'Going to copy it'
	    end else begin
		ff_todo = ''
	    end
	end
	;
	if (ff_todo ne '') then begin
	    break_file, ff_todo, dsk_log, dir0, filnam, ext
	    outfil = concat_dir(outdir, filnam+ext)
	    print, 'FTPing file: ', ff_todo
	    ftp_copy, ff_todo, node, 'mdi', 'istp_soho', outfil=outfil

	    tfd = str_replace(ff_todo, '.tfr', '.tfd')
	    outfil = str_replace(outfil, '.tfr', '.tfd')
	    ftp_copy, tfd, node, 'mdi', 'istp_soho', outfil=outfil

	    last_fid = filnam
	end
    end
    ;
    print, '---- Waiting 60 seconds before next check ---- (' + !stime + ')'
    wait, 60	;wait 60 seconds
end
;
end