return MEASURE_UNKNOWN;
}
-static enum trns_result
-add_measurement_level_trns_proc (void *mlt_, struct ccase **c,
- casenumber case_nr UNUSED)
+static void
+measurement_level_trns_run (struct measurement_level_trns *mlt,
+ const struct ccase *c)
{
- struct measurement_level_trns *mlt = mlt_;
for (size_t i = 0; i < mlt->n_vars; )
{
struct measurement_level_var *mlv = &mlt->vars[i];
- double value = case_num (*c, mlv->var);
+ double value = case_num (c, mlv->var);
enum measure m = add_measurement_level_trns_proc__ (mlv, value);
if (m != MEASURE_UNKNOWN)
{
else
i++;
}
+}
+
+static enum trns_result
+add_measurement_level_trns_proc (void *mlt_, struct ccase **c,
+ casenumber case_nr UNUSED)
+{
+ struct measurement_level_trns *mlt = mlt_;
+ measurement_level_trns_run (mlt, *c);
return TRNS_CONTINUE;
}
free (mlt);
}
-static bool
-add_measurement_level_trns_free (void *mlt_)
+static void
+measurement_level_trns_commit (struct measurement_level_trns *mlt)
{
- struct measurement_level_trns *mlt = mlt_;
for (size_t i = 0; i < mlt->n_vars; i++)
{
struct measurement_level_var *mlv = &mlt->vars[i];
var_set_measure (mlv->var, add_measurement_level_var_interpret (mlv));
}
+}
+
+static bool
+add_measurement_level_trns_free (void *mlt_)
+{
+ struct measurement_level_trns *mlt = mlt_;
+ measurement_level_trns_commit (mlt);
add_measurement_level_trns_free__ (mlt);
return true;
}
.destroy = add_measurement_level_trns_free,
};
-static void
-add_measurement_level_trns (struct dataset *ds, struct dictionary *dict)
+static struct measurement_level_trns *
+create_measurement_level_trns (struct dictionary *dict)
{
struct measurement_level_var *mlvs = NULL;
size_t n_mlvs = 0;
hmap_init (mlv->values);
}
if (!n_mlvs)
- return;
+ return NULL;
struct measurement_level_trns *mlt = xmalloc (sizeof *mlt);
*mlt = (struct measurement_level_trns) {
.vars = mlvs,
.n_vars = n_mlvs,
};
- add_transformation (ds, &add_measurement_level_trns_class, mlt);
+ return mlt;
+}
+
+static void
+add_measurement_level_trns (struct dataset *ds, struct dictionary *dict)
+{
+ struct measurement_level_trns *mlt = create_measurement_level_trns (dict);
+ if (mlt)
+ add_transformation (ds, &add_measurement_level_trns_class, mlt);
}
static void
add_measurement_level_trns_free__ (mlt);
chain->n--;
}
+
+bool
+measure_guesser_is_needed (struct dataset *ds)
+{
+ struct measurement_level_trns *mlt
+ = create_measurement_level_trns (dataset_dict (ds));
+ if (mlt)
+ {
+ add_measurement_level_trns_free__ (mlt);
+ return true;
+ }
+ return false;
+}
+
+void
+measure_guesser_run (struct dataset *ds, const struct casereader *reader)
+{
+ struct measurement_level_trns *mlt
+ = create_measurement_level_trns (dataset_dict (ds));
+ if (!mlt)
+ return;
+
+ struct casereader *r = casereader_clone (reader);
+ while (mlt->n_vars > 0)
+ {
+ struct ccase *c = casereader_read (r);
+ measurement_level_trns_run (mlt, c);
+ case_unref (c);
+ }
+ casereader_destroy (r);
+
+ measurement_level_trns_commit (mlt);
+ add_measurement_level_trns_free__ (mlt);
+}
\f
static void
dataset_changed__ (struct dataset *ds)
}
static bool
-ctables_execute (struct dataset *ds, struct ctables *ct)
+ctables_execute (struct dataset *ds, struct casereader *input,
+ struct ctables *ct)
{
for (size_t i = 0; i < ct->n_tables; i++)
{
}
struct dictionary *dict = dataset_dict (ds);
- struct casereader *input = proc_open (ds);
struct casegrouper *grouper
= (dict_get_split_type (dict) == SPLIT_SEPARATE
? casegrouper_create_splits (input, dict)
ctables_table_clear (t);
}
}
- bool ok = casegrouper_destroy (grouper);
- return proc_commit (ds) && ok;
+ return casegrouper_destroy (grouper);
}
\f
/* Postcomputes. */
int
cmd_ctables (struct lexer *lexer, struct dataset *ds)
{
+ struct casereader *input;
+ if (measure_guesser_is_needed (ds))
+ {
+ input = proc_open (ds);
+ measure_guesser_run (ds, input);
+ }
+ else
+ input = NULL;
+
size_t n_vars = dict_get_n_vars (dataset_dict (ds));
enum ctables_vlabel *vlabels = xnmalloc (n_vars, sizeof *vlabels);
enum settings_value_show tvars = settings_get_show_variables ();
}
while (lex_token (lexer) != T_ENDCMD);
- bool ok = ctables_execute (ds, ct);
+ if (!input)
+ input = proc_open (ds);
+ bool ok = ctables_execute (ds, input, ct);
+ ok = proc_commit (ds) && ok;
+
ctables_destroy (ct);
return ok ? CMD_SUCCESS : CMD_FAILURE;
error:
+ if (input)
+ proc_commit (ds);
ctables_destroy (ct);
return CMD_FAILURE;
}