/* nag_bessel_j_alpha (s18ekc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * NAG C Library
 *
 * Mark 6, 2000.
 * Mark 8 revised, 2004.
 *
 */

#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nags.h>

int main(void)
{

  Complex  *b = 0;
  Integer  exit_status = 0, i, nl;
  NagError fail;
  double   a, alpha, d, x;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_bessel_j_alpha (s18ekc) Example Program Results\n");
  if (!(b = NAG_ALLOC(101, Complex)))
    {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  while (scanf("%lf %lf %ld%*[^\n]", &x, &a, &nl) != EOF)
    {
      printf("  x     a      nl\n");
      printf("%4.1f  %4.1f %6ld\n\n", x, a, nl);
      /* nag_bessel_j_alpha (s18ekc).
       * Bessel functions J_(alpha + n - 1)(x) or
       * J_(alpha - n + 1)(x) for real x != 0, non-negative
       * alpha < 1 and n = 1 , 2 , ... , |N| + 1
       */
      nag_bessel_j_alpha(x, a, nl, b, &fail);
      if (fail.code == NE_NOERROR)
        {
          printf(" Requested values of J_alpha(X)\n\n");
          alpha = a;
          printf("     alpha              J_alpha(X)\n");
          for (i = 0; i < ABS(nl) + 1; ++i)
            {
              printf(" %13.4e   (%13.4e, %13.4e)\n", alpha,
                      b[i].re, b[i].im);
              d = (double) nl;
              alpha += SIGN(1.0, d);
            }
        }
      else
        {
          printf("Error from nag_bessel_j_alpha (s18ekc).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
    }
 END:
  NAG_FREE(b);
  return exit_status;
}