subroutine plot_fp_ii(n1,n2,evec1,fvec1,evec2,tvec2,wkvec,farr)

  ! plot II data from fpreact

  use iso_c_binding, only: fp => c_double
  use adas_mod, only : adas_sigv,adas_btsigv
  use fpreact_parameters

  implicit NONE

  ! data buffers -- uninitialized!

  integer, intent(in) :: n1,n2  ! dimension info

  real(fp) :: evec1(n1)             ! E/A-vector for f(E) plot
  real(fp) :: fvec1(n1)             ! for f(E) plot
  real(fp) :: tevec1(n2)          ! T/A-vector for f(E) or f(E,T) plot
  real(fp) :: evec2(n2),tvec2(n2)   ! E/A,T/A for f(E,T) plot
  real(fp) :: farr(n2,n2)           ! for f(E,T) plot
  real(fp), dimension(:), allocatable :: fvec1_adas
  real(fp), dimension(:,:), allocatable :: farr2

  !----------------------------------
  integer luntrm,lnout
  logical lxout,lchar

  integer izneut,izion,ihandle,idum1,idum2,iopt,i

  real(fp) :: erange1,erange2,trange1,trange2

  character*60 zlbl1,zlbl2,zlbl3

  character*30 flbl,flbl2
  character*15 funs
  character*10 zbzi

  real(fp) :: wkvec(n2,2)
  integer fadas_II,ii
  integer, parameter :: NEUTRAL=1, ION=2 ! beam type: =neutral or =ion

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

  luntrm=lnout(0)

  zlbl1='preact/fpreact "II" database'
  zlbl2='[sigma*v](E/A) impact ionization rate coefficient'

  luntrm=lnout(0)
  if(lxout(0)) write(luntrm,1001)
1001 format(/ &
         'plot of impact ionization of selected neutral specie as a'/ &
         'function of interaction energy-per-nucleon (E/A), or...'/ &
         'beam target <sigma*V>(Eb/Ab,Ti/Ai) table... (hit "," to exit)'/)

  izion=0
  do
     izneut=0
     call ureadi('select neutral (beam) specie: 1 for H, 2 for He:$',izneut)
     if(izneut.eq.0) exit
     izneut=max(1,min(2,izneut))
     write(luntrm,*)' for PREACT ion specie: 1 for H+, 2 for He++,  only'
     call ureadi('select ion specie: 1 for H+, 2 for He++ or more:$',izion)
