subroutine rfxqlo_verify_ready(ierr)

  !  verify that module is ready for use...

  use rfxqlo_private
  implicit NONE

  integer, intent(out) :: ierr

  if(ready) then
     ierr=0
  else
     ierr=1
     write(lunmsg,*) ' ?rfxqlo_verify_ready -- module not ready.'
     write(lunmsg,*) '  rfxqlo_verify_input failed or was never called.'
  endif
end subroutine rfxqlo_verify_ready

subroutine rfxqlo_verify_input(ierr)

  !  verify all inputs.  If OK: ierr=0 on exit.

  use rfxqlo_private
  implicit NONE

  integer, intent(out) :: ierr

  !--------------------------------------------------------------------
  ! verify that all input data necessary to run RF wave codes has been
  ! provided...
  !--------------------------------------------------------------------
  integer :: i,j,ick,ierrp,ierv,iera,iert,idum,id=0,id_g,id_q,ix,itmp,imulti
  integer :: ilen
  real(r8qlo), parameter :: ZERO = 0.0d0
  real(r8qlo), parameter :: ONE = 1.0d0
  real(r8qlo) :: zwsum,jnphi,zw_nphi,zxmin,zxmax,zden,ztemp,zr,zz,zg,ztmp
  real(r8qlo) :: zxip(2),zip(2),zx1(1),za1(1)

  real(r8qlo), dimension(:), allocatable :: xtmp,zr2i
  real(r8qlo) :: azmin,azmax,bbmin,bbmax,bbmin1,bbmax1,zharmin,zharmax,zomeg
  !--------------------------------------------------------------------
  ! basic checks first...

  ierr=0
  if(.not.init) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: module not allocated.'
  endif

  !-------------------------------------
  if(n_antenna.eq.0) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: n_antenna = 0'
  endif

  !-------------------------------------
  if(max_nphi.eq.0) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: max_nphi = 0'
  endif

  !-------------------------------------
  if(.not.have_sys) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: no "system" info provided.'
     ierr=ierr+1
  endif

  !-------------------------------------
  if(.not.have_profile) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: no "profile" info provided.'
     ierr=ierr+1
  endif

  !-------------------------------------
  if(.not.have_ions) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: no "ions" info provided.'
     ierr=ierr+1
  endif

  !-------------------------------------
  if(.not.have_rfgrid) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: no "rfgrid" info provided.'
     ierr=ierr+1
  endif

  !-------------------------------------
  if(.not.have_options) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: no "options" info provided.'
     ierr=ierr+1
  endif

  !--------------------------------------------------------------------
  if(ierr.ne.0) return

  !--------------------------------------------------------------------
  ! check system parameters

  ierrp=ierr
  do i=1,5
     if(rfx_sys%lunut(i).eq.0) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo_verify_input: rfx_sys%lunut(',i,')=0'
     endif
  enddo
  if(rfx_sys%luntmp1.eq.0) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: rfx_sys%luntmp1 = 0'
  endif
  if(rfx_sys%luntmp2.eq.0) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: rfx_sys%luntmp2 = 0'
  endif
  if(ierr.ne.ierrp) then
     write(lunmsg,*) &
          ' -->rfxqlo_verify_input: Fortran i/o unit numbers missing.'
  endif

  if(rfx_sys%run_id.eq.' ') then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: rfx_sys%run_id is blank.'
     write(lunmsg,*) '  non-blank string needed for temporary filenames.'
  endif

  if(ierr.ne.ierrp) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: "system" information is missing.'
  endif

  ! if "filepath" is non-blank, make sure it ends with a "/" character

  if(rfx_sys%filepath.ne.' ') then
     ilen = len(trim(rfx_sys%filepath))
     if(rfx_sys%filepath(ilen:ilen).ne.'/') then
        ilen = ilen + 1
        rfx_sys%filepath(ilen:ilen) = '/'
     endif
  endif

  !--------------------------------------------------------------------
  !  check profile information...

  ierrp=ierr

  call eq_rholim(zxmin,zxmax)
  
  if(rfx_prof%xplasma_file.eq.' ') then
     write(lunmsg,*) ' %rfxqlo_verify_input: rfx_prof%xplasma_file is blank.'
  endif

  if((rfx_prof%id_q.eq.0).and.(rfx_prof%xnam_q.eq.' ')) then
     call eqm_gen_q('RFXQLO_Q',id,ierv)  ! get q profile from XPLASMA
     if(ierv.ne.0) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo_verify_input: error setting up q profile.'
     endif
     rfx_prof%id_q=id
     rfx_prof%xnam_q='RFXQLO_Q'
  endif

  call chk1('rfx_prof','G',rfx_prof%id_g,rfx_prof%xnam_g)
  call chk1('rfx_prof','Q',rfx_prof%id_q,rfx_prof%xnam_q)
  call chk1('rfx_prof','TE',rfx_prof%id_te,rfx_prof%xnam_te)
  call chk1('rfx_prof','NE',rfx_prof%id_ne,rfx_prof%xnam_ne)

  call chk1('rfx_prof','TIAV',rfx_prof%id_tiav,rfx_prof%xnam_tiav)
  call chk1('rfx_prof','VLOOP',rfx_prof%id_vloop,rfx_prof%xnam_vloop)
  call chk1('rfx_prof','EPOT',rfx_prof%id_epot,rfx_prof%xnam_epot)
  call chk1('rfx_prof','OMEGA',rfx_prof%id_omega,rfx_prof%xnam_omega)

  zx1 = zxmax
  call eq_rgetf(1,zx1,rfx_prof%id_ne,0,za1,ierv)
  zden = za1(1)

  if(vacden.le.1.0e-20_r8qlo) then
     vacden=zden/2
  else
     vacden=min(zden,max(zden/100,vacden))
  endif

  call eq_rgetf(1,zx1,rfx_prof%id_te,0,za1,ierv)
  ztemp = za1(1)

  if(vactemp.le.1.0e-20_r8qlo) then
     vactemp=ztemp/2
  else
     vactemp=min(ztemp,max(ztemp/100,vactemp))
  endif

  if(ierr.gt.ierrp) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: error with RF input profiles.'
  endif

  id_g=rfx_prof%id_g
  id_q=rfx_prof%id_q

  !--------------------------------------------------------------------
  !  check ions...

  ierrp=ierr

  if(rfx_ions%n_ions.eq.0) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo_verify_input: # of ion species = 0.'
  endif

  azmin=3
  azmax=1
  do i=1,rfx_ions%n_ions
     ierv=ierr
     if(rfx_ions%a_ions(i).le.0) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo_verify_input: Ai < or = 0 '
     endif
     if(rfx_ions%z_ions(i).le.0) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo_verify_input: Zi < or = 0 '
     endif
     if(rfx_ions%z_ions(i).gt.rfx_ions%a_ions(i)) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo_verify_input: Zi > Ai'
     endif
     if(rfx_ions%name_ions(i).eq.' ') then
        write(lunmsg,*) ' %rfxqlo_verify_input: name_ions entry is blank.'
     endif
     call chk1('rfx_ions','NI',rfx_ions%id_ni(i),rfx_ions%xnam_ni(i))
     call chk1('rfx_ions','TI',rfx_ions%id_ti(i),rfx_ions%xnam_ti(i))
     call chk1('rfx_ions','TPLL',rfx_ions%id_tpll(i),rfx_ions%xnam_tpll(i))
     if(ierv.gt.ierr) then
        write(lunmsg,*) &
             ' %rfxqlo_verify_input: above errors apply to ion species no. ', &
             i,':'
        write(lunmsg,*) '  name = "',trim(rfx_ions%name_ions(i)),'" ', &
             ' Ai = ',rfx_ions%a_ions(i),' Zi = ',rfx_ions%z_ions(i)
     endif
     if(ierr.eq.0) then
        azmin=min(azmin,rfx_ions%a_ions(i)/rfx_ions%z_ions(i))
        azmax=max(azmax,rfx_ions%a_ions(i)/rfx_ions%z_ions(i))
     endif
  enddo

  if(ierr.gt.ierrp) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: error in ion species description.'
  endif

  !--------------------------------------------------------------------
  !  check (1/R) field and plasma currents
  
  ierrp=ierr

  if(min(rmaj0,btor0).le.1.0e-20_r8qlo) then
     call eq_rzget(1,ZERO,ZERO,ZERO,zr,zz,idum,ierv)
     if(ierv.ne.0) then
        write(lunmsg,*) ' ?rfxqlo_verify_input: eq_rzget(axis) error.'
        ierr=ierr+1
     else
        zx1=ONE
        call eq_rgetf(1,zx1,id_g,0,za1,ierv)
        zg=za1(1)
        if(ierv.ne.0) then
           write(lunmsg,*) ' ?rfxqlo_verify_input: eq_rgetf(g) error.'
           ierr=ierr+1
        else
           rmaj0=zr
           btor0=zg/zr
        endif
     endif
  endif

  if(placur.le.1.0e-20_r8qlo) then
     zxip(1)=zxmax/2; zxip(2)=zxmax
     ztmp=zxmax*1.0e-7_r8qlo
     call eq_flxint_init(0,2,zxip,ztmp,ierv)
     if(ierv.ne.0) then
        write(lunmsg,*) ' ?rfxqlo_verify_input: eq_flxint_init(placur) error.'
        ierr=ierr+1
     else
        call eq_flxint('Itor',1,zip,1,2,ierv)
        if(ierv.ne.0) then
           write(lunmsg,*) &
                ' ?rfxqlo_verify_input: eq_flxint_init(placur) error.'
           ierr=ierr+1
        else
           placur = zip(2)
        endif
     endif
  endif

  if(ierr.gt.ierrp) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: vacuum (Rmaj0,Btor0) block error.'
  endif

  !--------------------------------------------------------------------
  ! check antenna specifications -- normalize Nphi spectrum weights.

  do i=1,n_antenna
     call ck_antenna(antenna_array(i)%nantrz, &
          antenna_array(i)%antRgeo,antenna_array(i)%antZgeo, i)

     if((antenna_array(i)%antHH.le.ZERO).and. &
          (antenna_array(i)%nantrz.gt.0)) then
        call rfx_antcen(antenna_array(i)%nantrz, &
             antenna_array(i)%antRgeo,antenna_array(i)%antZgeo, &
             antenna_array(i)%antRcen,antenna_array(i)%antZcen, &
             antenna_array(i)%anthh)
     endif

     ick=0
     if(antenna_array(i)%freq.le.ZERO) then
        if(antenna_array(i)%power.gt.ZERO) then
           write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
                ' frequency is .le. ZERO'
           write(lunmsg,*) '  and has non-zero power.'
           ierr=ierr+1
           ick=ick+1
        endif
     endif

     if(antenna_array(i)%num_nphi.le.0) then
        write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
             ' no. of Nphi spectrum values is .le.0'
        ierr=ierr+1
        ick=ick+1
     endif
     if(ick.gt.0) cycle

     zwsum=ZERO
     do j=antenna_array(i)%num_nphi,1,-1
        jnphi=antenna_array(i)%nphi(j)
        zw_nphi=antenna_array(i)%wnphi_vac(j)
        if(antenna_array(i)%sym_nphi) then
           if(jnphi.le.0) then
              write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
                   ' negative Nphi incompatible with symmetric spectrum.'
              ierr=ierr+1
              exit
           endif
        else
           if(jnphi.eq.0) then
              write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
                   ' Nphi=0 not allowed.'
              ierr=ierr+1
              exit
           endif
        endif
        if(j.gt.1) then
           if(antenna_array(i)%nphi(j).le.antenna_array(i)%nphi(j-1)) then
              write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
                   ' Nphi not in ascending order:'
              write(lunmsg,*) &
                   antenna_array(i)%nphi(1:antenna_array(i)%num_nphi)
              ierr=ierr+1
              exit
           endif
        endif
        zw_nphi=max(ZERO,zw_nphi)
        zwsum=zwsum+zw_nphi
        antenna_array(i)%wnphi_vac(j)=zw_nphi
     enddo
     if(zwsum.eq.ZERO) then
        write(lunmsg,*) ' ?rfxqlo_verify_input: antenna #',i,':', &
             ' sum of Nphi vacuum spectrum weights is ZERO.'
        ierr=ierr+1
        cycle
     endif
     antenna_array(i)%wnphi_vac = antenna_array(i)%wnphi_vac/zwsum
  enddo

  !--------------------------------------------------------------------
  !  the grid...

  ierrp=ierr

  if(max(abs(zxmin),abs(zxmax-1.0_r8qlo)).gt.1.0e-6_r8qlo) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo: xplasma "rho" grid does not cover range [0,1]'
  endif

  if((rfx_grid%id_xqlo.eq.0).and.(rfx_grid%xnam_xqlo.eq." ")) then
     ierr=ierr+1
     write(lunmsg,*) ' ?rfxqlo: xqlo grid not defined.'
  else if(rfx_grid%id_xqlo.eq.0) then
     call eq_ganum(rfx_grid%xnam_xqlo,rfx_grid%id_xqlo)
     if(rfx_grid%id_xqlo.eq.0) then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo: xqlo grid id not found: ', &
             trim(rfx_grid%xnam_xqlo)
     endif
  else if(rfx_grid%xnam_xqlo.eq." ") then
     call eq_get_aname(rfx_grid%id_xqlo,rfx_grid%xnam_xqlo)
     if(rfx_grid%xnam_xqlo.eq." ") then
        ierr=ierr+1
        write(lunmsg,*) ' ?rfxqlo: xqlo grid name not found: ',rfx_grid%id_xqlo
     endif
  endif

  if(ierr.eq.0) then
     !-------------------------------------------------------------
     !  construct sqrt(Psi/Psilim) profile -- monotonic function, usable
     !  as alternate grid (rfx_grid%id_xqlo is sqrt(Phi/Philim))-- toroidal
     !  not poloidal flux.

     rfx_grid%xnam_xpsi='RFXQLO_XPSI'
     call rfxqlo_xpsi(rfx_grid%id_xqlo,id_q,rfx_grid%xnam_xpsi, &
          rfx_grid%id_xpsi,ierr)
  endif

  if(ierr.eq.0) then
     !-------------------------------------------------------------
     !  basic test OK; build arrays needed for QLO evaluation...
     !  also estimate harmonic range for each antenna, if not already
     !  given by the user...

     !  addl arrays for QLO:

     call eq_ngrid(rfx_grid%id_xqlo,itmp)
     itmp=itmp-1
     allocate(xtmp(0:itmp))
     call eq_grid(rfx_grid%id_xqlo,xtmp,itmp+1,idum,ierv)  ! orig. grid

     !  expanded gridsize:

     imulti = rfx_grid%nxmulti
     nx_qlo = itmp*imulti              ! zone count, not bdy count

     if(allocated(x_qlo)) deallocate(x_qlo,xb_qlo)
     allocate(x_qlo(nx_qlo),xb_qlo(0:nx_qlo))

     xb_qlo(0)=0.0_r8qlo
     ix=0
     call eq_glimb(xtmp(0),bbmin,bbmax,ierv)
     do i=1,itmp
        call eq_glimb(xtmp(i),bbmin1,bbmax1,ierv)
        bbmin=min(bbmin,bbmin1)
        bbmax=max(bbmax,bbmax1)
        do j=1,imulti
           ix=ix+1
           xb_qlo(ix)=(xtmp(i-1)*(imulti-j)+xtmp(i)*j)/imulti
           x_qlo(ix)=(xb_qlo(ix)+xb_qlo(ix-1))/2
        enddo
     enddo

     deallocate(xtmp)

     !-------------------------
     ! get dV elements

     if(allocated(dv_qlo)) deallocate(dv_qlo,v_qlo)
     allocate(dv_qlo(nx_qlo),v_qlo(0:nx_qlo))

     if(allocated(da_qlo)) deallocate(da_qlo,a_qlo,Iphi_qlo)
     allocate(da_qlo(nx_qlo),a_qlo(0:nx_qlo),Iphi_qlo(0:nx_qlo))

     ! use numerical integration for volumes profile
     ztmp=x_qlo(nx_qlo)*1.0e-7_r8qlo
     call eq_flxint_init(0,nx_qlo+1,xb_qlo,ztmp,ierv)
     if(ierv.ne.0) then
        write(lunmsg,*) &
             ' ?rfxqlo_verify_input: eq_flxint_init failure (volumes).'
        ierr=ierr+1
     else
        call eq_flxint('DVOL',1,dv_qlo,1,nx_qlo,ierv)
        if(ierv.ne.0) then
           write(lunmsg,*) &
                ' ?rfxqlo_verify_input: eq_flxint failure (volumes).'
           ierr=ierr+1
        endif
        call eq_flxint('DAREA',1,da_qlo,1,nx_qlo,iera)
        if(iera.ne.0) then
           write(lunmsg,*) &
                ' ?rfxqlo_verify_input: eq_flxint failure (areas).'
           ierr=ierr+1
        endif
        call eq_flxint('ITOR',1,Iphi_qlo,1,nx_qlo+1,iert)
        if(iert.ne.0) then
           write(lunmsg,*) &
                ' ?rfxqlo_verify_input: eq_flxint failure (Itor).'
           ierr=ierr+1
        endif
     endif
     if(ierr.eq.0) then
        v_qlo(0)=0.0_r8qlo
        a_qlo(0)=0.0_r8qlo
        do i=1,nx_qlo
           v_qlo(i)=v_qlo(i-1)+dv_qlo(i)  ! m**3
           a_qlo(i)=a_qlo(i-1)+da_qlo(i)  ! m**2
        enddo
     endif

     !-------------------------
     !  q and g profiles

     if(allocated(qzb)) deallocate(qzb,qzc,gzb,gzc)
     allocate(qzb(0:nx_qlo),qzc(nx_qlo),gzb(0:nx_qlo),gzc(nx_qlo))

     call eq_rgetf(nx_qlo+1,xb_qlo,id_q,0,qzb,ierv)
     if(ierv.ne.0) ierr=ierr+1
     call eq_rgetf(nx_qlo,x_qlo,id_q,0,qzc,ierv)
     if(ierv.ne.0) ierr=ierr+1

     call eq_rgetf(nx_qlo+1,xb_qlo,id_g,0,gzb,ierv)
     if(ierv.ne.0) ierr=ierr+1
     call eq_rgetf(nx_qlo,x_qlo,id_g,0,gzc,ierv)
     if(ierv.ne.0) ierr=ierr+1

     !-------------------------
     !  if defaulted, compute toroidal flux now...
     if(tflux.le.0.0d0) then
        tflux=0.0d0
        allocate(zr2i(nx_qlo))
        call eq_flxint('<1/R^2>',1,zr2i,1,nx_qlo,ierv)
        do i=1,nx_qlo
           tflux=tflux+gzc(i)*dv_qlo(i)*zr2i(i)/c2pi
        enddo
        deallocate(zr2i)
     endif
     !-------------------------
     maxthofb = 200  ! poloidal grid (for now...)
     numpsi = max(201,5*nx_qlo+1)
     delxpsi=1.0d0/(numpsi-1)

     call rfxqlo_misc_free

     allocate(BAVGOFR(2*nx_qlo),BDELOFR(2*nx_qlo),BMAXOFR(2*nx_qlo), &
          BMINOFR(2*nx_qlo),DELTHOFB(2*nx_qlo),NUMTHOFB(2*nx_qlo))
     allocate(OMPPOFR(maxthofb,2*nx_qlo,2))
     allocate(YOFBR(maxthofb,2*nx_qlo,2))
     allocate(THOFBR(maxthofb,2*nx_qlo,2))
     allocate(PSI(numpsi))
     allocate(RATBMAXM(2*nx_qlo),RATBMAXP(2*nx_qlo),RATBMIN(2*nx_qlo))
     allocate(YATBMAXM(2*nx_qlo),YATBMAXP(2*nx_qlo),YATBMIN(2*nx_qlo))
     allocate(THBMAXM(2*nx_qlo),THBMAXP(2*nx_qlo),THBMIN(2*nx_qlo))

     call rfxqlo_psical

     !  antenna harmonics range estimate (allow some margin):
     bbmin=0.9*bbmin; bbmax=1.1*bbmax

     do i=1,n_antenna
        if((antenna_array(i)%nharm_min.eq.0).or. &
             (antenna_array(i)%nharm_max.eq.0)) then
           zomeg=c2pi*antenna_array(i)%freq
           zharmin=zomeg*azmin/(bbmax*9.579e7_r8qlo)
           zharmax=zomeg*azmax/(bbmin*9.579e7_r8qlo)
           antenna_array(i)%nharm_min=zharmin+1
           antenna_array(i)%nharm_max=zharmax
        endif
        nharm_max=max(nharm_max,antenna_array(i)%nharm_max)
     enddo

  endif

  if(ierr.gt.ierrp) then
     write(lunmsg,*) ' ?rfxqlo_verify_input: error setting up RF(QLO) grid.'
  endif

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

  if(ierr.eq.0) then
     ready = .TRUE.
  else
     return
  endif

  !-----------------------------------------------------
  !  filenames (for TORIC4/5 communications...)

  profnt_file = ' '
  equigs_file = ' '
  xx_file = ' '
  ppjte=0.0
  ppjti=0.0

  call uupper(rfx_sys%wavecode)

  if((rfx_sys%wavecode.eq.'TORIC4').or.(rfx_sys%wavecode.eq.'TORIC5')) then

     profnt_file = trim(rfx_sys%run_id)//'_profnt.dat'
     call rfxqlo_profnt_write(rfx_sys%luntmp1,ierv)
     if(ierv.ne.0) ierr=ierr+1

     xx_file = trim(rfx_sys%run_id)//'_xx.dat'
     call rfxqlo_xx_write(rfx_sys%luntmp1,ierv)
     if(ierv.ne.0) ierr=ierr+1

     if(rfx_options%numeric_mhd) then
        equigs_file = trim(rfx_sys%run_id)//'_equigs.dat'
        call rfxqlo_equigs_write(rfx_sys%luntmp1,ierv)
        if(ierv.ne.0) ierr=ierr+1
     else
        call rfxqlo_genppj
     endif
  endif

  if(ierr.eq.0) then
     ready = .TRUE.
  else
     ready = .FALSE.
     return
  endif

  !-----------------------------------------------------
  !  allocate output structures...

  if(allocated(calculated)) deallocate(calculated)
  allocate(calculated(max_nphi,n_antenna)); calculated=.FALSE.

  if(allocated(outpros)) deallocate(outpros)
  allocate(outpros(max_nphi,n_antenna))

  do j=1,n_antenna
     do i=1,max_nphi
        call rfxqlo_outpro_blank(outpros(i,j))
     enddo
  enddo

  call rfxqlo_wavefields_alloc(ierr)
  if(ierr.ne.0) ready = .FALSE.

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

  contains
    subroutine chk1(lblobj,lbl,id,name)
      character*(*) lblobj,lbl  ! labels for compound object, individual item.
      integer :: id             ! xplasma id
      character*(*) name        ! xplasma name

      integer iertmp

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

      iertmp=ierr  ! old error count

      if((id.eq.0).and.(name.eq.' ')) then
         ierr=ierr+1
      else if(name.ne.' ') then
         call eq_gfnum(name,id)
         if(id.eq.0) then
            ierr=ierr+1
            write(lunmsg,*) lblobj,'%xnam_',lbl,': invalid xplasma name.'
         endif
      else
         call eq_get_fname(id,name)
         if(name.eq.' ') then
            ierr=ierr+1
            write(lunmsg,*) lblobj,'%id_',lbl,': invalid xplasma id.'
         endif
      endif

      if(ierr.ne.iertmp) then
         write(lunmsg,*) ' ?rfxqlo_verify_input: ',lblobj, &
              ': no information for: ',lbl
      endif
      
    end subroutine chk1

    subroutine ck_antenna(jantry,zntRgeo,zntYgeo,iant)

      ! check antenna geometry
      ! moved here from trfpi/tr_rfprep: DMC July 2008

      integer, intent(in) :: jantry
      real*8, intent(in) :: zntRgeo(:),zntYgeo(:)
      integer, intent(in) :: iant

      real*8 :: zdist,zdistp,zcosdot,zR,zY,zdx,zdy,zdxp,zdyp,zang
      real*8 :: zRp,zYp,zxi
      real*8 :: zxa(jantry),ztha(jantry),zphia(jantry)
      integer :: iregion(jantry),iry

      real*8, parameter :: ztol_qk=2.0d-3
      real*8, parameter :: xpi = 3.1415926535897931D+00

      zphia=0.0_r8qlo
      call eq_inv(jantry,zntRgeo,zntYgeo,zphia,ztol_qk,zxa,ztha,iregion,ierr)
      if(ierr.ne.0) then
         write(lunmsg,*) ' ?tr_rfprep(ck_antenna): unexpected eq_inv error!'
         ierr=ierr+1
         return
      endif

      zdist=ZERO
      zR=ZERO
      zY=ZERO
      zdx=ZERO
      zdy=ZERO

      do iry=1,jantry

         zRp=zR
         zYp=zY

         zR=zntRgeo(iry)
         zY=zntYgeo(iry)
         zxi=zxa(iry)

         if((zxi.lt.0.8_r8qlo).or.(zxi.gt.1.2_r8qlo)) then
            write(lunmsg,*) '%rfxqlo_verify(ck_antenna):  antenna point #', &
                 iry, ' is far from plasma bdy.'
            write(lunmsg,*) '  R=',zR,' Y=',zY,' r/a = ',zxi
            write(lunmsg,*) ' ICRF antenna #: ',iant
         endif

         if(iry.gt.1) then
            zdistp=zdist
            zdist=sqrt((zY-zYp)**2+(zR-zRp)**2)
            if(zdist.eq.ZERO) then
               zdist=zdistp
               write(lunmsg,*) '%tr_rfprep:  antenna point #',iry, &
                    ' and previous point overlap.'
               write(lunmsg,*) '  R=',zR,'  Y=',zY
               write(lunmsg,*) ' ICRF antenna #: ',iant
            else
               zdxp=zdx
               zdyp=zdy
               zdx=(zR-zRp)/zdist
               zdy=(zY-zYp)/zdist
               if(zdistp.gt.ZERO) then
                  zcosdot=zdxp*zdx+zdyp*zdy
                  zcosdot=max(-ONE,min(ONE,zcosdot))
                  zang=acos(zcosdot)
                  if(zang.gt.(xpi/4)) then
                     write(lunmsg,*) &
                          '%tr_rfprep:  detected sharp bend in antenna', &
                          'point #',iry
                     write(lunmsg,*) ' ICRF antenna #: ',iant
                  endif
               endif                    ! zdistp.gt.0
            endif                       ! zdist.gt.0
         endif                          ! iry.gt.1
      enddo

    end subroutine ck_antenna         ! (contained subroutine)

end subroutine rfxqlo_verify_input

subroutine rfxqlo_update_input(ierr)

  !  update input files (if necessary) -- call if temperatures or densities
  !  change

  use rfxqlo_private
  implicit NONE

  integer, intent(out) :: ierr

  !------------
  integer :: ierv
  !------------


  ierr=0

  profnt_file = ' '

  if((rfx_sys%wavecode.eq.'TORIC4').or.(rfx_sys%wavecode.eq.'TORIC5')) then

     profnt_file = trim(rfx_sys%run_id)//'_profnt.dat'
     call rfxqlo_profnt_write(rfx_sys%luntmp1,ierv)
     if(ierv.ne.0) ierr=ierr+1

  endif

end subroutine rfxqlo_update_input
