#include "file-handle.h"
#include "lexer.h"
#include "misc.h"
+#include "moments.h"
#include "pool.h"
#include "settings.h"
#include "sfm.h"
#include "sort.h"
-#include "stats.h"
#include "str.h"
#include "var.h"
#include "vfm.h"
int int1, int2;
char *string;
int missing;
+ struct moments1 *moments;
};
/* Aggregation functions. */
if (token == T_STRING)
{
- ds_truncate (&tokstr, 120);
- dest_label[n_dest - 1] = xstrdup (ds_value (&tokstr));
+ ds_truncate (&tokstr, 255);
+ dest_label[n_dest - 1] = xstrdup (ds_c_str (&tokstr));
lex_get ();
}
}
lex_match (',');
if (token == T_STRING)
{
- arg[i].c = xstrdup (ds_value (&tokstr));
+ arg[i].c = xstrdup (ds_c_str (&tokstr));
type = ALPHA;
}
else if (token == T_NUM)
agr->vars = v;
tail = v;
tail->next = NULL;
+ v->moments = NULL;
/* Create the target variable in the aggregate
dictionary. */
free (iter->arg[i].c);
free (iter->string);
}
+ else if (iter->function == SD)
+ moments1_destroy (iter->moments);
free (iter);
}
free (agr->prev_break);
{
struct agr_var *iter;
double weight;
+ int bad_warn = 1;
- weight = dict_get_case_weight (default_dict, input);
+ weight = dict_get_case_weight (default_dict, input, &bad_warn);
for (iter = agr->vars; iter; iter = iter->next)
if (iter->src)
iter->dbl[0] += v->f * weight;
iter->dbl[1] += weight;
break;
- case SD:
- {
- double product = v->f * weight;
- iter->dbl[0] += product;
- iter->dbl[1] += product * v->f;
- iter->dbl[2] += weight;
- break;
- }
+ case SD:
+ moments1_add (iter->moments, v->f, weight);
+ break;
case MAX:
iter->dbl[0] = max (iter->dbl[0], v->f);
iter->int1 = 1;
v->f = i->dbl[1] != 0.0 ? i->dbl[0] / i->dbl[1] : SYSMIS;
break;
case SD:
- v->f = ((i->dbl[2] > 1.0)
- ? calc_stddev (calc_variance (i->dbl, i->dbl[2]))
- : SYSMIS);
+ {
+ double variance;
+
+ /* FIXME: we should use two passes. */
+ moments1_calculate (i->moments, NULL, NULL, &variance,
+ NULL, NULL);
+ if (variance != SYSMIS)
+ v->f = sqrt (variance);
+ else
+ v->f = SYSMIS;
+ }
break;
case MAX:
case MIN:
case MAX | FSTRING:
memset (iter->string, 0, iter->src->width);
break;
+ case SD:
+ if (iter->moments == NULL)
+ iter->moments = moments1_create (MOMENT_VARIANCE);
+ else
+ moments1_clear (iter->moments);
+ break;
default:
iter->dbl[0] = iter->dbl[1] = iter->dbl[2] = 0.0;
iter->int1 = iter->int2 = 0;