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

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

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

int main(void) {
  Integer exit_status = 0, i, n;
  NagError fail;
  double *vec = 0;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_sort_realvec_sort (m01cac) Example Program Results\n");
  scanf("%" NAG_IFMT "", &n);
  if (n >= 1) {
    if (!(vec = NAG_ALLOC(n, double))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  } else {
    printf("Invalid n.\n");
    exit_status = 1;
    return exit_status;
  }
  for (i = 0; i < n; ++i)
    scanf("%lf", &vec[i]);
  /* nag_sort_realvec_sort (m01cac).
   * Quicksort of set of values of data type double
   */
  nag_sort_realvec_sort(vec, (size_t)n, Nag_Ascending, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_sort_realvec_sort (m01cac).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }
  printf("Sorted numbers\n\n");
  for (i = 0; i < n; ++i)
    printf("%10.6g%c", vec[i], (i % 7 == 6 || i == n - 1) ? '\n' : ' ');
END:
  NAG_FREE(vec);
  return exit_status;
}