projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added src/ui/terminal/automake.mk and src/ui/gui/automake.mk
[pspp]
/
src
/
frequencies.q
diff --git
a/src/frequencies.q
b/src/frequencies.q
index 1484776acb9b40ab4ea983d3c61eb12c2293f753..5754be7e61e6de277491488c814ba99af96c2057 100644
(file)
--- a/
src/frequencies.q
+++ b/
src/frequencies.q
@@
-14,8
+14,8
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
/*
TODO:
/*
TODO:
@@
-51,6
+51,11
@@
#include "vfm.h"
#include "settings.h"
#include "chart.h"
#include "vfm.h"
#include "settings.h"
#include "chart.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
/* (headers) */
#include "debug-print.h"
/* (headers) */
#include "debug-print.h"
@@
-183,7
+188,7
@@
static double scale, incr; /* FIXME */
static int normal; /* FIXME */
/* Variables for which to calculate statistics. */
static int normal; /* FIXME */
/* Variables for which to calculate statistics. */
-static
in
t n_variables;
+static
size_
t n_variables;
static struct variable **v_variables;
/* Arenas used to store semi-permanent storage. */
static struct variable **v_variables;
/* Arenas used to store semi-permanent storage. */
@@
-279,7
+284,9
@@
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);
static void do_piechart(const struct variable *var,
const struct freq_tab *frq_tab);
-void freq_tab_to_hist(const struct freq_tab *ft, gsl_histogram *hist);
+gsl_histogram *
+freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var);
+
\f
/* Parser and outline. */
\f
/* Parser and outline. */
@@
-486,7
+493,7
@@
static int
calc (struct ccase *c, void *aux UNUSED)
{
double weight;
calc (struct ccase *c, void *aux UNUSED)
{
double weight;
-
in
t i;
+
size_
t i;
int bad_warn = 1;
weight = dict_get_case_weight (default_dict, c, &bad_warn);
int bad_warn = 1;
weight = dict_get_case_weight (default_dict, c, &bad_warn);
@@
-540,7
+547,7
@@
calc (struct ccase *c, void *aux UNUSED)
static void
precalc (void *aux UNUSED)
{
static void
precalc (void *aux UNUSED)
{
-
in
t i;
+
size_
t i;
pool_destroy (gen_pool);
gen_pool = pool_create ();
pool_destroy (gen_pool);
gen_pool = pool_create ();
@@
-584,7
+591,7
@@
precalc (void *aux UNUSED)
static void
postcalc (void *aux UNUSED)
{
static void
postcalc (void *aux UNUSED)
{
-
in
t i;
+
size_
t i;
for (i = 0; i < n_variables; i++)
{
for (i = 0; i < n_variables; i++)
{
@@
-625,20
+632,21
@@
postcalc (void *aux UNUSED)
dump_statistics (v, !dumped_freq_tab);
dump_statistics (v, !dumped_freq_tab);
+
if ( chart == GFT_HIST)
{
double d[frq_n_stats];
struct normal_curve norm;
if ( chart == GFT_HIST)
{
double d[frq_n_stats];
struct normal_curve norm;
+ gsl_histogram *hist ;
- gsl_histogram *hist = gsl_histogram_alloc(7);
- norm.N = vf->tab.
total
_cases;
+ norm.N = vf->tab.
valid
_cases;
calc_stats(v,d);
norm.mean = d[frq_mean];
norm.stddev = d[frq_stddev];
calc_stats(v,d);
norm.mean = d[frq_mean];
norm.stddev = d[frq_stddev];
-
freq_tab_to_hist(ft, hist
);
+
hist = freq_tab_to_hist(ft,v
);
histogram_plot(hist, var_to_string(v), &norm, normal);
histogram_plot(hist, var_to_string(v), &norm, normal);
@@
-652,6
+660,7
@@
postcalc (void *aux UNUSED)
}
}
+
cleanup_freq_tab (v);
}
cleanup_freq_tab (v);
}
@@
-688,7
+697,7
@@
not_missing (const void *f_, void *v_)
const struct freq *f = f_;
struct variable *v = v_;
const struct freq *f = f_;
struct variable *v = v_;
- return !
is_missing (&f->v,
v);
+ return !
mv_is_value_missing (&v->miss, &f->
v);
}
/* Summarizes the frequency table data for variable V. */
}
/* Summarizes the frequency table data for variable V. */
@@
-698,7
+707,7
@@
postprocess_freq_tab (struct variable *v)
hsh_compare_func *compare;
struct freq_tab *ft;
size_t count;
hsh_compare_func *compare;
struct freq_tab *ft;
size_t count;
- void **data;
+ void *
const
*data;
struct freq *freqs, *f;
size_t i;
struct freq *freqs, *f;
size_t i;
@@
-711,7
+720,7
@@
postprocess_freq_tab (struct variable *v)
data = hsh_data (ft->data);
/* Copy dereferenced data into freqs. */
data = hsh_data (ft->data);
/* Copy dereferenced data into freqs. */
- freqs = x
malloc (count *
sizeof *freqs);
+ freqs = x
nmalloc (count,
sizeof *freqs);
for (i = 0; i < count; i++)
{
struct freq *f = data[i];
for (i = 0; i < count; i++)
{
struct freq *f = data[i];
@@
-764,8
+773,8
@@
frq_custom_variables (struct cmd_frequencies *cmd UNUSED)
int mode;
int min = 0, max = 0;
int mode;
int min = 0, max = 0;
-
in
t old_n_variables = n_variables;
-
in
t i;
+
size_
t old_n_variables = n_variables;
+
size_
t i;
lex_match ('=');
if (token != T_ALL && (token != T_ID
lex_match ('=');
if (token != T_ALL && (token != T_ID
@@
-826,8
+835,8
@@
frq_custom_variables (struct cmd_frequencies *cmd UNUSED)
{
vf->tab.min = min;
vf->tab.max = max;
{
vf->tab.min = min;
vf->tab.max = max;
- vf->tab.vector = pool_alloc (int_pool,
-
sizeof (struct freq) * (max - min + 1)
);
+ vf->tab.vector = pool_
n
alloc (int_pool,
+
max - min + 1, sizeof *vf->tab.vector
);
}
else
vf->tab.vector = NULL;
}
else
vf->tab.vector = NULL;
@@
-847,14
+856,14
@@
frq_custom_grouped (struct cmd_frequencies *cmd UNUSED)
|| token == T_ID)
for (;;)
{
|| token == T_ID)
for (;;)
{
-
in
t i;
+
size_
t i;
/* Max, current size of list; list itself. */
int nl, ml;
double *dl;
/* Variable list. */
/* Max, current size of list; list itself. */
int nl, ml;
double *dl;
/* Variable list. */
-
in
t n;
+
size_
t n;
struct variable **v;
if (!parse_variables (default_dict, &v, &n,
struct variable **v;
if (!parse_variables (default_dict, &v, &n,
@@
-864,12
+873,12
@@
frq_custom_grouped (struct cmd_frequencies *cmd UNUSED)
{
nl = ml = 0;
dl = NULL;
{
nl = ml = 0;
dl = NULL;
- while (
token == T_NUM
)
+ while (
lex_integer ()
)
{
if (nl >= ml)
{
ml += 16;
{
if (nl >= ml)
{
ml += 16;
- dl = pool_
realloc (int_pool, dl, ml * sizeof (double)
);
+ dl = pool_
nrealloc (int_pool, dl, ml, sizeof *dl
);
}
dl[nl++] = tokval;
lex_get ();
}
dl[nl++] = tokval;
lex_get ();
@@
-940,9
+949,8
@@
add_percentile (double x)
if (i >= n_percentiles || tokval != percentiles[i].p)
{
if (i >= n_percentiles || tokval != percentiles[i].p)
{
- percentiles
- = pool_realloc (int_pool, percentiles,
- (n_percentiles + 1) * sizeof (struct percentile ));
+ percentiles = pool_nrealloc (int_pool, percentiles,
+ n_percentiles + 1, sizeof *percentiles);
if (i < n_percentiles)
memmove (&percentiles[i + 1], &percentiles[i],
if (i < n_percentiles)
memmove (&percentiles[i + 1], &percentiles[i],
@@
-1537,33
+1545,32
@@
dump_statistics (struct variable *v, int show_varname)
}
}
-
-/* Populate a gsl_histogram from a freq_tab */
-void
-freq_tab_to_hist(const struct freq_tab *ft, gsl_histogram *hist)
+/* Create a gsl_histogram from a freq_tab */
+gsl_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;
{
int i;
double x_min = DBL_MAX;
double x_max = -DBL_MAX;
-
+
+ gsl_histogram *hist;
+ const double bins = 11;
+
struct hsh_iterator hi;
struct hsh_table *fh = ft->data;
struct freq *frq;
struct hsh_iterator hi;
struct hsh_table *fh = ft->data;
struct freq *frq;
- gsl_histogram_reset(hist);
-
/* Find out the extremes of the x value */
/* Find out the extremes of the x value */
-
- for ( frq = hsh_first(fh, &hi);
- frq != 0;
- frq = hsh_next(fh, &hi) )
+ for ( frq = hsh_first(fh, &hi); frq != 0; frq = hsh_next(fh, &hi) )
{
{
+ if ( mv_is_value_missing(&var->miss, &frq->v))
+ continue;
+
if ( frq->v.f < x_min ) x_min = frq->v.f ;
if ( frq->v.f > x_max ) x_max = frq->v.f ;
}
if ( frq->v.f < x_min ) x_min = frq->v.f ;
if ( frq->v.f > x_max ) x_max = frq->v.f ;
}
-
- gsl_histogram_set_ranges_uniform(hist, x_min, x_max);
+ hist = histogram_create(bins, x_min, x_max);
for( i = 0 ; i < ft->n_valid ; ++i )
{
for( i = 0 ; i < ft->n_valid ; ++i )
{
@@
-1571,8
+1578,10
@@
freq_tab_to_hist(const struct freq_tab *ft, gsl_histogram *hist)
gsl_histogram_accumulate(hist, frq->v.f, frq->c);
}
gsl_histogram_accumulate(hist, frq->v.f, frq->c);
}
+ return hist;
}
}
+
static struct slice *
freq_tab_to_slice_array(const struct freq_tab *frq_tab,
const struct variable *var,
static struct slice *
freq_tab_to_slice_array(const struct freq_tab *frq_tab,
const struct variable *var,
@@
-1593,7
+1602,7
@@
freq_tab_to_slice_array(const struct freq_tab *frq_tab,
*n_slices = frq_tab->n_valid;
*n_slices = frq_tab->n_valid;
- slices = x
malloc ( *n_slices * sizeof (struct slice )
);
+ slices = x
nmalloc (*n_slices, sizeof *slices
);
for (i = 0 ; i < *n_slices ; ++i )
{
for (i = 0 ; i < *n_slices ; ++i )
{
@@
-1602,15
+1611,14
@@
freq_tab_to_slice_array(const struct freq_tab *frq_tab,
slices[i].label = value_to_string(&frq->v, var);
slices[i].magnetude = frq->c;
slices[i].label = value_to_string(&frq->v, var);
slices[i].magnetude = frq->c;
-
}
}
-
return slices;
}
return slices;
}
+
static void
do_piechart(const struct variable *var, const struct freq_tab *frq_tab)
{
static void
do_piechart(const struct variable *var, const struct freq_tab *frq_tab)
{
@@
-1622,11
+1630,9
@@
do_piechart(const struct variable *var, const struct freq_tab *frq_tab)
piechart_plot(var_to_string(var), slices, n_slices);
free(slices);
piechart_plot(var_to_string(var), slices, n_slices);
free(slices);
-
}
}
-
/*
Local Variables:
mode: c
/*
Local Variables:
mode: c