1 /* PSPP - computes sample statistics.
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include <libpspp/alloc.h>
21 #include <libpspp/compiler.h>
22 #include "casefilter.h"
26 #include <data/case.h>
27 #include <data/variable.h>
28 #include <data/missing-values.h>
34 const struct variable **vars;
39 /* Returns true iff the entire case should be skipped */
41 casefilter_skip_case (const struct casefilter *filter, const struct ccase *c)
45 for (i = 0; i < filter->n_vars; ++i)
47 if ( casefilter_variable_missing (filter, c, filter->vars[i]))
54 /* Returns true iff the variable V in case C is missing */
56 casefilter_variable_missing (const struct casefilter *filter,
57 const struct ccase *c,
58 const struct variable *var)
60 const union value *val = case_data (c, var) ;
61 return var_is_value_missing (var, val, filter->class);
64 /* Create a new casefilter that drops cases in which any of the
65 N_VARS variables in VARS are in the given CLASS of missing values.
66 VARS is an array of variables which if *any* of them are missing.
67 N_VARS is the size of VARS.
70 casefilter_create (enum mv_class class, struct variable **vars, int n_vars)
73 struct casefilter * filter = xmalloc (sizeof (*filter)) ;
75 filter->class = class;
76 filter->vars = xnmalloc (n_vars, sizeof (*filter->vars) );
78 for ( i = 0 ; i < n_vars ; ++i )
79 filter->vars[i] = vars[i];
81 filter->n_vars = n_vars ;
87 /* Add the variables in VARS to the list of variables for which the
88 filter considers. N_VARS is the size of VARS */
90 casefilter_add_variables (struct casefilter *filter,
91 struct variable *const *vars, int n_vars)
95 filter->vars = xnrealloc (filter->vars, filter->n_vars + n_vars,
96 sizeof (*filter->vars) );
98 for ( i = 0 ; i < n_vars ; ++i )
99 filter->vars[i + filter->n_vars] = vars[i];
101 filter->n_vars += n_vars ;
104 /* Destroy the filter FILTER */
106 casefilter_destroy (struct casefilter *filter)