X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdictionary.c;h=20d64bc525b56e5b271d76612809177d6ef5f933;hb=2c9a5954d98d4dd508d8fbf2496f2bb819527a46;hp=f2ac187a1dcf1805a61096b7b2ba713800c61e15;hpb=bb7fdfcf1c9c380dafc165c556123094ad816825;p=pspp diff --git a/src/dictionary.c b/src/dictionary.c index f2ac187a1d..20d64bc525 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -22,6 +22,7 @@ #include #include "algorithm.h" #include "alloc.h" +#include "case.h" #include "hash.h" #include "misc.h" #include "str.h" @@ -558,11 +559,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); @@ -571,9 +575,15 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c) return 1.0; else { - double w = c->data[d->weight->fv].f; - if (w < 0.0) + double w = case_num (c, d->weight->fv); + 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; } }