/* nag_complex_bessel_j_seq (s18gkc) Example Program.
 *
 * NAGPRODCODE Version.
 *
 * Copyright 2016 Numerical Algorithms Group.
 *
 * Mark 26, 2016.
 */

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

int main(void)
{
  Integer exit_status = 0;
  Complex z, b[20];
  double a, alpha;
  Integer i, nl;
  NagError fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_complex_bessel_j_seq (s18gkc) Example Program Results\n");
  while (scanf(" (%lf,%lf) %lf %" NAG_IFMT "%*[^\n] ", &z.re, &z.im, &a,
               &nl) != EOF) {
    /* nag_complex_bessel_j_seq (s18gkc).
     * Bessel function of the 1st kind J_(alpha+/-n)(z)
     */
    nag_complex_bessel_j_seq(z, a, nl, b, &fail);
    if (fail.code == NE_NOERROR) {
      printf("         z             a       nl\n");
      printf(" (%7.3f,%7.3f)  %lf    %" NAG_IFMT "\n\n", z.re, z.im, a, nl);
      printf("Requested values of J_alpha(Z)\n\n");
      alpha = a;
      printf("     alpha              J_alpha(z)\n");
      for (i = 0; i < ABS(nl) + 1; i++) {
        printf("%13.4e   (%13.4e,%13.4e)\n", alpha, b[i].re, b[i].im);
        if (nl > 0)
          alpha += 1.0;
        else
          alpha -= 1.0;
      }
    }
    else {
      printf("Error from nag_complex_bessel_j_seq (s18gkc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
  }

END:

  return exit_status;
}