function value = r8_bid ( x )

%*****************************************************************************80
%
%% R8_BID evaluates the derivative of the Airy function Bi of an R8 argument.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 October 2011
%
%  Author:
%
%    Original FORTRAN77 version by Wayne Fullerton.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Wayne Fullerton,
%    Portable Special Function Routines,
%    in Portability of Numerical Software,
%    edited by Wayne Cowell,
%    Lecture Notes in Computer Science, Volume 57,
%    Springer 1977,
%    ISBN: 978-3-540-08446-4,
%    LC: QA297.W65.
%
%  Parameters:
%
%    Input, real X, the argument.
%
%    Output, real VALUE, the derivative of the Airy function Bi of X.
%
  persistent bif2cs
  persistent bifcs
  persistent big2cs
  persistent bigcs
  persistent nbif
  persistent nbif2
  persistent nbig
  persistent nbig2
  persistent x2sml
  persistent x3sml
  persistent xmax

  if ( isempty ( nbif ) )

    bif2cs = [ ...
       0.32349398760352203352119193596266015, ...
       0.08629787153556355913888835323811100, ...
       0.00299402555265539742613821050727155, ...
       0.00005143052836466163720464316950821, ...
       0.00000052584025003681146026033098613, ...
       0.00000000356175137395770028102730600, ...
       0.00000000001714686400714584830518308, ...
       0.00000000000006166351969232555406693, ...
       0.00000000000000017191082154315985806, ...
       0.00000000000000000038236889518803943, ...
       0.00000000000000000000069424173624884, ...
       0.00000000000000000000000104833932510, ...
       0.00000000000000000000000000133721972, ...
       0.00000000000000000000000000000145986, ...
        0.00000000000000000000000000000000138 ]';
    bifcs = [ ...
       0.115353679082857024267474446284908879, ...
       0.020500789404919287530357789445940252, ...
       0.000213529027890287581892679619451158, ...
       0.000001078396061467683042209155523569, ...
       0.000000003209470883320666783353670420, ...
       0.000000000006293040671833540390213316, ...
       0.000000000000008740304300063083340121, ...
       0.000000000000000009047915683496049529, ...
       0.000000000000000000007249923164709251, ...
       0.000000000000000000000004629576649604, ...
       0.000000000000000000000000002411236436, ...
       0.000000000000000000000000000001043825, ...
       0.000000000000000000000000000000000382 ]';
    big2cs = [ ...
       1.606299946362129457759284537862622883, ...
       0.744908881987608865201476685194753972, ...
       0.047013873861027737964095177635353019, ...
       0.001228442206254823907016188785848091, ...
       0.000017322241225662362670987355613727, ...
       0.000000152190165236801893711508366563, ...
       0.000000000911356024911957704145528786, ...
       0.000000000003954791842356644201722554, ...
       0.000000000000013001737033862320007309, ...
       0.000000000000000033493506858269079763, ...
       0.000000000000000000069419094403694057, ...
       0.000000000000000000000118248256604581, ...
       0.000000000000000000000000168462493472, ...
       0.000000000000000000000000000203684674, ...
       0.000000000000000000000000000000211619, ...
       0.000000000000000000000000000000000191 ]';
    bigcs = [ ...
      -0.0971964404164435373897790974606802, ...
       0.1495035768431670665710843445326264, ...
       0.0031135253871213260419419176839631, ...
       0.0000247085705798212967777021920569, ...
       0.0000001029496277313786081987324295, ...
       0.0000000002639703739869432892676778, ...
       0.0000000000004582792707803206608181, ...
       0.0000000000000005742829740893447321, ...
       0.0000000000000000005438275385238549, ...
       0.0000000000000000000004028347267083, ...
       0.0000000000000000000000002397823826, ...
       0.0000000000000000000000000001171956, ...
       0.0000000000000000000000000000000479 ]';

    eta = 0.1 * r8_mach ( 3 );
    nbif = r8_inits ( bifcs, 13, eta );
    nbig = r8_inits ( bigcs, 13, eta );
    nbif2 = r8_inits ( bif2cs, 15, eta );
    nbig2 = r8_inits ( big2cs, 16, eta );
    x2sml = sqrt ( eta );
    x3sml = eta^0.3333;
    xmax = ( 1.5 * log ( r8_mach ( 2 ) ) )^0.6666;

  end

  if ( x < - 1.0 )
    [ xn, phi ] = r8_admp ( x );
    value = xn * sin ( phi );
  elseif ( abs ( x ) <= x2sml )
    x2 = 0.0;
    x3 = 0.0;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) + 0.25 ) ...
      + r8_csevl ( x3, bigcs, nbig ) + 0.5;
  elseif ( abs ( x ) <= x3sml )
    x2 = x * x;
    x3 = 0.0;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) + 0.25 ) ...
      + r8_csevl ( x3, bigcs, nbig ) + 0.5;
  elseif ( x <= 1.0 )
    x2 = x * x;
    x3 = x * x * x;
    value = x2 * ( r8_csevl ( x3, bifcs, nbif ) + 0.25 ) ...
      + r8_csevl ( x3, bigcs, nbig ) + 0.5;
  elseif ( x <= 2.0 )
    z = ( 2.0 * x * x * x - 9.0 ) / 7.0;
    value = x * x * ( r8_csevl ( z, bif2cs, nbif2 ) + 0.25 ) ...
      + r8_csevl ( z, big2cs, nbig2 ) + 0.5;
  else
    value = r8_bide ( x ) * exp ( 2.0 * x * sqrt ( x ) / 3.0 );
  end

  return
end
