Revert "Remove bad tests"
[pspp] / src / language / stats / means.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2011, 2012, 2013, 2019 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef MEANS_H
18 #define MEANS_H
19
20 #include "libpspp/compiler.h"
21
22 struct cell_container
23 {
24   /* A hash table containing the cells.  The table is indexed by a hash
25      based on the cell's categorical value.  */
26   struct hmap map;
27
28   /* A binary tree containing the cells.  This  is
29    used to sort the elements in order of their categorical
30    values.  */
31   struct bt bt;
32 };
33
34
35
36 struct layer
37 {
38   size_t n_factor_vars;
39   const struct variable **factor_vars;
40
41   /* A container holding the union of all instances of values used
42      as categories forming this layer.  */
43   struct cell_container instances;
44 };
45
46
47 struct per_var_data;
48
49 typedef struct per_var_data *stat_create (struct pool *pool);
50 typedef void stat_update  (struct per_var_data *stat, double w, double x);
51 typedef double stat_get   (const struct per_var_data *);
52
53
54 struct cell_spec
55 {
56   /* Printable title for output */
57   const char *title;
58
59   /* Keyword for syntax */
60   const char *keyword;
61
62   stat_create *sc;
63   stat_update *su;
64   stat_get *sd;
65 };
66
67
68 /* The thing parsed after TABLES= */
69 struct mtable
70 {
71   size_t n_dep_vars;
72   const struct variable **dep_vars;
73
74   const struct variable **control_vars;
75
76   struct layer **layers;
77   int n_layers;
78
79   struct cell *root_cell;
80 };
81
82 /* A structure created by the parser.  Contains the definition of the
83    what the procedure should calculate.  */
84 struct means
85 {
86   const struct dictionary *dict;
87
88   /* The "tables" (ie, a definition of how the data should
89      be broken down).  */
90   struct mtable *table;
91   size_t n_tables;
92
93   /* Missing value class for categorical variables.  */
94   enum mv_class exclude;
95
96   /* Missing value class for dependent variables */
97   enum mv_class dep_exclude;
98
99   bool listwise_exclude;
100
101
102   /* The statistics to be calculated for each cell.  */
103   int *statistics;
104   int n_statistics;
105
106   /* Pool on which cell functions may allocate data.  */
107   struct pool *pool;
108 };
109
110
111
112 #define n_MEANS_STATISTICS 17
113 extern const struct cell_spec cell_spec[n_MEANS_STATISTICS];
114
115 /* This enum must be consistent with the array cell_spec (in means-calc.c).
116    A bitfield instead of enums would in my opinion be
117    more elegent.  However we want the order of the specified
118    statistics to be retained in the output.  */
119 enum
120   {
121     MEANS_MEAN = 0,
122     MEANS_N,
123     MEANS_STDDEV
124   };
125
126
127
128 struct dataset;
129 struct casereader;
130 void run_means (struct means *cmd, struct casereader *input, const struct dataset *ds UNUSED);
131
132 void means_shipout (const struct mtable *mt, const struct means *means);
133
134 #endif