/* nag_mv_promax (g03bdc) Example Program. * * Copyright 2008, Numerical Algorithms Group. * * Mark 9, 2009. */ /* Pre-processor includes */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *outfile = 0; /*Integer scalar and array declarations */ Integer exit_status = 0; Integer i, iter, j, m, maxit, n; Integer pdfp, pdfs, pdphi, pdr, pdro, pdx; /*Double scalar and array declarations */ double acc, g, power; double *fp = 0, *fs = 0, *phi = 0, *r = 0, *ro = 0, *x = 0; /*Character scalar and array declarations */ char sstand[20]; /*NAG types */ Nag_OrderType order; Nag_RotationLoading stand; 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); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "%s\n", "nag_mv_promax (g03bdc) Example Program Results"); /* Skip heading in data file*/ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%s %ld%ld%lf%*[^\n] ", sstand, &n, &m, &power); stand = (Nag_RotationLoading) nag_enum_name_to_value(sstand); pdfp = m; #define FP(I, J) fp[(I-1)*pdfp + J-1] pdfs = m; #define FS(I, J) fs[(I-1)*pdfs + J-1] pdphi = m; #define PHI(I, J) phi[(I-1)*pdphi + J-1] pdr = m; #define R(I, J) r[(I-1)*pdr + J-1] pdro = m; #define RO(I, J) ro[(I-1)*pdro + J-1] pdx = pdfp; #define X(I, J) x[(I-1)*pdx + J-1] if (!(fp = NAG_ALLOC(pdfp*n, double)) || !(fs = NAG_ALLOC(pdfs*n, double)) || !(phi = NAG_ALLOC(pdphi*m, double)) || !(r = NAG_ALLOC(pdr*m, double)) || !(ro = NAG_ALLOC(pdro*m, double)) || !(x = NAG_ALLOC(pdx*n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read loadings matrix.*/ for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) fscanf(fpin, "%lf ", &FP(i, j)); } fscanf(fpin, "%*[^\n] "); /* * nag_mv_orthomax (g03bac) * Orthogonal rotations */ g = 1.0e0; acc = 1.0e-5; maxit = 200; nag_mv_orthomax(stand, g, n, m, fp, pdx, x, ro, pdro, acc, maxit, &iter, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_mv_orthomax (g03bac).\n%s\n", fail.message); exit_status = 1; goto END; } /* * nag_mv_promax (g03bdc) * ProMax rotations */ nag_mv_promax(stand, n, m, x, pdx, ro, pdro, power, fp, pdfp, r, pdr, phi, pdphi, fs, pdfs, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_mv_promax (g03bdc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); order = Nag_RowMajor; nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, fp, pdfp, "Factor pattern", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, m, m, r, pdr, "ProMax rotation", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, m, m, phi, pdphi, "Inter-factor correlations", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); /* * nag_gen_real_mat_print (x04cac) * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, fs, pdfs, "Factor structure", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (fp) NAG_FREE(fp); if (fs) NAG_FREE(fs); if (phi) NAG_FREE(phi); if (r) NAG_FREE(r); if (ro) NAG_FREE(ro); if (x) NAG_FREE(x); return exit_status; }