subroutine rfxqlo_select_antenna(iant,ierr)
  use rfxqlo_private
  implicit NONE

  integer, intent(in) :: iant
  integer, intent(out) :: ierr  ! =0: OK; =1: iant out of range

  !  set the current antenna index; subsequent calls
  !  referencing antenna data will use this index.

  if(.not.init) then
     write(lunmsg,*) ' ?rfxqlo_select: rfxqlo module not initialized.'
     ierr=1
  else if((iant.le.0).or.(iant.gt.n_antenna)) then
     write(lunmsg,*) ' ?rfxqlo_select: passed antenna index iant=',iant
     write(lunmsg,*) '  not in range 1 to n_antenna = ',n_antenna
     ierr=1
  else
     selected_antenna = iant
     ierr=0
  endif

end subroutine rfxqlo_select_antenna

subroutine rfxqlo_select_nphi(i_nphi,ierr)
  use rfxqlo_private
  implicit NONE

  integer, intent(in) :: i_nphi
  integer, intent(out) :: ierr  ! =0: OK; =1: i_nphi out of range

  !  set the current nphi index; subsequent calls
  !  referencing antenna nphi data will use this index.

  integer num_nphi

  if(.not.init) then
     write(lunmsg,*) ' ?rfxqlo_select: rfxqlo module not initialized.'
     ierr=1
  else if(selected_antenna.eq.0) then
     write(lunmsg,*) ' ?rfxqlo_select: antenna index needs to be selected.'
     ierr=1
  else 
     num_nphi = antenna_array(selected_antenna)%num_nphi
     if((i_nphi.le.0).or.(i_nphi.gt.num_nphi)) then
        write(lunmsg,*) ' ?rfxqlo_select: passed Nphi index i_nphi=',i_nphi
        write(lunmsg,*) '  not in range 1 to num_nphi = ',num_nphi
        write(lunmsg,*) '  for antenna no. ',selected_antenna
        ierr=1
     else
        selected_nphi = i_nphi
        ierr=0
     endif
  endif

end subroutine rfxqlo_select_nphi
