/* nag_mv_distance_mat_2 (g03ebc) Example Program.
*
* Copyright 2023 Numerical Algorithms Group.
*
* Mark 29.2, 2023.
*
*/
#include <nag.h>
#include <stdio.h>
int main(void) {
Integer exit_status = 0;
Integer i, j, k, m, n, l, pdx, pdy;
Integer *isv = 0;
double p;
double *d = 0, *sx = 0, *sy = 0, *x = 0, *y = 0;
char nag_enum_1[40], nag_enum_2[40], nag_enum_3[40];
Nag_MatUpdate update;
Nag_VarScaleType scale;
Nag_VarScaleYType stype;
NagError fail;
INIT_FAIL(fail);
printf("nag_mv_distance_mat_2 (g03ebc) Example Program Results\n\n");
/* Skip heading and read in problem parameters */
scanf("%*[^\n]");
scanf("%lf", &p);
scanf("%" NAG_IFMT "", &m);
scanf("%" NAG_IFMT "", &n);
scanf("%" NAG_IFMT "", &l);
if (n >= 1 && m >= 1 && l >= 1) {
pdx = m;
pdy = n;
if (!(d = NAG_ALLOC(m*n, double)) ||
!(sx = NAG_ALLOC(l, double)) ||
!(sy = NAG_ALLOC(l, double)) ||
!(x = NAG_ALLOC(pdx*l, double)) ||
!(y = NAG_ALLOC(pdy*l, double)) ||
!(isv = NAG_ALLOC(l, Integer))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
} else {
printf("Invalid m, n or l.\n");
exit_status = 1;
return exit_status;
}
scanf("%39s", nag_enum_1);
scanf("%39s", nag_enum_2);
scanf("%39s", nag_enum_3);
/* nag_enum_name_to_value (x04nac).
* Converts NAG enum member name to value
*/
update = (Nag_MatUpdate)nag_enum_name_to_value(nag_enum_1);
scale = (Nag_VarScaleType)nag_enum_name_to_value(nag_enum_2);
stype = (Nag_VarScaleYType)nag_enum_name_to_value(nag_enum_3);
for (i = 0; i < m; ++i) {
for (k = 0; k < l; ++k) {
scanf("%lf", &x[i+pdx*k]);
}
}
for (j = 0; j < n; ++j) {
for (k = 0; k < l; ++k) {
scanf("%lf", &y[j+pdy*k]);
}
}
for (i = 0; i < l; ++i) {
scanf("%" NAG_IFMT "", &isv[i]);
}
for (i = 0; i < l; ++i) {
scanf("%lf", &sx[i]);
}
for (i = 0; i < l; ++i) {
scanf("%lf", &sy[i]);
}
/* nag_mv_distance_mat_2 (g03ebc).
* Compute distance (dissimilarity) matrix
*/
nag_mv_distance_mat_2(update, scale, stype, p, m, n, l, x, pdx, isv, y,
pdy, sx, sy, d, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_mv_distance_mat (g03eac).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
/* Print the distance matrix */
printf(" Distance Matrix \n\n");
printf(" %s\n", " 1 2 3 4\n");
for (i = 0; i < m; ++i) {
printf("%2" NAG_IFMT " ", i+1);
for (j = 0; j < n; ++j) {
printf("%5.2f ", d[i+j*m]);
}
printf("\n");
}
END:
NAG_FREE(d);
NAG_FREE(sx);
NAG_FREE(sy);
NAG_FREE(x);
NAG_FREE(y);
NAG_FREE(isv);
return exit_status;
}