NAG Library Manual, Mark 28.3
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_specfun_bessel_zeros (s17alc) Example Program.
 *
 * Copyright 2022 Numerical Algorithms Group.
 *
 * NAG C Library
 *
 * Mark 28.3, 2022.
 *
 */

#include <math.h>
#include <nag.h>
#include <stdio.h>

int main(void) {

#define NMAX 100

  Integer exit_status = 0, i, mode, n;
  NagError fail;
  double a, rel, *x = 0;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_specfun_bessel_zeros (s17alc) Example Program Results\n\n");

  if (!(x = NAG_ALLOC(NMAX, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }
  /* nag_machine_precision (x02ajc).
   * The machine precision
   */
  rel = sqrt(nag_machine_precision);
  scanf("%lf %" NAG_IFMT " %" NAG_IFMT "", &a, &n, &mode);
  /* nag_specfun_bessel_zeros (s17alc).
   * Zeros of Bessel functions J_alpha(x), (J_alpha')(x),
   * Y_alpha(x) or (Y_alpha')(x)
   */
  nag_specfun_bessel_zeros(a, n, mode, rel, x, &fail);

  if (fail.code == NE_NOERROR) {
    printf("   a   n   mode\n");
    printf(" %4.1f%3" NAG_IFMT "%6" NAG_IFMT "\n\n", a, n, mode);
    if (mode == 1)
      printf("Leading n positive zeros of J\n");
    else if (mode == 2)
      printf("Leading n positive zeros of Y\n");
    else if (mode == 3) {
      if (a == 0.0)
        printf("Leading n non-negative zeros of J'\n");
      else
        printf("Leading n positive zeros of J'\n");
    } else if (mode == 4)
      printf("Leading n positive zeros of Y'\n\n");
    for (i = 0; i <= n - 1; ++i)
      printf("  x = %13.4e\n", x[i]);
    printf("\n");
  } else {
    printf("Error from nag_specfun_bessel_zeros (s17alc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }
END:
  NAG_FREE(x);
  return exit_status;
}