Implement the MCONVERT command.
[pspp] / src / language / data-io / matrix-reader.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2017 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 MATRIX_READER_H
18 #define MATRIX_READER_H
19
20 #include <gsl/gsl_matrix.h>
21 #include <stdbool.h>
22
23 struct casereader;
24 struct ccase;
25 struct dictionary;
26 struct matrix_reader;
27 struct variable;
28
29 struct matrix_reader
30   {
31     const struct dictionary *dict;
32     struct casegrouper *grouper;
33
34     /* Variables in 'dict'. */
35     const struct variable **svars;  /* Split variables. */
36     size_t n_svars;
37     const struct variable *rowtype; /* ROWTYPE_. */
38     const struct variable **fvars;  /* Factor variables. */
39     size_t n_fvars;
40     const struct variable *varname; /* VARNAME_. */
41     const struct variable **cvars;  /* Continuous variables. */
42     size_t n_cvars;
43   };
44
45 struct matrix_material
46 {
47   gsl_matrix *corr;             /* The correlation matrix */
48   gsl_matrix *cov;              /* The covariance matrix */
49
50   /* Moment matrices */
51   gsl_matrix *n;                /* MOMENT 0 */
52   gsl_matrix *mean_matrix;      /* MOMENT 1 */
53   gsl_matrix *var_matrix;       /* MOMENT 2 */
54 };
55
56 #define MATRIX_MATERIAL_INIT { .corr = NULL }
57 void matrix_material_uninit (struct matrix_material *);
58
59 struct matrix_reader *matrix_reader_create (const struct dictionary *,
60                                             struct casereader *);
61
62 bool matrix_reader_destroy (struct matrix_reader *mr);
63
64 bool matrix_reader_next (struct matrix_material *mm, struct matrix_reader *mr,
65                          struct casereader **groupp);
66
67 struct substring matrix_reader_get_string (const struct ccase *,
68                                            const struct variable *);
69 void matrix_reader_set_string (struct ccase *, const struct variable *,
70                                struct substring);
71
72
73 #endif