/* 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
#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>
};
-/* 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;
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;
}
/* 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,
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);
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)
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++;
}
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;
}
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))
{
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);
}
{
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;
}
}
/* 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 ||
{
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;
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;