;
;+
;NAME:
;	attlog_copy
;PURPOSE:
;	To copy the ATTLOG program output from the Mainframe and to update
;	the commanded pointing log file.
;HISTORY:
;	Written 5-Oct-93 by M.Morrison
;	3-Jan-94 (MDM) - Changed mailing list
;	15-Nov-94 (MDM) - Changed to read ATSA.ATTLOG.DATA in addition
;			  to S88239.ATTLOG.DATA(TOBAN)
;			- Modified to use FTP_COPY
;	15-Nov-94 (MDM) - Check for duplicates in "new" before trying
;			  to append
;       14-sep-96 (SLF) - taught to use PW file (ads/att single point maint)
;-
;
outdir = getenv('ys') + '/gen/status
logdir  = '$ys/site/script'
ftp_fil = concat_dir(logdir, 'attlog_copy.ftp')
his_fil = concat_dir(outdir, 'pointing.history')
infil = ["'S88239.ATTLOG.DATA(TOBAN)'", "'ATSA.ATTLOG.DATA'"]
infil_len = [80, 137]
bas_fil = [concat_dir(outdir, 'attlog1'), concat_dir(outdir, 'attlog2')]
out_fil1 = bas_fil + '.ebc'
out_fil2 = bas_fil + '.asc'

pwf=(concat_dir('$DIR_SITE_DOC','ads_account.pw'))(0)
if not file_exist(pwf) then begin
     message,/info,"NO ADS/ATT PW FILE: " + pwf
        return
endif

dat=rd_tfile(pwf,nocomment=';',/auto)
nd=n_elements(dat(0,*))
last=nd-1
node=dat(0,last)
user=dat(1,last)
passwd=dat(2,last)
	

result = ''
ftp_copy, infil, node, user, passwd, /get, outfil = out_fil1, /binary, ftp_results=result
prstr, result
;
nfil = n_elements(out_fil1)
for i=0,nfil-1 do wrt_ebc2asc, out_fil1(i), out_fil2(i), infil_len(i)
;
new = rd_tfile(out_fil2(0))
new2 = rd_tfile(out_fil2(1))
if (n_elements(new2) gt 1) then new = [new, strmid(new2(1:*), 0, 80)]
new = new(uniq(new, sort(new)))
;
file_append, his_fil, new, /uniq, nlines=nlines
;
if (nlines ge 1) then begin
    message = ['ATTLOG_COPY Message', $
	' ', $
	string(nlines) + ' of the following were appended to POINTING.HISTORY', $
	' ', $
	new]
    mail, message, user='$MAIL_CRONJOBS'
    prstr, message
end else begin
    print, 'ATTLOG: No changes to the spacecraft pointing'
end
;
end
