+
+/*
+ Which coefficient is associated with V? The VAL argument is relevant
+ only to categorical variables.
+ */
+const struct pspp_linreg_coeff *
+pspp_linreg_get_coeff (const pspp_linreg_cache * c,
+ const struct variable *v, const union value *val)
+{
+ int i = 1;
+ struct pspp_linreg_coeff *result = NULL;
+ const struct variable *tmp = NULL;
+
+ if (c == NULL)
+ {
+ return NULL;
+ }
+ if (c->coeff == NULL || c->n_indeps == NULL || v == NULL)
+ {
+ return NULL;
+ }
+
+ result = c->coeff + i;
+ tmp = pspp_linreg_coeff_get_var (result, 0);
+ while (tmp->index != v->index && i < c->n_coeffs)
+ {
+ result = c->coeff + i;
+ tmp = pspp_linreg_coeff_get_var (result, 0);
+ i++;
+ }
+ if (i > c->n_coeffs)
+ {
+ return NULL;
+ }
+ if (v->type == NUMERIC)
+ {
+ return result;
+ }
+ else if (val != NULL)
+ {
+ /*
+ If v is categorical, we need to ensure the coefficient
+ matches the VAL.
+ */
+ while (tmp->index != v->index && i < c->n_coeffs
+ && compare_values (pspp_linreg_coeff_get_value (result, tmp),
+ val, v->width))
+ { /* FIX THIS */
+ i++;
+ result = c->coeff + i;
+ tmp = pspp_linreg_coeff_get_var (result, 0);
+ }
+ if (i == c->n_coeffs)
+ {
+ return NULL;
+ }
+ return result;
+ }
+ return NULL;
+}