Added files in src/math
[pspp] / src / descript.c
index 05e0767d40694fe71c2e6302f1089de690fbbed8..a7152301abfdfcfcefb93af2dfea68b6d1b3205f 100644 (file)
@@ -68,7 +68,6 @@ struct dsc_z_score
 /* DESCRIPTIVES transformation (for calculating Z-scores). */
 struct dsc_trns
   {
-    struct trns_header h;
     struct dsc_z_score *z_scores; /* Array of Z-scores. */
     int z_score_cnt;            /* Number of Z-scores. */
     struct variable **vars;     /* Variables for listwise missing checks. */
@@ -170,7 +169,7 @@ static void free_dsc_proc (struct dsc_proc *);
 /* Z-score functions. */
 static int try_name (struct dsc_proc *dsc, char *name);
 static int generate_z_varname (struct dsc_proc *dsc, char *z_name,
-                               const char *name, int *z_cnt);
+                               const char *name, size_t *z_cnt);
 static void dump_z_table (struct dsc_proc *);
 static void setup_z_trns (struct dsc_proc *);
 
@@ -186,10 +185,10 @@ cmd_descriptives (void)
 {
   struct dsc_proc *dsc;
   struct variable **vars = NULL;
-  int var_cnt = 0;
+  size_t var_cnt = 0;
   int save_z_scores = 0;
-  int z_cnt = 0;
-  int i;
+  size_t z_cnt = 0;
+  size_t i;
 
   /* Create and initialize dsc. */
   dsc = xmalloc (sizeof *dsc);
@@ -311,7 +310,7 @@ cmd_descriptives (void)
                                     PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC))
                goto error;
 
