/* nag_reorder_vector (m01esc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 2 revised, 1992. * Mark 5 revised, 1998. * Mark 7 revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static Integer NAG_CALL compare(const Nag_Pointer a, const Nag_Pointer b) { double x = *((const double *)a) - *((const double *)b); return (x<0.0 ? -1 : (x==0.0 ? 0 : 1)); } #ifdef __cplusplus } #endif #define A(I,J) a[(I)*tda + J] int main(void) { Integer exit_status=0, tda; NagError fail; double *a=0; size_t i, *indices=0, j, k, m, n; INIT_FAIL(fail); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vprintf("nag_reorder_vector (m01esc) Example Program Results\n"); Vscanf("%u%u%u", &m, &n, &k); if (m>=1&& n>=1 && k>=1 && k<=n) { if ( !( a = NAG_ALLOC(m*n, double)) || !( indices = NAG_ALLOC(m, size_t)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; } else { Vprintf("Invalid m or n or k.\n"); exit_status = 1; return exit_status; } for (i=0; i