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/compiler.h>
38 const struct variable **v1, **v2;
42 static struct cor_set *cor_list, *cor_last;
44 static struct file_handle *matrix_file;
46 static void free_correlations_state (void);
47 static int internal_cmd_correlations (struct lexer *lexer, struct dataset *ds);
50 cmd_correlations (struct lexer *lexer, struct dataset *ds)
52 int result = internal_cmd_correlations (lexer, ds);
53 free_correlations_state ();
58 "CORRELATIONS" (cor_):
60 missing=miss:!pairwise/listwise,
62 +print=tail:!twotail/onetail,
64 +format=fmt:!matrix/serial;
66 +statistics[st_]=descriptives,xprod,all.
72 internal_cmd_correlations (struct lexer *lexer, struct dataset *ds)
74 struct cmd_correlations cmd;
76 cor_list = cor_last = NULL;
79 if (!parse_correlations (lexer, ds, &cmd, NULL))
81 fh_unref (matrix_file);
85 free_correlations (&cmd);
86 fh_unref (matrix_file);
92 cor_custom_variables (struct lexer *lexer, struct dataset *ds, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
94 const struct variable **v1, **v2;
98 /* Ensure that this is a VARIABLES subcommand. */
99 if (!lex_match_id (lexer, "VARIABLES")
100 && (lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)) != NULL)
101 && lex_token (lexer) != T_ALL)
103 lex_match (lexer, '=');
105 if (!parse_variables_const (lexer, dataset_dict (ds), &v1, &nv1,
106 PV_NO_DUPLICATE | PV_NUMERIC))
109 if (lex_match (lexer, T_WITH))
111 if (!parse_variables_const (lexer, dataset_dict (ds), &v2, &nv2,
112 PV_NO_DUPLICATE | PV_NUMERIC))
124 cor = xmalloc (sizeof *cor);
131 cor_last = cor_last->next = cor;
133 cor_list = cor_last = cor;
139 cor_custom_matrix (struct lexer *lexer, struct dataset *ds UNUSED, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
141 if (!lex_force_match (lexer, '('))
144 if (lex_match (lexer, '*'))
148 fh_unref (matrix_file);
149 matrix_file = fh_parse (lexer, FH_REF_FILE);
150 if (matrix_file == NULL)
154 if (!lex_force_match (lexer, ')'))
161 free_correlations_state (void)
163 struct cor_set *cor, *next;
165 for (cor = cor_list; cor != NULL; cor = next)
168 if (cor->v1 != cor->v2)