+/*
+ Create a covariance struct for a two-pass algorithm. If categorical
+ variables are involed, the dimension cannot be know until after the
+ first data pass, so the actual covariances will not be allocated
+ until then.
+ */
+struct covariance *
+covariance_2pass_create (size_t n_vars, const struct variable **vars,
+ size_t n_catvars, const struct variable **catvars,
+ const struct variable *weight, enum mv_class exclude)
+{
+ size_t i;
+ struct covariance *cov = xmalloc (sizeof *cov);
+ cov->vars = xmalloc (sizeof *cov->vars * n_vars);
+ cov->catvars = xnmalloc (n_catvars, sizeof (*cov->catvars));
+ cov->n_categories = xnmalloc (n_catvars, sizeof (cov->n_categories));
+
+ cov->wv = weight;
+ cov->n_vars = n_vars;
+ cov->n_catvars = n_catvars;
+
+ for (i = 0; i < n_vars; ++i)
+ cov->vars[i] = vars[i];
+
+ for (i = 0; i < n_catvars; i++)
+ {
+ cov->catvars[i] = catvars[i];
+ cov->n_categories[i] = 0;
+ }
+
+ cov->moments = xmalloc (sizeof *cov->moments * n_MOMENTS);
+
+ cov->exclude = exclude;
+
+ return cov;
+}
+