/* nag_binary_factor_service (g11sbc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, p, ns, j, n, nrx, pdx; NagError fail; Nag_OrderType order; char flag; /* Arrays */ Integer *irl = 0; Nag_Boolean *x = 0; #ifdef NAG_COLUMN_MAJOR #define X(I,J) x[(J-1)*pdx + I - 1] order = Nag_ColMajor; #else #define X(I,J) x[(I-1)*pdx + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); exit_status = 0; Vprintf("nag_binary_factor_service (g11sbc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%*[^\n] ", &n, &p); if (n > 0 && p > 0) { /* Allocate arrays */ nrx = n; if ( !(irl = NAG_ALLOC(n, Integer)) || !(x = NAG_ALLOC(nrx * p, Nag_Boolean)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (order == Nag_ColMajor) pdx = nrx; else pdx = p; for (i = 1; i <= n; ++i) { for (j = 1; j <= p; ++j) { Vscanf(" %c", &flag); X(i,j) = (flag == 'T'); } Vscanf("%*[^\n] "); } /* nag_binary_factor_service (g11sbc). * Frequency count for nag_binary_factor (g11sac) */ nag_binary_factor_service(order, p, n, &ns, x, pdx, irl, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_binary_factor_service (g11sbc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("Frequency Score pattern\n"); Vprintf("\n"); for (i = 1; i <= ns; ++i) { Vprintf("%5ld ", irl[i-1]); for (j = 1; j <= p; ++j) { if (X(i,j)) flag = 'T'; else flag = 'F'; Vprintf(" %c", flag); } Vprintf("\n"); } } END: if (irl) NAG_FREE(irl); if (x) NAG_FREE(x); return exit_status; }