!     izion=max(1,min(2,izion))

     call uread('enter "0" for cold target plot; "1" for beam-target table:$')

     iopt=0
     if(lchar('0')) then

        !  get [sigma*v] table range
        call hatom_handle(fpreact_II,izneut,izion,ihandle)
        call cx_coldtarget_erange(ihandle,erange1,erange2,idum1,idum2)

        call plot_fp_mkvec(erange1,erange2,n1,evec1)

        if(lxout(0)) write(luntrm,*) &
             ' A -- ADAS [sigma*v]' 
        if(izion.le.2) then
           if(lxout(0)) write(luntrm,*) &
                ' P -- PREACT [sigma*v]' 
           if(lxout(0)) write(luntrm,*) &
                ' C -- COMPARE ADAS and PREACT ' 
        endif
        if(lxout(0)) write(luntrm,*) &
             ' hit "," to exit' 
        call uread('select option:$')

        if(izneut.eq.1) then
           if(izion.eq.1) then
              zlbl3='impact ionization of H0 by H+, vs. Erel/A'
           else
              zlbl3='impact ionization of H0 by He++, vs. Erel/A'
           endif
        else if(izneut.eq.2) then
           if(izion.eq.1) then
              zlbl3='impact ionization of He0 by H+, vs. Erel/A'
           else
              zlbl3='impact ionization of He0 by He++, vs. Erel/A'
           endif
        endif
        if(lchar('P')) then !PREACT DATA
           zlbl1='preact/fpreact "II" database'
           call hatom_sigv(fpreact_II,evec1,n1,izneut,izion,fvec1,idum1)

           call gaxspc(3) ! log-log
           call r8_grafx1(evec1,fvec1,n1,'KeV','m**3/sec',zlbl1,zlbl2,zlbl3)
           call gaxspc(1) ! restore default
        elseif(lchar('A')) then !ADAS DATA
           zlbl1='ADAS "II" database'
           fadas_II=2 !II
           call adas_sigv(fadas_II,evec1,n1,izneut,dble(izion),fvec1,idum1)

           call gaxspc(3) ! log-log
           call r8_grafx1(evec1,fvec1,n1,'KeV','m**3/sec',zlbl1,zlbl2,zlbl3)
           call gaxspc(1) ! restore default
        elseif(lchar('C')) then !ADAS vs PREACT  DATA
           zlbl1='PREACT/ADAS "II" database'
           flbl2='II sigma*v'
           if(allocated(fvec1_adas)) deallocate(fvec1_adas)
           allocate(fvec1_adas(n1))
           fvec1_adas=0.0_fp
           call hatom_sigv(fpreact_II,evec1,n1,izneut,izion, &
                fvec1,idum1)
           fadas_II=2 ! ii full ionization
           call adas_sigv(fadas_II,evec1,n1,izneut,dble(izion),fvec1_adas,idum1)

           call gaxspc(3) ! log-log
           call r8_grafx2(evec1,fvec1,fvec1_adas,n1,'KeV','m**3/sec',zlbl1,zlbl2,zlbl3)
           call gaxspc(1) ! restore default
        endif

     else if(lchar('1')) then

        iopt=fpreact_II  ! ii beam target table

     else
        call uermsg('plot_fp_ii: invalid option.',' ',0)
     endif

     if(iopt.gt.0) then
        ! get table range information
        call hatom_handle(iopt,izneut,izion,ihandle)
        call ii_warmtarget_erange(ihandle,erange1,erange2,idum1,idum2)
        call ii_warmtarget_trange(ihandle,trange1,trange2,idum1,idum2)
        call plot_fp_mkvec(erange1,erange2,n2,evec2)
        call plot_fp_mkvec(trange1,trange2,n2,tvec2)

        flbl='<sigma*v> impact ionization'
        funs='m**3/sec'

        if(lxout(0)) write(luntrm,*) &
             ' A -- ADAS <sigma*v>' 
        if(izion.le.2) then
           if(lxout(0)) write(luntrm,*) &
                ' P -- PREACT <sigma*v>' 
           if(lxout(0)) write(luntrm,*) &
                ' C -- COMPARE ADAS and PREACT ' 
        endif
        if(lxout(0)) write(luntrm,*) &
             ' hit "," to exit' 
        call uread('select option:$')
        if(lchar('P'))then
           zlbl1='PREACT "II" database'
           do i=1,n2
              wkvec(1:n2,1)=tvec2(i)
              call hatom_btsigv(iopt,fpreact_NEUTRAL_BEAM, &
                   evec2,wkvec(1:n2,1),n2,izneut,izion, &
                   farr(1:n2,i),idum1)
           enddo

           write(zbzi,'(''Zb='',i1,'', Zi='',i1)') izneut,izion
           call r8_grf3f1(evec2,farr,tvec2,wkvec,n2,n2,n2, &
                'beam Eb/Ab',flbl,'target Ti/Ai', &
                'KeV(Eb/Ab)',funs,'KeV(Ti/Ai)',zlbl1,zbzi,0)
           
        else if(lchar('A'))then
           zlbl1='ADAS "II" database'
           fadas_II=2
           wkvec(1:n2,1)=tvec2
           do i=1,n2
              tevec1(1:n2)=tvec2(i)
              call adas_btsigv(fadas_II,NEUTRAL,evec2,tevec1,n2,izneut,dble(izion),farr(1:n2,i),idum1)
              
              !           ikey=2 ! for FOR BEAM TARGET <sig*v>
           enddo

           write(zbzi,'(''Zb='',i1,'', Zi='',i1)') izneut,izion
           call r8_grf3f1(evec2,farr,tvec2,wkvec,n2,n2,n2, &
                'beam Eb/Ab',flbl,'target Ti/Ai', &
                'KeV(Eb/Ab)',funs,'KeV(Ti/Ai)',zlbl1,zbzi,0)
        else if(lchar('C'))then
           zlbl1='PREACT/ADAS "II" database'
           fadas_II=2
           wkvec(1:n2,2)=evec2
           do i=1,n2
              wkvec(1:n2,1)=tvec2(i)
              call hatom_btsigv(iopt,fpreact_NEUTRAL_BEAM, &
                   evec2,wkvec(1:n2,1),n2,izneut,izion, &
                   farr(1:n2,i),idum1)
           enddo
           if(allocated(farr2)) deallocate(farr2)
           allocate(farr2(n2,n2))
           farr2=0.0_fp
           wkvec(1:n2,1)=tvec2
           do i=1,n2
              tevec1(1:n2)=dble(tvec2(i))
              call adas_btsigv(fadas_II,NEUTRAL,evec2,tevec1,n2,izneut,dble(izion),farr2(1:n2,i),idum1)
!           ikey=2 ! for FOR BEAM TARGET <sig*v>
           enddo

           flbl='PREACT: <sigma*v> II'
           flbl2='ADAS: <sigma*v> II'
           write(zbzi,'(''Zb='',i1,'', Zi='',i1)') izneut,izion
           call r8_grf3f2(evec2,farr,farr2,tvec2,wkvec,n2,n2,n2, &
                'beam Eb/Ab',flbl,flbl2,'target Ti/Ai', &
                'KeV(Eb/Ab)',funs,'KeV(Ti/Ai)',zlbl1,zbzi,0)
           

        endif

     endif

  enddo

end subroutine plot_fp_ii
