1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include "debug-print.h"
40 +format=lab:!labels/nolabels/nocatlabs,
44 +missing=miss:!table/include/dependent;
45 +cells[cl_]=default,count,sum,mean,stddev,variance,all;
46 +statistics[st_]=anova,linearity,all,none.
51 /* TABLES: Variable lists for each dimension. */
52 int n_dim; /* Number of dimensions. */
53 int *nv_dim; /* Number of variables in each dimension. */
54 struct variable ***v_dim; /* Variables in each dimension. */
56 /* VARIABLES: List of variables. */
58 struct variable **v_var;
60 /* Parses and executes the T-TEST procedure. */
65 int success = CMD_FAILURE;
72 if (!parse_means (&cmd))
78 for (i = 0; i < MNS_CL_count; i++)
81 if (i >= MNS_CL_count)
82 cmd.a_cells[MNS_CL_ALL] = 1;
85 cmd.a_cells[MNS_CL_DEFAULT] = 1;
86 if (cmd.a_cells[MNS_CL_DEFAULT] || cmd.a_cells[MNS_CL_ALL])
87 cmd.a_cells[MNS_CL_MEAN] = cmd.a_cells[MNS_CL_STDDEV] = cmd.a_cells[MNS_CL_COUNT] = 1;
88 if (cmd.a_cells[MNS_CL_ALL])
89 cmd.a_cells[MNS_CL_SUM] = cmd.a_cells[MNS_CL_VARIANCE] = 1;
91 if (cmd.sbc_statistics)
93 if (!cmd.a_statistics[MNS_ST_ANOVA] && !cmd.a_statistics[MNS_ST_LINEARITY])
94 cmd.a_statistics[MNS_ST_ANOVA] = 1;
95 if (cmd.a_statistics[MNS_ST_ALL])
96 cmd.a_statistics[MNS_ST_ANOVA] = cmd.a_statistics[MNS_ST_LINEARITY] = 1;
101 msg (SE, _("Missing required subcommand TABLES."));
105 success = CMD_SUCCESS;
111 for (i = 0; i < n_dim; i++)
121 /* Parses the TABLES subcommand. */
123 mns_custom_tables (struct cmd_means *cmd)
125 struct var_set *var_set;
127 if (!lex_match_id ("TABLES")
128 && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
133 if (cmd->sbc_tables || cmd->sbc_crossbreak)
135 msg (SE, _("TABLES or CROSSBREAK subcommand may not appear more "
140 if (cmd->sbc_variables)
141 var_set = var_set_create_from_array (v_var, n_var);
143 var_set = var_set_create_from_dict (default_dict);
144 assert (var_set != NULL);
149 struct variable **vl;
151 if (!parse_var_set_vars (var_set, &vl, &nvl,
152 PV_NO_DUPLICATE | PV_NO_SCRATCH))
156 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
157 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
159 nv_dim[n_dim - 1] = nvl;
160 v_dim[n_dim - 1] = vl;
162 if (cmd->sbc_variables)
166 for (i = 0; i < nv_dim[0]; i++)
168 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
170 if (v_inf->min == SYSMIS)
172 msg (SE, _("Variable %s specified on TABLES or "
173 "CROSSBREAK, but not specified on "
181 v_inf->min = (int) v_inf->min;
182 v_inf->max = (int) v_inf->max;
184 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
186 msg (SE, _("LOWEST and HIGHEST may not be used "
187 "for independent variables (%s)."),
191 if (v_inf->min != (int) v_inf->min
192 || v_inf->max != (int) v_inf->max)
194 msg (SE, _("Independent variables (%s) may not "
195 "have noninteger endpoints in their "
204 while (lex_match (T_BY));
206 var_set_destroy (var_set);
210 var_set_destroy (var_set);
214 /* Parse CROSSBREAK subcommand. */
216 mns_custom_crossbreak (struct cmd_means *cmd)
218 return mns_custom_tables (cmd);
221 /* Parses the VARIABLES subcommand. */
223 mns_custom_variables (struct cmd_means *cmd)
227 msg (SE, _("VARIABLES must precede TABLES."));
231 if (cmd->sbc_variables == 1)
235 for (i = 0; i < dict_get_var_cnt (default_dict); i++)
236 dict_get_var (default_dict, i)->p.mns.min = SYSMIS;
245 if (!parse_variables (default_dict, &v_var, &n_var,
246 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
249 if (!lex_force_match ('('))
254 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
258 if (!lex_force_num ())
268 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
272 if (!lex_force_num ())
278 if (!lex_force_match (')'))
284 msg (SE, _("Upper value (%g) is less than lower value "
285 "(%g) on VARIABLES subcommand."), max, min);
292 for (i = orig_n; i < n_var; i++)
294 struct means_proc *v_inf = &v_var[i]->p.mns;
301 while (token != '/' && token != '.');