# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
program make_ref
  use sep
  use lagrange
  use spline_mod
  implicit none
  integer :: n1,n2,i1,npts
  integer, external :: getch
  real :: d1,o1
  real :: x(20),z(20)
  integer :: norder,nin
  real, pointer :: wts(:),x_out(:),ref(:,:),x_in(:),z_in(:)
  real,pointer :: aa(:,:)
  call from_param("norder",norder)
  call from_param("n1",n1)
  call from_param("o1",o1)
  call from_param("d1",d1)
  call to_history("n1",n1)
  call sep_put_data_axis_par("out",1,n1,o1,d1,"none")
  call to_history("n2",1)
  call to_history("esize",4)
!npts=getch("x","f",x)
  i1=getch("z","f",z)
!if(npts< norder) norder=npts
  call from_history("n1",npts)
  allocate(aa(2,npts))
  allocate(x_in(npts),z_in(npts))
  call sreed("in",aa,size(aa)*4)
  x_in(1:npts)=aa(1,1:npts)
  z_in(1:npts)=aa(2,1:npts)
  if (.not. spline_init(x_in,z_in)) then
    call erexit("trouble initializing spline")
  end if
  allocate(ref(2,n1))
!d1=(x(npts)-x(1))/(n1-1)
  do i1=1,n1
    ref(1,i1)=(i1-1)*d1+o1
    ref(2,i1)=spline_interp(ref(1,i1))
  end do
  call srite("out",ref(2,:),size(ref)*4)
end program
