+
+
+/* Sets V's measurement level to MEASURE. */
+void
+var_set_measure (struct variable *v, enum measure measure)
+{
+ struct variable *ov = var_clone (v);
+ var_set_measure_quiet (v, measure);
+ dict_var_changed (v, VAR_TRAIT_MEASURE, ov);
+}
+
+
+/* Returns the default measurement level for a variable of the
+ given TYPE, as set by var_create. The return value can be
+ used to reset a variable's measurement level to the
+ default. */
+enum measure
+var_default_measure (enum val_type type)
+{
+ return type == VAL_NUMERIC ? MEASURE_SCALE : MEASURE_NOMINAL;
+}
+\f
+/* Returns true if M is a valid variable role,
+ false otherwise. */
+bool
+var_role_is_valid (enum var_role role)
+{
+ switch (role)
+ {
+ case ROLE_NONE:
+ case ROLE_INPUT:
+ case ROLE_TARGET:
+ case ROLE_BOTH:
+ case ROLE_PARTITION:
+ case ROLE_SPLIT:
+ return true;
+
+ default:
+ return false;
+ }
+}
+
+/* Returns a string version of ROLE, for display to a user. */
+const char *
+var_role_to_string (enum var_role role)
+{
+ switch (role)
+ {
+ case ROLE_INPUT:
+ return _("Input");
+
+ case ROLE_TARGET:
+ return _("Output");
+
+ case ROLE_BOTH:
+ return _("Both");
+
+ case ROLE_NONE:
+ return _("None");
+
+ case ROLE_PARTITION:
+ return _("Partition");
+
+ case ROLE_SPLIT:
+ return _("Split");
+
+ default:
+ return "Invalid";
+ }
+}
+
+/* Returns a string version of ROLE, for use in PSPP comamnd syntax. */
+const char *
+var_role_to_syntax (enum var_role role)
+{
+ switch (role)
+ {
+ case ROLE_INPUT:
+ return "INPUT";
+
+ case ROLE_TARGET:
+ return "TARGET";
+
+ case ROLE_BOTH:
+ return "BOTH";
+
+ case ROLE_NONE:
+ return "NONE";
+
+ case ROLE_PARTITION:
+ return "PARTITION";
+
+ case ROLE_SPLIT:
+ return "SPLIT";
+
+ default:
+ return "<invalid>";
+ }
+}
+
+/* Returns V's role. */
+enum var_role
+var_get_role (const struct variable *v)
+{
+ return v->role;
+}
+
+/* Sets V's role to ROLE. */
+static void
+var_set_role_quiet (struct variable *v, enum var_role role)
+{
+ assert (var_role_is_valid (role));
+ v->role = role;
+}
+
+
+/* Sets V's role to ROLE. */
+void
+var_set_role (struct variable *v, enum var_role role)
+{
+ struct variable *ov = var_clone (v);
+ var_set_role_quiet (v, role);
+ dict_var_changed (v, VAR_TRAIT_ROLE, ov);
+}