- weight = dict_get_case_weight (agr->src_dict, input, &bad_warn);
-
- for (iter = agr->agr_vars; iter; iter = iter->next)
- if (iter->src)
- {
- const union value *v = case_data (input, iter->src);
- int src_width = var_get_width (iter->src);
-
- if (var_is_value_missing (iter->src, v, iter->exclude))
- {
- switch (iter->function)
- {
- case NMISS:
- case NMISS | FSTRING:
- iter->dbl[0] += weight;
- break;
- case NUMISS:
- case NUMISS | FSTRING:
- iter->int1++;
- break;
- }
- iter->saw_missing = true;
- continue;
- }
-
- /* This is horrible. There are too many possibilities. */
- switch (iter->function)
- {
- case SUM:
- iter->dbl[0] += v->f * weight;
- iter->int1 = 1;
- break;
- case MEAN:
- iter->dbl[0] += v->f * weight;
- iter->dbl[1] += weight;
- break;
- case MEDIAN:
- {
- double wv ;
- struct ccase *cout;
-
- cout = case_create (casewriter_get_proto (iter->writer));
-
- case_data_rw (cout, iter->subject)->f
- = case_data (input, iter->src)->f;
-
- wv = dict_get_case_weight (agr->src_dict, input, NULL);
-
- case_data_rw (cout, iter->weight)->f = wv;
-
- iter->cc += wv;
-
- casewriter_write (iter->writer, cout);
- }
- 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;
- break;
- case MAX | FSTRING:
- if (memcmp (iter->string, value_str (v, src_width), src_width) < 0)
- memcpy (iter->string, value_str (v, src_width), src_width);
- iter->int1 = 1;
- break;
- case MIN:
- iter->dbl[0] = MIN (iter->dbl[0], v->f);
- iter->int1 = 1;
- break;
- case MIN | FSTRING:
- if (memcmp (iter->string, value_str (v, src_width), src_width) > 0)
- memcpy (iter->string, value_str (v, src_width), src_width);
- iter->int1 = 1;
- break;
- case FGT:
- case PGT:
- if (v->f > iter->arg[0].f)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FGT | FSTRING:
- case PGT | FSTRING:
- if (memcmp (iter->arg[0].c,
- value_str (v, src_width), src_width) < 0)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FLT:
- case PLT:
- if (v->f < iter->arg[0].f)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FLT | FSTRING:
- case PLT | FSTRING:
- if (memcmp (iter->arg[0].c,
- value_str (v, src_width), src_width) > 0)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FIN:
- case PIN:
- if (iter->arg[0].f <= v->f && v->f <= iter->arg[1].f)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FIN | FSTRING:
- case PIN | FSTRING:
- if (memcmp (iter->arg[0].c,
- value_str (v, src_width), src_width) <= 0
- && memcmp (iter->arg[1].c,
- value_str (v, src_width), src_width) >= 0)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FOUT:
- case POUT:
- if (iter->arg[0].f > v->f || v->f > iter->arg[1].f)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case FOUT | FSTRING:
- case POUT | FSTRING:
- if (memcmp (iter->arg[0].c,
- value_str (v, src_width), src_width) > 0
- || memcmp (iter->arg[1].c,
- value_str (v, src_width), src_width) < 0)
- iter->dbl[0] += weight;
- iter->dbl[1] += weight;
- break;
- case N:
- case N | FSTRING:
- iter->dbl[0] += weight;
- break;
- case NU:
- case NU | FSTRING:
- iter->int1++;
- break;
- case FIRST:
- if (iter->int1 == 0)
- {
- iter->dbl[0] = v->f;
- iter->int1 = 1;
- }
- break;
- case FIRST | FSTRING:
- if (iter->int1 == 0)
- {
- memcpy (iter->string, value_str (v, src_width), src_width);
- iter->int1 = 1;
- }
- break;
- case LAST:
- iter->dbl[0] = v->f;
- iter->int1 = 1;
- break;
- case LAST | FSTRING:
- memcpy (iter->string, value_str (v, src_width), src_width);
- iter->int1 = 1;
- break;
- case NMISS:
- case NMISS | FSTRING:
- case NUMISS:
- case NUMISS | FSTRING:
- /* Our value is not missing or it would have been
- caught earlier. Nothing to do. */
- break;
- default:
- NOT_REACHED ();
- }
- } else {
- switch (iter->function)
- {
- case N_NO_VARS:
- iter->dbl[0] += weight;
- break;
- case NU_NO_VARS:
- iter->int1++;
- break;
- default:
- NOT_REACHED ();
- }
+ /* This is horrible. There are too many possibilities. */
+ av->W += weight;
+ switch (av->function)
+ {
+ case AGRF_SUM:
+ av->dbl += v->f * weight;
+ av->int1 = 1;
+ break;
+
+ case AGRF_MEAN:
+ av->dbl += v->f * weight;
+ break;
+
+ case AGRF_MEDIAN:
+ {
+ struct ccase *cout = case_create (casewriter_get_proto (av->writer));
+ *case_num_rw (cout, av->subject) = case_num (input, av->src);
+ *case_num_rw (cout, av->weight) = weight;
+ casewriter_write (av->writer, cout);
+ }
+ break;
+
+ case AGRF_SD:
+ moments1_add (av->moments, v->f, weight);
+ break;
+
+ case AGRF_MAX:
+ if (!is_string)
+ av->dbl = MAX (av->dbl, v->f);
+ else if (memcmp (av->string, v->s, src_width) < 0)
+ memcpy (av->string, v->s, src_width);
+ av->int1 = 1;
+ break;
+
+ case AGRF_MIN:
+ if (!is_string)
+ av->dbl = MIN (av->dbl, v->f);
+ else if (memcmp (av->string, v->s, src_width) > 0)
+ memcpy (av->string, v->s, src_width);
+ av->dbl = MIN (av->dbl, v->f);
+ av->int1 = 1;
+ break;
+
+ case AGRF_FGT:
+ case AGRF_PGT:
+ case AGRF_CGT:
+ if (is_string
+ ? ss_compare_rpad (av->arg[0].s, vs) < 0
+ : v->f > av->arg[0].f)
+ av->dbl += weight;
+ break;
+
+ case AGRF_FLT:
+ case AGRF_PLT:
+ case AGRF_CLT:
+ if (is_string
+ ? ss_compare_rpad (av->arg[0].s, vs) > 0
+ : v->f < av->arg[0].f)
+ av->dbl += weight;
+ break;
+
+ case AGRF_FIN:
+ case AGRF_PIN:
+ case AGRF_CIN:
+ if (is_string
+ ? (ss_compare_rpad (av->arg[0].s, vs) <= 0
+ && ss_compare_rpad (av->arg[1].s, vs) >= 0)
+ : av->arg[0].f <= v->f && v->f <= av->arg[1].f)
+ av->dbl += weight;
+ break;
+
+ case AGRF_FOUT:
+ case AGRF_POUT:
+ case AGRF_COUT:
+ if (is_string
+ ? (ss_compare_rpad (av->arg[0].s, vs) > 0
+ || ss_compare_rpad (av->arg[1].s, vs) < 0)
+ : av->arg[0].f > v->f || v->f > av->arg[1].f)
+ av->dbl += weight;
+ break;
+
+ case AGRF_N:
+ av->dbl += weight;
+ break;
+
+ case AGRF_NU:
+ av->int1++;
+ break;
+
+ case AGRF_FIRST:
+ if (av->int1 == 0)
+ {
+ if (is_string)
+ memcpy (av->string, v->s, src_width);
+ else
+ av->dbl = v->f;
+ av->int1 = 1;
+ }
+ break;
+
+ case AGRF_LAST:
+ if (is_string)
+ memcpy (av->string, v->s, src_width);
+ else
+ av->dbl = v->f;
+ av->int1 = 1;
+ break;
+
+ case AGRF_NMISS:
+ case AGRF_NUMISS:
+ /* Our value is not missing or it would have been
+ caught earlier. Nothing to do. */
+ break;
+ }
+ }
+ else
+ {
+ av->W += weight;
+ switch (av->function)
+ {
+ case AGRF_N:
+ break;
+
+ case AGRF_NU:
+ av->int1++;
+ break;
+
+ case AGRF_SUM:
+ case AGRF_MEAN:
+ case AGRF_MEDIAN:
+ case AGRF_SD:
+ case AGRF_MAX:
+ case AGRF_MIN:
+ case AGRF_PGT:
+ case AGRF_PLT:
+ case AGRF_PIN:
+ case AGRF_POUT:
+ case AGRF_FGT:
+ case AGRF_FLT:
+ case AGRF_FIN:
+ case AGRF_FOUT:
+ case AGRF_CGT:
+ case AGRF_CLT:
+ case AGRF_CIN:
+ case AGRF_COUT:
+ case AGRF_NMISS:
+ case AGRF_NUMISS:
+ case AGRF_FIRST:
+ case AGRF_LAST:
+ NOT_REACHED ();
+ }
+ }