func removepaths(sarr)
 ;assumes sarr is a string array or just a string containing
 ;filename(s) and returns another string array (or string) with
 ;the paths removed
 if isstrarr(sarr) then {
   ns = num_elem(sarr)
   sout = strarr(ns)
   for i=0,ns-1 do sout(i) = removepath(sarr(i))
   return, sout
 }
 else if isstr(sarr) then
   return, removepath(sarr)
 } else {
   ty,'error in input argument for removepaths'  return, 0
 }
 endfunc
;============================================================================
subr checklist, s
 ;check that we have some files and sort then and remove paths
 if isstrarr(s) then {
   s = removepaths(s)
   s = sort(s)
 } else {
   ty,'FATAL error, no files in list'
   retall
 }
 endsubr
;============================================================================
subr comparelists, jside, uside
 ;compare the lists, they are assumed sorted
 nusideonly = 0
 njsideonly = 0
 ndiffer = 0
 njside = num_elem(jside)
 nuside = num_elem(uside)
 nn = njside>nuside   ;the max of the 2
 ij = 0
 iu = 0
 while (1) do {
   jname = jside(ij)
   uname = uside(iu)
   stat = strcmp(jname, uname)
   if stat eq 0 {
     ;a match in names, usual case we hope, do a diff
     sq = 'diff -w -q '+ $usidepath+uname+' '+$jsidepath+jname
     spawn, sq
     if !spawn ne 0 then {
       ty,'for diff we get' , !spawn
       if ndiffer eq 0 then sdifs = [jname] else sdifs = [sdifs,jname]
       ndiffer += 1
     }
     ij += 1   iu += 1
   } else if stat lt 0 {
     ty,'lt case, iu, ij = ', iu, ij
     ;this should mean that the jname is not in the uname list
     if njsideonly eq 0 then jonlys = [jname] else jonlys = [jonlys, jname]
     njsideonly += 1
     ij += 1
   } else {
     ty,'gt case, iu, ij = ', iu, ij
     ;means jname gt uname, and uname is not in the jname list
     if nusideonly eq 0 then uonlys = [jname] else uonlys = [uonlys, jname]
     nusideonly += 1
     iu += 1
   }
   if iu ge nuside then {
     ;uside exhausted, any remaining jsides are not in the uside
     if ij lt (njside-1) then for i=ij,njside-1 do {
       jname = jside(i)
       if njsideonly eq 0 then jonlys = [jname] else jonlys = [jonlys, jname]
       njsideonly += 1
     }
     break   ;this escapes the infinite while loop
   }
   if ij ge njside then {
     ;jside exhausted, any remaining usides are not in the jside
     if iu lt (nuside-1) then for i=iu,nuside-1 do {
       uname = uside(i)
       if nusideonly eq 0 then uonlys = [jname] else uonlys = [uonlys, jname]
       nusideonly += 1
     }
     break   ;this escapes the infinite while loop
   }
 }
 ;what do we have?
 ty, 'nusideonly, njsideonly, ndiffer = ', nusideonly, njsideonly, ndiffer
 if nusideonly then {
   ty,'USIDE only files (to be copied to JSIDE):'
   ty, uonlys
 }
 if njsideonly then {
   ty,'JSIDE only files (this is bad):'
   ty, jonlys
 }
 if ndiffer then {
   ty,'MISMATCHES, files that differ (this is bad):
   ty, sdifs
 }
 endsubr
;============================================================================
block comparexmls
 ;first the FG PAR's
 $usidepath = '/Users/shine/uside/ops/plans/FG/PAR/'
 $jsidepath = '/Users/shine/jside/ops/plans/FG/PAR/'
 uside = getmatchedfiles('FGPAR-.....xml$',$usidepath,10000)
 checklist, uside
 jside = getmatchedfiles('FGPAR-.....xml$',$jsidepath,10000)
 checklist, jside
 
 comparelists, jside, uside
 endblock
;============================================================================

