subroutine r8_nbi_datchki(nonlin,ng,aplasm,backz, &
     nhydr,ndeut,ntrit,nhel3,nhel4,nlith,iwarn,ierct)
 
  use iso_c_binding, only: fp => c_double
  implicit none
 
  !  using no use or include statements, get thermal species indices
  !  from thermal species a & z lists
  !  the names are from transp common, originally...
 
  integer,intent(in) :: nonlin  ! lun for messages
 
  integer,intent(in) :: ng
  real(fp),intent(in) :: aplasm(ng),backz(ng)  ! a & z of thermal species
 
  integer,intent(out) :: nhydr  ! index to h if any, or zero
  integer,intent(out) :: ndeut  ! index to d if any, or zero
  integer,intent(out) :: ntrit  ! index to t if any, or zero
  integer,intent(out) :: nhel3  ! index to he3 if any, or zero
  integer,intent(out) :: nhel4  ! index to he4 if any, or zero
  integer,intent(out) :: nlith  ! index to li, if any, or zero
 
  integer,intent(out) :: iwarn  ! set if any specie cannot be classified
  integer,intent(inout) :: ierct  ! incremented if list has duplicates
 
  !$r8real_input: aplasm,backz
 
  ! the routine writes messages on `nonlin' in case of warning or error
  !---------------------------------------
  ! local:
 
  integer ig,iflag
 
  !---------------------------------------
 
  nhydr=0
  ndeut=0
  ntrit=0
  nhel3=0
  nhel4=0
  nlith=0
 
  iwarn=0
 
  iflag=0
 
  do ig=1,ng
     if((abs(aplasm(ig)-1.0_fp).le.0.05_fp).and. &
          (abs(backz(ig)-1.0_fp).le.0.05_fp)) then
        if(nhydr.gt.0) then
           iflag=ig
        else
           nhydr=ig
        endif
     else if((abs(aplasm(ig)-2.0_fp).le.0.05_fp).and. &
          (abs(backz(ig)-1.0_fp).le.0.05_fp)) then
        if(ndeut.gt.0) then
           iflag=ig
        else
           ndeut=ig
        endif
     else if((abs(aplasm(ig)-3.0_fp).le.0.05_fp).and. &
          (abs(backz(ig)-1.0_fp).le.0.05_fp)) then
        if(ntrit.gt.0) then
           iflag=ig
        else
           ntrit=ig
        endif
     else if((abs(aplasm(ig)-3.0_fp).le.0.05_fp).and. &
          (abs(backz(ig)-2.0_fp).le.0.05_fp)) then
        if(nhel3.gt.0) then
           iflag=ig
        else
           nhel3=ig
        endif
     else if((abs(aplasm(ig)-4.0_fp).le.0.05_fp).and. &
          (abs(backz(ig)-2.0_fp).le.0.05_fp)) then
        if(nhel4.gt.0) then
           iflag=ig
        else
           nhel4=ig
        endif
     else if((abs(backz(ig)-3.0_fp).le.0.05_fp).and. &
          ((abs(aplasm(ig)-6.0_fp).le.0.15_fp).or.(abs(aplasm(ig)-7.0_fp).le.0.15_fp)) &
          ) then
        if(nlith.gt.0) then
           iflag=ig
        else
           nlith=ig
        endif
     else
        iwarn=iwarn+1
        write(nonlin,*) '%nbi_datchki:  could not classify specie no. ',ig
        write(nonlin,*) '   aplasm(',ig,')=',aplasm(ig)
        write(nonlin,*) '    backz(',ig,')=',backz(ig)
     endif
  enddo
 
  if(iflag.gt.0) then
     ierct=ierct+1
     write(nonlin,*) ' ?nbi_datchki:  duplicate thermal species:  no.',iflag
     write(nonlin,*) aplasm(1:ng)
     write(nonlin,*) backz(1:ng)
  endif
 
end subroutine r8_nbi_datchki
