pro copy_merge, node1, user1, dir1, node2, user2, dir2
;
;
;
;node1 = 'quake'	& user1 = 'mons'	& dir1 = '/home/mons/soft/mdi'
;node2 = 'sxt2'		& user2 = 'morrison'	& dir2 = '/yd3/morrison/mdi'
;node2 = 'sxt2'		& user2 = 'morrison'	& dir2 = '/2p/morrison/soft/mdi'
;
spawn, 'rsh ' + node1 + ' -l ' + user1 + ' ls -l ' + dir1, ls1
spawn, 'rsh ' + node2 + ' -l ' + user2 + ' ls -l ' + dir2, ls2
;
ss = where(strmid(ls1, 0, 1) ne 'd') 	& ls1 = ls1(ss)
ss = where(strmid(ls2, 0, 1) ne 'd') 	& ls2 = ls2(ss)
;
n1 = file_info2(dummy, finfo1, ls=ls1)
n2 = file_info2(dummy, finfo2, ls=ls2)
;
filnames = [finfo1.filename, finfo2.filename]
filnames = filnames(uniq(filnames, sort(filnames)))
ss = where(filnames ne ' ') & filnames = filnames(ss)
n = n_elements(filnames)
qcopy1to2 = bytarr(n)
qcopy2to1 = bytarr(n)
;
for i=0,n-1 do begin
    fil0 = filnames(i)
    ss1 = where(finfo1.filename eq fil0)	& ss1=ss1(0)
    ss2 = where(finfo2.filename eq fil0)	& ss2=ss2(0)
    str = strmid(fil0+'                                ', 0, 30)
    if (ss1 eq -1) then begin
	str = str + 'Not on node ' + node1 + '.  Copy to ' + node1
	qcopy2to1(i) = 1
    end
    if (ss2 eq -1) then begin
	str = str + 'Not on node ' + node2 + '.  Copy to ' + node2
	qcopy1to2(i) = 1
    end
    if (ss1 ne -1) and (ss2 ne -1) then begin
	dt = int2secarr(finfo1(ss1), finfo2(ss2))
	if (dt gt 0) then begin
	    str = str + 'Newer copy on ' + node1 + '.  Copy to ' + node2
	    qcopy1to2(i) = 1
	end
	if (dt lt 0) then begin
	    str = str + 'Newer copy on ' + node2 + '.  Copy to ' + node1
	    qcopy2to1(i) = 1
	end

	ds = finfo1(ss1).size - finfo2(ss2).size
	if (ds gt 0) and (qcopy2to1(i)+qcopy1to2(i) eq 0) then begin
	    str = str + 'Copy is larger on ' + node1 + '.  Copy to ' + node2
	    qcopy1to2(i) = 1
	end
	if (ds lt 0) and (qcopy1to2(i)+qcopy2to1(i) eq 0) then begin
	    str = str + 'Copy is larger on ' + node2 + '.  Copy to ' + node1
	    qcopy2to1(i) = 1
	end
    end
    print, str
end
;
print, 'Files to copy from ', node1, ' to ', node2, ':'
ss1 = where(qcopy1to2)
if (ss1(0) eq -1) then print, '    No files to copy' $
		else prstr, '     ' + filnames(ss1)
print, ' '
print, 'Files to copy from ', node2, ' to ', node1, ':'
ss2 = where(qcopy2to1)
if (ss2(0) eq -1) then print, '    No files to copy' $
		else prstr, '     ' + filnames(ss2)
print, ' '
;
cmd0 = 'rsh ' + node1		;always issue command from node1 (quake)
if (ss1(0) ne -1) or (ss2(0) ne -1) then begin
    yesnox, 'Perform the copy commands? ', ans, 'Y'
end else begin
    ans = 0
    print, 'NO FILES NEED TO BE COPIED EITHER DIRECTION'
end
if (ans) then begin
    if (ss1(0) ne -1) then begin		;copy from 1 to 2 (quake to sxt2) -issue command from quake
	for i=0,n_elements(ss1)-1 do begin
	    cmd = cmd0 + ' rcp -p ' + concat_dir(dir1, filnames(ss1(i))) + ' ' + node2 + ':' + concat_dir(dir2, '.')
	    print, cmd
	    if (not keyword_set(qdebug)) then spawn, cmd
	end
    end
    if (ss2(0) ne -1) then begin		;copy from 2 to 1 (sxt2 to quake) -issue command from quake
	for i=0,n_elements(ss2)-1 do begin
	    cmd = cmd0 + ' rcp -p ' + node2 + ':' + concat_dir(dir2, filnames(ss2(i))) + ' ' + concat_dir(dir1, '.')
	    print, cmd
	    if (not keyword_set(qdebug)) then spawn, cmd
	end
    end
end

;
end
;------------------------------------------------------------------------------
 copy_merge, 'quake', 'morrison', '/home/morrison/soft/mdi',	'sxt3', 'morrison', '/3p/morrison/soft/mdi'
;copy_merge, 'quake', 'morrison', '/home/morrison/soft/mdi',	'sxt2', 'morrison', '/2p/morrison/soft/mdi'
;copy_merge, 'quake', 'morrison', '/home/morrison/soft/mdi/txt','sxt2', 'morrison', '/2p/morrison/soft/mdi/txt'
end

