1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 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, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <data/dictionary.h>
24 #include <data/file-handle-def.h>
25 #include <data/procedure.h>
26 #include <data/variable.h>
27 #include <language/command.h>
28 #include <language/data-io/file-handle.h>
29 #include <language/lexer/lexer.h>
30 #include <language/lexer/variable-parser.h>
31 #include <libpspp/alloc.h>
32 #include <libpspp/compiler.h>
39 struct variable **v1, **v2;
43 static struct cor_set *cor_list, *cor_last;
45 static struct file_handle *matrix_file;
47 static void free_correlations_state (void);
48 static int internal_cmd_correlations (struct lexer *lexer, struct dataset *ds);
51 cmd_correlations (struct lexer *lexer, struct dataset *ds)
53 int result = internal_cmd_correlations (lexer, ds);
54 free_correlations_state ();
59 "CORRELATIONS" (cor_):
61 missing=miss:!pairwise/listwise,
63 +print=tail:!twotail/onetail,
65 +format=fmt:!matrix/serial;
67 +statistics[st_]=descriptives,xprod,all.
73 internal_cmd_correlations (struct lexer *lexer, struct dataset *ds)
75 struct cmd_correlations cmd;
77 cor_list = cor_last = NULL;
80 if (!parse_correlations (lexer, ds, &cmd, NULL))
83 free_correlations (&cmd);
89 cor_custom_variables (struct lexer *lexer, struct dataset *ds, 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 (lexer, "VARIABLES")
97 && (lex_token (lexer) != T_ID || dict_lookup_var (dataset_dict (ds), lex_tokid (lexer)) != NULL)
98 && lex_token (lexer) != T_ALL)
100 lex_match (lexer, '=');
102 if (!parse_variables (lexer, dataset_dict (ds), &v1, &nv1,
103 PV_NO_DUPLICATE | PV_NUMERIC))
106 if (lex_match (lexer, T_WITH))
108 if (!parse_variables (lexer, dataset_dict (ds), &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 lexer *lexer, struct dataset *ds UNUSED, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
138 if (!lex_force_match (lexer, '('))
141 if (lex_match (lexer, '*'))
145 matrix_file = fh_parse (lexer, FH_REF_FILE);
146 if (matrix_file == NULL)
150 if (!lex_force_match (lexer, ')'))
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)