#include "fpreproc/f77_dcomplx.h"
      subroutine rfxplot

      !  plot the wavefield description as interpolated for the QLO
      !  (wavefield for the selected antenna & nphi)

      use rfxqlo_private
      implicit NONE

      real*8, dimension(:,:), allocatable :: zra,zza
      real*8, dimension(:,:,:), allocatable :: zwk
      REAL*8, PARAMETER :: C100TH = 0.01d0
      REAL*8, PARAMETER :: TWO = 2.0d0
      REAL*8, PARAMETER :: ONE = 1.0d0
      REAL*8, PARAMETER :: ZERO = 0.0d0

      real*8 :: zjac(2,2),zxi,zth,zpi
      integer :: i,j,iphi,iant,nticrf

c---------------------------------------
      iphi = selected_nphi
      iant = selected_antenna

      nticrf=rfx_grid%nchi_in
      allocate(zra(nticrf+1,nx_qlo),zza(nticrf+1,nx_qlo))
      allocate(zwk(nticrf+1,nx_qlo,4))
c
c  contour plots of icrf wave code output
c
      zra=ZERO
      zza=ZERO
      zwk=ZERO
c
      zpi=abs(acos(-ONE))
      do i=1,nx_qlo
         zxi=x_qlo(i)
         do j=1,nticrf
            zth=(j-1)*TWO*zpi/nticrf
            call rfmomry1(zxi,zth,0,zra(j,i),zza(j,i),zjac)
            zra(j,i)=C100TH*zra(j,i)
            zza(j,i)=C100TH*zza(j,i)
            zwk(j,i,1)=AREAL(wavefields(iphi,iant)%crfpol(i,j))
            zwk(j,i,2)=AIMAG(wavefields(iphi,iant)%crfpol(i,j))
            zwk(j,i,3)=wavefields(iphi,iant)%skperp(i,j)
            zwk(j,i,4)=wavefields(iphi,iant)%eplus(i,j)
         enddo
         zra(nticrf+1,i)=zra(1,i)
         zza(nticrf+1,i)=zza(1,i)
         do j=1,4
            zwk(nticrf+1,i,j)=zwk(1,i,j)
         enddo
      enddo
c
#ifdef __DEBUG
      call conturs(zwk(1,1,4),zra,zza,'Eplus(V/m)$',
     >   nticrf,nx_qlo,nticrf,nx_qlo)
c
      call conturs(zwk(1,1,3),zra,zza,'kperp(1/m)$',
     >   nticrf,nx_qlo,nticrf,nx_qlo)
c
      call conturs(zwk(1,1,1),zra,zza,'Re(crfpol)$',
     >   nticrf,nx_qlo,nticrf,nx_qlo)
c
      call conturs(zwk(1,1,2),zra,zza,'Im(crfpol)$',
     >   nticrf,nx_qlo,nticrf,nx_qlo)
c
#endif
      deallocate(zra,zza,zwk)
      return
      end
C---------------------
      subroutine rfxplot_all

      use rfxqlo_private
      implicit NONE

      integer :: isava,isavn,iant,inphi

      isava = selected_antenna
      isavn = selected_nphi

      do iant=1,n_antenna
         selected_antenna = iant

         do inphi = 1,antenna_array(iant)%num_nphi
            selected_nphi = inphi

            if(antenna_array(iant)%power*
     >         antenna_array(iant)%wnphi_vac(inphi).gt.0.0d0) then

               call rfxplot

            endif

         enddo
      enddo

      selected_antenna = isava
      selected_nphi = isavn

      return
      end
