pro get_ads239, infil, outdir=outdir, result=result, fail=fail, $
		odisk=odisk, main2=main2, mtl=mtl
;
;+
;NAME:
;	get_ads
;PURPOSE:
;	To read the ADS file from the mainframe
;CALLING SEQUENCE:
;	get_ads, infil
;INPUT:
;	infil	- The filename on the mainframe
;		  Example: "PSK239.SAADF.A9206(T2200003)"
;OPTIONAL KEYWORD INPUT:
;	outdir	- The output directory for the file
;       odisk   - If set, correct infile for Optical Disk conv.
;KEYWORD OUTPUT:
;	fail	- Equals 1 if failed (otherwise = 0)
;HISTORY:
;	Written 18-Jul-92 by M.Morrison
;	27-Aug-92 (MDM) - Added fail keyword
;        2-Sep-92 (slf) - modified get_ads for FACOM2 
;			  added odisk keyword
;       14-Sep-92 (slf) - added main2 keyword
;	 9-Oct-92 (slf) - change password
;       20-Oct-92 (slf) - changed name from get_ads2 to get_ads
;	27-Oct-92 (slf) - chmod 666 for all
;	10-Nov-92 (slf) - changed account info
;	13-Nov-92 (slf) - changed account info (dedicated ads account)
;			  force use of 133.74.2.3 (main2 keyword has no effect
;			  change naming convention for old files
;	25-Nov-92 (slf) - change node due to ISAS HW upgrades
;-
;
;-----------------------------------------------------------------------------
; slf, 13-Nov - new ISAS HW  configurtion changed - altered logic
; 		to always used IP address fro M780
; facom_tel=['5','3']			;last field
; node='133.74.2.' + facom_tel(keyword_set(main2))
node='133.74.2.3'
node='133.74.16.201'
;-----------------------------------------------------------------------------
;
if (n_elements(outdir) eq 0) then outdir=getenv('DIR_GEN_ADS')
;
getfil=infil
odisk=keyword_set(odisk) or keyword_set(mtl)			;slf,13-Nov-92
if keyword_set(odisk) then $
;   getfil=str_replace(getfil,'PSK239.SAA','S80669.@SAA')	;slf,2-sep-92
    getfil=str_replace(getfil,'PSK239.SAA','SOLARA.SAA')	;slf,13-Nov-92
ftp_fil = '/ydb/ads/ads_ftp'
outfil=concat_dir(outdir,infil)
outfil=outfil(0)
openw, lun, ftp_fil, /get_lun
printf, lun, 'open ' +  node		; may be facom 1 or 2
;printf, lun, 'user s81716 solar10'	;slf, 9-oct-92
;printf, lun, 'user s80671 solar11'	;slf, 10-oct-92
;printf,  lun, 'user s82653 freeland'	;slf, 13-nov-92
printf,  lun, 'user s88239 solar12'	;slf, 17-dec-92
printf, lun, 'binary'
printf, lun, 'get ' + getfil + ' ' +  outfil
printf, lun, 'close
printf, lun, 'bye
free_lun, lun
;
cmd = 'ftp -vn < ' + ftp_fil
spawn, cmd, result
spawn,'chmod 666 "' + outfil + '"'
;
print, result
fail = 0
for i=0,n_elements(result)-1 do if (strpos(result(i), 'fail') ne -1) then fail=1
;
end
