draft pspp sav file api
[pspp] / include / pspp / pspp-sav.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010 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 PSPP_SAV_H
18 #define PSPP_SAV_H 1
19
20 struct pspp_sav_header
21   {
22     char *product;
23     int compressed;
24     int weight_index;
25     int n_cases;
26     double bias;
27     time_t created;
28     char *file_label;
29   };
30
31 /* Values for 'type' member of struct pspp_sav_format. */
32 #define PSPP_SAV_FMT_A            1
33 #define PSPP_SAV_FMT_AHEX         2
34 #define PSPP_SAV_FMT_COMMA        3
35 #define PSPP_SAV_FMT_DOLLAR       4
36 #define PSPP_SAV_FMT_F            5
37 #define PSPP_SAV_FMT_IB           6
38 #define PSPP_SAV_FMT_PIBHEX       7
39 #define PSPP_SAV_FMT_P            8
40 #define PSPP_SAV_FMT_PIB          9
41 #define PSPP_SAV_FMT_PK           10
42 #define PSPP_SAV_FMT_RB           11
43 #define PSPP_SAV_FMT_RBHEX        12
44 /* 13 and 14 are not used. */
45 #define PSPP_SAV_FMT_Z            15
46 #define PSPP_SAV_FMT_N            16
47 #define PSPP_SAV_FMT_E            17
48 /* 18 and 19 are not used. */
49 #define PSPP_SAV_FMT_DATE         20
50 #define PSPP_SAV_FMT_TIME         21
51 #define PSPP_SAV_FMT_DATETIME     22
52 #define PSPP_SAV_FMT_ADATE        23
53 #define PSPP_SAV_FMT_JDATE        24
54 #define PSPP_SAV_FMT_DTIME        25
55 #define PSPP_SAV_FMT_WKDAY        26
56 #define PSPP_SAV_FMT_MONTH        27
57 #define PSPP_SAV_FMT_MOYR         28
58 #define PSPP_SAV_FMT_QYR          29
59 #define PSPP_SAV_FMT_WKYR         30
60 #define PSPP_SAV_FMT_PCT          31
61 #define PSPP_SAV_FMT_DOT          32
62 #define PSPP_SAV_FMT_CCA          33
63 #define PSPP_SAV_FMT_CCB          34
64 #define PSPP_SAV_FMT_CCC          35
65 #define PSPP_SAV_FMT_CCD          36
66 #define PSPP_SAV_FMT_CCE          37
67 #define PSPP_SAV_FMT_EDATE        38
68 #define PSPP_SAV_FMT_SDATE        39
69
70 struct pspp_sav_format
71   {
72     int type;                   /* One of PSPP_SAV_FMT_*. */
73     int w;                      /* Width. */
74     int d;                      /* Number of decimal places, 0 for strings. */
75   };
76
77 union pspp_sav_value
78   {
79     double number;
80     char *string;
81   };
82
83 struct pspp_sav_missing_values
84   {
85     size_t n_values;
86     union pspp_sav_value *values;
87
88     int has_range;
89     int range_lowest;
90     int range_highest;
91     union pspp_sav_value lo, hi;
92   };
93
94 struct pspp_sav_variable
95   {
96     char *short_name;
97     int width;
98     char *var_label;
99     struct pspp_sav_format print;
100     struct pspp_sav_format write;
101     struct pspp_sav_missing_values missing;
102   };
103
104 struct pspp_sav_value_label
105   {
106     union pspp_sav_value value;
107     char *label;
108   };
109
110 struct pspp_sav_value_labels
111   {
112     /* The variables that are labeled. */
113     int *var_indexes;
114     size_t n_vars;
115
116     /* The labels. */
117     struct pspp_sav_value_label *labels;
118     size_t n_labels;
119   };
120
121 struct pspp_sav_document
122   {
123     char **lines;
124     size_t n_lines;
125   };
126
127 #define PSPP_SAV_FP_IEEE754     1
128 #define PSPP_SAV_FP_IBM370      2
129 #define PSPP_SAV_FP_DECVAXE     3
130
131 #define PSPP_SAV_ENDIAN_BIG     1
132 #define PSPP_SAV_ENDIAN_LITTLE  2
133
134 #define PSPP_SAV_CC_EBCDIC      1
135 #define PSPP_SAV_CC_ASCII7      2
136 #define PSPP_SAV_CC_ASCII8      3
137 #define PSPP_SAV_CC_DECKANJI    4
138
139 struct pspp_sav_integer_info
140   {
141     int version_major;
142     int version_minor;
143     int version_revision;
144     int machine_code;
145     int float_rep;
146     int compression_code;
147     int endianness;
148     int character_code;
149   };
150
151 struct pspp_sav_float_info
152   {
153     double sysmis;
154     double highest;
155     double lowest;
156   };
157
158 /* Type of a multiple response set. */
159 #define PSPP_SAV_MRSET_MDGROUP  0  /* Multiple dichotomy group. */
160 #define PSPP_SAV_MRSET_MCGROUP  1  /* Multiple category group. */
161
162 /* Source of category labels for a multiple dichotomy group. */
163 #define PSPP_SAV_MDGROUP_VARLABELS      0 /* Variable labels. */
164 #define PSPP_SAV_MDGROUP_COUNTEDVALUES  1 /* Value labels for counted value. */
165
166 struct pspp_sav_mrset
167   {
168     char *name;
169     char *label;
170     char **var_short_names;
171     size_t n_vars;
172     int type;                   /* One of PSPP_SAV_MRSET_*. */
173
174     /* PSPP_SAV_MRSET_MDGROUP only */
175     int cat_source;               /* Source of category labels. */
176     bool label_from_var_label;    /* 'label' taken from variable label? */
177     union pspp_sav_value counted; /* Counted value. */
178     int width;                    /* Width of 'counted'. */
179   };
180
181 /* Measurement level. */
182 #define PSPP_SAV_MEASURE_UNKNOWN        0
183 #define PSPP_SAV_MEASURE_NOMINAL        1
184 #define PSPP_SAV_MEASURE_ORDINAL        2
185 #define PSPP_SAV_MEASURE_CONTINUOUS     3
186
187 /* Alignment. */
188 #define PSPP_SAV_ALIGN_LEFT             0
189 #define PSPP_SAV_ALIGN_RIGHT            1
190 #define PSPP_SAV_ALIGN_CENTER           2
191
192 struct pspp_sav_display
193   {
194     int measure;                /* One of PSPP_SAV_MEASURE_*. */
195     int width;                  /* Display width in ems, 0 if not present. */
196     int alignment;              /* One of PSPP_SAV_ALIGN_*. */
197   };
198
199 struct pspp_sav_display_params
200   {
201     struct pspp_sav_display *params;
202     size_t n_params;
203   };
204
205 struct pspp_sav_long_name
206   {
207     char *short_name;
208     char *long_name;
209   };
210
211 struct pspp_sav_very_long_string
212   {
213     char *short_name;
214     short int full_width;
215   };
216
217 struct pspp_sav_encoding
218   {
219     char *encoding;
220   };
221
222 struct pspp_sav_long_string_value_labels
223   {
224     /* Labeled variable. */
225     char *var_name;             /* Name of labeled variable. */
226     int width;                  /* Width of labeled variable, in [9,32767]. */
227
228     /* Labels. */
229     struct pspp_sav_value_label *labels;
230     size_t n_labels;
231   };
232
233 struct pspp_sav_attribute
234   {
235     char *long_var_name;        /* Variable name (NULL for file attribute). */
236     char *attr_name;            /* Attribute name. */
237     char **values;              /* All the values. */
238     size_t n_values;            /* Number of values. */
239   };
240
241 struct pspp_sav_ncases64
242   {
243     long long int n_cases;
244   };
245
246 /* Compression opcodes. */
247 #define PSPP_SAV_OP_IGNORE      0   /* No-op */
248 #define PSPP_SAV_OP_INT_MIN     1   /* Minimum compressed integer opcode. */
249 #define PSPP_SAV_OP_INT_MIN     251 /* Maximum compressed integer opcode. */
250 #define PSPP_SAV_OP_EOF         252 /* End of data. */
251 #define PSPP_SAV_OP_LITERAL     253 /* 8-byte uncompressible data follows. */
252 #define PSPP_SAV_OP_SPACES      254 /* Represents 8 bytes of spaces. */
253 #define PSPP_SAV_OP_SYSMIS      255 /* Represents system missing value. */
254
255 #endif /* pspp-sav.h */