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 if (!parse_means (&cmd))
82 for (i = 0; i < MNS_CL_count; i++)
85 if (i >= MNS_CL_count)
86 cmd.a_cells[MNS_CL_ALL] = 1;
89 cmd.a_cells[MNS_CL_DEFAULT] = 1;
90 if (cmd.a_cells[MNS_CL_DEFAULT] || cmd.a_cells[MNS_CL_ALL])
91 cmd.a_cells[MNS_CL_MEAN] = cmd.a_cells[MNS_CL_STDDEV] = cmd.a_cells[MNS_CL_COUNT] = 1;
92 if (cmd.a_cells[MNS_CL_ALL])
93 cmd.a_cells[MNS_CL_SUM] = cmd.a_cells[MNS_CL_VARIANCE] = 1;
95 if (cmd.sbc_statistics)
97 if (!cmd.a_statistics[MNS_ST_ANOVA] && !cmd.a_statistics[MNS_ST_LINEARITY])
98 cmd.a_statistics[MNS_ST_ANOVA] = 1;
99 if (cmd.a_statistics[MNS_ST_ALL])
100 cmd.a_statistics[MNS_ST_ANOVA] = cmd.a_statistics[MNS_ST_LINEARITY] = 1;
105 msg (SE, _("Missing required subcommand TABLES."));
113 success = CMD_SUCCESS;
119 for (i = 0; i < n_dim; i++)
129 /* Parses the TABLES subcommand. */
131 mns_custom_tables (struct cmd_means *cmd)
133 struct var_set *var_set;
135 if (!lex_match_id ("TABLES")
136 && (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
141 if (cmd->sbc_tables || cmd->sbc_crossbreak)
143 msg (SE, _("TABLES or CROSSBREAK subcommand may not appear more "
148 if (cmd->sbc_variables)
149 var_set = var_set_create_from_array (v_var, n_var);
151 var_set = var_set_create_from_dict (default_dict);
152 assert (var_set != NULL);
157 struct variable **vl;
159 if (!parse_var_set_vars (var_set, &vl, &nvl,
160 PV_NO_DUPLICATE | PV_NO_SCRATCH))
164 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
165 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
167 nv_dim[n_dim - 1] = nvl;
168 v_dim[n_dim - 1] = vl;
170 if (cmd->sbc_variables)
174 for (i = 0; i < nv_dim[0]; i++)
176 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
178 if (v_inf->min == SYSMIS)
180 msg (SE, _("Variable %s specified on TABLES or "
181 "CROSSBREAK, but not specified on "
189 v_inf->min = (int) v_inf->min;
190 v_inf->max = (int) v_inf->max;
192 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
194 msg (SE, _("LOWEST and HIGHEST may not be used "
195 "for independent variables (%s)."),
199 if (v_inf->min != (int) v_inf->min
200 || v_inf->max != (int) v_inf->max)
202 msg (SE, _("Independent variables (%s) may not "
203 "have noninteger endpoints in their "
212 while (lex_match (T_BY));
214 var_set_destroy (var_set);
218 var_set_destroy (var_set);
222 /* Parse CROSSBREAK subcommand. */
224 mns_custom_crossbreak (struct cmd_means *cmd)
226 return mns_custom_tables (cmd);
229 /* Parses the VARIABLES subcommand. */
231 mns_custom_variables (struct cmd_means *cmd)
235 msg (SE, _("VARIABLES must precede TABLES."));
239 if (cmd->sbc_variables == 1)
243 for (i = 0; i < dict_get_var_cnt (default_dict); i++)
244 dict_get_var (default_dict, i)->p.mns.min = SYSMIS;
253 if (!parse_variables (default_dict, &v_var, &n_var,
254 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
257 if (!lex_force_match ('('))
262 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
266 if (!lex_force_num ())
276 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
280 if (!lex_force_num ())
286 if (!lex_force_match (')'))
292 msg (SE, _("Upper value (%g) is less than lower value "
293 "(%g) on VARIABLES subcommand."), max, min);
300 for (i = orig_n; i < n_var; i++)
302 struct means_proc *v_inf = &v_var[i]->p.mns;
309 while (token != '/' && token != '.');
316 debug_print (struct cmd_means *cmd)
322 if (cmd->sbc_variables)
326 printf (" VARIABLES=");
327 for (i = 0; i < default_dict.nvar; i++)
329 struct variable *v = default_dict.var[i];
331 if (v->p.mns.min == SYSMIS)
335 printf ("%s(", v->name);
336 if (v->p.mns.min == LOWEST)
339 printf ("%g", v->p.mns.min);
341 if (v->p.mns.max == HIGHEST)
344 printf ("%g", v->p.mns.max);
351 for (i = 0; i < n_dim; i++)
358 for (j = 0; j < nv_dim[i]; j++)
362 printf (v_dim[i][j]->name);
367 #endif /* DEBUGGING */