function [ ampl, theta ] = r8_b1mp ( x )

%*****************************************************************************80
%
%% R8_B1MP evaluates the modulus and phase for the Bessel J1 and Y1 functions.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 October 2011
%
%  Author:
%
%    Original FORTRAN77version 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, THETA, the modulus and phase.
%
  persistent bm12cs
  persistent bm1cs
  persistent bt12cs
  persistent bth1cs
  persistent nbm1
  persistent nbm12
  persistent nbt12
  persistent nbth1
  persistent xmax

  if ( isempty ( nbm1 ) )

    bm12cs = [ ...
      +0.9807979156233050027272093546937E-01, ...
      +0.1150961189504685306175483484602E-02, ...
      -0.4312482164338205409889358097732E-05, ...
      +0.5951839610088816307813029801832E-07, ...
      -0.1704844019826909857400701586478E-08, ...
      +0.7798265413611109508658173827401E-10, ...
      -0.4958986126766415809491754951865E-11, ...
      +0.4038432416421141516838202265144E-12, ...
      -0.3993046163725175445765483846645E-13, ...
      +0.4619886183118966494313342432775E-14, ...
      -0.6089208019095383301345472619333E-15, ...
      +0.8960930916433876482157048041249E-16, ...
      -0.1449629423942023122916518918925E-16, ...
      +0.2546463158537776056165149648068E-17, ...
      -0.4809472874647836444259263718620E-18, ...
      +0.9687684668292599049087275839124E-19, ...
      -0.2067213372277966023245038117551E-19, ...
      +0.4646651559150384731802767809590E-20, ...
      -0.1094966128848334138241351328339E-20, ...
      +0.2693892797288682860905707612785E-21, ...
      -0.6894992910930374477818970026857E-22, ...
      +0.1830268262752062909890668554740E-22, ...
      -0.5025064246351916428156113553224E-23, ...
      +0.1423545194454806039631693634194E-23, ...
      -0.4152191203616450388068886769801E-24, ...
      +0.1244609201503979325882330076547E-24, ...
      -0.3827336370569304299431918661286E-25, ...
      +0.1205591357815617535374723981835E-25, ...
      -0.3884536246376488076431859361124E-26, ...
      +0.1278689528720409721904895283461E-26, ...
      -0.4295146689447946272061936915912E-27, ...
      +0.1470689117829070886456802707983E-27, ...
      -0.5128315665106073128180374017796E-28, ...
      +0.1819509585471169385481437373286E-28, ...
      -0.6563031314841980867618635050373E-29, ...
      +0.2404898976919960653198914875834E-29, ...
      -0.8945966744690612473234958242979E-30, ...
      +0.3376085160657231026637148978240E-30, ...
      -0.1291791454620656360913099916966E-30, ...
      +0.5008634462958810520684951501254E-31 ]';
    bm1cs = [ ...
      +0.1069845452618063014969985308538, ...
      +0.3274915039715964900729055143445E-02, ...
      -0.2987783266831698592030445777938E-04, ...
      +0.8331237177991974531393222669023E-06, ...
      -0.4112665690302007304896381725498E-07, ...
      +0.2855344228789215220719757663161E-08, ...
      -0.2485408305415623878060026596055E-09, ...
      +0.2543393338072582442742484397174E-10, ...
      -0.2941045772822967523489750827909E-11, ...
      +0.3743392025493903309265056153626E-12, ...
      -0.5149118293821167218720548243527E-13, ...
      +0.7552535949865143908034040764199E-14, ...
      -0.1169409706828846444166290622464E-14, ...
      +0.1896562449434791571721824605060E-15, ...
      -0.3201955368693286420664775316394E-16, ...
      +0.5599548399316204114484169905493E-17, ...
      -0.1010215894730432443119390444544E-17, ...
      +0.1873844985727562983302042719573E-18, ...
      -0.3563537470328580219274301439999E-19, ...
      +0.6931283819971238330422763519999E-20, ...
      -0.1376059453406500152251408930133E-20, ...
      +0.2783430784107080220599779327999E-21, ...
      -0.5727595364320561689348669439999E-22, ...
      +0.1197361445918892672535756799999E-22, ...
      -0.2539928509891871976641440426666E-23, ...
      +0.5461378289657295973069619199999E-24, ...
      -0.1189211341773320288986289493333E-24, ...
      +0.2620150977340081594957824000000E-25, ...
      -0.5836810774255685901920938666666E-26, ...
      +0.1313743500080595773423615999999E-26, ...
      -0.2985814622510380355332778666666E-27, ...
      +0.6848390471334604937625599999999E-28, ...
      -0.1584401568222476721192960000000E-28, ...
      +0.3695641006570938054301013333333E-29, ...
      -0.8687115921144668243012266666666E-30, ...
      +0.2057080846158763462929066666666E-30, ...
      -0.4905225761116225518523733333333E-31 ]';
    bt12cs = [ ...
      +0.73823860128742974662620839792764, ...
      -0.33361113174483906384470147681189E-02, ...
      +0.61463454888046964698514899420186E-04, ...
      -0.24024585161602374264977635469568E-05, ...
      +0.14663555577509746153210591997204E-06, ...
      -0.11841917305589180567005147504983E-07, ...
      +0.11574198963919197052125466303055E-08, ...
      -0.13001161129439187449366007794571E-09, ...
      +0.16245391141361731937742166273667E-10, ...
      -0.22089636821403188752155441770128E-11, ...
      +0.32180304258553177090474358653778E-12, ...
      -0.49653147932768480785552021135381E-13, ...
      +0.80438900432847825985558882639317E-14, ...
      -0.13589121310161291384694712682282E-14, ...
      +0.23810504397147214869676529605973E-15, ...
      -0.43081466363849106724471241420799E-16, ...
      +0.80202544032771002434993512550400E-17, ...
      -0.15316310642462311864230027468799E-17, ...
      +0.29928606352715568924073040554666E-18, ...
      -0.59709964658085443393815636650666E-19, ...
      +0.12140289669415185024160852650666E-19, ...
      -0.25115114696612948901006977706666E-20, ...
      +0.52790567170328744850738380799999E-21, ...
      -0.11260509227550498324361161386666E-21, ...
      +0.24348277359576326659663462400000E-22, ...
      -0.53317261236931800130038442666666E-23, ...
      +0.11813615059707121039205990399999E-23, ...
      -0.26465368283353523514856789333333E-24, ...
      +0.59903394041361503945577813333333E-25, ...
      -0.13690854630829503109136383999999E-25, ...
      +0.31576790154380228326413653333333E-26, ...
      -0.73457915082084356491400533333333E-27, ...
      +0.17228081480722747930705920000000E-27, ...
      -0.40716907961286507941068800000000E-28, ...
      +0.96934745136779622700373333333333E-29, ...
      -0.23237636337765716765354666666666E-29, ...
      +0.56074510673522029406890666666666E-30, ...
      -0.13616465391539005860522666666666E-30, ...
      +0.33263109233894654388906666666666E-31 ]';
    bth1cs = [ ...
      +0.74749957203587276055443483969695, ...
      -0.12400777144651711252545777541384E-02, ...
      +0.99252442404424527376641497689592E-05, ...
      -0.20303690737159711052419375375608E-06, ...
      +0.75359617705690885712184017583629E-08, ...
      -0.41661612715343550107630023856228E-09, ...
      +0.30701618070834890481245102091216E-10, ...
      -0.28178499637605213992324008883924E-11, ...
      +0.30790696739040295476028146821647E-12, ...
      -0.38803300262803434112787347554781E-13, ...
      +0.55096039608630904934561726208562E-14, ...
      -0.86590060768383779940103398953994E-15, ...
      +0.14856049141536749003423689060683E-15, ...
      -0.27519529815904085805371212125009E-16, ...
      +0.54550796090481089625036223640923E-17, ...
      -0.11486534501983642749543631027177E-17, ...
      +0.25535213377973900223199052533522E-18, ...
      -0.59621490197413450395768287907849E-19, ...
      +0.14556622902372718620288302005833E-19, ...
      -0.37022185422450538201579776019593E-20, ...
      +0.97763074125345357664168434517924E-21, ...
      -0.26726821639668488468723775393052E-21, ...
      +0.75453300384983271794038190655764E-22, ...
      -0.21947899919802744897892383371647E-22, ...
      +0.65648394623955262178906999817493E-23, ...
      -0.20155604298370207570784076869519E-23, ...
      +0.63417768556776143492144667185670E-24, ...
      -0.20419277885337895634813769955591E-24, ...
      +0.67191464220720567486658980018551E-25, ...
      -0.22569079110207573595709003687336E-25, ...
      +0.77297719892989706370926959871929E-26, ...
      -0.26967444512294640913211424080920E-26, ...
      +0.95749344518502698072295521933627E-27, ...
      -0.34569168448890113000175680827627E-27, ...
      +0.12681234817398436504211986238374E-27, ...
      -0.47232536630722639860464993713445E-28, ...
      +0.17850008478186376177858619796417E-28, ...
      -0.68404361004510395406215223566746E-29, ...
      +0.26566028671720419358293422672212E-29, ...
      -0.10450402527914452917714161484670E-29, ...
      +0.41618290825377144306861917197064E-30, ...
      -0.16771639203643714856501347882887E-30, ...
      +0.68361997776664389173535928028528E-31, ...
      -0.28172247861233641166739574622810E-31 ]';

    eta = 0.1 * r8_mach ( 3 );
    nbm1 = r8_inits ( bm1cs, 37, eta );
    nbt12 = r8_inits ( bt12cs, 39, eta );
    nbm12 = r8_inits ( bm12cs, 40, eta );
    nbth1 = r8_inits ( bth1cs, 44, eta );
    xmax = 1.0 / r8_mach ( 4 );

  end

  if ( x < 4.0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'R8_B1MP - Fatal error!\n' );
    fprintf ( 1, '  X < 4.\n' );
    error ( 'R8_B1MP - Fatal error!' )
  elseif ( x <= 8.0 )
    z = ( 128.0 / x / x - 5.0 ) / 3.0;
    ampl = ( 0.75 + r8_csevl ( z, bm1cs, nbm1 ) ) / sqrt ( x );
    theta = x - 0.75 * pi + r8_csevl ( z, bt12cs, nbt12 ) / x;
  else
    z = 128.0 / x / x - 1.0;
    ampl = ( 0.75 + r8_csevl ( z, bm12cs, nbm12 ) ) / sqrt ( x );
    theta = x - 0.75 * pi + r8_csevl ( z, bth1cs, nbth1 ) / x;
  end

  return
end
