X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdictionary.c;h=8cceaf1a804b31c9e3e0797d9e296970af431120;hb=cf89e411db41c05c39753b05cf144c8b26a44d96;hp=953b5646657ea4fa61e48a9ece84841435d10f97;hpb=14e7292894533c5491a774a2d749386362660812;p=pspp diff --git a/src/dictionary.c b/src/dictionary.c index 953b564665..8cceaf1a80 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -18,7 +18,7 @@ 02111-1307, USA. */ #include -#include +#include "error.h" #include #include "algorithm.h" #include "alloc.h" @@ -558,11 +558,14 @@ dict_get_weight (const struct dictionary *d) return d->weight; } -/* Returns the value of D's weighting variable in case C, except - that a negative weight is returned as 0. Returns 1 if the - dictionary is unweighted. */ +/* Returns the value of D's weighting variable in case C, except that a + negative weight is returned as 0. Returns 1 if the dictionary is + unweighted. Will warn about missing, negative, or zero values if + warn_on_invalid is nonzero. The function will set warn_on_invalid to zero + if an invalid weight is found. */ double -dict_get_case_weight (const struct dictionary *d, const struct ccase *c) +dict_get_case_weight (const struct dictionary *d, const struct ccase *c, + int *warn_on_invalid) { assert (d != NULL); assert (c != NULL); @@ -572,8 +575,14 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c) else { double w = c->data[d->weight->fv].f; - if (w < 0.0) + if ( w < 0.0 || w == SYSMIS || is_num_user_missing(w, d->weight) ) w = 0.0; + if ( w == 0.0 && *warn_on_invalid ) { + *warn_on_invalid = 0; + msg (SW, _("At least one case in the data file had a weight value " + "that was user-missing, system-missing, zero, or " + "negative. These case(s) were ignored.")); + } return w; } } @@ -661,6 +670,7 @@ dict_compact_values (struct dictionary *d) { size_t i; + d->next_value_idx = 0; for (i = 0; i < d->var_cnt; ) { struct variable *v = d->var[i];