Added some extraneous crud to .cvsignore files
[pspp] / src / language / stats / rank.q
index 12024239f09ca5666739986d98acf1892a96b0ad..63319d9b7b75ae4b88bd4bca922c44603081eaad 100644 (file)
@@ -1,7 +1,6 @@
 /* PSPP - RANK. -*-c-*-
 
 Copyright (C) 2005, 2006 Free Software Foundation, Inc.
-Author: John Darrington <john@darrington.wattle.id.au>, 
         Ben Pfaff <blp@gnu.org>.
 
 This program is free software; you can redistribute it and/or
@@ -24,6 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 #include "sort-criteria.h"
 
 #include <data/dictionary.h>
+#include <data/format.h>
+#include <data/missing-values.h>
 #include <data/procedure.h>
 #include <data/variable.h>
 #include <data/case.h>
@@ -147,8 +148,8 @@ struct rank_spec
 };
 
 
-/* Function to use for testing for missing values */
-static mv_is_missing_func *value_is_missing;
+/* Categories of missing values to exclude. */
+static enum mv_class exclude_values;
 
 static struct rank_spec *rank_specs;
 static size_t n_rank_specs;
@@ -247,13 +248,13 @@ rank_cmd (struct dataset *ds, const struct sort_criteria *sc,
   for (i = 0; i < n_splits ; i++) 
     {
       struct variable *v = dict_get_split_vars (dataset_dict (ds))[i];
-      criteria.crits[i].fv = v->fv;
+      criteria.crits[i].fv = var_get_case_index (v);
       criteria.crits[i].width = var_get_width (v);
       criteria.crits[i].dir = SRT_ASCEND;
     }
   for (i = 0; i < n_group_vars; i++) 
     {
-      criteria.crits[i + n_splits].fv = group_vars[i]->fv;
+      criteria.crits[i + n_splits].fv = var_get_case_index (group_vars[i]);
       criteria.crits[i + n_splits].width = var_get_width (group_vars[i]);
       criteria.crits[i + n_splits].dir = SRT_ASCEND;
     }
@@ -273,8 +274,8 @@ rank_cmd (struct dataset *ds, const struct sort_criteria *sc,
       /* Sort CF into SORTED_CF. */
       reader = casefile_get_destructive_reader (cf) ;
       criteria.crits[criteria.crit_cnt - 1] = sc->crits[i];
-      assert ( sc->crits[i].fv == src_vars[i]->fv );
-      sorted_cf = sort_execute (reader, &criteria);
+      assert ( sc->crits[i].fv == var_get_case_index (src_vars[i]) );
+      sorted_cf = sort_execute (reader, &criteria, NULL);
       casefile_destroy (cf);
 
       out = rank_sorted_casefile (sorted_cf, &criteria,
@@ -519,7 +520,7 @@ rank_cases (struct casereader *cr,
       if (!casereader_read_xfer (cr, &this_case))
         break;
       
-      this_value = case_data (&this_case, fv);
+      this_value = case_data_idx (&this_case, fv);
       c = dict_get_case_weight (dict, &this_case, &warn);
               
       lookahead = casereader_clone (cr);
@@ -527,7 +528,7 @@ rank_cases (struct casereader *cr,
       while (casereader_cnum (lookahead) < end
              && casereader_read_xfer (lookahead, &lookahead_case))
         {
-          const union value *lookahead_value = case_data (&lookahead_case, fv);
+          const union value *lookahead_value = case_data_idx (&lookahead_case, fv);
           int diff = compare_values (this_value, lookahead_value, width);
 
           if (diff != 0) 
@@ -546,26 +547,26 @@ rank_cases (struct casereader *cr,
       casereader_destroy (lookahead);
 
       cc_1 = cc;
-      if ( !value_is_missing (mv, this_value) )
+      if ( !mv_is_value_missing (mv, this_value, exclude_values) )
        cc += c;
 
       do
         {
           for (i = 0; i < n_rank_specs; ++i) 
             {
-              const int dest_idx = rs[i].destvars[dest_var_index]->fv;
+              const struct variable *dst_var = rs[i].destvars[dest_var_index];
 
-             if  ( value_is_missing (mv, this_value) )
-               case_data_rw (&this_case, dest_idx)->f = SYSMIS;
+             if  ( mv_is_value_missing (mv, this_value, exclude_values) )
+               case_data_rw (&this_case, dst_var)->f = SYSMIS;
              else
-               case_data_rw (&this_case, dest_idx)->f = 
+               case_data_rw (&this_case, dst_var)->f = 
                  rank_func[rs[i].rfunc](c, cc, cc_1, iter, w);
             }
           casefile_append_xfer (dest, &this_case); 
         }
       while (n-- > 0 && casereader_read_xfer (cr, &this_case));
 
-      if ( !value_is_missing (mv, this_value) )
+      if ( !mv_is_value_missing (mv, this_value, exclude_values) )
        iter++;
     }
 
@@ -582,8 +583,8 @@ same_group (const struct ccase *a, const struct ccase *b,
   for (i = 0; i < crit->crit_cnt - 1; i++)
     {
       struct sort_criterion *c = &crit->crits[i];
-      if (compare_values (case_data (a, c->fv), case_data (b, c->fv),
-                          c->width) != 0)
+      if (compare_values (case_data_idx (a, c->fv),
+                          case_data_idx (b, c->fv), c->width) != 0)
         return false;
     }
 
@@ -612,15 +613,15 @@ rank_sorted_casefile (struct casefile *cf,
       struct ccase this_case;
       const union value *this_value ;
       double w = 0.0;
-      this_value = case_data( &group_case, ultimate_crit->fv);
+      this_value = case_data_idx( &group_case, ultimate_crit->fv);
 
-      if ( !value_is_missing(mv, this_value) )
+      if ( !mv_is_value_missing (mv, this_value, exclude_values) )
        w = dict_get_case_weight (dict, &group_case, &warn);
 
       while (casereader_read (lookahead, &this_case)) 
         {
          const union value *this_value = 
-           case_data(&this_case, ultimate_crit->fv);
+           case_data_idx(&this_case, ultimate_crit->fv);
           double c = dict_get_case_weight (dict, &this_case, &warn);
           if (!same_group (&group_case, &this_case, crit)) 
             {
@@ -635,7 +636,7 @@ rank_sorted_casefile (struct casefile *cf,
               case_destroy (&group_case);
               case_move (&group_case, &this_case);
             }
-         if ( !value_is_missing (mv, this_value) )
+         if ( !mv_is_value_missing (mv, this_value, exclude_values) )
            w += c;
           case_destroy (&this_case);
         }
@@ -661,7 +662,7 @@ create_resort_key (void *key_var_, struct ccase *cc, casenumber case_num)
 {
   struct variable *key_var = key_var_;
 
-  case_data_rw(cc, key_var->fv)->f = case_num;
+  case_data_rw(cc, key_var)->f = case_num;
   
   return TRNS_CONTINUE;
 }
@@ -772,11 +773,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
     }
 
   /* If /MISSING=INCLUDE is set, then user missing values are ignored */
-  if (cmd.miss == RANK_INCLUDE ) 
-    value_is_missing = mv_is_value_system_missing;
-  else
-    value_is_missing = mv_is_value_missing;
-
+  exclude_values = cmd.miss == RANK_INCLUDE ? MV_SYSTEM : MV_ANY;
 
   /* Default to /RANK if no function subcommands are given */
   if ( !( cmd.sbc_normal  || cmd.sbc_ntiles || cmd.sbc_proportion || 
@@ -907,7 +904,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
   {
     struct sort_criteria criteria;
     struct sort_criterion restore_criterion ;
-    restore_criterion.fv = order->fv;
+    restore_criterion.fv = var_get_case_index (order);
     restore_criterion.width = 0;
     restore_criterion.dir = SRT_ASCEND;
 
@@ -951,7 +948,7 @@ rank_custom_variables (struct lexer *lexer, struct dataset *ds, struct cmd_rank
 
       if (!parse_variables (lexer, dataset_dict (ds), 
                            &group_vars, &n_group_vars,
-                           PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
+                           PV_NO_DUPLICATE | PV_NO_SCRATCH) )
        {
          free (group_vars);
          return 0;