subroutine rfxqlo_antenna_dflts(zant)

  use rfxqlo_private
  implicit NONE

  type (rfxqlo_antenna), intent(out) :: zant

  !  set default values for rfxqlo_antenna compound data type

  zant%freq = 0           ! frequency & power
  zant%power = 0

  zant%sym_nphi = .TRUE.  ! Nphi spectrum
  zant%num_nphi = 1
  zant%nphi = 0
  zant%wnphi_vac = 1
  zant%wnphi_renorm = .TRUE.  ! req. renorm for antenna-plasma coupling

  zant%nharm_min = 0
  zant%nharm_max = 0

  zant%bzcorr = 1
  zant%bpcorr = 1

  zant%antRcen = 0        ! simple geometry specification
  zant%antZcen = 0
  zant%anthh = 0

  zant%nantrz = 0         ! general geometry specification
  zant%antRgeo = 0
  zant%antZgeo = 0

  zant%dx_farsh = 0.02d0  ! (m) -- dist. antenna to Faraday Shield (TORIC only)
  zant%antlc = 1.0d0      ! (TORIC ANTLC): antenna propogation constant.

end subroutine rfxqlo_antenna_dflts
  
subroutine rfxqlo_antenna_set(zant,ierr)

  use rfxqlo_private
  implicit NONE

  type (rfxqlo_antenna), intent(in) :: zant
  integer, intent(out) :: ierr

  !  set rfxqlo module antenna parameters

  if(.not.init) then
     ierr=1
     write(lunmsg,*) ' ?rfxqlo_antenna_set: rfxqlo module not initialized.'
  else if(selected_antenna.le.0) then
     write(lunmsg,*) ' ?rfxqlo_antenna_set: selected_antenna <= 0.'
     write(lunmsg,*) '    selected_antenna = ',selected_antenna
     write(lunmsg,*) '  call rfxqlo_select_antenna first.'
     ierr=1
  else if(selected_antenna.gt.n_antenna) then
     write(lunmsg,*) ' ?rfxqlo_antenna_set: selected_antenna > n_antenna.'
     write(lunmsg,*) '    selected_antenna = ',selected_antenna
     write(lunmsg,*) '    n_antenna        = ',n_antenna
     write(lunmsg,*) '  call rfxqlo_select_antenna first.'
     ierr=1
  else
     ierr=0

     !!!     antenna_array(selected_antenna) = zant
     !!!   replaced w/ element by element copy to avoid unexplained seg faults

     antenna_array(selected_antenna)%freq = zant%freq  ! frequency & power
     antenna_array(selected_antenna)%power = zant%power

     antenna_array(selected_antenna)%sym_nphi = zant%sym_nphi ! Nphi spectrum
     antenna_array(selected_antenna)%num_nphi = zant%num_nphi
     antenna_array(selected_antenna)%nphi = zant%nphi
     antenna_array(selected_antenna)%wnphi_vac = zant%wnphi_vac
     antenna_array(selected_antenna)%wnphi_renorm = zant%wnphi_renorm

     antenna_array(selected_antenna)%nharm_min = zant%nharm_min
     antenna_array(selected_antenna)%nharm_max = zant%nharm_max

     antenna_array(selected_antenna)%bzcorr = zant%bzcorr
     antenna_array(selected_antenna)%bpcorr = zant%bpcorr

     antenna_array(selected_antenna)%antRcen = zant%antRcen  ! simplified geo
     antenna_array(selected_antenna)%antZcen = zant%antZcen
     antenna_array(selected_antenna)%anthh = zant%anthh

     antenna_array(selected_antenna)%nantrz = zant%nantrz   ! general geometry
     antenna_array(selected_antenna)%antRgeo = zant%antRgeo
     antenna_array(selected_antenna)%antZgeo = zant%antZgeo

     antenna_array(selected_antenna)%dx_farsh = zant%dx_farsh
     antenna_array(selected_antenna)%antlc = zant%antlc

  endif

end subroutine rfxqlo_antenna_set

subroutine rfxqlo_antenna_get(zant,ierr)

  use rfxqlo_private
  implicit NONE

  type (rfxqlo_antenna), intent(out) :: zant
  integer, intent(out) :: ierr

  !  get rfxqlo module antenna parameters

  if(.not.init) then
     ierr=1
     write(lunmsg,*) ' ?rfxqlo_antenna_get: rfxqlo module not initialized.'
  else if(selected_antenna.le.0) then
     write(lunmsg,*) ' ?rfxqlo_antenna_get: selected_antenna <= 0.'
     write(lunmsg,*) '    selected_antenna = ',selected_antenna
     write(lunmsg,*) '  call rfxqlo_select_antenna first.'
     ierr=1
  else if(selected_antenna.gt.n_antenna) then
     write(lunmsg,*) ' ?rfxqlo_antenna_set: selected_antenna > n_antenna.'
     write(lunmsg,*) '    selected_antenna = ',selected_antenna
     write(lunmsg,*) '    n_antenna        = ',n_antenna
     write(lunmsg,*) '  call rfxqlo_select_antenna first.'
     ierr=1
  else
     ierr=0
     !!!     zant = antenna_array(selected_antenna)
     !!!   replaced w/ element by element copy to avoid unexplained seg faults

     zant%freq = antenna_array(selected_antenna)%freq   ! frequency & power
     zant%power = antenna_array(selected_antenna)%power

     zant%sym_nphi = antenna_array(selected_antenna)%sym_nphi  ! Nphi spectrum
     zant%num_nphi = antenna_array(selected_antenna)%num_nphi
     zant%nphi = antenna_array(selected_antenna)%nphi
     zant%wnphi_vac = antenna_array(selected_antenna)%wnphi_vac
     zant%wnphi_renorm = antenna_array(selected_antenna)%wnphi_renorm

     zant%nharm_min = antenna_array(selected_antenna)%nharm_min
     zant%nharm_max = antenna_array(selected_antenna)%nharm_max

     zant%bzcorr = antenna_array(selected_antenna)%bzcorr
     zant%bpcorr = antenna_array(selected_antenna)%bpcorr

     zant%antRcen = antenna_array(selected_antenna)%antRcen ! simplified geo
     zant%antZcen = antenna_array(selected_antenna)%antZcen
     zant%anthh = antenna_array(selected_antenna)%anthh

     zant%nantrz = antenna_array(selected_antenna)%nantrz  ! general geometry
     zant%antRgeo = antenna_array(selected_antenna)%antRgeo
     zant%antZgeo = antenna_array(selected_antenna)%antZgeo

     zant%dx_farsh = antenna_array(selected_antenna)%dx_farsh
     zant%antlc = antenna_array(selected_antenna)%antlc

  endif

end subroutine rfxqlo_antenna_get

