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

NAG CL Interface Introduction
Example description
/* nag_tsa_uni_diff (g13aac) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.2, 2024.
 */

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

int main(void) {
  /* Scalars */
  Integer exit_status, i, d, ds, s, nx, nxd;
  NagError fail;

  /* Arrays */
  double *x = 0, *xd = 0;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_tsa_uni_diff (g13aac) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &nx, &d,
        &ds, &s);

  if (nx > 0) {
    /* Allocate memory */
    if (!(x = NAG_ALLOC(nx, double)) || !(xd = NAG_ALLOC(nx, double))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }

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

    printf("\n");
    printf("Non-seasonal differencing of order %" NAG_IFMT " "
           "and seasonal differencing\nof order %" NAG_IFMT " "
           "with seasonality %" NAG_IFMT " are applied\n",
           d, ds, s);

    /* nag_tsa_uni_diff (g13aac).
     * Univariate time series, seasonal and non-seasonal
     * differencing
     */
    nag_tsa_uni_diff(x, nx, d, ds, s, xd, &nxd, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_tsa_uni_diff (g13aac).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }

    printf("\n");
    printf("The output array holds %2" NAG_IFMT " values, of which the "
           "first %2" NAG_IFMT " are differenced values\n\n",
           nx, nxd);

    for (i = 1; i <= nx; ++i) {
      printf("%10.1f", xd[i - 1]);
      if (i % 5 == 0 || i == nx)
        printf("\n");
    }
  }

END:
  NAG_FREE(x);
  NAG_FREE(xd);

  return exit_status;
}