/* nag_zload (f16hbc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Complex alpha; Integer exit_status, i, incx, n, xlen; /* Arrays */ Complex *x = 0; /* Nag Types */ NagError fail; exit_status = 0; 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_zload (f16hbc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read length of vector and increment. */ fscanf(fpin, "%ld%ld%*[^\n] ", &n, &incx); /* Read scalar parameter */ fscanf(fpin, " ( %lf , %lf ) %*[^\n] ", &alpha.re, &alpha.im); xlen = MAX(1, 1 + (n - 1)*ABS(incx)); if (n > 0) { /* Allocate memory */ if (!(x = NAG_ALLOC(xlen, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n\n"); exit_status = 1; return exit_status; } /* nag_zload(f16hbc). * Broadcast a complex scalar to a complex vector. * */ nag_zload(n, alpha, x, incx, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_zload.\n%s\n", fail.message); exit_status = 1; goto END; } /* Print x. */ fprintf(fpout, "Loaded vector x:\n\n"); for (i = 0; i < xlen; i = i + incx) fprintf(fpout, " x[%1ld] = (%5.2f, %5.2f)\n", i, x[i].re, x[i].im); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); return exit_status; }