Fixed a bug in the levene test, and added the levene test to the oneway cmd
[pspp] / src / sfm-write.c
index 67cdf2317d06ec84db46c127baca574ebebd6ab2..8769e2358146cdddf367a1f63a0a93370fc03477 100644 (file)
@@ -20,7 +20,7 @@
 #include <config.h>
 #include "sfm.h"
 #include "sfmP.h"
-#include <assert.h>
+#include "error.h"
 #include <stdlib.h>
 #include <ctype.h>
 #include <errno.h>
@@ -29,7 +29,6 @@
 #include <unistd.h>    /* Required by SunOS4. */
 #endif
 #include "alloc.h"
-#include "approx.h"
 #include "error.h"
 #include "file-handle.h"
 #include "getline.h"
@@ -93,23 +92,25 @@ sfm_write_dictionary (struct sfm_write_info *inf)
 
   if (inf->h->class != NULL)
     {
-      msg (ME, _("Cannot write file %s as system file: already opened for %s."),
-          fh_handle_name (inf->h), inf->h->class->name);
+      msg (ME, _("Cannot write file %s as system file: "
+                 "already opened for %s."),
+          handle_get_name (inf->h), inf->h->class->name);
       return 0;
     }
 
   msg (VM (1), _("%s: Opening system-file handle %s for writing."),
-       fh_handle_filename (inf->h), fh_handle_name (inf->h));
+       handle_get_filename (inf->h), handle_get_name (inf->h));
   
   /* Open the physical disk file. */
   inf->h->class = &sfm_w_class;
   inf->h->ext = ext = xmalloc (sizeof (struct sfm_fhuser_ext));
-  ext->file = fopen (inf->h->norm_fn, "wb");
+  ext->file = fopen (handle_get_filename (inf->h), "wb");
   ext->elem_type = NULL;
   if (ext->file == NULL)
     {
       msg (ME, _("An error occurred while opening \"%s\" for writing "
-          "as a system file: %s."), inf->h->fn, strerror (errno));
+                 "as a system file: %s."),
+           handle_get_filename (inf->h), strerror (errno));
       err_cond_fail ();
       free (ext);
       return 0;
@@ -364,6 +365,7 @@ write_variable (struct sfm_write_info *inf, struct variable *v)
       break;
     default:
       assert (0);
+      abort ();
     }
 
   sv.n_missing_values = nm;
@@ -379,13 +381,13 @@ write_variable (struct sfm_write_info *inf, struct variable *v)
       struct label
        {
          int32 label_len P;
-         char label[120] P;
+         char label[255] P;
        }
       l;
 
       int ext_len;
 
-      l.label_len = min (strlen (v->label), 120);
+      l.label_len = min (strlen (v->label), 255);
       ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
       memcpy (l.label, v->label, l.label_len);
       memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
@@ -601,7 +603,8 @@ bufwrite (struct file_handle * h, const void *buf, size_t nbytes)
   assert (buf);
   if (1 != fwrite (buf, nbytes, 1, ext->file))
     {
-      msg (ME, _("%s: Writing system file: %s."), h->fn, strerror (errno));
+      msg (ME, _("%s: Writing system file: %s."),
+           handle_get_filename (h), strerror (errno));
       return 0;
     }
   return 1;
@@ -676,13 +679,13 @@ sfm_write_case (struct file_handle * h, const flt64 *elem, int n_elem)
              *ext->x++ = 255;
               continue;
             }
-         else
+         else if (*elem > INT_MIN && *elem < INT_MAX)
            {
-             int value = *elem < 0 ? *elem - EPSILON : *elem + EPSILON;
+             int value = *elem;
 
              if (value >= 1 - COMPRESSION_BIAS
                  && value <= 251 - COMPRESSION_BIAS
-                 && approx_eq (value, *elem))
+                 && value == *elem)
                 {
                  *ext->x++ = value + COMPRESSION_BIAS;
                   continue;
@@ -737,7 +740,8 @@ sfm_close (struct file_handle * h)
     }
 
   if (EOF == fclose (ext->file))
-    msg (ME, _("%s: Closing system file: %s."), h->fn, strerror (errno));
+    msg (ME, _("%s: Closing system file: %s."),
+         handle_get_filename (h), strerror (errno));
   free (ext->buf);
 
   free (ext->elem_type);