subroutine kdsaw_iotb_r4(ziotb,zmix,ierr)

  ! REAL interface to REAL*8 kdsaw_iotb routine
  ! call this only after kdsaw_init has been called.

  use kdsaw_module
  implicit NONE

  real, intent(out) :: ziotb(nzones+1)   ! post-sawtooth iota(bar) profile

  real, intent(in) :: zmix         ! mixing parameter in range [0,1]
                                   ! see kdsaw_iotb

  integer, intent(out) :: ierr     ! completion code, ierr=0 means OK

  !--------------------------------
  real*8 zmixr8,ziotbr8(nzones+1)
  !--------------------------------

  ziotb=0
  if(.not.kdsaw_flag) then
     write(abs(nonlin),*) ' ?kdsaw_iotb_r4: cannot return iota(bar) profile.'
     write(abs(nonlin),*) '  --> call kdsaw_init first.'
     ierr=1
  else
     zmixr8=zmix
     call kdsaw_iotb(ziotbr8,zmixr8,ierr)
     if(ierr.eq.0) then
        ziotb=ziotbr8
     endif
  endif

end subroutine kdsaw_iotb_r4


subroutine kdsaw_iotb(ziotb,zmix,ierr)

  ! return the post-sawtooth iota(bar) profile
  ! call this only after kdsaw_init has been called.

  ! user control:
  ! mixing parameter: zmix=1 ==> return fully mixed post-sawtooth profile
  !                   zmix=0 ==> return pre-sawtooth profile unchanged
  !                   0<zmix<1 ==> return
  !                       (1-zmix)*[pre-sawtooth profile] +
  !                         (zmix)*[post-sawtooth profile]
  !
  ! warning issued if zmix out of range; zmixl = max(0,min(1,zmix)) is used.
  !
  ! note: dimension of ziotb array is equal to "izones+1" where "izones"
  ! was the dimensioning argument provided in an earlier call to kdsaw_init.

  use kdsaw_module
  implicit NONE

  real*8, intent(out) :: ziotb(nzones+1)
                                   ! (mixed) post-sawtooth iota(bar) profile

  real*8, intent(in) :: zmix       ! mixing parameter in range [0,1]

  integer, intent(out) :: ierr     ! completion code, ierr=0 means OK

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

  real*8 zmixuse

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

  if(.not.kdsaw_flag) then
     write(abs(nonlin),*) ' ?kdsaw_iotb: cannot return iota(bar) profile.'
     write(abs(nonlin),*) '  --> call kdsaw_init first.'
     ierr=1
     ziotb=0
     return
  else
     ierr=0
  endif

  if((zmix.lt.0).or.(zmix.gt.1)) then
     write(abs(nonlin),*) &
          ' %kdsaw_iotb warning: not in range [0,1]: zmix=',zmix
     zmixuse=max(zero,min(one,zmix))
  else
     zmixuse=zmix
  endif

  ziotb=(1-zmixuse)*xiotbp(lcentr:lep1,1) + zmixuse*xiotb(lcentr:lep1,1)

end subroutine kdsaw_iotb
