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
35 #include "debug-print.h"
42 +format=lab:!labels/nolabels/nocatlabs,
46 +missing=miss:!table/include/dependent;
47 +cells[cl_]=default,count,sum,mean,stddev,variance,all;
48 +statistics[st_]=anova,linearity,all,none.
54 static void debug_print (struct cmd_means *cmd);
57 /* TABLES: Variable lists for each dimension. */
58 int n_dim; /* Number of dimensions. */
59 int *nv_dim; /* Number of variables in each dimension. */
60 struct variable ***v_dim; /* Variables in each dimension. */
62 /* VARIABLES: List of variables. */
64 struct variable **v_var;
66 /* Parses and executes the T-TEST procedure. */
71 int success = CMD_FAILURE;
78 lex_match_id ("MEANS");
79 if (!parse_means (&cmd))
85 for (i = 0; i < MNS_CL_count; i++)
88 if (i >= MNS_CL_count)
89 cmd.a_cells[MNS_CL_ALL] = 1;
92 cmd.a_cells[MNS_CL_DEFAULT] = 1;
93 if (cmd.a_cells[MNS_CL_DEFAULT] || cmd.a_cells[MNS_CL_ALL])
94 cmd.a_cells[MNS_CL_MEAN] = cmd.a_cells[MNS_CL_STDDEV] = cmd.a_cells[MNS_CL_COUNT] = 1;
95 if (cmd.a_cells[MNS_CL_ALL])
96 cmd.a_cells[MNS_CL_SUM] = cmd.a_cells[MNS_CL_VARIANCE] = 1;
98 if (cmd.sbc_statistics)
100 if (!cmd.a_statistics[MNS_ST_ANOVA] && !cmd.a_statistics[MNS_ST_LINEARITY])
101 cmd.a_statistics[MNS_ST_ANOVA] = 1;
102 if (cmd.a_statistics[MNS_ST_ALL])
103 cmd.a_statistics[MNS_ST_ANOVA] = cmd.a_statistics[MNS_ST_LINEARITY] = 1;
108 msg (SE, _("Missing required subcommand TABLES."));
116 success = CMD_SUCCESS;
122 for (i = 0; i < n_dim; i++)
132 /* Returns nonzero only if value V is valid as an endpoint for a
133 dependent variable in integer mode. */
135 validate_dependent_endpoint (double V)
137 return V == (int) V && V != LOWEST && V != HIGHEST;
140 /* Parses the TABLES subcommand. */
142 mns_custom_tables (struct cmd_means *cmd)
144 struct dictionary *dict;
145 struct dictionary temp_dict;
147 if (!lex_match_id ("TABLES")
148 && (token != T_ID || !is_varname (tokid))
153 if (cmd->sbc_tables || cmd->sbc_crossbreak)
155 msg (SE, _("TABLES or CROSSBREAK subcommand may not appear more "
160 if (cmd->sbc_variables)
163 temp_dict.var = v_var;
164 temp_dict.nvar = n_var;
169 temp_dict.var_by_name = avl_create (NULL, cmp_variable, NULL);
170 for (i = 0; i < temp_dict.nvar; i++)
171 avl_force_insert (temp_dict.var_by_name, temp_dict.var[i]);
175 dict = &default_dict;
180 struct variable **vl;
182 if (!parse_variables (dict, &vl, &nvl, PV_NO_DUPLICATE | PV_NO_SCRATCH))
186 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
187 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
189 nv_dim[n_dim - 1] = nvl;
190 v_dim[n_dim - 1] = vl;
192 if (cmd->sbc_variables)
196 for (i = 0; i < nv_dim[0]; i++)
198 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
200 if (v_inf->min == SYSMIS)
202 msg (SE, _("Variable %s specified on TABLES or "
203 "CROSSBREAK, but not specified on "
211 v_inf->min = (int) v_inf->min;
212 v_inf->max = (int) v_inf->max;
214 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
216 msg (SE, _("LOWEST and HIGHEST may not be used "
217 "for independent variables (%s)."),
221 if (v_inf->min != (int) v_inf->min
222 || v_inf->max != (int) v_inf->max)
224 msg (SE, _("Independent variables (%s) may not "
225 "have noninteger endpoints in their "
234 while (lex_match (T_BY));
236 /* Check for duplicates. */
240 for (i = 0; i < default_dict.nvar; i++)
241 default_dict.var[i]->foo = 0;
242 for (i = 0; i < dict->nvar; i++)
243 if (dict->var[i]->foo++)
245 msg (SE, _("Variable %s is multiply specified on TABLES "
252 if (cmd->sbc_variables)
253 avl_destroy (temp_dict.var_by_name, NULL);
258 /* Parse CROSSBREAK subcommand. */
260 mns_custom_crossbreak (struct cmd_means *cmd)
262 return mns_custom_tables (cmd);
265 /* Parses the VARIABLES subcommand. */
267 mns_custom_variables (struct cmd_means *cmd)
271 msg (SE, _("VARIABLES must precede TABLES."));
275 if (cmd->sbc_variables == 1)
279 for (i = 0; i < default_dict.nvar; i++)
280 default_dict.var[i]->p.mns.min = SYSMIS;
289 if (!parse_variables (&default_dict, &v_var, &n_var,
290 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
293 if (!lex_force_match ('('))
298 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
302 if (!lex_force_num ())
312 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
316 if (!lex_force_num ())
322 if (!lex_force_match (')'))
328 msg (SE, _("Upper value (%g) is less than lower value "
329 "(%g) on VARIABLES subcommand."), max, min);
336 for (i = orig_n; i < n_var; i++)
338 struct means_proc *v_inf = &v_var[i]->p.mns;
345 while (token != '/' && token != '.');
352 debug_print (struct cmd_means *cmd)
358 if (cmd->sbc_variables)
362 printf (" VARIABLES=");
363 for (i = 0; i < default_dict.nvar; i++)
365 struct variable *v = default_dict.var[i];
367 if (v->p.mns.min == SYSMIS)
371 printf ("%s(", v->name);
372 if (v->p.mns.min == LOWEST)
375 printf ("%g", v->p.mns.min);
377 if (v->p.mns.max == HIGHEST)
380 printf ("%g", v->p.mns.max);
387 for (i = 0; i < n_dim; i++)
394 for (j = 0; j < nv_dim[i]; j++)
398 printf (v_dim[i][j]->name);
403 #endif /* DEBUGGING */