FREQUENCIES: Remove unused pool.
[pspp] / src / language / stats / frequencies.c
index 8bd6c600205d3fe75dc6a99dd230c2ab9591146b..d741edbdea4b011954d773989bc54b3396d3befe 100644 (file)
 #include "libpspp/hmap.h"
 #include "libpspp/message.h"
 #include "libpspp/misc.h"
-#include "libpspp/pool.h"
 
 #include "math/histogram.h"
 #include "math/moments.h"
 #include "math/chart-geometry.h"
 
 
-#include "output/chart-item.h"
 #include "output/charts/barchart.h"
 #include "output/charts/piechart.h"
 #include "output/charts/plot-hist.h"
@@ -191,10 +189,6 @@ struct var_freqs
     /* Freqency table. */
     struct freq_tab tab;       /* Frequencies table to use. */
 
-    /* Percentiles. */
-    int n_groups;              /* Number of groups. */
-    double *groups;            /* Groups. */
-
     /* Statistics. */
     double stat[FRQ_ST_count];
 
@@ -225,6 +219,8 @@ struct frq_proc
 
     /* Histogram and pie chart settings. */
     struct frq_chart *hist, *pie, *bar;
+
+    bool warn;
   };
 
 
@@ -294,7 +290,7 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv)
   const struct freq_tab *ft = &vf->tab;
 
   struct pivot_table *table = pivot_table_create__ (pivot_value_new_variable (
-                                                      vf->var));
+                                                      vf->var), "Frequencies");
   pivot_table_set_weight_var (table, wv);
 
   pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
@@ -407,7 +403,7 @@ not_missing (const void *f_, const void *v_)
   const struct freq *f = f_;
   const struct variable *v = v_;
 
-  return !var_is_value_missing (v, f->values, MV_ANY);
+  return !var_is_value_missing (v, f->values);
 }
 
 
@@ -441,7 +437,7 @@ postprocess_freq_tab (const struct frq_proc *frq, struct var_freqs *vf)
 
   /* Summary statistics. */
   ft->valid_cases = 0.0;
-  for(i = 0 ;  i < ft->n_valid ; ++i )
+  for(i = 0 ;  i < ft->n_valid ; ++i)
     {
       f = &ft->valid[i];
       ft->valid_cases += f->count;
@@ -449,7 +445,7 @@ postprocess_freq_tab (const struct frq_proc *frq, struct var_freqs *vf)
     }
 
   ft->total_cases = ft->valid_cases ;
-  for(i = 0 ;  i < ft->n_missing ; ++i )
+  for(i = 0 ;  i < ft->n_missing ; ++i)
     {
       f = &ft->missing[i];
       ft->total_cases += f->count;
@@ -469,7 +465,7 @@ cleanup_freq_tab (struct var_freqs *vf)
 static void
 calc (struct frq_proc *frq, const struct ccase *c, const struct dataset *ds)
 {
-  double weight = dict_get_case_weight (dataset_dict (ds), c, NULL);
+  double weight = dict_get_case_weight (dataset_dict (ds), c, &frq->warn);
   size_t i;
 
   for (i = 0; i < frq->n_vars; i++)
@@ -543,14 +539,14 @@ postcalc (struct frq_proc *frq, const struct dataset *ds)
 
          histogram = freq_tab_to_hist (frq, &vf->tab, vf->var);
 
-         if ( histogram)
+         if (histogram)
            {
-             chart_item_submit (histogram_chart_create (
-                               histogram->gsl_hist, var_to_string(vf->var),
-                               vf->tab.valid_cases,
-                               d[FRQ_ST_MEAN],
-                               d[FRQ_ST_STDDEV],
-                               frq->hist->draw_normal));
+             chart_submit (histogram_chart_create (
+                              histogram->gsl_hist, var_to_string(vf->var),
+                              vf->tab.valid_cases,
+                              d[FRQ_ST_MEAN],
+                              d[FRQ_ST_STDDEV],
+                              frq->hist->draw_normal));
 
              statistic_destroy (&histogram->parent);
            }
@@ -592,7 +588,6 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
   int hi_pcnt = INT_MIN;
   int hi_norm = FRQ_NONORMAL;
 
-  frq.pool = pool_create ();
   frq.sort = FRQ_AVALUE;
 
   frq.vars = NULL;
@@ -613,13 +608,14 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
   frq.hist = NULL;
   frq.pie = NULL;
   frq.bar = NULL;
+  frq.warn = true;
 
 
   /* Accept an optional, completely pointless "/VARIABLES=" */
   lex_match (lexer, T_SLASH);
   if (lex_match_id  (lexer, "VARIABLES"))
     {
-      if (! lex_force_match (lexer, T_EQUALS) )
+      if (! lex_force_match (lexer, T_EQUALS))
         goto error;
     }
 
@@ -629,7 +625,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                              PV_NO_DUPLICATE))
     goto error;
 
