+/*
+ Allocates MATRIX if necessary,
+ and populates row MROW, from the data in C corresponding to
+ variables in VARS. N_VARS is the length of VARS.
+*/
+static void
+matrix_fill_row (gsl_matrix **matrix,
+ const struct ccase *c, int mrow,
+ const struct variable **vars, size_t n_vars)
+{
+ int col;
+ if (*matrix == NULL)
+ *matrix = gsl_matrix_alloc (n_vars, n_vars);
+
+ for (col = 0; col < n_vars; ++col)
+ {
+ const struct variable *cv = vars [col];
+ double x = case_data (c, cv)->f;
+ assert (col < (*matrix)->size2);
+ assert (mrow < (*matrix)->size1);
+ gsl_matrix_set (*matrix, mrow, col, x);
+ }
+}
+