program main
  use sep
  use off2ang2d_sd_mod2
  use wei_type_mod
  implicit none
  type(axis)                      :: az, ah, ax, aang, adip
  integer                         :: nang_default, ndip_default, style, ix, stat
  real                            :: ang_min_default, ang_max_default, dang_default
  real                            :: dip_min_default, dip_max_default, ddip_default
  real                            :: x
  real, dimension(:,:)  , pointer :: data
  real, dimension(:,:,:), pointer :: modl
  logical, parameter              :: T = .true., F = .false.   
  call initpar()
 
  call from_history("n1", az%n); call from_history("d1", az%d); call from_history("o1", az%o)
  call from_history("n2", ah%n); call from_history("d2", ah%d); call from_history("o2", ah%o)
  call from_history("n3", ax%n); call from_history("d3", ax%d); call from_history("o3", ax%o)

  nang_default    = ah%n
  ang_min_default = -60
  ang_max_default = 60.
  if (nang_default == 1) then
     dang_default = 0.
  else
     dang_default = (ang_max_default - ang_min_default) / (nang_default - 1)
  end if
  call from_param("nang", aang%n, nang_default)
  call from_param("oang", aang%o, ang_min_default)
  call from_param("dang", aang%d, dang_default)

  ndip_default    = 51
  dip_min_default = -60
  dip_max_default = 60.
  if (ndip_default == 1) then
     ddip_default = 0
  else
     ddip_default = (dip_max_default - dip_min_default) / (ndip_default - 1)
  end if
  call from_param("ndip", adip%n, ndip_default)
  call from_param("odip", adip%o, dip_min_default)
  call from_param("ddip", adip%d, ddip_default)

  call from_param("style", style, 1)

  call to_history("n1", az%n  ); call to_history("d1", az%d  ); call to_history("o1", az%o  )
  call to_history("n2", aang%n); call to_history("d2", aang%d); call to_history("o2", aang%o)
  call to_history("n3", adip%n); call to_history("d3", adip%d); call to_history("o3", adip%o)
  call to_history("n4", ax%n  ); call to_history("d4", ax%d  ); call to_history("o4", ax%o)
  call to_history("label1", "z")
  call to_history("label2", "ang")
  call to_history("label3", "dip")
  call to_history("label4", "x")

  allocate(data(az%n, ah%n))
  allocate(modl(az%n, aang%n, adip%n))

  stat = off2ang2d_sd_init(az, ah, ax, aang, adip, style)

  do ix=1, ax%n
     x = ax%o + (ix-1)*ax%d
write(0,*)"ix=", ix
     data = 0.
     call sep_read(data)
     stat = off2ang2d_sd_oper(T, F, x, modl, data)
     call sep_write(modl)
     modl = 0.
  end do
  stat = off2ang2d_sd_clos()

  deallocate(data)
  deallocate(modl)
end program
