Add assertion to check code consitency
[pspp-builds.git] / src / language / stats / roc.c
index 0709992ce469ae113814f6996b549fe0d684b7fc..866eba83f3d7daebf4524f41fad839c6534e6f1a 100644 (file)
 
 #include <config.h>
 
-#include "roc.h"
 #include <data/procedure.h>
 #include <language/lexer/variable-parser.h>
 #include <language/lexer/value-parser.h>
+#include <language/command.h>
 #include <language/lexer/lexer.h>
 
 #include <data/casegrouper.h>
@@ -49,7 +49,7 @@ struct cmd_roc
   const struct variable **vars;
   const struct dictionary *dict;
 
-  struct variable *state_var ;
+  const struct variable *state_var ;
   union value state_value;
 
   /* Plot the roc curve */
@@ -98,18 +98,18 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
 
   if (!parse_variables_const (lexer, dict, &roc.vars, &roc.n_vars,
                              PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC))
-    return 2;
+    goto error;;
 
   if ( ! lex_force_match (lexer, T_BY))
     {
-      return 2;
+      goto error;;
     }
 
   roc.state_var = parse_variable (lexer, dict);
 
   if ( !lex_force_match (lexer, '('))
     {
-      return 2;
+      goto error;;
     }
 
   parse_value (lexer, &roc.state_value, var_get_width (roc.state_var));
@@ -117,7 +117,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
 
   if ( !lex_force_match (lexer, ')'))
     {
-      return 2;
+      goto error;;
     }
 
 
@@ -140,7 +140,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
              else
                {
                   lex_error (lexer, NULL);
-                 return 2;
+                 goto error;;
                }
            }
        }
@@ -164,7 +164,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
          else
            {
              lex_error (lexer, NULL);
-             return 2;
+             goto error;;
            }
        }
       else if (lex_match_id (lexer, "PRINT"))
@@ -183,7 +183,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
              else
                {
                  lex_error (lexer, NULL);
-                 return 2;
+                 goto error;;
                }
            }
        }
@@ -206,7 +206,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
                  else
                    {
                      lex_error (lexer, NULL);
-                     return 2;
+                     goto error;;
                    }
                  lex_force_match (lexer, ')');
                }
@@ -224,7 +224,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
                  else
                    {
                      lex_error (lexer, NULL);
-                     return 2;
+                     goto error;;
                    }
                  lex_force_match (lexer, ')');
                }
@@ -250,14 +250,14 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
                  else
                    {
                      lex_error (lexer, NULL);
-                     return 2;
+                     goto error;;
                    }
                  lex_force_match (lexer, ')');
                }
              else
                {
                  lex_error (lexer, NULL);
-                 return 2;
+                 goto error;;
                }
            }
        }
@@ -268,9 +268,14 @@ cmd_roc (struct lexer *lexer, struct dataset *ds)
        }
     }
 
-  run_roc (ds, &roc);
+  if ( ! run_roc (ds, &roc)) 
+    goto error;;
 
-  return 1;
+  return CMD_SUCCESS;
+
+ error:
+  free (roc.vars);
+  return CMD_FAILURE;
 }
 
 
@@ -388,12 +393,13 @@ accumulate_counts (struct casereader *cutpoint_rdr,
   struct ccase *cpc;
   double prev_cp = SYSMIS;
 
-
   for ( ; (cpc = casereader_read (r) ); case_unref (cpc))
     {
       struct ccase *new_case;
       const double cp = case_data_idx (cpc, CUTPOINT)->f;
 
+      assert (cp != SYSMIS);
+
       /* We don't want duplicates here */
       if ( cp == prev_cp )
        continue;
@@ -640,14 +646,21 @@ do_roc (struct cmd_roc *roc, struct casereader *reader, struct dictionary *dict)
   struct subcase up_ordering;
   struct subcase down_ordering;
 
+  struct casewriter *neg_wtr = NULL;
+
   struct casereader *input = casereader_create_filter_missing (reader,
                                                               roc->vars, roc->n_vars,
                                                               roc->exclude,
                                                               NULL,
                                                               NULL);
 
+  input = casereader_create_filter_missing (input,
+                                           &roc->state_var, 1,
+                                           roc->exclude,
+                                           NULL,
+                                           NULL);
 
-  struct casewriter *neg_wtr = autopaging_writer_create (casereader_get_proto (input));
+  neg_wtr = autopaging_writer_create (casereader_get_proto (input));
 
   prepare_cutpoints (roc, rs, input);