/* nag_mv_discrim_mahaldist (g03dbc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * */ #include #include #include #include #define NMAX 21 #define MMAX 2 #define GPMAX 3 int main(void) { double d[NMAX][GPMAX], det[GPMAX], gc[(GPMAX+1)*MMAX*(MMAX+1)/2], gmean[GPMAX][MMAX], wt[NMAX], x[NMAX][MMAX]; double stat; double df; double sig; double *wtptr=0; Integer nobs, nvar; Integer ing[NMAX], isx[MMAX], nig[GPMAX]; Integer i, j, m, n; Integer ng; Integer tdd=GPMAX, tdgmean=MMAX, tdx=MMAX; char char_equal[2]; char weight[2]; Nag_GroupCovars equal; Vprintf("g03dbc Example Program Results\n\n"); /* Skip headings in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&m); Vscanf("%ld",&nvar); Vscanf("%ld",&ng); Vscanf("%s",weight); if (n <= NMAX && m <= MMAX) { if (*weight == 'W') { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); Vscanf("%ld",&ing[i]); Vscanf("%lf",&wt[i]); } wtptr = wt; } else { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); Vscanf("%ld",&ing[i]); } } for (j = 0; j < m; ++j) Vscanf("%ld",&isx[j]); g03dac(n, m, &x[0][0], tdx, isx, nvar, ing, ng, wtptr, nig, &gmean[0][0], tdgmean, det, gc, &stat, &df, &sig, NAGERR_DEFAULT); Vscanf("%ld",&nobs); Vscanf("%s",char_equal); if (nobs <= NMAX) { for (i = 0; i < nobs; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); } if (*char_equal == 'E') { equal = Nag_EqualCovar; } else if (*char_equal == 'U') { equal = Nag_NotEqualCovar; } g03dbc(equal, Nag_SamplePoints, nvar, ng, &gmean[0][0], tdgmean, gc, nobs, m, isx, &x[0][0], tdx, &d[0][0], tdd, NAGERR_DEFAULT); Vprintf("\n Obs Distances\n\n"); for (i = 0; i < nobs; ++i) { Vprintf(" %3ld",i+1); for (j = 0; j < ng; ++j) Vprintf("%10.3f",d[i][j]); Vprintf("\n"); } } return EXIT_SUCCESS; } else { Vprintf("Incorrect input value of n or m.\n"); return EXIT_FAILURE; } }