}
}
+static int
+compare_int(const void *a_, const void *b_)
+{
+ const int *a = a_;
+ const int *b = b_;
+ return *a < *b ? -1 : *a > *b;
+}
+
static void
dump_data(void)
{
-#if 1
- int a[16];
- for (int i = 0; i < 3 + n_dims; i++)
- a[i] = get_u32();
- printf ("data intro:");
- for (int i = 0; i < 3 + n_dims; i++)
- printf(" %d", a[i]);
- printf("\n");
-#else
- fprintf (stderr,"data intro (%d dims):", n_dims);
- for (int i = 0; i < 3+n_dims; i++)
- fprintf (stderr," %d", get_u32());
- fprintf(stderr,"\n");
-#endif
+ /* The first three numbers add to the number of dimensions. */
+ int t = get_u32();
+ t += get_u32();
+ match_u32_assert(n_dims - t);
+
+ /* The next n_dims numbers are a permutation of the dimension numbers. */
+ int a[n_dims], b[n_dims];
+ for (int i = 0; i < n_dims; i++)
+ a[i] = b[i] = get_u32();
+ qsort(b, n_dims, sizeof *b, compare_int);
+ for (int i = 0; i < n_dims; i++)
+ if (b[i] != i)
+ {
+ fprintf(stderr, "bad dimension permutation:");
+ for (int i = 0; i < n_dims; i++)
+ fprintf(stderr, " %d", a[i]);
+ putc('\n', stderr);
+ exit(1);
+ }
+
int x = get_u32();
printf ("%d data values, starting at %08x\n", x, pos);
for (int i = 0; i < x; i++)