From 2aed65a53e0d5ae8d7abc77f6cbd7cf055b37ceb Mon Sep 17 00:00:00 2001
From: Ben Pfaff <blp@cs.stanford.edu>
Date: Sun, 3 Jan 2016 23:57:05 -0800
Subject: [PATCH] Specify dimension list at beginning of data.

---
 dump.c               | 15 +++++++++++----
 spv-file-format.texi | 17 +++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/dump.c b/dump.c
index 70ecab6320..1cdb749f81 100644
--- a/dump.c
+++ b/dump.c
@@ -694,14 +694,21 @@ static void
 dump_data(void)
 {
   /* The first three numbers add to the number of dimensions. */
-  int t = get_u32();
-  t += get_u32();
-  match_u32_assert(n_dims - t);
+  int l = get_u32();
+  int r = get_u32();
+  int c = n_dims - l - r;
+  match_u32_assert(c);
 
   /* The next n_dims numbers are a permutation of the dimension numbers. */
   int a[n_dims];
   for (int i = 0; i < n_dims; i++)
-    a[i] = get_u32();
+    {
+      int dim = get_u32();
+      a[i] = dim;
+
+      const char *name = i < l ? "layer" : i < l + r ? "row" : "column";
+      printf ("<%s dimension=\"%d\"/>\n", name, dim);
+    }
   check_permutation(a, n_dims, "dimensions");
 
   int x = get_u32();
diff --git a/spv-file-format.texi b/spv-file-format.texi
index c587233795..bb615a2384 100644
--- a/spv-file-format.texi
+++ b/spv-file-format.texi
@@ -554,3 +554,20 @@ are terminal categories that directly represent data values for a
 variable (e.g. in a frequency table or crosstabulation, a group of
 values in a variable being tabulated) and i0 otherwise, but this might
 be naive.
+
+@example
+data := int[layers] int[rows] int[columns] int*[n-dimensions]
+@end example
+
+The values of @code{layers}, @code{rows}, and @code{columns} each
+specifies the number of dimensions represented in layers or rows or
+columns, respectively, and their values sum to the number of
+dimensions.
+
+The @code{n-dimensions} integers are a permutation of the 0-based
+dimension numbers.  The first @code{layers} of them specify each of
+the dimensions represented by layers, the next @code{rows} of them
+specify the dimensions represented by rows, and the final
+@code{columns} of them specify the dimensions represented by columns.
+When there is more than one dimension of a given kind, the inner
+dimensions are given first.
-- 
2.30.2