if (pro%narg.ne.2) then
  say "Usage "
  say "   @ multi-spectral UVData Smooth"
  say "         UVData    UV data file name"
  say "         Smooth    Spectral smoothing factor"
  say " "
  return
endif
UV_SELECT DATA  ! Make sure we start from a clean state
!
! Clean a doubly-smmoothed version of the data
define logical debug 
let debug pro%narg.gt.1
!
READ UV &1
UV_SMOOTH &2
UV_MAP
CLEAN 
write clean multi-&1-smooth
write cct multi-&1-smooth.cct
if (debug) then
  view clean
  VIEW CCT
endif
!
! Subtract the Clean Components from the original high spectral resolution data
READ UV &1 
read CCT multi-&1-smooth.cct
UV_RESIDUAL
UV_SELECT RESIDUAL
UV_MAP
CLEAN
write clean multi-&1-diff
if (debug) then
  view clean 
  view cct
endif
write cct multi-&1-diff.cct
!
! Concatenate the two CCT
define image a multi-&1-smooth.cct read
define image b multi-&1-diff.cct read
defin integer na nb n ma
let na a%dim[3]
let nb b%dim[3]
let n na+nb
define image c['a%dim[1]','a%dim[2]',n] multi-&1.cct real
let c% a%
let c 0
let c[,,1:na] a
!
! Concatenate at first null component
for i 1 to a%dim[2]  ! Loop on channels
  for j 1 to na
    if c[3,i,j].eq.0 then
      ma = j
      break
    endif
  next
  let c[,i,'ma':'ma+nb-1'] b[,i,1:nb]
next
dele /var c b a
!
! Use the cumulative Clean Component Table to restore the high resolution data
read cct multi-&1
READ UV &1 
UV_SELECT DATA
UV_RESTORE
VIEW CLEAN
write clean multi-&1

