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

NAG CL Interface Introduction
Example description
/* nag_stat_prob_chisq_lincomb (g01jdc) Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 *
 * Mark 27.3, 2021.
 */

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

int main(void) {
  /* Scalars */
  double c, d, prob;
  Integer exit_status, i, n;
  /* Arrays */
  char nag_enum_arg[40];
  double *rlam = 0;
  Nag_LCCMethod method;
  NagError fail;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_stat_prob_chisq_lincomb (g01jdc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  n = 10;

  /* Allocate memory */
  if (!(rlam = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }
  scanf(" %39s%lf%lf%*[^\n] ", nag_enum_arg, &d, &c);
  /* nag_enum_name_to_value (x04nac).
   * Converts NAG enum member name to value
   */
  method = (Nag_LCCMethod)nag_enum_name_to_value(nag_enum_arg);

  for (i = 1; i <= n; ++i)
    scanf("%lf", &rlam[i - 1]);
  scanf("%*[^\n] ");

  /* nag_stat_prob_chisq_lincomb (g01jdc).
   * Computes lower tail probability for a linear combination
   * of (central) chi^2 variables
   */
  nag_stat_prob_chisq_lincomb(method, n, rlam, d, c, &prob, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_stat_prob_chisq_lincomb (g01jdc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\n");
  printf(" Values of lambda ");
  for (i = 1; i <= n; ++i) {
    if (i % 6 == 0)
      printf("%18s", " ");

    printf("%6.2f ", rlam[i - 1]);

    if (i % 5 == 0 || i == n)
      printf("\n");
  }
  printf(" Value of D       %6.2f\n", d);
  printf(" Value of C       %6.2f\n\n", c);
  printf(" Probability = %11.4f\n", prob);

END:
  NAG_FREE(rlam);

  return exit_status;
}