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>
32 bool exclude_user_missing;
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) ;
62 if ( var_is_numeric (var) && val->f == SYSMIS )
65 if ( filter->exclude_user_missing &&
66 var_is_value_user_missing (var, val) )
72 /* Create a new casefilter.
73 If EXCL is true, then the filter user missing values to be missing,
74 otherwise they are considered at their face value.
75 VARS is an array of variables which if *any* of them are missing.
76 N_VARS is the size of VARS.
79 casefilter_create (bool excl, struct variable **vars, int n_vars)
82 struct casefilter * filter = xmalloc (sizeof (*filter)) ;
84 filter->exclude_user_missing = excl ;
85 filter->vars = xnmalloc (n_vars, sizeof (*filter->vars) );
87 for ( i = 0 ; i < n_vars ; ++i )
88 filter->vars[i] = vars[i];
90 filter->n_vars = n_vars ;
96 /* Add the variables in VARS to the list of variables for which the
97 filter considers. N_VARS is the size of VARS */
99 casefilter_add_variables (struct casefilter *filter,
100 struct variable *const *vars, int n_vars)
104 filter->vars = xnrealloc (filter->vars, filter->n_vars + n_vars,
105 sizeof (*filter->vars) );
107 for ( i = 0 ; i < n_vars ; ++i )
108 filter->vars[i + filter->n_vars] = vars[i];
110 filter->n_vars += n_vars ;
113 /* Destroy the filter FILTER */
115 casefilter_destroy (struct casefilter *filter)