From: John Darrington Date: Sat, 6 Nov 2004 12:45:30 +0000 (+0000) Subject: Made EXAMINE cope properly with splits. X-Git-Tag: v0.4.0~239 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e67442312d9600ed738c0e812e2db6d60d288ab4;p=pspp-builds.git Made EXAMINE cope properly with splits. --- diff --git a/src/ChangeLog b/src/ChangeLog index 3b6dc154..1c1f40be 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Sat Nov 6 20:40:38 WST 2004 John Darrington + + * examine.q Fixed problem where examine wasn't dealing properly with + splits + Sat Nov 6 14:49:47 WST 2004 John Darrington * oneway.q Fixed problem where oneway wasn't dealing properly with diff --git a/src/examine.q b/src/examine.q index 546fcc05..f4d8867d 100644 --- a/src/examine.q +++ b/src/examine.q @@ -68,11 +68,15 @@ static struct hsh_table *hash_table_factors; struct factor { - struct variable *v1; - struct hsh_table *hash_table_v1; + /* The independent variable for this factor */ + struct variable *indep_var; + + /* The list of values of the independent variable */ + struct hsh_table *hash_table_val; + + /* The subfactor (if any) */ + struct factor *subfactor; - struct variable *v2; - struct hsh_table *hash_table_v2; }; @@ -107,16 +111,15 @@ static void show_extremes(struct variable **dependent_var, int n_extremities); -/* Calculations */ -static void calculate(const struct casefile *cf, void *cmd_); +/* Per Split function */ +static void run_examine(const struct casefile *cf, void *cmd_); + +static void output_examine(void); int cmd_examine(void) { - int i; - short total=1; - if ( !parse_examine(&cmd) ) @@ -128,14 +131,26 @@ cmd_examine(void) if ( ! cmd.sbc_cinterval) cmd.n_cinterval[0] = 95.0; - if ( cmd.sbc_nototal ) - total = 0; - multipass_procedure_with_splits (calculate, &cmd); + multipass_procedure_with_splits (run_examine, &cmd); + + + hsh_destroy(hash_table_factors); + + + return CMD_SUCCESS; +}; + + +/* Show all the appropriate tables */ +static void +output_examine(void) +{ /* Show totals if appropriate */ - if ( total || !hash_table_factors || 0 == hsh_count (hash_table_factors)) + if ( ! cmd.sbc_nototal || + ! hash_table_factors || 0 == hsh_count (hash_table_factors)) { show_summary(dependent_vars, n_dependent_vars,0); @@ -164,18 +179,17 @@ cmd_examine(void) if ( cmd.sbc_statistics ) { if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES]) - show_descriptives(dependent_vars, n_dependent_vars,f); + show_descriptives(dependent_vars, n_dependent_vars, f); if ( cmd.a_statistics[XMN_ST_EXTREME]) - show_extremes(dependent_vars, n_dependent_vars,f,cmd.st_n); + show_extremes(dependent_vars, n_dependent_vars, f, cmd.st_n); } } } - hsh_destroy(hash_table_factors); - return CMD_SUCCESS; -}; +} + /* TOTAL and NOTOTAL are simple, mutually exclusive flags */ @@ -410,8 +424,8 @@ show_descriptives(struct variable **dependent_var, tab_hline (t, TAL_2, 0, n_cols - 1, heading_rows ); - tab_vline (t, TAL_2, heading_columns, 0, n_rows - 1); - tab_vline (t, TAL_1, n_cols - 2, 0, n_rows - 1); + tab_vline (t, TAL_1, heading_columns, 0, n_rows - 1); + tab_vline (t, TAL_2, n_cols - 2, 0, n_rows - 1); tab_vline (t, TAL_1, n_cols - 1, 0, n_rows - 1); tab_text (t, n_cols - 2, 0, TAB_CENTER | TAT_TITLE, _("Statistic")); @@ -791,23 +805,39 @@ show_summary(struct variable **dependent_var, static int bad_weight_warn = 1; static void -calculate(const struct casefile *cf, void *cmd_) +run_examine(const struct casefile *cf, void *cmd_) { + struct hsh_iterator hi; + struct factor *fctr; + struct casereader *r; struct ccase c; - struct cmd_examine *cmd = (struct cmd_examine *) cmd_; + const struct cmd_examine *cmd = (struct cmd_examine *) cmd_; + + /* Make sure we haven't got rubbish left over from a + previous split */ + if ( hash_table_factors ) + { + for ( fctr = hsh_first(hash_table_factors, &hi); + fctr != 0; + fctr = hsh_next (hash_table_factors, &hi) ) + { + hsh_clear(fctr->hash_table_v1); + if ( fctr->hash_table_v2 ) + hsh_clear(fctr->hash_table_v2); + } + } + for(r = casefile_get_reader (cf); casereader_read (r, &c) ; case_destroy (&c)) { int i; - struct hsh_iterator hi; - struct factor *fctr; const double weight = - dict_get_case_weight(default_dict,&c,&bad_weight_warn); + dict_get_case_weight(default_dict, &c, &bad_weight_warn); if ( hash_table_factors ) { @@ -815,21 +845,20 @@ calculate(const struct casefile *cf, void *cmd_) fctr != 0; fctr = hsh_next (hash_table_factors, &hi) ) { - union value *val; - - - val = case_data (&c, fctr->v1->fv); - hsh_insert(fctr->hash_table_v1,val); + const union value *val = case_data (&c, fctr->v1->fv); + hsh_insert(fctr->hash_table_v1, (void *) val); if ( fctr->hash_table_v2 ) { val = case_data (&c, fctr->v2->fv); - hsh_insert(fctr->hash_table_v2,val); + hsh_insert(fctr->hash_table_v2, (void *) val); } } } } + + output_examine(); }