/* MdsMap.cc */ #include #include extern "C" { int mds_(); } int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr,"Usage: %s ndtyp dim\n", argv[0]); fprintf(stderr," ndtyp: Measurment level\n"); fprintf(stderr," 1 - ratio (metric)\n"); fprintf(stderr," 2 - interval (metric, additive constant)\n"); fprintf(stderr," 3 - ordinal (non-metric, Kruskal)\n"); fprintf(stderr," 4 - nominal (non-metric, few distiguishable classes)\n"); fprintf(stderr," dim: number of dimensions\n"); exit(-1); } FILE *DistFile = fopen("MDS_DIST", "r"); if (DistFile == NULL) { printf("Cannot open file MDS_DIST\n"); return -1; } int n; fscanf(DistFile, "%d\n", &n); float dist[n][n]; for (int i=0; i < n; i++) for (int j=0; j < n; j++) fscanf(DistFile, "%f ", &dist[i][j]); fclose(DistFile); float x[6][n], stress; printf("Starting Mds...\n"); int ndtyp=atoi(argv[1]); int dim=atoi(argv[2]); mds_(&n, &n, &dist, &ndtyp, &dim, &dim, &x[0][0], &x[1][0], &x[2][0], &x[3][0], &x[4][0], &x[5][0], &stress); printf("STRESS=%f\n", stress); FILE *OutFile = fopen("MDS_PAIRS", "w"); if (OutFile == NULL) { printf("Cannot open file MDS_PAIRS\n"); return -1; } fprintf(OutFile, "%d\n", dim); for (int i=0; i < n; i++) { for (int j=0; j < dim; j++) fprintf(OutFile, "%f ", x[j][i]); fprintf(OutFile, "\n"); } fclose(OutFile); }