program Alias
  ! Make increasingly sparse signal
  ! Alias n1=200  pair={0,1} > out.H
  !  pair=0 makes usual seplib output file
  !  pair>0 makes (coord,ord) pairs
  use sep
  implicit none

  integer                             :: n1, esize, pairs, nd, i1
  integer, dimension (:), allocatable :: itau
  logical, dimension (:), allocatable :: miss
  real,    dimension (:), allocatable :: data, tau, sintau, ord, coord
  real                                :: d1,o1, tmax, scale

  call sep_init ()
  call from_par ("n1",n1,200)
  call from_par ("esize",esize,4)
  call from_par ("scale",scale,1.)

  allocate (data   (n1))
  allocate (tau    (n1)) 
  allocate (itau   (n1))
  allocate (miss   (n1))
  allocate (sintau (n1))

  call from_par ("tmax",tmax,30.)

  d1 = tmax/n1 ; o1 = 0.

  call to_history ("d1",d1)   
  call to_history ("o1",o1)

  tau = (/ (o1 + d1 * (i1-1), i1 = 1, n1) /) 
  tau = exp( 20. * tau/tmax ) - 1. + .15*n1*d1
  itau = 1.5 + (tau - o1) / d1
  tau = o1 + d1 * (itau-1)
  miss = itau < n1*.85
  sintau = sin (tau) * scale/2

  data = 0.
  where (miss) data (itau) = sintau

  call from_par ("pairs",pairs,0)
  if( pairs == 0 ) then
     call to_history ("n2",1)
     call sep_close()
     call sep_write (data)
  else
     nd = count (miss)     
     allocate (  ord (nd)) ;   ord = pack (sintau, miss) 
     allocate (coord (nd)) ; coord = pack (   tau, miss)
     call to_history ("n1",nd)
     call to_history ("n2",2)
     call sep_close()
     call sep_write (coord)
     call sep_write (ord)
  end if

  call exit (0)
end program Alias

