
!
! --------------------- adp_reset ----------------------
! calls adpak's adset initialization routine ADSET() only if the 
! parameters have changed since the last call.  If the kldrmlt
! parameter is nonzero then the appropriate dielectronic
! input values should have been set in adpak_mod.
!
subroutine adp_reset(knucz, kladen, kladtip, kleci, kldrmlt, ier)
  use adpak_mod
  implicit none

  integer, intent(in) :: knucz   ! atomic number of impurity
  integer, intent(in) :: kladen  ! -1 -> do not change
                                 !  0 -> use H. MAYER SHIELDING CONSTANTS
                                 !  1 -> use R. MORE REVISED SHIELDING CONSTANTS
  integer, intent(in) :: kladtip ! -1 -> do not change
                                 !  0 -> do not use tabulated ionization potentials
                                 !  1 -> use the tabulated ionization potentials
  integer, intent(in) :: kleci   ! switch for selecting formula to use for electron collisional ionization rate
                                 ! -1 -> do not change
                                 !  1 -> USE XSNQ DERIVED IONIZATION RATE CALCULATION
                                 !  2 -> USE BELFAST GROUP LIGHT ELEMENT RATE FITS
                                 !  3 -> USE YOUNGER'S RATES FOR AVAILABLE ELEMENTS AND SHELLS
                                 !       XSNQ RATES OTHERWISE ON A CHARGE STATE-BY-CHARGE STATE BASIS
  integer, intent(in) :: kldrmlt ! setup DIELECTRONIC RECOMBINATION RATE COEFFICIENT ARRAYS CDNN,CDNM
                                 ! -1 -> do not change
                                 !  0 -> USE CDNN, CDNM ARRAYS AS GIVEN
                                 !  1 -> CDNN, CDNM ARRAYS SET TO 1.0
                                 !  2 -> USE Y. HAHN FACTORS TO SETUP CDNN, CDNM
  integer, intent(out) :: ier    ! nonzero if there was an error setting up adpak

  ier=0
  if (knucz /= nucz) goto 10
  if (kladen>=0 .and. kladen/=laden) goto 10
  if (kladtip>=0 .and. kladtip/=ladtip) goto 10
  if (kleci>=0 .and. kleci/=leci) goto 10
  if (kldrmlt>=0 .and. kldrmlt/=ldrmlt) goto 10

  return  ! do nothing

10 continue
  ! -- update --
  if (kladen>=0)  laden  = kladen
  if (kladtip>=0) ladtip = kladtip
  if (kleci>=0)   leci   = kleci
  if (kldrmlt>=0) ldrmlt = kldrmlt

  ! write(*,'(a,5(i3,1x))') 'adreset = ', knucz, kladen, kladtip, kleci, kldrmlt
  call adset(knucz,ier)   ! get error code

end subroutine adp_reset