-              dsc->vars = xrealloc (dsc->vars, sizeof *dsc->vars * var_cnt);
+              dsc->vars = xnrealloc (dsc->vars, var_cnt, sizeof *dsc->vars);
               for (i = dsc->var_cnt; i < var_cnt; i++)
                 {
                   struct dsc_var *dv = &dsc->vars[i];
@@ -361,7 +360,7 @@ cmd_descriptives (void)
     {
       if (save_z_scores) 
         {
-          int gen_cnt = 0;
+          size_t gen_cnt = 0;
 
           for (i = 0; i < dsc->var_cnt; i++)
             if (dsc->vars[i].z_name[0] == 0) 
@@ -464,7 +463,7 @@ free_dsc_proc (struct dsc_proc *dsc)
 static int
 try_name (struct dsc_proc *dsc, char *name)
 {
-  int i;
+  size_t i;
 
   if (dict_lookup_var (default_dict, name) != NULL)
     return 0;
@@ -480,7 +479,7 @@ try_name (struct dsc_proc *dsc, char *name)
    copies the new name into Z_NAME.  On failure, returns zero. */
 static int
 generate_z_varname (struct dsc_proc *dsc, char *z_name,
-                    const char *var_name, int *z_cnt)
+                    const char *var_name, size_t *z_cnt)
 {
   char name[LONG_NAME_LEN + 1];
 
@@ -527,11 +526,11 @@ generate_z_varname (struct dsc_proc *dsc, char *z_name,
 static void
 dump_z_table (struct dsc_proc *dsc)
 {
-  int cnt = 0;
+  size_t cnt = 0;
   struct tab_table *t;
   
   {
-    int i;
+    size_t i;
     
     for (i = 0; i < dsc->var_cnt; i++)
       if (dsc->vars[i].z_name[0] != '\0')
@@ -549,7 +548,7 @@ dump_z_table (struct dsc_proc *dsc)
   tab_dim (t, tab_natural_dimensions);
 
   {
-    int i, y;
+    size_t i, y;
     
     for (i = 0, y = 1; i < dsc->var_cnt; i++)
       if (dsc->vars[i].z_name[0] != '\0')
@@ -569,10 +568,10 @@ dump_z_table (struct dsc_proc *dsc)
    (either system or user-missing values that weren't included).
 */
 static int
-descriptives_trns_proc (struct trns_header *trns, struct ccase * c,
+descriptives_trns_proc (void *trns_, struct ccase * c,
                         int case_idx UNUSED)
 {
-  struct dsc_trns *t = (struct dsc_trns *) trns;
+  struct dsc_trns *t = trns_;
   struct dsc_z_score *z;
   struct variable **vars;
   int all_sysmis = 0;
@@ -611,9 +610,9 @@ descriptives_trns_proc (struct trns_header *trns, struct ccase * c,
 
 /* Frees a descriptives_trns struct. */
 static void
-descriptives_trns_free (struct trns_header * trns)
+descriptives_trns_free (void *trns_)
 {
-  struct dsc_trns *t = (struct dsc_trns *) trns;
+  struct dsc_trns *t = trns_;
 
   free (t->z_scores);
   assert((t->missing_type != DSC_LISTWISE) ^ (t->vars != NULL));
@@ -625,23 +624,21 @@ static void
 setup_z_trns (struct dsc_proc *dsc)
 {
   struct dsc_trns *t;
-  int cnt, i;
+  size_t cnt, i;
 
   for (cnt = i = 0; i < dsc->var_cnt; i++)
     if (dsc->vars[i].z_name[0] != '\0')
       cnt++;
 
   t = xmalloc (sizeof *t);
-  t->h.proc = descriptives_trns_proc;
-  t->h.free = descriptives_trns_free;
-  t->z_scores = xmalloc (cnt * sizeof *t->z_scores);
+  t->z_scores = xnmalloc (cnt, sizeof *t->z_scores);
   t->z_score_cnt = cnt;
   t->missing_type = dsc->missing_type;
   t->include_user_missing = dsc->include_user_missing;
   if ( t->missing_type == DSC_LISTWISE )
     {
       t->var_cnt = dsc->var_cnt;
-      t->vars = xmalloc(t->var_cnt * sizeof *t->vars);
+      t->vars = xnmalloc (t->var_cnt, sizeof *t->vars);
       for (i = 0; i < t->var_cnt; i++)
        t->vars[i] = dsc->vars[i].v;
     }
@@ -650,7 +647,6 @@ setup_z_trns (struct dsc_proc *dsc)
       t->var_cnt = 0;
       t->vars = NULL;
     }
-  
 
   for (cnt = i = 0; i < dsc->var_cnt; i++)
     {
@@ -685,7 +681,7 @@ setup_z_trns (struct dsc_proc *dsc)
        }
     }
 
-  add_transformation ((struct trns_header *) t);
+  add_transformation (descriptives_trns_proc, descriptives_trns_free, t);
 }
 \f
 /* Statistical calculation. */
@@ -700,7 +696,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_)
   struct dsc_proc *dsc = dsc_;
   struct casereader *reader;
   struct ccase c;
-  int i;
+  size_t i;
 
   for (i = 0; i < dsc->var_cnt; i++)
     {
@@ -838,7 +834,7 @@ calc_descriptives (const struct casefile *cf, void *dsc_)
 static int
 listwise_missing (struct dsc_proc *dsc, const struct ccase *c) 
 {
-  int i;
+  size_t i;
 
   for (i = 0; i < dsc->var_cnt; i++)
     {
@@ -861,7 +857,7 @@ static algo_compare_func descriptives_compare_dsc_vars;
 static void
 display (struct dsc_proc *dsc)
 {
-  int i, j;
+  size_t i;
   int nc;
   struct tab_table *t;
 
@@ -902,6 +898,7 @@ display (struct dsc_proc *dsc)
   for (i = 0; i < dsc->var_cnt; i++)
     {
       struct dsc_var *dv = &dsc->vars[i];
+      size_t j;
 
       nc = 0;
       tab_text (t, nc++, i + 1, TAB_LEFT, dv->v->name);