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.
52 static void debug_print (struct cmd_means *cmd);
55 /* TABLES: Variable lists for each dimension. */
56 int n_dim; /* Number of dimensions. */
57 int *nv_dim; /* Number of variables in each dimension. */
58 struct variable ***v_dim; /* Variables in each dimension. */
60 /* VARIABLES: List of variables. */
62 struct variable **v_var;
64 /* Parses and executes the T-TEST procedure. */
69 int success = CMD_FAILURE;
76 lex_match_id ("MEANS");
77 if (!parse_means (&cmd))
83 for (i = 0; i < MNS_CL_count; i++)
86 if (i >= MNS_CL_count)
87 cmd.a_cells[MNS_CL_ALL] = 1;
90 cmd.a_cells[MNS_CL_DEFAULT] = 1;
91 if (cmd.a_cells[MNS_CL_DEFAULT] || cmd.a_cells[MNS_CL_ALL])
92 cmd.a_cells[MNS_CL_MEAN] = cmd.a_cells[MNS_CL_STDDEV] = cmd.a_cells[MNS_CL_COUNT] = 1;
93 if (cmd.a_cells[MNS_CL_ALL])
94 cmd.a_cells[MNS_CL_SUM] = cmd.a_cells[MNS_CL_VARIANCE] = 1;
96 if (cmd.sbc_statistics)
98 if (!cmd.a_statistics[MNS_ST_ANOVA] && !cmd.a_statistics[MNS_ST_LINEARITY])
99 cmd.a_statistics[MNS_ST_ANOVA] = 1;
100 if (cmd.a_statistics[MNS_ST_ALL])
101 cmd.a_statistics[MNS_ST_ANOVA] = cmd.a_statistics[MNS_ST_LINEARITY] = 1;
106 msg (SE, _("Missing required subcommand TABLES."));
114 success = CMD_SUCCESS;
120 for (i = 0; i < n_dim; i++)
130 /* Parses the TABLES subcommand. */
132 mns_custom_tables (struct cmd_means *cmd)
134 struct var_set *var_set;
136 if (!lex_match_id ("TABLES")
137 && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
142 if (cmd->sbc_tables || cmd->sbc_crossbreak)
144 msg (SE, _("TABLES or CROSSBREAK subcommand may not appear more "
149 if (cmd->sbc_variables)
150 var_set = var_set_create_from_array (v_var, n_var);
152 var_set = var_set_create_from_dict (default_dict);
153 assert (var_set != NULL);
158 struct variable **vl;
160 if (!parse_var_set_vars (var_set, &vl, &nvl,
161 PV_NO_DUPLICATE | PV_NO_SCRATCH))
165 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
166 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
168 nv_dim[n_dim - 1] = nvl;
169 v_dim[n_dim - 1] = vl;
171 if (cmd->sbc_variables)
175 for (i = 0; i < nv_dim[0]; i++)
177 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
179 if (v_inf->min == SYSMIS)
181 msg (SE, _("Variable %s specified on TABLES or "
182 "CROSSBREAK, but not specified on "
190 v_inf->min = (int) v_inf->min;
191 v_inf->max = (int) v_inf->max;
193 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
195 msg (SE, _("LOWEST and HIGHEST may not be used "
196 "for independent variables (%s)."),
200 if (v_inf->min != (int) v_inf->min
201 || v_inf->max != (int) v_inf->max)
203 msg (SE, _("Independent variables (%s) may not "
204 "have noninteger endpoints in their "
213 while (lex_match (T_BY));
215 var_set_destroy (var_set);
219 var_set_destroy (var_set);
223 /* Parse CROSSBREAK subcommand. */
225 mns_custom_crossbreak (struct cmd_means *cmd)
227 return mns_custom_tables (cmd);
230 /* Parses the VARIABLES subcommand. */
232 mns_custom_variables (struct cmd_means *cmd)
236 msg (SE, _("VARIABLES must precede TABLES."));
240 if (cmd->sbc_variables == 1)
244 for (i = 0; i < dict_get_var_cnt (default_dict); i++)
245 dict_get_var (default_dict, i)->p.mns.min = SYSMIS;
254 if (!parse_variables (default_dict, &v_var, &n_var,
255 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
258 if (!lex_force_match ('('))
263 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
267 if (!lex_force_num ())
277 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
281 if (!lex_force_num ())
287 if (!lex_force_match (')'))
293 msg (SE, _("Upper value (%g) is less than lower value "
294 "(%g) on VARIABLES subcommand."), max, min);
301 for (i = orig_n; i < n_var; i++)
303 struct means_proc *v_inf = &v_var[i]->p.mns;
310 while (token != '/' && token != '.');
317 debug_print (struct cmd_means *cmd)
323 if (cmd->sbc_variables)
327 printf (" VARIABLES=");
328 for (i = 0; i < default_dict.nvar; i++)
330 struct variable *v = default_dict.var[i];
332 if (v->p.mns.min == SYSMIS)
336 printf ("%s(", v->name);
337 if (v->p.mns.min == LOWEST)
340 printf ("%g", v->p.mns.min);
342 if (v->p.mns.max == HIGHEST)
345 printf ("%g", v->p.mns.max);
352 for (i = 0; i < n_dim; i++)
359 for (j = 0; j < nv_dim[i]; j++)
363 printf (v_dim[i][j]->name);
368 #endif /* DEBUGGING */