function value = r8_bie ( x )

%*****************************************************************************80
%
%% r8_bie() evaluates the exponentially scaled Airy function Bi of an R8 argument.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 September 2011
%
%  Author:
%
%    Original FORTRAN77 version by Wayne Fullerton.
%    This 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.
%
%  Input:
%
%    real X, the argument.
%
%  Output:
%
%    real VALUE, the exponentially scaled Airy function Bi of X.
%
  persistent atr
  persistent bif2cs
  persistent bifcs
  persistent big2cs
  persistent bigcs
  persistent bip1cs
  persistent bip2cs
  persistent btr
  persistent nbif
  persistent nbif2
  persistent nbig
  persistent nbig2
  persistent nbip1
  persistent nbip2
  persistent x32sml
  persistent x3sml
  persistent xbig


  atr = 8.75069057084843450880771988210148;
  btr = -2.09383632135605431360096498526268;

  if ( isempty ( nbif ) )

    bif2cs = [ ...
      +0.0998457269381604104468284257993, ...
      +0.47862497786300553772211467318231, ...
      +0.25155211960433011771324415436675E-01, ...
      +0.58206938852326456396515697872216E-03, ...
      +0.74997659644377865943861457378217E-05, ...
      +0.61346028703493836681403010356474E-07, ...
      +0.34627538851480632900434268733359E-09, ...
      +0.14288910080270254287770846748931E-11, ...
      +0.44962704298334641895056472179200E-14, ...
      +0.11142323065833011708428300106666E-16, ...
      +0.22304791066175002081517866666666E-19, ...
      +0.36815778736393142842922666666666E-22, ...
      +0.50960868449338261333333333333333E-25, ...
      +0.60003386926288554666666666666666E-28, ...
      +0.60827497446570666666666666666666E-31 ]';
    bifcs = [ ...
      -0.16730216471986649483537423928176E-01, ...
      +0.10252335834249445611426362777757, ...
      +0.17083092507381516539429650242013E-02, ...
      +0.11862545467744681179216459210040E-04, ...
      +0.44932907017792133694531887927242E-07, ...
      +0.10698207143387889067567767663628E-09, ...
      +0.17480643399771824706010517628573E-12, ...
      +0.20810231071761711025881891834399E-15, ...
      +0.18849814695665416509927971733333E-18, ...
      +0.13425779173097804625882666666666E-21, ...
      +0.77159593429658887893333333333333E-25, ...
      +0.36533879617478566399999999999999E-28, ...
      +0.14497565927953066666666666666666E-31 ]';
    big2cs = [ ...
      +0.033305662145514340465176188111647, ...
      +0.161309215123197067613287532084943, ...
      +0.631900730961342869121615634921173E-02, ...
      +0.118790456816251736389780192304567E-03, ...
      +0.130453458862002656147116485012843E-05, ...
      +0.937412599553521729546809615508936E-08, ...
      +0.474580188674725153788510169834595E-10, ...
      +0.178310726509481399800065667560946E-12, ...
      +0.516759192784958180374276356640000E-15, ...
      +0.119004508386827125129496251733333E-17, ...
      +0.222982880666403517277063466666666E-20, ...
      +0.346551923027689419722666666666666E-23, ...
      +0.453926336320504514133333333333333E-26, ...
      +0.507884996513522346666666666666666E-29, ...
      +0.491020674696533333333333333333333E-32 ]';
    bigcs = [ ...
      +0.22466223248574522283468220139024E-01, ...
      +0.37364775453019545441727561666752E-01, ...
      +0.44476218957212285696215294326639E-03, ...
      +0.24708075636329384245494591948882E-05, ...
      +0.79191353395149635134862426285596E-08, ...
      +0.16498079851827779880887872402706E-10, ...
      +0.24119906664835455909247501122841E-13, ...
      +0.26103736236091436985184781269333E-16, ...
      +0.21753082977160323853123792000000E-19, ...
      +0.14386946400390433219483733333333E-22, ...
      +0.77349125612083468629333333333333E-26, ...
      +0.34469292033849002666666666666666E-29, ...
      +0.12938919273216000000000000000000E-32 ]';
    bip1cs = [ ...
      -0.83220474779434474687471864707973E-01, ...
      +0.11461189273711742889920226128031E-01, ...
      +0.42896440718911509494134472566635E-03, ...
      -0.14906639379950514017847677732954E-03, ...
      -0.13076597267876290663136340998881E-04, ...
      +0.63275983961030344754535716032494E-05, ...
      -0.42226696982681924884778515889433E-06, ...
      -0.19147186298654689632835494181277E-06, ...
      +0.64531062845583173611038157880934E-07, ...
      -0.78448546771397719289748310448628E-08, ...
      -0.96077216623785085879198533565432E-09, ...
      +0.70004713316443966339006074402068E-09, ...
      -0.17731789132814932022083128056698E-09, ...
      +0.22720894783465236347282126389311E-10, ...
      +0.16540456313972049847032860681891E-11, ...
      -0.18517125559292316390755369896693E-11, ...
      +0.59576312477117290165680715534277E-12, ...
      -0.12194348147346564781055769498986E-12, ...
      +0.13347869253513048815386347813597E-13, ...
      +0.17278311524339746664384792889731E-14, ...
      -0.14590732013016720735268871713166E-14, ...
      +0.49010319927115819978994989520104E-15, ...
      -0.11556545519261548129262972762521E-15, ...
      +0.19098807367072411430671732441524E-16, ...
      -0.11768966854492179886913995957862E-17, ...
      -0.63271925149530064474537459677047E-18, ...
      +0.33861838880715361614130191322316E-18, ...
      -0.10725825321758625254992162219622E-18, ...
      +0.25995709605617169284786933115562E-19, ...
      -0.48477583571081193660962309494101E-20, ...
      +0.55298913982121625361505513198933E-21, ...
      +0.49421660826069471371748197444266E-22, ...
      -0.55162121924145707458069720814933E-22, ...
      +0.21437560417632550086631884499626E-22, ...
      -0.61910313387655605798785061137066E-23, ...
      +0.14629362707391245659830967336959E-23, ...
      -0.27918484471059005576177866069333E-24, ...
      +0.36455703168570246150906795349333E-25, ...
      +0.58511821906188711839382459733333E-27, ...
      -0.24946950487566510969745047551999E-26, ...
      +0.10979323980338380977919579477333E-26, ...
      -0.34743388345961115015034088106666E-27, ...
      +0.91373402635349697363171082240000E-28, ...
      -0.20510352728210629186247720959999E-28, ...
      +0.37976985698546461748651622399999E-29, ...
      -0.48479458497755565887848448000000E-30, ...
      -0.10558306941230714314205866666666E-31 ]';
    bip2cs = [ ...
      -0.11359673758598867913797310895527, ...
      +0.41381473947881595760052081171444E-02, ...
      +0.13534706221193329857696921727508E-03, ...
      +0.10427316653015353405887183456780E-04, ...
      +0.13474954767849907889589911958925E-05, ...
      +0.16965374054383983356062511163756E-06, ...
      -0.10096500865641624301366228396373E-07, ...
      -0.16729119493778475127836973095943E-07, ...
      -0.45815364485068383217152795613391E-08, ...
      +0.37366813665655477274064749384284E-09, ...
      +0.57669303201452448119584643502111E-09, ...
      +0.62181265087850324095393408792371E-10, ...
      -0.63294120282743068241589177281354E-10, ...
      -0.14915047908598767633999091989487E-10, ...
      +0.78896213942486771938172394294891E-11, ...
      +0.24960513721857797984888064000127E-11, ...
      -0.12130075287291659477746664734814E-11, ...
      -0.37404939108727277887343460402716E-12, ...
      +0.22377278140321476798783446931091E-12, ...
      +0.47490296312192466341986077472514E-13, ...
      -0.45261607991821224810605655831294E-13, ...
      -0.30172271841986072645112245876020E-14, ...
      +0.91058603558754058327592683478908E-14, ...
      -0.98149238033807062926643864207709E-15, ...
      -0.16429400647889465253601245251589E-14, ...
      +0.55334834214274215451182114635164E-15, ...
      +0.21750479864482655984374381998156E-15, ...
      -0.17379236200220656971287029558087E-15, ...
      -0.10470023471443714959283909313604E-17, ...
      +0.39219145986056386925441403311462E-16, ...
      -0.11621293686345196925824005665910E-16, ...
      -0.54027474491754245533735411307773E-17, ...
      +0.45441582123884610882675428553304E-17, ...
      -0.28775599625221075729427585480086E-18, ...
      -0.10017340927225341243596162960440E-17, ...
      +0.44823931215068369856332561906313E-18, ...
      +0.76135968654908942328948982366775E-19, ...
      -0.14448324094881347238956060145422E-18, ...
      +0.40460859449205362251624847392112E-19, ...
      +0.20321085700338446891325190707277E-19, ...
      -0.19602795471446798718272758041962E-19, ...
      +0.34273038443944824263518958211738E-20, ...
      +0.37023705853905135480024651593154E-20, ...
      -0.26879595172041591131400332966712E-20, ...
      +0.28121678463531712209714454683364E-21, ...
      +0.60933963636177797173271119680329E-21, ...
      -0.38666621897150844994172977893413E-21, ...
      +0.25989331253566943450895651927228E-22, ...
      +0.97194393622938503767281175216084E-22, ...
      -0.59392817834375098415630478204591E-22, ...
      +0.38864949977113015409591960439444E-23, ...
      +0.15334307393617272869721512868769E-22, ...
      -0.97513555209762624036336521409724E-23, ...
      +0.96340644440489471424741339383726E-24, ...
      +0.23841999400208880109946748792454E-23, ...
      -0.16896986315019706184848044205207E-23, ...
      +0.27352715888928361222578444801478E-24, ...
      +0.35660016185409578960111685025730E-24, ...
      -0.30234026608258827249534280666954E-24, ...
      +0.75002041605973930653144204823232E-25, ...
      +0.48403287575851388827455319838748E-25, ...
      -0.54364137654447888432698010297766E-25, ...
      +0.19281214470820962653345978809756E-25, ...
      +0.50116355020532656659611814172172E-26, ...
      -0.95040744582693253786034620869972E-26, ...
      +0.46372646157101975948696332245611E-26, ...
      +0.21177170704466954163768170577046E-28, ...
      -0.15404850268168594303692204548726E-26, ...
      +0.10387944293201213662047889194441E-26, ...
      -0.19890078156915416751316728235153E-27, ...
      -0.21022173878658495471177044522532E-27, ...
      +0.21353099724525793150633356670491E-27, ...
      -0.79040810747961342319023537632627E-28, ...
      -0.16575359960435585049973741763592E-28, ...
      +0.38868342850124112587625586496537E-28, ...
      -0.22309237330896866182621562424717E-28, ...
      +0.27777244420176260265625977404382E-29, ...
      +0.57078543472657725368712433782772E-29, ...
      -0.51743084445303852800173371555280E-29, ...
      +0.18413280751095837198450927071569E-29, ...
      +0.44422562390957094598544071068647E-30, ...
      -0.98504142639629801547464958226943E-30, ...
      +0.58857201353585104884754198881995E-30, ...
      -0.97636075440429787961402312628595E-31, ...
      -0.13581011996074695047063597884122E-30, ...
      +0.13999743518492413270568048380345E-30, ...
      -0.59754904545248477620884562981118E-31, ...
      -0.40391653875428313641045327529856E-32 ]';

    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, 15, eta );
    nbip1 = r8_inits ( bip1cs, 47, eta );
    nbip2 = r8_inits ( bip2cs, 88, eta );
    x3sml = eta^0.3333;
    x32sml = 1.3104 * x3sml * x3sml;
    xbig = r8_mach ( 2 )^0.6666;

  end

  if ( x < - 1.0 )
    [ xm, theta ] = r8_aimp ( x );
    value = xm * sin ( theta );
  elseif ( abs ( x ) <= x3sml )
    z = 0.0;
    value = 0.625 + r8_csevl ( z, bifcs, nbif ) ...
      + x * ( 0.4375 + r8_csevl ( z, bigcs, nbig ) );
    if (  x32sml <= x )
      value = value * exp ( - 2.0 * x * sqrt ( x ) / 3.0 );
    end
  elseif ( x <= 1.0 )
    z = x * x * x;
    value = 0.625 + r8_csevl ( z, bifcs, nbif ) ...
      + x * ( 0.4375 + r8_csevl ( z, bigcs, nbig ) );
    if (  x32sml <= x )
      value = value * exp ( - 2.0 * x * sqrt ( x ) / 3.0 );
    end
  elseif ( x <= 2.0 )
    z = ( 2.0 * x * x * x - 9.0 ) / 7.0;
    value = exp ( - 2.0 * x * sqrt ( x ) / 3.0 ) ...
      * ( 1.125 + r8_csevl ( z, bif2cs, nbif2 ) ...
      + x * ( 0.625 + r8_csevl ( z, big2cs, nbig2 ) ) );
  elseif ( x <= 4.0 )
    sqrtx = sqrt ( x );
    z = atr / x / sqrtx + btr;
    value = ( 0.625 + r8_csevl ( z, bip1cs, nbip1 ) ) / sqrt ( sqrtx );
  elseif ( x < xbig )
    sqrtx = sqrt ( x );
    z = 16.0 / ( x * sqrtx ) - 1.0;
    value = ( 0.625 + r8_csevl ( z, bip2cs, nbip2 ) ) / sqrt ( sqrtx );
  else
    sqrtx = sqrt ( x );
    z = - 1.0;
    value = ( 0.625 + r8_csevl ( z, bip2cs, nbip2 ) ) / sqrt ( sqrtx );
  end

  return
end
