/* nag_complex_bessel_y (s17dcc) Example Program.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.1, 2017.
 */

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

int main(void)
{
  Integer exit_status = 0;
  Complex z, cy[2];
  double fnu;
  const Integer n = 2;
  Integer nz;
  Nag_ScaleResType scal;
  char nag_enum_arg[40];
  NagError fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_complex_bessel_y (s17dcc) Example Program Results\n");
  printf("Calling with n = %" NAG_IFMT "\n", n);
  printf("   fnu           z              scal            cy[0]     "
         "        cy[1]      nz\n");
  while (scanf(" %lf (%lf,%lf) %39s%*[^\n] ", &fnu, &z.re, &z.im,
               nag_enum_arg) != EOF) {
    /* Convert scal character to enum */
    scal = (Nag_ScaleResType) nag_enum_name_to_value(nag_enum_arg);

    /* nag_complex_bessel_y (s17dcc).
     * Bessel functions Y_(nu+a)(z), real a >= 0, complex z,
     * nu = 0,1,2, ...
     */
    nag_complex_bessel_y(fnu, z, n, scal, cy, &nz, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_complex_bessel_y (s17dcc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%7.4f (%7.3f,%7.3f) %-14s (%7.3f,%7.3f) (%7.3f,%7.3f) "
           "%" NAG_IFMT "\n", fnu, z.re, z.im, nag_enum_arg, cy[0].re,
           cy[0].im, cy[1].re, cy[1].im, nz);
  }

END:

  return exit_status;
}