1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <data/dictionary.h>
22 #include <data/file-handle-def.h>
23 #include <data/procedure.h>
24 #include <data/variable.h>
25 #include <language/command.h>
26 #include <language/data-io/file-handle.h>
27 #include <language/lexer/lexer.h>
28 #include <language/lexer/variable-parser.h>
29 #include <libpspp/alloc.h>
30 #include <libpspp/compiler.h>
37 const struct variable **v1, **v2;
41 static struct cor_set *cor_list, *cor_last;
43 static struct file_handle *matrix_file;
45 static void free_correlations_state (void);
46 static int internal_cmd_correlations (struct lexer *lexer, struct dataset *ds);
49 cmd_correlations (struct lexer *lexer, struct dataset *ds)
51 int result = internal_cmd_correlations (lexer, ds);
52 free_correlations_state ();
57 "CORRELATIONS" (cor_):
59 missing=miss:!pairwise/listwise,
61 +print=tail:!twotail/onetail,
63 +format=fmt:!matrix/serial;
65 +statistics[st_]=descriptives,xprod,all.
71 internal_cmd_correlations (struct lexer *lexer, struct dataset *ds)
73 struct cmd_correlations cmd;
75 cor_list = cor_last = NULL;
78 if (!parse_correlations (lexer, ds, &cmd, NULL))
81 free_correlations (&cmd);
87 cor_custom_variables (struct lexer *lexer, struct dataset *ds, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
89 const struct variable **v1, **v2;
93 /* Ensure that this is a VARIABLES subcommand. */
94 if (!lex_match_id (lexer, "VARIABLES")
95 && (lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)) != NULL)
96 && lex_token (lexer) != T_ALL)
98 lex_match (lexer, '=');
100 if (!parse_variables_const (lexer, dataset_dict (ds), &v1, &nv1,
101 PV_NO_DUPLICATE | PV_NUMERIC))
104 if (lex_match (lexer, T_WITH))
106 if (!parse_variables_const (lexer, dataset_dict (ds), &v2, &nv2,
107 PV_NO_DUPLICATE | PV_NUMERIC))
119 cor = xmalloc (sizeof *cor);
126 cor_last = cor_last->next = cor;
128 cor_list = cor_last = cor;
134 cor_custom_matrix (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
136 if (!lex_force_match (lexer, '('))
139 if (lex_match (lexer, '*'))
143 matrix_file = fh_parse (lexer, FH_REF_FILE);
144 if (matrix_file == NULL)
148 if (!lex_force_match (lexer, ')'))
155 free_correlations_state (void)
157 struct cor_set *cor, *next;
159 for (cor = cor_list; cor != NULL; cor = next)
162 if (cor->v1 != cor->v2)