Example description
/* nag_roots_lambertw_real (c05bac) Example Program.
 *
 * Copyright 2020 Numerical Algorithms Group.
 *
 * Mark 27.1, 2020.
 */

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

int main(void) {
  /* Scalars */
  double w, x;
  Integer branch;
  Integer exit_status = 0;
  char offset[10];
  Nag_Boolean offsetenum;
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_roots_lambertw_real (c05bac) Example Program Results\n");
  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%*[^\n] ", &branch);
  scanf("%9s%*[^\n] ", offset);
  /*
   * nag_enum_name_to_value (x04nac).
   * Converts NAG enum member name to value
   */
  offsetenum = (Nag_Boolean)nag_enum_name_to_value(offset);
  printf("\n");
  printf("branch = %" NAG_IFMT "\n", branch);
  printf("offset = %s\n", offset);
  printf("\n      x           w(x)\n\n");
  while (scanf("%lf%*[^\n] ", &x) != EOF)
  {
    /*
     * nag_roots_lambertw_real (c05bac)
     * Real values of Lambert's W function, W(x)
     */
    w = nag_roots_lambertw_real(x, branch, offsetenum, &fail);
    if (fail.code == NE_NOERROR) {
      printf("%14.5e%14.5e\n", x, w);
    } else {
      printf("Error from nag_roots_lambertw_real (c05bac).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
  }

END:
  return exit_status;
}