1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "missing-values.h"
34 NUMERIC, /* A numeric variable. */
35 ALPHA /* A string variable. */
38 bool var_type_is_valid (enum var_type);
39 const char *var_type_adj (enum var_type);
40 const char *var_type_noun (enum var_type);
42 /* Alignment of data for display. */
51 bool alignment_is_valid (enum alignment);
53 /* How data is measured. */
62 bool measure_is_valid (enum measure);
64 /* Maximum lengths of short and long variable names.
65 Most operations support long variable names,
66 but some file formats are limited to short names. */
67 #define SHORT_NAME_LEN 8 /* Short name length. */
68 #define LONG_NAME_LEN 64 /* Long name length. */
70 /* A variable's dictionary entry. */
73 /* Dictionary information. */
74 char name[LONG_NAME_LEN + 1]; /* Variable name. Mixed case. */
75 int width; /* 0 for numeric, otherwise string width. */
76 struct missing_values miss; /* Missing values. */
77 struct fmt_spec print; /* Default format for PRINT. */
78 struct fmt_spec write; /* Default format for WRITE. */
79 struct val_labs *val_labs; /* Value labels. */
80 char *label; /* Variable label. */
82 /* GUI information. */
83 enum measure measure; /* Nominal, ordinal, or continuous. */
84 int display_width; /* Width of data editor column. */
85 enum alignment alignment; /* Alignment of data in GUI. */
87 /* Case information. */
88 int fv; /* Index into `value's. */
89 bool leave; /* Leave value from case to case? */
91 /* Data for use by containing dictionary. */
92 int index; /* Dictionary index. */
94 /* Short name, used only for system and portable file input
95 and output. Upper case only. There is no index for short
96 names. Short names are not necessarily unique. Any
97 variable may have no short name, indicated by an empty
99 char short_name[SHORT_NAME_LEN + 1];
101 /* Each command may use these fields as needed. */
103 void (*aux_dtor) (struct variable *);
105 /* Values of a categorical variable. Procedures need
106 vectors with binary entries, so any variable of type ALPHA will
107 have its values stored here. */
108 struct cat_vals *obs_vals;
111 /* Variable names. */
112 const char *var_get_name (const struct variable *);
113 void var_set_name (struct variable *, const char *);
114 bool var_is_valid_name (const char *, bool issue_error);
115 bool var_is_plausible_name (const char *name, bool issue_error);
116 int compare_var_names (const void *, const void *, const void *);
117 unsigned hash_var_name (const void *, const void *);
119 /* Variable types and widths. */
120 enum var_type var_get_type (const struct variable *);
121 int var_get_width (const struct variable *);
122 void var_set_width (struct variable *, int width);
123 bool var_is_numeric (const struct variable *);
124 bool var_is_alpha (const struct variable *);
125 bool var_is_short_string (const struct variable *);
126 bool var_is_long_string (const struct variable *);
127 bool var_is_very_long_string (const struct variable *);
129 /* Variables' missing values. */
130 const struct missing_values *var_get_missing_values (const struct variable *);
131 void var_set_missing_values (struct variable *, const struct missing_values *);
132 void var_clear_missing_values (struct variable *);
133 bool var_has_missing_values (const struct variable *);
135 typedef bool var_is_missing_func (const struct variable *,
136 const union value *);
137 bool var_is_value_missing (const struct variable *, const union value *);
138 bool var_is_num_missing (const struct variable *, double);
139 bool var_is_str_missing (const struct variable *, const char[]);
140 bool var_is_value_user_missing (const struct variable *,
141 const union value *);
142 bool var_is_num_user_missing (const struct variable *, double);
143 bool var_is_str_user_missing (const struct variable *, const char[]);
144 bool var_is_value_system_missing (const struct variable *,
145 const union value *);
147 /* Print and write formats. */
148 const struct fmt_spec *var_get_print_format (const struct variable *);
149 void var_set_print_format (struct variable *, const struct fmt_spec *);
150 const struct fmt_spec *var_get_write_format (const struct variable *);
151 void var_set_write_format (struct variable *, const struct fmt_spec *);
152 void var_set_both_formats (struct variable *, const struct fmt_spec *);
154 /* Variable labels. */
155 const char *var_get_label (const struct variable *);
156 void var_set_label (struct variable *, const char *);
157 void var_clear_label (struct variable *);
158 bool var_has_label (const struct variable *);
160 /* GUI information. */
161 enum measure var_get_measure (const struct variable *);
162 void var_set_measure (struct variable *, enum measure);
164 int var_get_display_width (const struct variable *);
165 void var_set_display_width (struct variable *, int display_width);
167 enum alignment var_get_alignment (const struct variable *);
168 void var_set_alignment (struct variable *, enum alignment);
170 /* Variable location in cases. */
171 size_t var_get_value_cnt (const struct variable *);
173 /* Whether variables' values should be preserved from case to
175 bool var_get_leave (const struct variable *);
178 const char *var_get_short_name (const struct variable *);
179 void var_set_short_name (struct variable *, const char *);
180 void var_set_short_name_suffix (struct variable *, const char *, int suffix);
181 void var_clear_short_name (struct variable *);
183 /* Pointers to `struct variable', by name. */
184 int compare_var_ptr_names (const void *, const void *, const void *);
185 unsigned hash_var_ptr_name (const void *, const void *);
187 /* Variable auxiliary data. */
188 void *var_attach_aux (struct variable *,
189 void *aux, void (*aux_dtor) (struct variable *));
190 void var_clear_aux (struct variable *);
191 void *var_detach_aux (struct variable *);
192 void var_dtor_free (struct variable *);
194 /* Classes of variables. */
197 DC_ORDINARY, /* Ordinary identifier. */
198 DC_SYSTEM, /* System variable. */
199 DC_SCRATCH /* Scratch variable. */
202 enum dict_class dict_class_from_id (const char *name);
203 const char *dict_class_to_name (enum dict_class dict_class);
205 /* Vector of variables. */
208 int idx; /* Index for dict_get_vector(). */
209 char name[LONG_NAME_LEN + 1]; /* Name. */
210 struct variable **var; /* Vector of variables. */
211 int cnt; /* Number of variables. */
215 /* Return a string representing this variable, in the form most
216 appropriate from a human factors perspective.
217 (IE: the label if it has one, otherwise the name )
219 const char * var_to_string(const struct variable *var);
222 int width_to_bytes(int width);
225 #endif /* !variable.h */