+/* Reports cluster membership for each case. */
+static void
+quick_cluster_show_membership (struct Kmeans *kmeans, const struct casereader *reader, const struct qc *qc)
+{
+ struct tab_table *t;
+ int nc, nr, i;
+
+ struct ccase *c;
+ struct casereader *cs = casereader_clone (reader);
+ nc = 2;
+ nr = kmeans->n + 1;
+ t = tab_create (nc, nr);
+ tab_headers (t, 0, nc - 1, 0, 0);
+ tab_title (t, _("Cluster Membership"));
+ tab_text (t, 0, 0, TAB_CENTER, _("Case Number"));
+ tab_text (t, 1, 0, TAB_CENTER, _("Cluster"));
+ tab_box (t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, nc - 1, nr - 1);
+ tab_hline (t, TAL_1, 0, nc - 1, 1);
+
+ gsl_permutation *ip = gsl_permutation_alloc (qc->ngroups);
+ gsl_permutation_inverse (ip, kmeans->group_order);
+
+ for (i = 0; (c = casereader_read (cs)) != NULL; i++, case_unref (c))
+ {
+ int clust = -1;
+ assert (i < kmeans->n);
+ kmeans_get_nearest_group (kmeans, c, qc, &clust, NULL, NULL, NULL);
+ clust = ip->data[clust];
+ tab_text_format (t, 0, i+1, TAB_CENTER, "%d", (i + 1));
+ tab_text_format (t, 1, i+1, TAB_CENTER, "%d", (clust + 1));
+ }
+ gsl_permutation_free (ip);
+ assert (i == kmeans->n);
+ tab_submit (t);
+ casereader_destroy (cs);
+}
+
+