/* nag_complex_airy_bi (s17dhc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 7, 2002.
 */

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

int main(void)
{
  Integer          exit_status = 0;
  Complex          z, bi;
  char             nag_enum_deriv[40], nag_enum_scal[40];
  Nag_ScaleResType scal;
  Nag_FunType      deriv;
  NagError         fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_complex_airy_bi (s17dhc) Example Program Results\n");
  printf(
          "    deriv               z              scal                bi\n");
  while (scanf(" %39s (%lf,%lf) %39s%*[^\n] ",
               nag_enum_deriv, &z.re, &z.im, nag_enum_scal) != EOF)
    {
      /* nag_enum_name_to_value (x04nac).
       * Converts NAG enum member name to value
       */
      deriv = (Nag_FunType) nag_enum_name_to_value(nag_enum_deriv);
      scal = (Nag_ScaleResType) nag_enum_name_to_value(nag_enum_scal);

      /* nag_complex_airy_bi (s17dhc).
       * Airy functions Bi(z), complex z
       */
      nag_complex_airy_bi(deriv, z, scal, &bi, &fail);
      if (fail.code != NE_NOERROR)
        {
          printf("Error from nag_complex_airy_bi (s17dhc).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
      printf(" %-12s  (%7.3f,%7.3f)  %-14s  (%7.3f,%7.3f)\n",
              nag_enum_deriv, z.re, z.im, nag_enum_scal, bi.re, bi.im);
    }

 END:

  return exit_status;
}