!-------------------------------------------------------------------------
subroutine rfxqlo_dim_dflts(zdim)

  use rfxqlo_private
  implicit NONE

  !  set default dimensioning information for rfxqlo module

  type (rfxqlo_dims), intent(out) :: zdim

  zdim%n_antenna = 1
  zdim%max_nphi = 1

end subroutine rfxqlo_dim_dflts

!-------------------------------------------------------------------------
subroutine rfxqlo_dim_set(zdim,ierr)

  use rfxqlo_private
  implicit NONE

  !  set rfxqlo module dimensioning

  type (rfxqlo_dims), intent(in) :: zdim
  integer, intent(out) :: ierr   ! 0: OK; 1: invalid dimension value

  !-----------------------------------------------------

  integer i

  !-----------------------------------------------------
  !  check for errors...

  if(init) then
     ierr=1
     write(lunmsg,*) ' ?rfxqlo_dim_set:  dimensions were already set.'
  else
     ierr=0
     if(zdim%n_antenna.lt.0) then
        ierr=1
        write(lunmsg,*) &
             ' ?rfxqlo_dim_set: illegal n_antenna value: ',zdim%n_antenna
     endif
     if(zdim%n_antenna.gt.rfxqlo_maxfrq) then
        ierr=1
        write(lunmsg,*) &
             ' ?rfxqlo_dim_set: n_antenna value: ',zdim%n_antenna, &
             ' exceeds maximum: ',rfxqlo_maxfrq
        write(lunmsg,*) ' (update rfxqlo_types.f90 & rebuild) '
     endif
     if(zdim%max_nphi.lt.0) then
        ierr=1
        write(lunmsg,*) &
             ' ?rfxqlo_dim_set: illegal max_nphi value: ',zdim%max_nphi
     endif
     if(zdim%max_nphi.gt.rfxqlo_maxnphi) then
        ierr=1
        write(lunmsg,*) &
             ' ?rfxqlo_dim_set: max_nphi value: ',zdim%max_nphi, &
             ' exceeds maximum: ',rfxqlo_maxnphi
        write(lunmsg,*) ' (update rfxqlo_types.f90 & rebuild) '
     endif
  endif

  if(ierr.eq.0) then
     ! OK, do it...
     init = .TRUE.
     n_antenna = zdim%n_antenna
     max_nphi = zdim%max_nphi

     allocate(antenna_array(n_antenna))
     do i=1,n_antenna
        call rfxqlo_antenna_dflts(antenna_array(i))
     enddo
     ready=.FALSE.  ! allocated but not filled in yet...

     !---------------- 
     !  With new wavefield and antenna structures allocated,
     !  clear the Bessel table (to assure reproducibility in rfxqlo_rfoper)

     argmax_save = 0
     if(allocated(besa)) deallocate(arga,besa)

     !----------------
  endif

end subroutine rfxqlo_dim_set

subroutine rfxqlo_dim_get(zdim,ierr)

  use rfxqlo_private
  implicit NONE

  !  return information on rfxqlo module data dimensioning

  type (rfxqlo_dims), intent(out) :: zdim
  integer, intent(out) :: ierr   ! 0: OK; 1: dimensions were never set.

  if(.not.init) then
     ierr = 1
     zdim%n_antenna = 0
     zdim%max_nphi = 0
  else
     ierr = 0
     zdim%n_antenna = n_antenna
     zdim%max_nphi = max_nphi
  endif

end subroutine rfxqlo_dim_get
