/* nag_quad_md_numth_coeff_2prime (d01gzc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 23, 2011.
 */

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

int main(void)
{
  Integer exit_status = 0;
  Integer i, ndim, np1, np2;
  double *vk = 0;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_quad_md_numth_coeff_2prime (d01gzc) Example Program Results\n");
  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%ld", &ndim);
  scanf("%ld %ld%*[^\n] ", &np1, &np2);

  if (!(vk = NAG_ALLOC(ndim, double)))
    {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }

  /* nag_quad_md_numth_coeff_2prime (d01gzc).
   * Korobov optimal coefficients for use in d01gdc,
   * when number of points is product of two primes.
   */
  nag_quad_md_numth_coeff_2prime(ndim, np1, np2, vk, &fail);
  if (fail.code != NE_NOERROR)
    {
      printf("Error from nag_quad_md_numth_coeff_2prime (d01gzc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }

  printf("\nndim = %3ld np1 = %6ld np2 = %6ld\n",
         ndim, np1, np2);
  printf("\nCoefficients =");
  for (i = 0; i < ndim; i++)
    printf("%4.0f ", vk[i]);
  printf("\n");

 END:
  NAG_FREE(vk);

  return exit_status;
}