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., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <data/dictionary.h>
25 #include <data/file-handle-def.h>
26 #include <data/procedure.h>
27 #include <data/variable.h>
28 #include <language/command.h>
29 #include <language/data-io/file-handle.h>
30 #include <language/lexer/lexer.h>
31 #include <language/lexer/variable-parser.h>
32 #include <libpspp/alloc.h>
33 #include <libpspp/compiler.h>
40 struct variable **v1, **v2;
44 struct cor_set *cor_list, *cor_last;
46 struct file_handle *matrix_file;
48 static void free_correlations_state (void);
49 static int internal_cmd_correlations (void);
52 cmd_correlations (void)
54 int result = internal_cmd_correlations ();
55 free_correlations_state ();
60 "CORRELATIONS" (cor_):
62 missing=miss:!pairwise/listwise,
64 +print=tail:!twotail/onetail,
66 +format=fmt:!matrix/serial;
68 +statistics[st_]=descriptives,xprod,all.
74 internal_cmd_correlations (void)
76 struct cmd_correlations cmd;
78 cor_list = cor_last = NULL;
81 if (!parse_correlations (&cmd, NULL))
83 free_correlations (&cmd);
89 cor_custom_variables (struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
91 struct variable **v1, **v2;
95 /* Ensure that this is a VARIABLES subcommand. */
96 if (!lex_match_id ("VARIABLES")
97 && (token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL)
102 if (!parse_variables (dataset_dict (current_dataset), &v1, &nv1,
103 PV_NO_DUPLICATE | PV_NUMERIC))
106 if (lex_match (T_WITH))
108 if (!parse_variables (dataset_dict (current_dataset), &v2, &nv2,
109 PV_NO_DUPLICATE | PV_NUMERIC))
121 cor = xmalloc (sizeof *cor);
128 cor_last = cor_last->next = cor;
130 cor_list = cor_last = cor;
136 cor_custom_matrix (struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
138 if (!lex_force_match ('('))
145 matrix_file = fh_parse (FH_REF_FILE);
146 if (matrix_file == NULL)
150 if (!lex_force_match (')'))
157 free_correlations_state (void)
159 struct cor_set *cor, *next;
161 for (cor = cor_list; cor != NULL; cor = next)
164 if (cor->v1 != cor->v2)