-  frq.vars = xzalloc (frq.n_vars * sizeof (*frq.vars));
+  frq.vars = xcalloc (frq.n_vars, sizeof (*frq.vars));
   for (i = 0; i < frq.n_vars; ++i)
     {
       frq.vars[i].var = vars[i];
@@ -795,7 +791,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
               else if (lex_match_id (lexer, "LIMIT"))
                 {
                   if (!lex_force_match (lexer, T_LPAREN)
-                      || !lex_force_int (lexer))
+                      || !lex_force_int_range (lexer, "LIMIT", 0, INT_MAX))
                     goto error;
 
                   frq.max_categories = lex_integer (lexer);
@@ -831,12 +827,11 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
         {
          lex_match (lexer, T_EQUALS);
 
-         if (lex_force_int (lexer))
+         if (lex_force_int_range (lexer, "NTILES", 0, INT_MAX))
            {
-             int i;
              int n = lex_integer (lexer);
              lex_get (lexer);
-             for (i = 0; i < n + 1; ++i)
+             for (int i = 0; i < n + 1; ++i)
                {
                  frq.percentiles =
                    xrealloc (frq.percentiles,
@@ -894,13 +889,9 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                   hi_scale = FRQ_FREQ;
                   if (lex_match (lexer, T_LPAREN))
                     {
-                      if (lex_force_int (lexer))
+                      if (lex_force_int_range (lexer, "FREQ", 1, INT_MAX))
                         {
                          hi_freq = lex_integer (lexer);
-                         if (hi_freq <= 0)
-                           {
-                             lex_error (lexer, _("Histogram frequency must be greater than zero."));
-                           }
                          lex_get (lexer);
                          if (! lex_force_match (lexer, T_RPAREN))
                            goto error;
@@ -912,13 +903,9 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                   hi_scale = FRQ_PERCENT;
                   if (lex_match (lexer, T_LPAREN))
                     {
-                      if (lex_force_int (lexer))
+                      if (lex_force_int_range (lexer, "PERCENT", 1, INT_MAX))
                        {
                          hi_pcnt = lex_integer (lexer);
-                         if (hi_pcnt <= 0)
-                           {
-                             lex_error (lexer, _("Histogram percentage must be greater than zero."));
-                           }
                          lex_get (lexer);
                          if (! lex_force_match (lexer, T_RPAREN))
                            goto error;
@@ -1034,7 +1021,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                }
              else if (lex_match_id (lexer, "FREQ"))
                {
-                 if ( lex_match (lexer, T_LPAREN))
+                 if (lex_match (lexer, T_LPAREN))
                    {
                      if (lex_force_num (lexer))
                        {
@@ -1048,7 +1035,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
                }
              else if (lex_match_id (lexer, "PERCENT"))
                {
-                 if ( lex_match (lexer, T_LPAREN))
+                 if (lex_match (lexer, T_LPAREN))
                    {
                      if (lex_force_num (lexer))
                        {
@@ -1251,7 +1238,6 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
   free (frq.pie);
   free (frq.hist);
   free (frq.percentiles);
-  pool_destroy (frq.pool);
 
   return CMD_SUCCESS;
 
@@ -1263,7 +1249,6 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds)
   free (frq.pie);
   free (frq.hist);
   free (frq.percentiles);
-  pool_destroy (frq.pool);
 
   return CMD_FAILURE;
 }
@@ -1295,7 +1280,7 @@ chart_includes_value (const struct frq_chart *chart,
                       const struct variable *var,
                       const union value *value)
 {
-  if (!chart->include_missing && var_is_value_missing (var, value, MV_ANY))
+  if (!chart->include_missing && var_is_value_missing (var, value))
     return false;
 
   if (var_is_numeric (var)
@@ -1348,7 +1333,7 @@ freq_tab_to_hist (const struct frq_proc *frq, const struct freq_tab *ft,
 
   histogram = histogram_create (bin_width, x_min, x_max);
 
-  if ( histogram == NULL)
+  if (histogram == NULL)
     return NULL;
 
   for (i = 0; i < ft->n_valid; i++)
@@ -1474,7 +1459,7 @@ do_piechart(const struct frq_chart *pie, const struct variable *var,
     msg (SW, _("Omitting pie chart for %s, which has over 50 unique values."),
          var_get_name (var));
   else
-    chart_item_submit (piechart_create (var, slices, n_slices));
+    chart_submit (piechart_create (var, slices, n_slices));
 
   free (slices);
 }
@@ -1487,10 +1472,13 @@ do_barchart(const struct frq_chart *bar, const struct variable **var,
   int n_slices;
   struct freq **slices = pick_cat_counts_ptr (bar, frq_tab, &n_slices);
 
-  chart_item_submit (barchart_create (var, 1,
-                                     (bar->y_scale == FRQ_FREQ) ? _("Count") : _("Percent"),
-                                     (bar->y_scale == FRQ_PERCENT),
-                                     slices, n_slices));
+  if (n_slices < 1)
+    msg (SW, _("Omitting bar chart, which has no values."));
+  else
+    chart_submit (barchart_create (var, 1,
+                                   (bar->y_scale == FRQ_FREQ) ? _("Count") : _("Percent"),
+                                   (bar->y_scale == FRQ_PERCENT),
+                                   slices, n_slices));
   free (slices);
 }