work on CTABLES
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 27 Dec 2021 00:01:47 +0000 (16:01 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 30 Dec 2021 22:10:12 +0000 (14:10 -0800)
src/language/command.def
src/language/stats/automake.mk
src/language/stats/ctables.c [new file with mode: 0644]

index 352f7c107893067ce6e3ae8ce873d211969b3e27..6db5e74e2e60b54bfe28603f9fc833c03a2166b3 100644 (file)
@@ -114,6 +114,7 @@ DEF_CMD (S_DATA, 0, "AUTORECODE", cmd_autorecode)
 DEF_CMD (S_DATA, 0, "BEGIN DATA", cmd_begin_data)
 DEF_CMD (S_DATA, 0, "COUNT", cmd_count)
 DEF_CMD (S_DATA, 0, "CROSSTABS", cmd_crosstabs)
+DEF_CMD (S_DATA, 0, "CTABLES", cmd_ctables)
 DEF_CMD (S_DATA, 0, "CORRELATIONS", cmd_correlation)
 DEF_CMD (S_DATA, 0, "DELETE VARIABLES", cmd_delete_variables)
 DEF_CMD (S_DATA, 0, "DESCRIPTIVES", cmd_descriptives)
@@ -194,7 +195,6 @@ UNIMPL_CMD ("CSLOGISTIC", "Complex samples logistic regression")
 UNIMPL_CMD ("CSPLAN", "Complex samples design")
 UNIMPL_CMD ("CSSELECT", "Select complex samples")
 UNIMPL_CMD ("CSTABULATE", "Tabulate complex samples")
-UNIMPL_CMD ("CTABLES", "Display complex samples")
 UNIMPL_CMD ("CURVEFIT", "Fit curve to line plot")
 UNIMPL_CMD ("DATE", "Create time series data")
 UNIMPL_CMD ("DETECTANOMALY", "Find unusual cases")
index 460e95e7077d1cf1c773e3b298b2071ed449713f..99d00510817f89e48d5c080e9e1282ac2be1c523 100644 (file)
@@ -31,6 +31,7 @@ language_stats_sources = \
        src/language/stats/cochran.h \
        src/language/stats/correlations.c \
        src/language/stats/crosstabs.c \
+       src/language/stats/ctables.c \
        src/language/stats/descriptives.c \
        src/language/stats/examine.c \
        src/language/stats/factor.c \
diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c
new file mode 100644 (file)
index 0000000..6ac8a7f
--- /dev/null
@@ -0,0 +1,120 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "language/command.h"
+#include "language/lexer/lexer.h"
+#include "libpspp/message.h"
+
+#include "gl/xalloc.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+struct ctables
+  {
+    struct pivot_table_look *look;
+
+    /* If this is NULL, zeros are displayed using the normal print format.
+       Otherwise, this string is displayed. */
+    char *zero;
+
+    /* If this is NULL, missing values are displayed using the normal print
+       format.  Otherwise, this string is displayed. */
+    char *missing;
+
+    /* Contains "struct ctables_vlabel" structs.  */
+    struct hmap vlabels;
+
+    bool mrsets_count_duplicates; /* MRSETS. */
+    bool smissing_listwise;       /* SMISSING. */
+    struct variable *base_weight; /* WEIGHT. */
+    double hide_threshold;        /* HIDESMALLCOUNTS. */
+
+    struct ctables_table *tables;
+    size_t n_tables;
+  };
+
+struct ctables_vlabel
+  {
+    struct hmap_node hmap_node; /* In struct ctables's 'vlabels' hmap. */
+    const char *name;           /* Variable name. */
+
+    /* SETTINGS_VALUE_SHOW_DEFAULT is interpreted as "none". */
+    enum settings_value_show show;
+  };
+
+struct ctables_postcompute
+  {
+    struct hmap_node hmap_node; /* In struct ctables's 'pcompute' hmap. */
+    const char *name;           /* Name, without leading &. */
+
+    struct ctables_postcompute_expr *expr;
+    char *label;
+    /* XXX FORMAT */
+    bool hide_source_cats;
+  };
+
+struct ctables_postcompute_expr
+  {
+    enum ctables_postcompute_op
+      {
+        /* Terminals. */
+        CTPET_CAT_NUMBER,
+        CTPET_CAT_STRING,
+        CTPET_CAT_RANGE,
+        CTPET_CAT_MISSING,
+        /* XXX OTHERNM */
+        /* XXX SUBTOTAL and HSUBTOTAL */
+
+        /* Nonterminals. */
+        CTPET_ADD,
+        CTPET_SUB,
+        CTPET_MUL,
+        CTPET_DIV,
+        CTPET_POW,
+      }
+    op;
+
+    union
+      {
+        /* CTPET_CAT_NUMBER, CTPET_NUMBER. */
+        double number;
+
+        /* CTPET_CAT_RANGE.
+
+           XXX what about string ranges? */
+        struct
+          {
+            double low;         /* -DBL_MAX for LO. */
+            double high;        /* DBL_MAX for HIGH. */
+          }
+        range;
+
+        /* CTPET_ADD, CTPET_SUB, CTPET_MUL, CTPET_DIV, CTPET_POW. */
+        struct ctables_postcompute_expr *subs[2];
+      };
+  };
+
+
+int
+cmd_ctables (struct lexer *lexer, struct dataset *ds)
+{
+  
+
+}
+