X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffrequencies.q;h=cd370be821c8db73f2d88da8350613a7ea8c07b0;hb=deb4fd96c0c171fc8eb64f7f1e7f5c2af4931416;hp=93e16f7f2126bed8396fa45b6a043963734a6441;hpb=ddb6ce30f985ce39be0326193ae0bad452307127;p=pspp-builds.git diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index 93e16f7f..cd370be8 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2007, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,12 +38,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -60,6 +58,7 @@ #include "freq.h" #include "minmax.h" +#include "xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -269,7 +268,7 @@ static hsh_compare_func compare_freq_numeric_d, compare_freq_alpha_d; static void do_piechart(const struct variable *var, const struct freq_tab *frq_tab); -gsl_histogram * +struct histogram * freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var); @@ -311,7 +310,7 @@ internal_cmd_frequencies (struct lexer *lexer, struct dataset *ds) if (!parse_frequencies (lexer, ds, &cmd, NULL)) return CMD_FAILURE; - if (cmd.onepage_limit == NOT_LONG) + if (cmd.onepage_limit == LONG_MIN) cmd.onepage_limit = 50; /* Figure out statistics to calculate. */ @@ -377,11 +376,11 @@ internal_cmd_frequencies (struct lexer *lexer, struct dataset *ds) for (; casegrouper_get_next_group (grouper, &group); casereader_destroy (group)) { - struct ccase c; + struct ccase *c; precalc (group, ds); - for (; casereader_read (group, &c); case_destroy (&c)) - calc (&c, ds); + for (; (c = casereader_read (group)) != NULL; case_unref (c)) + calc (c, ds); postcalc (); } ok = casegrouper_destroy (grouper); @@ -536,13 +535,15 @@ calc (const struct ccase *c, const struct dataset *ds) static void precalc (struct casereader *input, struct dataset *ds) { - struct ccase c; + struct ccase *c; size_t i; - if (!casereader_peek (input, 0, &c)) - return; - output_split_file_values (ds, &c); - case_destroy (&c); + c = casereader_peek (input, 0); + if (c != NULL) + { + output_split_file_values (ds, c); + case_unref (c); + } pool_destroy (data_pool); data_pool = pool_create (); @@ -606,43 +607,38 @@ postcalc (void) if ( chart == GFT_HIST) { double d[frq_n_stats]; - struct normal_curve norm; - gsl_histogram *hist ; - - - norm.N = vf->tab.valid_cases; + struct histogram *hist ; calc_stats (v, d); - norm.mean = d[frq_mean]; - norm.stddev = d[frq_stddev]; - hist = freq_tab_to_hist(ft,v); + hist = freq_tab_to_hist (ft,v); - histogram_plot(hist, var_to_string(v), &norm, normal); + histogram_plot_n (hist, var_to_string(v), + vf->tab.valid_cases, + d[frq_mean], + d[frq_stddev], + normal); - gsl_histogram_free(hist); + statistic_destroy ((struct statistic *)hist); } - if ( chart == GFT_PIE) { do_piechart(v_variables[i], ft); } - - cleanup_freq_tab (v); } } /* Returns the comparison function that should be used for - sorting a frequency table by FRQ_SORT using VAR_TYPE - variables. */ + sorting a frequency table by FRQ_SORT using VAL_TYPE + values. */ static hsh_compare_func * -get_freq_comparator (int frq_sort, enum var_type var_type) +get_freq_comparator (int frq_sort, enum val_type val_type) { - bool is_numeric = var_type == VAR_NUMERIC; + bool is_numeric = val_type == VAL_NUMERIC; switch (frq_sort) { case FRQ_AVALUE: @@ -766,7 +762,7 @@ frq_custom_variables (struct lexer *lexer, struct dataset *ds, struct cmd_freque vf->groups = NULL; vf->width = var_get_width (v); vf->print = *var_get_print_format (v); - if (vf->width > MAX_SHORT_STRING && get_algorithm () == COMPATIBLE) + if (vf->width > MAX_SHORT_STRING && settings_get_algorithm () == COMPATIBLE) { enum fmt_type type = var_get_print_format (v)->type; vf->width = MAX_SHORT_STRING; @@ -1257,7 +1253,7 @@ calc_stats (const struct variable *v, double d[frq_n_stats]) double tp; if ( percentiles[i].flag2 ) continue ; - if ( get_algorithm() != COMPATIBLE ) + if ( settings_get_algorithm () != COMPATIBLE ) tp = (ft->valid_cases - 1) * percentiles[i].p; else @@ -1308,7 +1304,7 @@ calc_stats (const struct variable *v, double d[frq_n_stats]) double s; double dummy; - if ( get_algorithm() != COMPATIBLE ) + if ( settings_get_algorithm () != COMPATIBLE ) { s = modf((ft->valid_cases - 1) * percentiles[i].p , &dummy); } @@ -1437,14 +1433,14 @@ dump_statistics (const struct variable *v, int show_varname) /* Create a gsl_histogram from a freq_tab */ -gsl_histogram * -freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var) +struct histogram * +freq_tab_to_hist (const struct freq_tab *ft, const struct variable *var) { int i; double x_min = DBL_MAX; double x_max = -DBL_MAX; - gsl_histogram *hist; + struct statistic *hist; const double bins = 11; struct hsh_iterator hi; @@ -1461,15 +1457,15 @@ freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var) if ( frq->value[0].f > x_max ) x_max = frq->value[0].f ; } - hist = histogram_create(bins, x_min, x_max); + hist = histogram_create (bins, x_min, x_max); for( i = 0 ; i < ft->n_valid ; ++i ) { frq = &ft->valid[i]; - gsl_histogram_accumulate(hist, frq->value[0].f, frq->count); + histogram_add ((struct histogram *)hist, frq->value[0].f, frq->count); } - return hist; + return (struct histogram *)hist; } @@ -1499,7 +1495,8 @@ freq_tab_to_slice_array(const struct freq_tab *frq_tab, { const struct freq *frq = &frq_tab->valid[i]; - slices[i].label = var_get_value_name (var, frq->value); + ds_init_empty (&slices[i].label); + var_append_value_name (var, frq->value, &slices[i].label); slices[i].magnetude = frq->count; } @@ -1513,12 +1510,17 @@ static void do_piechart(const struct variable *var, const struct freq_tab *frq_tab) { struct slice *slices; - int n_slices; + int n_slices, i; slices = freq_tab_to_slice_array(frq_tab, var, &n_slices); piechart_plot(var_to_string(var), slices, n_slices); + for (i = 0 ; i < n_slices ; ++i ) + { + ds_destroy (&slices[i].label); + } + free(slices); }