1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "data/case.h"
22 #include "data/data-out.h"
23 #include "data/dataset.h"
24 #include "data/dictionary.h"
25 #include "data/format.h"
26 #include "data/value-labels.h"
27 #include "data/variable.h"
28 #include "language/command.h"
29 #include "language/dictionary/split-file.h"
30 #include "language/lexer/lexer.h"
31 #include "language/lexer/variable-parser.h"
32 #include "libpspp/message.h"
33 #include "libpspp/str.h"
34 #include "output/pivot-table.h"
36 #include "gl/xalloc.h"
39 #define N_(msgid) msgid
40 #define _(msgid) gettext (msgid)
43 cmd_split_file (struct lexer *lexer, struct dataset *ds)
45 if (lex_match_id (lexer, "OFF"))
46 dict_clear_split_vars (dataset_dict (ds));
52 enum split_type type = (!lex_match_id (lexer, "LAYERED")
53 && lex_match_id (lexer, "SEPARATE")
57 lex_match (lexer, T_BY);
58 if (!parse_variables (lexer, dataset_dict (ds), &v, &n, PV_NO_DUPLICATE))
59 return CMD_CASCADING_FAILURE;
63 verify (MAX_SPLITS == 8);
64 msg (SE, _("At most 8 split variables may be specified."));
66 return CMD_CASCADING_FAILURE;
69 dict_set_split_vars (dataset_dict (ds), v, n, type);
76 /* Dumps out the values of all the split variables for the case C. */
78 output_split_file_values (const struct dataset *ds, const struct ccase *c)
80 const struct dictionary *dict = dataset_dict (ds);
81 size_t n_vars = dict_get_n_splits (dict);
85 struct pivot_table *table = pivot_table_create (N_("Split Values"));
86 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Value"),
88 struct pivot_dimension *variables = pivot_dimension_create (
89 table, PIVOT_AXIS_ROW, N_("Variable"));
90 variables->root->show_label = true;
92 for (size_t i = 0; i < n_vars; i++)
94 const struct variable *v = dict_get_split_vars (dict)[i];
95 int row = pivot_category_create_leaf (variables->root,
96 pivot_value_new_variable (v));
98 pivot_table_put2 (table, 0, row,
99 pivot_value_new_var_value (v, case_data (c, v)));
102 pivot_table_submit (table);