/* nag_erfcx (s15agc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 9, 2009.
 */
/* Pre-processor includes */
#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nags.h>
int main(void)
{
  /*Integer scalar and array declarations */
  Integer    exit_status = 0;
  /*Double scalar and array declarations */
  double     x, y;

  NagError   fail;
  const char *str_fail;

  INIT_FAIL(fail);

  printf("nag_erfcx (s15agc) Example Program Results\n");
  /* Skip heading in data file*/
  scanf("%*[^\n] ");
  printf("\n%s\n\n", "       x          erfcx(x)     fail");
  while (scanf("%lf%*[^\n] ", &x) != EOF)
    {
      /*
       * nag_erfcx (s15agc)
       * Scaled complement of error function, erfcx(x)
       */
      y = nag_erfcx(x, &fail);
      if (fail.code != NE_NOERROR)
        {
          if (fail.code == NW_HI || fail.code == NW_NEG ||
              fail.code == NW_REAL)
            {
              /* nag_code_to_error_name (x04ndc).
               * Converts NAG error code to its string value
               */
              str_fail = nag_code_to_error_name(fail.code);
              printf("%14.5e  %-14.5e %s\n", x, y, str_fail);
            }
          else
            {
              printf("Error from nag_erfcx (s15agc).\n%s\n",
                      fail.message);
              exit_status = 1;
              goto END;
            }
        }
      else
        {
          printf("%14.5e  %-14.5e\n", x, y);
        }
    }

 END:

  return exit_status;
}