X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdescript.c;h=e84733acb02380eb33d73dc04b9834951dadf1ae;hb=a489451ddf22935fcbe115aa4aa5869b29f18103;hp=0492b33ed2378a232418f368326974eab88eaf00;hpb=2133a4941da5c903fe08c0961959e89b7d5f7321;p=pspp diff --git a/src/descript.c b/src/descript.c index 0492b33ed2..e84733acb0 100644 --- a/src/descript.c +++ b/src/descript.c @@ -26,8 +26,10 @@ #include #include "algorithm.h" #include "alloc.h" +#include "case.h" #include "casefile.h" #include "command.h" +#include "dictionary.h" #include "lexer.h" #include "error.h" #include "magic.h" @@ -261,11 +263,7 @@ cmd_descriptives (void) else if (lex_match_id ("DEFAULT")) dsc->show_stats |= DEFAULT_STATS; else - { - dsc->show_stats |= 1ul << (match_statistic ()); - if (dsc->show_stats == DSC_NONE) - dsc->show_stats = DEFAULT_STATS; - } + dsc->show_stats |= 1ul << (match_statistic ()); lex_match (','); } if (dsc->show_stats == 0) @@ -569,7 +567,7 @@ dump_z_table (struct dsc_proc *dsc) */ static int descriptives_trns_proc (struct trns_header *trns, struct ccase * c, - int case_num UNUSED) + int case_idx UNUSED) { struct dsc_trns *t = (struct dsc_trns *) trns; struct dsc_z_score *z; @@ -581,7 +579,7 @@ descriptives_trns_proc (struct trns_header *trns, struct ccase * c, assert(t->vars); for (vars = t->vars; vars < t->vars + t->var_cnt; vars++) { - double score = c->data[(*vars)->fv].f; + double score = case_num (c, (*vars)->fv); if ( score == SYSMIS || (!t->include_user_missing && is_num_user_missing(score, *vars)) ) { @@ -593,14 +591,15 @@ descriptives_trns_proc (struct trns_header *trns, struct ccase * c, for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++) { - double score = c->data[z->src_idx].f; + double input = case_num (c, z->src_idx); + double *output = &case_data_rw (c, z->dst_idx)->f; if (z->mean == SYSMIS || z->std_dev == SYSMIS - || all_sysmis || score == SYSMIS - || (!t->include_user_missing && is_num_user_missing(score, z->v))) - c->data[z->dst_idx].f = SYSMIS; + || all_sysmis || input == SYSMIS + || (!t->include_user_missing && is_num_user_missing(input, z->v))) + *output = SYSMIS; else - c->data[z->dst_idx].f = (score - z->mean) / z->std_dev; + *output = (input - z->mean) / z->std_dev; } return -1; } @@ -695,7 +694,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_) { struct dsc_proc *dsc = dsc_; struct casereader *reader; - const struct ccase *c; + struct ccase c; int i; for (i = 0; i < dsc->var_cnt; i++) @@ -712,15 +711,16 @@ calc_descriptives (const struct casefile *cf, void *dsc_) dsc->valid = 0.; /* First pass to handle most of the work. */ - reader = casefile_get_reader (cf); - while (casereader_read (reader, &c)) + for (reader = casefile_get_reader (cf); + casereader_read (reader, &c); + case_destroy (&c)) { - double weight = dict_get_case_weight (default_dict, c, &dsc->bad_warn); + double weight = dict_get_case_weight (default_dict, &c, &dsc->bad_warn); if (weight <= 0.0) - continue; + continue; /* Check for missing values. */ - if (listwise_missing (dsc, c)) + if (listwise_missing (dsc, &c)) { dsc->missing_listwise += weight; if (dsc->missing_type == DSC_LISTWISE) @@ -731,7 +731,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_) for (i = 0; i < dsc->var_cnt; i++) { struct dsc_var *dv = &dsc->vars[i]; - double x = c->data[dv->v->fv].f; + double x = case_num (&c, dv->v->fv); if (dsc->missing_type != DSC_LISTWISE && (x == SYSMIS @@ -743,12 +743,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_) } if (dv->moments != NULL) - { - if (dsc->max_moment > MOMENT_MEAN) - moments_pass_one (dv->moments, x, weight); - else - moments_pass_two (dv->moments, x, weight); - } + moments_pass_one (dv->moments, x, weight); if (x < dv->min) dv->min = x; @@ -761,23 +756,24 @@ calc_descriptives (const struct casefile *cf, void *dsc_) /* Second pass for higher-order moments. */ if (dsc->max_moment > MOMENT_MEAN) { - reader = casefile_get_reader (cf); - while (casereader_read (reader, &c)) + for (reader = casefile_get_reader (cf); + casereader_read (reader, &c); + case_destroy (&c)) { - double weight = dict_get_case_weight (default_dict, c, + double weight = dict_get_case_weight (default_dict, &c, &dsc->bad_warn); if (weight <= 0.0) continue; /* Check for missing values. */ - if (listwise_missing (dsc, c) + if (listwise_missing (dsc, &c) && dsc->missing_type == DSC_LISTWISE) continue; for (i = 0; i < dsc->var_cnt; i++) { struct dsc_var *dv = &dsc->vars[i]; - double x = c->data[dv->v->fv].f; + double x = case_num (&c, dv->v->fv); if (dsc->missing_type != DSC_LISTWISE && (x == SYSMIS @@ -842,7 +838,7 @@ listwise_missing (struct dsc_proc *dsc, const struct ccase *c) for (i = 0; i < dsc->var_cnt; i++) { struct dsc_var *dv = &dsc->vars[i]; - double x = c->data[dv->v->fv].f; + double x = case_num (c, dv->v->fv); if (x == SYSMIS || (!dsc->include_user_missing && is_num_user_missing (x, dv->v)))