/* nag_lambertW (c05bac) Example Program. * * Copyright 2008, Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double w, x; Integer branch; Integer exit_status = 0; char offset[10]; Nag_Boolean offsetenum; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_lambertW (c05bac) Example Program Results\n"); /* Skip heading in data file*/ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &branch); fscanf(fpin, "%s%*[^\n] ", offset); /* * nag_enum_name_to_value (x04nac). * Converts NAG enum member name to value */ offsetenum = (Nag_Boolean) nag_enum_name_to_value(offset); fprintf(fpout, "\n"); fprintf(fpout, "branch = %ld\n", branch); fprintf(fpout, "offset = %s\n", offset); fprintf(fpout, "\n x w(x)\n\n"); while (fscanf(fpin, "%lf%*[^\n] ", &x) != EOF) { /* * nag_lambertW (c05bac) * Real values of Lambert's W function, W(x) */ w = nag_lambertW(x, branch, offsetenum, &fail); if (fail.code == NE_NOERROR) { fprintf(fpout, "%14.5e%14.5e\n", x, w); } else { fprintf(fpout, "Error from nag_lambertW (c05bac).\n%s\n", fail.message); exit_status = 1; goto END; } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }