From: Jason Stover Date: Fri, 21 Apr 2006 20:48:56 +0000 (+0000) Subject: choose residual variable names correctly X-Git-Tag: v0.6.0~963 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc07e50f2779af741e913b6454565c07efba0caf;p=pspp-builds.git choose residual variable names correctly --- diff --git a/src/language/stats/ChangeLog b/src/language/stats/ChangeLog index 300a9302..8d6066ff 100644 --- a/src/language/stats/ChangeLog +++ b/src/language/stats/ChangeLog @@ -1,3 +1,11 @@ +2006-04-21 Jason Stover + + * regression.q (try_name): New function. (Partly copied from + try_name in descriptives.c.) + + * regression.q (subcommand_save): Choose residual variable names + correctly. + 2006-04-20 Jason Stover * regression.q (cmd_regression): Moved call to subcommand_save() diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 8103d914..34aef922 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -549,9 +549,23 @@ regression_trns_proc (void *m, struct ccase *c, int case_idx UNUSED) free (vals); return TRNS_CONTINUE; } +/* + Returns 0 if NAME is a duplicate of any existing variable name. +*/ +static int +try_name (char *name) +{ + if (dict_lookup_var (default_dict, name) != NULL) + return 0; + + return 1; +} + static void subcommand_save (int save, pspp_linreg_cache **models) { + int i; + char name[LONG_NAME_LEN + 1]; struct variable *residuals = NULL; pspp_linreg_cache **lc; @@ -559,11 +573,18 @@ subcommand_save (int save, pspp_linreg_cache **models) if (save) { + i = 1; + snprintf (name, LONG_NAME_LEN, "RES%d", i); for (lc = models; lc < models + cmd.n_dependent; lc++) { assert (*lc != NULL); assert ((*lc)->depvar != NULL); - residuals = dict_create_var (default_dict, "residuals", 0); + while (!try_name (name)) + { + i++; + snprintf (name, LONG_NAME_LEN, "RES%d", i); + } + residuals = dict_create_var (default_dict, name, 0); assert (residuals != NULL); (*lc)->resid = residuals; add_transformation (regression_trns_proc, pspp_linreg_cache_free, *lc);