--- /dev/null
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef OUTPUT_PIVOT_TABLE_H
+#define OUTPUT_PIVOT_TABLE_H 1
+
+#include "data/format.h"
+#include "data/subcase.h"
+#include "output/table.h"
+
+struct pivot_pane
+ {
+ int n[TABLE_N_AXES];
+ struct pivot_cell **cells; /* cells[y][x] */
+ };
+
+struct pivot_table
+ {
+ struct casereader *data;
+ struct dictionary *dict;
+ struct subcase split;
+ struct subcase dimensions[TABLE_N_AXES];
+ struct pivot_pane pane;
+ struct pivot_pane *summaries[TABLE_N_AXES];
+ };
+
+void pivot_table_dump (struct pivot_table *);
+
+enum pivot_comparison_type
+ {
+ PIVOT_RAW, /* No comparison. */
+
+ /* 1-dimensional comparisons. */
+ PIVOT_FRACTION, /* Fraction of an aggregate. */
+ PIVOT_PERCENT, /* Percentage of an aggregate. */
+
+ /* 2-dimensional comparisons. */
+ PIVOT_EXPECTED, /* row_sum * col_sum / grand_total */
+ PIVOT_RESIDUAL, /* value - expected */
+ PIVOT_SRESIDUAL, /* (value - expected) / sqrt(expected) */
+ PIVOT_ASRESIDUAL /* (value - expected)
+ / sqrt(expected
+ * (1 - row_sum / grand_total)
+ * (1 - col_sum / grand_total)) */
+ };
+
+/* A value, possibly compared against other values. */
+struct pivot_cell
+ {
+ struct pivot_value *base;
+
+ /* Comparison. */
+ enum pivot_comparison_type cmp;
+ struct pivot_value *cmp_args[3];
+
+ /* Formatting. */
+ char *label;
+ struct fmt_spec format;
+ };
+
+void pivot_cell_init (struct pivot_cell *, struct pivot_value *);
+
+/* How to combine potentially multiple values. */
+enum pivot_operator
+ {
+ PIVOT_EXACTLY_ONE, /* SYSMIS if no values or more than one. */
+ PIVOT_SUM,
+ PIVOT_MEAN,
+
+ PIVOT_N,
+ PIVOT_N_VALID,
+ PIVOT_N_MISSING,
+
+ PIVOT_MODE,
+
+ PIVOT_STDDEV,
+ PIVOT_VARIANCE,
+
+ PIVOT_MINIMUM,
+ PIVOT_MAXIMUM,
+ PIVOT_RANGE,
+ PIVOT_MEDIAN,
+ PIVOT_PERCENTILE
+ };
+
+enum pivot_value_include
+ {
+ PIVOT_INCLUDE_VALID = 1 << 0,
+ PIVOT_INCLUDE_SYSTEM_MISSING = 1 << 1,
+ PIVOT_INCLUDE_USER_MISSING = 1 << 2,
+ PIVOT_INCLUDE_ALL = 7
+ };
+
+/* A pivot_value specifies a function whose arguments are the values of:
+
+ - The split and dimension variables of the pivot table.
+
+ - The variable specified as part of the pivot_value. (PIVOT_N does not
+ require a variable.)
+
+ A pivot_value is notionally evaluated as:
+
+ Given a value for every variable:
+ For every row in the input data:
+ If the row's split variable equal their assigned values:
+ and the row's dimension variables equal their assigned values,
+ except that the aggregate variables, if any, are ignored,
+ and that the cumulative variables are equal or lexicographically
+ less than the assigned values,
+ and the value variable is included according to "include":
+ Submit the value to the operator.
+*/
+struct pivot_value
+ {
+ const struct variable *var;
+ enum pivot_operator operator;
+ int n_agg_vars[TABLE_N_AXES];
+ int n_cum_vars[TABLE_N_AXES];
+ enum pivot_value_include include;
+ };
+
+struct pivot_value *pivot_value_create (const struct variable *,
+ enum pivot_operator,
+ int n_vars_horz,
+ int n_vars_vert,
+ enum pivot_value_include);
+
+
+#endif /* output/pivot-table.h */