real(fp) function nbi_d1mach (i)
  use iso_c_binding, only: fp => c_double
  implicit none
  integer :: i
  integer :: ifirst

  real(fp) :: b, x
  real(fp), dimension(5) :: dmach
  save

  data ifirst /1/

!***begin prologue  d1mach
!***purpose  return floating point machine dependent constants.
!***library   slatec
!***category  r1
!***type      single precision (d1mach-s, d1mach-d)
!***keywords  machine constants
!***author  fox, p. a., (bell labs)
!           hall, a. d., (bell labs)
!           schryer, n. l., (bell labs)
!***description
!
!   d1mach can be used to obtain machine-dependent parameters for the
!   local machine environment.  it is a function subprogram with one
!   (input) argument, and can be referenced as follows:
!
!        a = d1mach(i)
!
!   where i=1,...,5.  the (output) value of a above is determined by
!   the (input) value of i.  the results for various values of i are
!   discussed below.
!
!   d1mach(1) = b**(emin-1), the smallest positive magnitude.
!   d1mach(2) = b**emax*(1 - b**(-t)), the largest magnitude.
!   d1mach(3) = b**(-t), the smallest relative spacing.
!   d1mach(4) = b**(1-t), the largest relative spacing.
!   d1mach(5) = log10(b)
!
!   assume single precision numbers are represented in the t-digit,
!   base-b form
!
!              sign (b**e)*( (x(1)/b) + ... + (x(t)/b**t) )
!
!   where 0 .le. x(i) .lt. b for i=1,...,t, 0 .lt. x(1), and
!   emin .le. e .le. emax.
!
!   the values of b, t, emin and emax are provided in i1mach as
!   follows:
!   i1mach(10) = b, the base.
!   i1mach(11) = t, the number of base-b digits.
!   i1mach(12) = emin, the smallest exponent e.
!   i1mach(13) = emax, the largest exponent e.
!
!
!***references  p. a. fox, a. d. hall and n. l. schryer, framework for
!                 a portable library, acm transactions on mathematical
!                 software 4, 2 (june 1978), pp. 177-188.
!***routines called  xermsg
!***revision history  (yymmdd)
!   790101  date written
!   960329  modified for fortran 90 (be after suggestions by ehg)
!***end prologue  d1mach
!
  x = 1.0_fp
  b = radix(x)
!$$$      select case (i)
!$$$        case (1)
!$$$          d1mach = b**(minexponent(x)-1) ! the smallest positive magnitude.
!$$$        case (2)
!$$$          d1mach = huge(x)               ! the largest magnitude.
!$$$        case (3)
!$$$          d1mach = b**(-digits(x))       ! the smallest relative spacing.
!$$$        case (4)
!$$$          d1mach = b**(1-digits(x))      ! the largest relative spacing.
!$$$        case (5)
!$$$          d1mach = log10(b)
!$$$        case default
!$$$          write (*, fmt = 9000)
!$$$ 9000     format ('1error    1 in d1mach - i out of bounds')
!$$$          stop
!$$$      end select
  if (ifirst.eq.1) then
     dmach(1) = b**(minexponent(x)-1) ! the smallest positive magnitude.
     dmach(2) = huge(x)               ! the largest magnitude.
     dmach(3) = b**(-digits(x))       ! the smallest relative spacing.
     dmach(4) = b**(1-digits(x))      ! the largest relative spacing.
     dmach(5) = log10(b)

     ifirst=0
     nbi_d1mach=dmach(i)
  else
     nbi_d1mach=dmach(i)
  endif
  return
end function nbi_d1mach

