function [ ampl, phi ] = r4_admp ( x )

%*****************************************************************************80
%
%% R4_ADMP: modulus and phase of the derivative of the Airy function.
%
%  Description:
%
%    This function must only be called when X <= -1.0.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    01 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 AMPL, PHI, the modulus and phase of the
%    derivative of the Airy function.
%
  persistent an20cs
  persistent an21cs
  persistent an22cs
  persistent aph0cs
  persistent aph1cs
  persistent aph2cs
  persistent nan20
  persistent nan21
  persistent nan22
  persistent naph0
  persistent naph1
  persistent naph2
  persistent pi34
  persistent xsml

  pi34 = 2.3561944901923449;

  if ( isempty ( nan20 ) )

    an20cs = [ ...
       0.0126732217145738027E+00, ...
      -0.0005212847072615621E+00, ...
      -0.0000052672111140370E+00, ...
      -0.0000001628202185026E+00, ...
      -0.0000000090991442687E+00, ...
      -0.0000000007438647126E+00, ...
      -0.0000000000795494752E+00, ...
      -0.0000000000104050944E+00, ...
      -0.0000000000015932426E+00, ...
      -0.0000000000002770648E+00, ...
      -0.0000000000000535343E+00, ...
      -0.0000000000000113062E+00, ...
      -0.0000000000000025772E+00, ...
      -0.0000000000000006278E+00, ...
      -0.0000000000000001621E+00, ...
      -0.0000000000000000441E+00 ]';
    an21cs = [ ...
       0.0198313155263169394E+00, ...
      -0.0029376249067087533E+00, ...
      -0.0001136260695958196E+00, ...
      -0.0000100554451087156E+00, ...
      -0.0000013048787116563E+00, ...
      -0.0000002123881993151E+00, ...
      -0.0000000402270833384E+00, ...
      -0.0000000084996745953E+00, ...
      -0.0000000019514839426E+00, ...
      -0.0000000004783865344E+00, ...
      -0.0000000001236733992E+00, ...
      -0.0000000000334137486E+00, ...
      -0.0000000000093702824E+00, ...
      -0.0000000000027130128E+00, ...
      -0.0000000000008075954E+00, ...
      -0.0000000000002463214E+00, ...
      -0.0000000000000767656E+00, ...
      -0.0000000000000243883E+00, ...
      -0.0000000000000078831E+00, ...
      -0.0000000000000025882E+00, ...
      -0.0000000000000008619E+00, ...
      -0.0000000000000002908E+00, ...
      -0.0000000000000000993E+00, ...
      -0.0000000000000000343E+00 ]';
    an22cs = [ ...
       0.0537418629629794329E+00, ...
      -0.0126661435859883193E+00, ...
      -0.0011924334106593007E+00, ...
      -0.0002032327627275655E+00, ...
      -0.0000446468963075164E+00, ...
      -0.0000113359036053123E+00, ...
      -0.0000031641352378546E+00, ...
      -0.0000009446708886149E+00, ...
      -0.0000002966562236472E+00, ...
      -0.0000000969118892024E+00, ...
      -0.0000000326822538653E+00, ...
      -0.0000000113144618964E+00, ...
      -0.0000000040042691002E+00, ...
      -0.0000000014440333684E+00, ...
      -0.0000000005292853746E+00, ...
      -0.0000000001967763374E+00, ...
      -0.0000000000740800096E+00, ...
      -0.0000000000282016314E+00, ...
      -0.0000000000108440066E+00, ...
      -0.0000000000042074801E+00, ...
      -0.0000000000016459150E+00, ...
      -0.0000000000006486827E+00, ...
      -0.0000000000002574095E+00, ...
      -0.0000000000001027889E+00, ...
      -0.0000000000000412846E+00, ...
      -0.0000000000000166711E+00, ...
      -0.0000000000000067657E+00, ...
      -0.0000000000000027585E+00, ...
      -0.0000000000000011296E+00, ...
      -0.0000000000000004645E+00, ...
      -0.0000000000000001917E+00, ...
      -0.0000000000000000794E+00, ...
      -0.0000000000000000330E+00 ]';
    aph0cs = [ ...
      -0.0855849241130933257E+00, ...
       0.0011214378867065261E+00, ...
       0.0000042721029353664E+00, ...
       0.0000000817607381483E+00, ...
       0.0000000033907645000E+00, ...
       0.0000000002253264423E+00, ...
       0.0000000000206284209E+00, ...
       0.0000000000023858763E+00, ...
       0.0000000000003301618E+00, ...
       0.0000000000000527010E+00, ...
       0.0000000000000094555E+00, ...
       0.0000000000000018709E+00, ...
       0.0000000000000004024E+00, ...
       0.0000000000000000930E+00, ...
       0.0000000000000000229E+00 ]';
    aph1cs = [ ...
      -0.1024172908077571694E+00, ...
       0.0071697275146591248E+00, ...
       0.0001209959363122329E+00, ...
       0.0000073361512841220E+00, ...
       0.0000007535382954272E+00, ...
       0.0000001041478171741E+00, ...
       0.0000000174358728519E+00, ...
       0.0000000033399795033E+00, ...
       0.0000000007073075174E+00, ...
       0.0000000001619187515E+00, ...
       0.0000000000394539982E+00, ...
       0.0000000000101192282E+00, ...
       0.0000000000027092778E+00, ...
       0.0000000000007523806E+00, ...
       0.0000000000002156369E+00, ...
       0.0000000000000635283E+00, ...
       0.0000000000000191757E+00, ...
       0.0000000000000059143E+00, ...
       0.0000000000000018597E+00, ...
       0.0000000000000005950E+00, ...
       0.0000000000000001934E+00, ...
       0.0000000000000000638E+00 ]';
    aph2cs = [ ...
      -0.2057088719781465107E+00, ...
       0.0422196961357771922E+00, ...
       0.0020482560511207275E+00, ...
       0.0002607800735165006E+00, ...
       0.0000474824268004729E+00, ...
       0.0000105102756431612E+00, ...
       0.0000026353534014668E+00, ...
       0.0000007208824863499E+00, ...
       0.0000002103236664473E+00, ...
       0.0000000644975634555E+00, ...
       0.0000000205802377264E+00, ...
       0.0000000067836273921E+00, ...
       0.0000000022974015284E+00, ...
       0.0000000007961306765E+00, ...
       0.0000000002813860610E+00, ...
       0.0000000001011749057E+00, ...
       0.0000000000369306738E+00, ...
       0.0000000000136615066E+00, ...
       0.0000000000051142751E+00, ...
       0.0000000000019351689E+00, ...
       0.0000000000007393607E+00, ...
       0.0000000000002849792E+00, ...
       0.0000000000001107281E+00, ...
       0.0000000000000433412E+00, ...
       0.0000000000000170801E+00, ...
       0.0000000000000067733E+00, ...
       0.0000000000000027017E+00, ...
       0.0000000000000010835E+00, ...
       0.0000000000000004367E+00, ...
       0.0000000000000001769E+00, ...
       0.0000000000000000719E+00, ...
       0.0000000000000000294E+00 ]';

    eta = 0.1 * r4_mach ( 3 );
    nan20 = r4_inits ( an20cs, 16, eta );
    nan21 = r4_inits ( an21cs, 24, eta );
    nan22 = r4_inits ( an22cs, 33, eta );
    naph0 = r4_inits ( aph0cs, 15, eta );
    naph1 = r4_inits ( aph1cs, 22, eta );
    naph2 = r4_inits ( aph2cs, 32, eta );
    xsml = - ( 128.0 / r4_mach ( 3 ) )^0.3333;

  end

  if ( x <= xsml )
    z = 1.0;
    ampl = 0.3125 + r4_csevl ( z, an20cs, nan20 );
    phi = - 0.625 + r4_csevl ( z, aph0cs, naph0 );
  elseif ( x < - 4.0 )
    z = 128.0 / x / x / x + 1.0;
    ampl = 0.3125 + r4_csevl ( z, an20cs, nan20 );
    phi = - 0.625 + r4_csevl ( z, aph0cs, naph0 );
  elseif ( x < - 2.0 )
    z = ( 128.0 / x / x / x + 9.0 ) / 7.0;
    ampl = 0.3125 + r4_csevl ( z, an21cs, nan21 );
    phi = - 0.625 + r4_csevl ( z, aph1cs, naph1 );
  elseif ( x <= - 1.0 )
    z = ( 16.0 / x / x / x + 9.0 ) / 7.0;
    ampl = 0.3125 + r4_csevl ( z, an22cs, nan22 );
    phi = - 0.625 + r4_csevl ( z, aph2cs, naph2 );
  else
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R4_ADMP - Fatal error!\n' );
    fprintf ( 1, '  - 1.0 < x.\n' );
    error ( 'R4_ADMP - Fatal error!' )
  end

  sqrtx = sqrt ( - x );
  ampl = sqrt ( ampl * sqrtx );
  phi = pi34 - x * sqrtx * phi;

  return
end
