+ assert (i < coef->n_vars);
+ return (coef->v_info + i)->v;
+}
+
+/*
+ Which coefficient does this variable match? If the variable is
+ categorical, and has more than one coefficient, use the VAL to find
+ its coefficient.
+ */
+struct pspp_coeff *
+pspp_coeff_var_to_coeff (const struct variable *v, struct pspp_coeff **coefs,
+ size_t n_coef, const union value *val)
+{
+ size_t i = 0;
+ size_t j = 0;
+ size_t v_idx;
+
+ struct pspp_coeff *result = NULL;
+
+ if (v != NULL)
+ {
+ v_idx = var_get_dict_index (v);
+ while (i < n_coef)
+ {
+ if (coefs[i]->v_info != NULL)
+ {
+ if (var_get_dict_index (coefs[i]->v_info->v) == v_idx)
+ {
+ break;
+ }
+ }
+ i++;
+ }
+ result = coefs[i];
+ if (var_is_alpha (v))
+ {
+ /*
+ Use the VAL to find the coefficient.
+ */
+ if (val != NULL)
+ {
+ int width = var_get_width (v);
+
+ j = i;
+ while (j < n_coef
+ && value_compare_3way (pspp_coeff_get_value (coefs[j], v),
+ val, width) != 0)
+ {
+ j++;
+ }
+ result = ((j < n_coef) ? coefs[j] : NULL);
+ }
+ }
+ }
+ return result;