Index: trunk/Nebulous/nebclient/src/nebulous.h
===================================================================
--- trunk/Nebulous/nebclient/src/nebulous.h	(revision 23687)
+++ trunk/Nebulous/nebclient/src/nebulous.h	(revision 23688)
@@ -1,5 +1,5 @@
 /* src/nebulous.h
    Generated by wsdl2h 1.2.12 from nebulous.wsdl and typemap.dat
-   2009-03-05 21:11:05 GMT
+   2009-04-03 00:34:43 GMT
    Copyright (C) 2001-2008 Robert van Engelen, Genivia Inc. All Rights Reserved.
    This part of the software is released under one of the following licenses:
Index: trunk/Nebulous/nebclient/src/soapC.c
===================================================================
--- trunk/Nebulous/nebclient/src/soapC.c	(revision 23687)
+++ trunk/Nebulous/nebclient/src/soapC.c	(revision 23688)
@@ -12,5 +12,5 @@
 #endif
 
-SOAP_SOURCE_STAMP("@(#) soapC.c ver 2.7.12 2009-03-05 21:11:05 GMT")
+SOAP_SOURCE_STAMP("@(#) soapC.c ver 2.7.12 2009-04-03 00:34:43 GMT")
 
 
Index: trunk/Nebulous/nebclient/src/soapClient.c
===================================================================
--- trunk/Nebulous/nebclient/src/soapClient.c	(revision 23687)
+++ trunk/Nebulous/nebclient/src/soapClient.c	(revision 23688)
@@ -10,5 +10,5 @@
 #endif
 
-SOAP_SOURCE_STAMP("@(#) soapClient.c ver 2.7.12 2009-03-05 21:11:05 GMT")
+SOAP_SOURCE_STAMP("@(#) soapClient.c ver 2.7.12 2009-04-03 00:34:43 GMT")
 
 
Index: trunk/Nebulous/nebclient/src/soapServer.c
===================================================================
--- trunk/Nebulous/nebclient/src/soapServer.c	(revision 23687)
+++ trunk/Nebulous/nebclient/src/soapServer.c	(revision 23688)
@@ -10,5 +10,5 @@
 #endif
 
-SOAP_SOURCE_STAMP("@(#) soapServer.c ver 2.7.12 2009-03-05 21:11:05 GMT")
+SOAP_SOURCE_STAMP("@(#) soapServer.c ver 2.7.12 2009-04-03 00:34:43 GMT")
 
 
Index: trunk/dbconfig/cam.md
===================================================================
--- trunk/dbconfig/cam.md	(revision 23687)
+++ trunk/dbconfig/cam.md	(revision 23688)
@@ -87,4 +87,5 @@
     path_base      STR      255
     fault          S16      0       # Key NOT NULL
+    quality        S16      0
 END
 
Index: trunk/dbconfig/changes.txt
===================================================================
--- trunk/dbconfig/changes.txt	(revision 23687)
+++ trunk/dbconfig/changes.txt	(revision 23688)
@@ -899,4 +899,8 @@
 update chipRun SET magicked = 1 where chip_id = 11955;
 
+
+-- Version 1.1.51
+
+-- Distribution updates
 CREATE TABLE distTarget (
     target_id   BIGINT AUTO_INCREMENT,
@@ -908,5 +912,4 @@
     PRIMARY KEY(target_id)
 )  ENGINE=innodb DEFAULT CHARSET=latin1;
-
 
 CREATE TABLE rcDSProduct (
@@ -931,5 +934,4 @@
 )  ENGINE=innodb DEFAULT CHARSET=latin1;
 
-
 CREATE TABLE rcInterest (
     int_id      BIGINT AUTO_INCREMENT,
@@ -967,5 +969,24 @@
 )  ENGINE=innodb DEFAULT CHARSET=latin1;
 
--- 1.1.51
-
 ALTER TABLE distRun ADD COLUMN no_magic TINYINT AFTER clean;
+
+
+-- Adding data quality flags
+DROP TABLE guidePendingExp;
+ALTER TABLE diffSkyfile ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+ALTER TABLE stackSumSkyfile ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+ALTER TABLE warpSkyfile ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+ALTER TABLE camProcessedExp ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+ALTER TABLE chipProcessedImfile ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+ALTER TABLE rawImfile ADD COLUMN quality SMALLINT NOT NULL DEFAULT 0 AFTER fault;
+
+ALTER TABLE warpSkyfile DROP COLUMN ignored;
+
+ALTER TABLE diffSkyfile ADD KEY(quality);
+ALTER TABLE stackSumSkyfile ADD KEY(quality);
+ALTER TABLE warpSkyfile ADD KEY(quality);
+ALTER TABLE camProcessedExp ADD KEY(quality);
+ALTER TABLE chipProcessedImfile ADD KEY(quality);
+ALTER TABLE rawImfile ADD KEY(quality);
+
+-- Version 1.1.52
Index: trunk/dbconfig/chip.md
===================================================================
--- trunk/dbconfig/chip.md	(revision 23687)
+++ trunk/dbconfig/chip.md	(revision 23688)
@@ -88,4 +88,5 @@
     path_base       STR     255
     fault           S16     0       # Key NOT NULL
+    quality         S16     0
     magicked        BOOL    f
 END
Index: trunk/dbconfig/config.md
===================================================================
--- trunk/dbconfig/config.md	(revision 23687)
+++ trunk/dbconfig/config.md	(revision 23688)
@@ -2,4 +2,4 @@
     pkg_name        STR     ippdb
     pkg_namespace   STR     ippdb
-    pkg_version     STR     1.1.50
+    pkg_version     STR     1.1.52
 END
Index: trunk/dbconfig/diff.md
===================================================================
--- trunk/dbconfig/diff.md	(revision 23687)
+++ trunk/dbconfig/diff.md	(revision 23688)
@@ -54,4 +54,5 @@
     good_frac    F32        0.0     # Key
     fault        S16        0       # Key
+    quality      S16        0
     magicked     BOOL       f
 END
Index: trunk/dbconfig/guide.md
===================================================================
--- trunk/dbconfig/guide.md	(revision 23687)
+++ 	(revision )
@@ -1,5 +1,0 @@
-guidePendingExp METADATA
-    guide_id    S64         0       # Primary Key AUTO_INCREMENT
-    exp_id     S64         64      # Key
-    recipe      STR         64
-END
Index: trunk/dbconfig/ipp.m4
===================================================================
--- trunk/dbconfig/ipp.m4	(revision 23687)
+++ trunk/dbconfig/ipp.m4	(revision 23688)
@@ -9,6 +9,7 @@
 dnl include(telescope.md)
 dnl include(skycell.md)
-include(tasks.md)
-include(guide.md)
+include(summitcopy.md)
+include(new.md)
+include(raw.md)
 include(chip.md)
 include(cam.md)
Index: trunk/dbconfig/new.md
===================================================================
--- trunk/dbconfig/new.md	(revision 23688)
+++ trunk/dbconfig/new.md	(revision 23688)
@@ -0,0 +1,25 @@
+newExp METADATA
+    exp_id      S64         0       # Primary Key AUTO_INCREMENT
+    tmp_exp_name STR        64      # Key
+    tmp_camera    STR       64      # Key
+    tmp_telescope STR       64      # Key
+    state       STR         64      # Key
+    workdir     STR         255     # destination for output files
+    workdir_state STR       64      # key
+    reduction   STR         64      # Reduction class
+    dvodb       STR         255
+    tess_id     STR         64
+    end_stage   STR         64      # Key
+    label       STR         64      # Key
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
+# class needs to be carried here so it can go into rawImfile and be normalized
+# from there
+newImfile METADATA
+    exp_id      S64         64      # Primary Key fkey(exp_id) ref newExp(exp_id)
+    tmp_class_id STR        64      # Primary Key
+    uri         STR         255
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
Index: trunk/dbconfig/raw.md
===================================================================
--- trunk/dbconfig/raw.md	(revision 23688)
+++ trunk/dbconfig/raw.md	(revision 23688)
@@ -0,0 +1,138 @@
+# paired with rawImfile
+rawExp METADATA
+    exp_id      S64         64      # Primary Key fkey(exp_id) ref newExp(exp_id)
+    exp_name    STR         64      # Key
+    camera      STR         64
+    telescope   STR         64
+    dateobs     UTC         0001-01-01T00:00:00Z
+    exp_tag     STR         255
+    exp_type    STR         64
+    filelevel   STR         64
+    workdir     STR         255     # destination for output files
+    reduction   STR         64      # Reduction class
+    dvodb       STR         255
+    tess_id     STR         64
+    end_stage   STR         64      # Key
+    filter      STR         64
+    comment     STR         80
+    obs_mode    STR         64      # data usage goal (eg, survey name, engineering, etc)
+    obs_group   STR         64      # identifier for data block (eg, observation sequence)
+    airmass     F32         0.0
+    ra          F64         0.0
+    decl        F64         0.0
+    exp_time    F32         0.0
+    sat_pixel_frac F32      0.0
+    bg          F64         0.0
+    bg_stdev    F64         0.0
+    bg_mean_stdev   F64     0.0
+    alt         F64         0.0
+    az          F64         0.0
+    ccd_temp    F32         0.0
+    posang      F64         0.0 
+    m1_x        F32         0.0
+    m1_y        F32         0.0
+    m1_z        F32         0.0
+    m1_tip      F32         0.0
+    m1_tilt     F32         0.0
+    m2_x        F32         0.0
+    m2_y        F32         0.0
+    m2_z        F32         0.0
+    m2_tip      F32         0.0
+    m2_tilt     F32         0.0
+    env_temperature F32     0.0
+    env_humidity    F32     0.0
+    env_wind_speed  F32     0.0
+    env_wind_dir    F32     0.0
+    teltemp_m1      F32     0.0
+    teltemp_m1cell  F32     0.0
+    teltemp_m2      F32     0.0
+    teltemp_spider  F32     0.0
+    teltemp_truss   F32     0.0
+    teltemp_extra   F32     0.0
+    pon_time        F32     0.0
+    user_1      F64         0.0
+    user_2      F64         0.0
+    user_3      F64         0.0
+    user_4      F64         0.0
+    user_5      F64         0.0
+    object      STR         64
+    sun_angle   F32         0.0
+    sun_alt     F32         0.0
+    moon_angle  F32         0.0
+    moon_alt    F32         0.0
+    moon_phase  F32         0.0
+    hostname    STR         64
+    fault       S16         0       # Key NOT NULL
+    epoch       UTC         0001-01-01T00:00:00Z
+    magicked	BOOL        f
+END
+
+rawImfile METADATA
+    exp_id      S64         64      # Primary Key fkey(exp_id, tmp_class_id) ref newImfile(exp_id, tmp_class_id)
+    exp_name    STR         64      # UINDEX(exp_id, tmp_class_id)
+    camera      STR         64
+    telescope   STR         64
+    dateobs     UTC         0001-01-01T00:00:00Z
+    tmp_class_id    STR     64      # Key
+    class_id    STR         64      # Primary Key
+    uri         STR         255
+    exp_type    STR         64
+# This field is used to set the per exp filelevel. Thus the values for all of
+# the imfiles in an exposure need to be sanity checked to make sure that this
+# value is in argeement.
+    filelevel   STR         64 
+    filter      STR         64
+    comment     STR         80
+    obs_mode    STR         64      # data usage goal (eg, survey name, engineering, etc)
+    obs_group   STR         64      # identifier for data block (eg, observation sequence)
+    airmass     F32         0.0
+    ra          F64         0.0
+    decl        F64         0.0
+    exp_time    F32         0.0
+    sat_pixel_frac F32      0.0
+    bg          F64         0.0
+    bg_stdev    F64         0.0
+    bg_mean_stdev   F64     0.0
+    alt         F64         0.0
+    az          F64         0.0
+    ccd_temp    F32         0.0
+    posang      F64         0.0 
+    m1_x        F32         0.0
+    m1_y        F32         0.0
+    m1_z        F32         0.0
+    m1_tip      F32         0.0
+    m1_tilt     F32         0.0
+    m2_x        F32         0.0
+    m2_y        F32         0.0
+    m2_z        F32         0.0
+    m2_tip      F32         0.0
+    m2_tilt     F32         0.0
+    env_temperature F32     0.0
+    env_humidity    F32     0.0
+    env_wind_speed  F32     0.0
+    env_wind_dir    F32     0.0
+    teltemp_m1      F32     0.0
+    teltemp_m1cell  F32     0.0
+    teltemp_m2      F32     0.0
+    teltemp_spider  F32     0.0
+    teltemp_truss   F32     0.0
+    teltemp_extra   F32     0.0
+    pon_time        F32     0.0
+    user_1      F64         0.0
+    user_2      F64         0.0
+    user_3      F64         0.0
+    user_4      F64         0.0
+    user_5      F64         0.0
+    object      STR         64
+    sun_angle   F32         0.0
+    sun_alt     F32         0.0
+    moon_angle  F32         0.0
+    moon_alt    F32         0.0
+    moon_phase  F32         0.0
+    ignored	BOOL        f
+    hostname    STR         64
+    fault       S16         0       # Key NOT NULL
+    quality     S16         0
+    epoch       UTC         0001-01-01T00:00:00Z
+    magicked    BOOL        f
+END
Index: trunk/dbconfig/stack.md
===================================================================
--- trunk/dbconfig/stack.md	(revision 23687)
+++ trunk/dbconfig/stack.md	(revision 23688)
@@ -46,3 +46,4 @@
     good_frac          F32    0.0     # Key
     fault              S16    0       # Key
+    quality            S16    0
 END
Index: trunk/dbconfig/summitcopy.md
===================================================================
--- trunk/dbconfig/summitcopy.md	(revision 23688)
+++ trunk/dbconfig/summitcopy.md	(revision 23688)
@@ -0,0 +1,60 @@
+pzDataStore METADATA
+    camera      STR         64      # Primary Key
+    telescope   STR         64      # Primary Key
+    uri         STR         255
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
+# list of source exposures -- updated as exposures are seen
+# summitExp.imfiles is updated as filesets are queried default value should be
+# -1 as NULL or 0 might be a valid value (empty fileset)
+summitExp METADATA
+    exp_name    STR         64      # Primary Key
+    camera      STR         64      # Primary Key
+    telescope   STR         64      # Primary Key
+    dateobs     UTC         NULL
+    exp_type    STR         64
+    uri         STR         255
+    imfiles     S32         0
+    fault       S16         0       # Key NOT NULL
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
+# class == type of file
+# class_id == type set id
+# list of source images -- updated as exposures/filesets are queried
+summitImfile METADATA
+    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
+    camera      STR         64      # Primary Key
+    telescope   STR         64      # Primary Key
+    file_id     STR         64      # Key
+    bytes       S32         0
+    md5sum      STR         32
+    class       STR         64      # Primary Key
+    class_id    STR         64      # Primary Key
+    uri         STR         255
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
+# list of exposures that have had their imfiles/files registered (but not
+# downloaded) 
+pzDownloadExp METADATA
+    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
+    camera      STR         64      # Primary Key
+    telescope   STR         64      # Primary Key
+    state       STR         64      # Key 
+    epoch       UTC         0001-01-01T00:00:00Z
+END
+
+pzDownloadImfile METADATA
+    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref pzDownloadExp(exp_name, camera, telescope)
+    camera      STR         64      # Primary Key fkey(exp_name, camera, telescope, class, class_id) ref summitImfile(exp_name, camera, telescope, class, class_id)
+    telescope   STR         64      # Primary Key
+    class       STR         64      # Primary Key
+    class_id    STR         64      # Primary Key
+    uri         STR         255
+    fault       S16         0       # Key NOT NULL
+    epoch       UTC         0001-01-01T00:00:00Z
+    hostname    STR         64
+END
+
Index: trunk/dbconfig/tasks.md
===================================================================
--- trunk/dbconfig/tasks.md	(revision 23687)
+++ 	(revision )
@@ -1,243 +1,0 @@
-# $Id: tasks.md,v 1.159 2008-12-13 20:17:34 bills Exp $
-
-# this table records all exposure ID ever seen from the summit
-# exp_name == fileset
-
-# note that dec is a MySQL reserved word
-# note that use is a MySQL reserved word
-# note that exp is a MySQL reserved word
-
-# for use with this stored procedure to generate exp_ids under Mysql 5+
-#
-#CREATE FUNCTION genTag (exp_name varchar(64)) RETURNS VARCHAR(64)
-#BEGIN
-#    UPDATE expTagCounter SET counter = LAST_INSERT_ID(counter + 1);
-#    RETURN CONCAT(exp_name, '.', LAST_INSERT_ID());
-#END
-#
-#expTagCounter METADATA
-#   counter     U64         0 
-#END
-
-pzDataStore METADATA
-    camera      STR         64      # Primary Key
-    telescope   STR         64      # Primary Key
-    uri         STR         255
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-# list of source exposures -- updated as exposures are seen
-# summitExp.imfiles is updated as filesets are queried default value should be
-# -1 as NULL or 0 might be a valid value (empty fileset)
-summitExp METADATA
-    exp_name    STR         64      # Primary Key
-    camera      STR         64      # Primary Key
-    telescope   STR         64      # Primary Key
-    dateobs     UTC         NULL
-    exp_type    STR         64
-    uri         STR         255
-    imfiles     S32         0
-    fault       S16         0       # Key NOT NULL
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-# class == type of file
-# class_id == type set id
-# list of source images -- updated as exposures/filesets are queried
-summitImfile METADATA
-    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
-    camera      STR         64      # Primary Key
-    telescope   STR         64      # Primary Key
-    file_id     STR         64      # Key
-    bytes       S32         0
-    md5sum      STR         32
-    class       STR         64      # Primary Key
-    class_id    STR         64      # Primary Key
-    uri         STR         255
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-# list of exposures that have had their imfiles/files registered (but not
-# downloaded) 
-pzDownloadExp METADATA
-    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref summitExp(exp_name, camera, telescope)
-    camera      STR         64      # Primary Key
-    telescope   STR         64      # Primary Key
-    state       STR         64      # Key 
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-pzDownloadImfile METADATA
-    exp_name    STR         64      # Primary Key fkey(exp_name, camera, telescope) ref pzDownloadExp(exp_name, camera, telescope)
-    camera      STR         64      # Primary Key fkey(exp_name, camera, telescope, class, class_id) ref summitImfile(exp_name, camera, telescope, class, class_id)
-    telescope   STR         64      # Primary Key
-    class       STR         64      # Primary Key
-    class_id    STR         64      # Primary Key
-    uri         STR         255
-    fault       S16         0       # Key NOT NULL
-    epoch       UTC         0001-01-01T00:00:00Z
-    hostname    STR         64
-END
-
-newExp METADATA
-    exp_id      S64         0       # Primary Key AUTO_INCREMENT
-    tmp_exp_name STR        64      # Key
-    tmp_camera    STR       64      # Key
-    tmp_telescope STR       64      # Key
-    state       STR         64      # Key
-    workdir     STR         255     # destination for output files
-    workdir_state STR       64      # key
-    reduction   STR         64      # Reduction class
-    dvodb       STR         255
-    tess_id     STR         64
-    end_stage   STR         64      # Key
-    label       STR         64      # Key
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-# class needs to be carried here so it can go into rawImfile and be normalized
-# from there
-newImfile METADATA
-    exp_id      S64         64      # Primary Key fkey(exp_id) ref newExp(exp_id)
-    tmp_class_id STR        64      # Primary Key
-    uri         STR         255
-    epoch       UTC         0001-01-01T00:00:00Z
-END
-
-# paired with rawImfile
-rawExp METADATA
-    exp_id      S64         64      # Primary Key fkey(exp_id) ref newExp(exp_id)
-    exp_name    STR         64      # Key
-    camera      STR         64
-    telescope   STR         64
-    dateobs     UTC         0001-01-01T00:00:00Z
-    exp_tag     STR         255
-    exp_type    STR         64
-    filelevel   STR         64
-    workdir     STR         255     # destination for output files
-    reduction   STR         64      # Reduction class
-    dvodb       STR         255
-    tess_id     STR         64
-    end_stage   STR         64      # Key
-    filter      STR         64
-    comment     STR         80
-    obs_mode    STR         64      # data usage goal (eg, survey name, engineering, etc)
-    obs_group   STR         64      # identifier for data block (eg, observation sequence)
-    airmass     F32         0.0
-    ra          F64         0.0
-    decl        F64         0.0
-    exp_time    F32         0.0
-    sat_pixel_frac F32      0.0
-    bg          F64         0.0
-    bg_stdev    F64         0.0
-    bg_mean_stdev   F64     0.0
-    alt         F64         0.0
-    az          F64         0.0
-    ccd_temp    F32         0.0
-    posang      F64         0.0 
-    m1_x        F32         0.0
-    m1_y        F32         0.0
-    m1_z        F32         0.0
-    m1_tip      F32         0.0
-    m1_tilt     F32         0.0
-    m2_x        F32         0.0
-    m2_y        F32         0.0
-    m2_z        F32         0.0
-    m2_tip      F32         0.0
-    m2_tilt     F32         0.0
-    env_temperature F32     0.0
-    env_humidity    F32     0.0
-    env_wind_speed  F32     0.0
-    env_wind_dir    F32     0.0
-    teltemp_m1      F32     0.0
-    teltemp_m1cell  F32     0.0
-    teltemp_m2      F32     0.0
-    teltemp_spider  F32     0.0
-    teltemp_truss   F32     0.0
-    teltemp_extra   F32     0.0
-    pon_time        F32     0.0
-    user_1      F64         0.0
-    user_2      F64         0.0
-    user_3      F64         0.0
-    user_4      F64         0.0
-    user_5      F64         0.0
-    object      STR         64
-    sun_angle   F32         0.0
-    sun_alt     F32         0.0
-    moon_angle  F32         0.0
-    moon_alt    F32         0.0
-    moon_phase  F32         0.0
-    hostname    STR         64
-    fault       S16         0       # Key NOT NULL
-    epoch       UTC         0001-01-01T00:00:00Z
-    magicked	BOOL        f
-END
-
-rawImfile METADATA
-    exp_id      S64         64      # Primary Key fkey(exp_id, tmp_class_id) ref newImfile(exp_id, tmp_class_id)
-    exp_name    STR         64      # UINDEX(exp_id, tmp_class_id)
-    camera      STR         64
-    telescope   STR         64
-    dateobs     UTC         0001-01-01T00:00:00Z
-    tmp_class_id    STR     64      # Key
-    class_id    STR         64      # Primary Key
-    uri         STR         255
-    exp_type    STR         64
-# This field is used to set the per exp filelevel. Thus the values for all of
-# the imfiles in an exposure need to be sanity checked to make sure that this
-# value is in argeement.
-    filelevel   STR         64 
-    filter      STR         64
-    comment     STR         80
-    obs_mode    STR         64      # data usage goal (eg, survey name, engineering, etc)
-    obs_group   STR         64      # identifier for data block (eg, observation sequence)
-    airmass     F32         0.0
-    ra          F64         0.0
-    decl        F64         0.0
-    exp_time    F32         0.0
-    sat_pixel_frac F32      0.0
-    bg          F64         0.0
-    bg_stdev    F64         0.0
-    bg_mean_stdev   F64     0.0
-    alt         F64         0.0
-    az          F64         0.0
-    ccd_temp    F32         0.0
-    posang      F64         0.0 
-    m1_x        F32         0.0
-    m1_y        F32         0.0
-    m1_z        F32         0.0
-    m1_tip      F32         0.0
-    m1_tilt     F32         0.0
-    m2_x        F32         0.0
-    m2_y        F32         0.0
-    m2_z        F32         0.0
-    m2_tip      F32         0.0
-    m2_tilt     F32         0.0
-    env_temperature F32     0.0
-    env_humidity    F32     0.0
-    env_wind_speed  F32     0.0
-    env_wind_dir    F32     0.0
-    teltemp_m1      F32     0.0
-    teltemp_m1cell  F32     0.0
-    teltemp_m2      F32     0.0
-    teltemp_spider  F32     0.0
-    teltemp_truss   F32     0.0
-    teltemp_extra   F32     0.0
-    pon_time        F32     0.0
-    user_1      F64         0.0
-    user_2      F64         0.0
-    user_3      F64         0.0
-    user_4      F64         0.0
-    user_5      F64         0.0
-    object      STR         64
-    sun_angle   F32         0.0
-    sun_alt     F32         0.0
-    moon_angle  F32         0.0
-    moon_alt    F32         0.0
-    moon_phase  F32         0.0
-    ignored	BOOL        f
-    hostname    STR         64
-    fault       S16         0       # Key NOT NULL
-    epoch       UTC         0001-01-01T00:00:00Z
-    magicked    BOOL        f
-END
Index: trunk/dbconfig/warp.md
===================================================================
--- trunk/dbconfig/warp.md	(revision 23687)
+++ trunk/dbconfig/warp.md	(revision 23688)
@@ -55,6 +55,6 @@
     ymin           S32      0
     ymax           S32      0
-    ignored        BOOL     f       # Key
     fault          S16      0       # Key
+    quality        S16      0
     magicked       BOOL     f
 END
Index: trunk/ippScripts/scripts/camera_exp.pl
===================================================================
--- trunk/ippScripts/scripts/camera_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/camera_exp.pl	(revision 23688)
@@ -263,7 +263,6 @@
             &my_die("Unable to perform psastro: $error_code", $cam_id, $error_code);
         }
-        # XXX do we want to give an error if astrometry fails here?
-        &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
-
+
+        my $quality;            # Quality flag
         if ($do_stats) {
             my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
@@ -282,4 +281,10 @@
             }
             chomp $cmdflags;
+
+            ($quality) = $cmdflags =~ /-quality (\d+)/;
+        }
+
+        if (!$quality) {
+            &my_die("Unable to find expected output file: $fpaObjects", $cam_id, $PS_EXIT_PROG_ERROR) unless -f $ipprc->file_resolve($fpaObjects);
         }
 
@@ -375,5 +380,5 @@
             $command .= " -addprocessedexp";
             $command .= " -uri UNKNOWN";
-            $command .= " -code $exit_code";
+            $command .= " -fault $exit_code";
             $command .= " -path_base $outroot";
             $command .= " -path_base $outroot" if defined $outroot;
@@ -381,5 +386,5 @@
         } else {
             $command .= " -updateprocessedexp";
-            $command .= " -code $exit_code";
+            $command .= " -fault $exit_code";
         }
         $command .= " -hostname $host" if defined $host;
Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 23688)
@@ -181,21 +181,8 @@
     ## allow the output images to be optional, depending on the recipe / reduction class
     my $outputImageExpect = metadataLookupBool($recipeData, 'CHIP.FITS');
-    if ($outputImageExpect) {
-        &my_die("Couldn't find expected output file: $outputImage\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
-    }
-
     my $outputMaskExpect = metadataLookupBool($recipeData, 'CHIP.MASK.FITS');
-    if ($outputMaskExpect) {
-        &my_die("Couldn't find expected output file: $outputMask\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-    }
-
     my $outputWeightExpect = metadataLookupBool($recipeData, 'CHIP.VARIANCE.FITS');
-    if ($outputWeightExpect) {
-        &my_die("Couldn't find expected output file: $outputWeight\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
-    }
-
-    &my_die("Couldn't find expected output file: $outputBin1\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
-    &my_die("Couldn't find expected output file: $outputBin2\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
-
+
+    my $quality;                # Quality flag
     if ($do_stats) {
         my $outputStatsReal = $ipprc->file_resolve($outputStats);
@@ -214,5 +201,15 @@
         }
         chomp $cmdflags;
-    }
+        ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+    }
+
+    if (!$quality) {
+        &my_die("Couldn't find expected output file: $outputImage\n",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless !$outputImageExpect or $ipprc->file_exists($outputImage);
+        &my_die("Couldn't find expected output file: $outputMask\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless !$outputMaskExpect or $ipprc->file_exists($outputMask);
+        &my_die("Couldn't find expected output file: $outputWeight\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless !$outputWeightExpect or $ipprc->file_exists($outputWeight);
+        &my_die("Couldn't find expected output file: $outputBin1\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1);
+        &my_die("Couldn't find expected output file: $outputBin2\n",   $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2);
+    }
+
 }
 
@@ -277,5 +274,5 @@
         $command .= " -chip_id $chip_id";
         $command .= " -class_id $class_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_correct_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_correct_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_correct_imfile.pl	(revision 23688)
@@ -132,5 +132,5 @@
         $command .= " -class_id $class_id";
         $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_norm_apply.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_norm_apply.pl	(revision 23688)
@@ -206,5 +206,5 @@
         $command .= " -class_id $class_id";
         $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_norm_calc.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_norm_calc.pl	(revision 23688)
@@ -239,5 +239,5 @@
         $command .= " -iteration $iter";
         # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_norm_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_norm_exp.pl	(revision 23688)
@@ -191,5 +191,5 @@
         $command .= " -iteration $iter";
         $command .= " -path_base $outroot ";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_process_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_process_exp.pl	(revision 23688)
@@ -205,5 +205,5 @@
         $command .= " -det_id $det_id";
         $command .= " -exp_id $exp_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -path_base $outroot";
         $command .= " -dbname $dbname" if defined $dbname;
Index: trunk/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 23688)
@@ -195,5 +195,5 @@
         $command .= " -class_id $class_id";
         $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 23688)
@@ -344,5 +344,5 @@
         $command .= " -iteration $iter";
         # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_resid_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_resid_exp.pl	(revision 23688)
@@ -651,5 +651,5 @@
         $command .= " -exp_id $exp_id";
         $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_resid_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_resid_imfile.pl	(revision 23688)
@@ -265,5 +265,5 @@
         $command .= " -class_id $class_id";
         $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/detrend_stack.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_stack.pl	(revision 23687)
+++ trunk/ippScripts/scripts/detrend_stack.pl	(revision 23688)
@@ -262,5 +262,5 @@
         $command .= " -class_id $class_id";
         # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/diff_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/diff_skycell.pl	(revision 23687)
+++ trunk/ippScripts/scripts/diff_skycell.pl	(revision 23688)
@@ -248,10 +248,4 @@
         &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code);
     }
-    &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
-    &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-    &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
-#    &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
-#    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
 
     my $outputStatsReal = $ipprc->file_resolve($outputStats);
@@ -270,4 +264,15 @@
     }
     chomp $cmdflags;
+
+    my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+
+    if (!$quality) {
+        &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
+        &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+        &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
+#        &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+#        &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
+#        &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
+    }
 }
 
@@ -304,5 +309,5 @@
     warn($msg);
     if (defined $diff_id and defined $skycell_id and not $no_update) {
-        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -code $exit_code";
+        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
         $command .= " -hostname $host" if defined $host;
Index: trunk/ippScripts/scripts/dist_advancerun.pl
===================================================================
--- trunk/ippScripts/scripts/dist_advancerun.pl	(revision 23687)
+++ trunk/ippScripts/scripts/dist_advancerun.pl	(revision 23688)
@@ -134,5 +134,5 @@
     my $command = "$disttool -updaterun";
     $command   .= " -dist_id $dist_id";
-    $command   .= " -code $exit_code";
+    $command   .= " -fault $exit_code";
     $command   .= " -dbname $dbname" if defined $dbname;
 
Index: trunk/ippScripts/scripts/dist_component.pl
===================================================================
--- trunk/ippScripts/scripts/dist_component.pl	(revision 23687)
+++ trunk/ippScripts/scripts/dist_component.pl	(revision 23688)
@@ -304,5 +304,5 @@
     $command   .= " -dist_id $dist_id";
     $command   .= " -component $component";
-    $command   .= " -code $exit_code";
+    $command   .= " -fault $exit_code";
     $command   .= " -dbname $dbname" if defined $dbname;
 
Index: trunk/ippScripts/scripts/fake_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/fake_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/fake_imfile.pl	(revision 23688)
@@ -216,5 +216,5 @@
         $command .= " -path_base $outroot";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/flatcorr_proc.pl
===================================================================
--- trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 23687)
+++ trunk/ippScripts/scripts/flatcorr_proc.pl	(revision 23688)
@@ -320,5 +320,5 @@
         my $command = "$flatcorr -addprocess";
 	$command .= " -corr_id $corr_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 23687)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 23688)
@@ -274,5 +274,5 @@
     $command   .= " -magic_ds_id $magic_ds_id";
     $command   .= " -component $component";
-    $command   .= " -code $exit_code";
+    $command   .= " -fault $exit_code";
     $command   .= " -dbname $dbname" if defined $dbname;
 
Index: trunk/ippScripts/scripts/magic_mask.pl
===================================================================
--- trunk/ippScripts/scripts/magic_mask.pl	(revision 23687)
+++ trunk/ippScripts/scripts/magic_mask.pl	(revision 23688)
@@ -152,5 +152,5 @@
         my $command = "$magictool -addmask";
         $command .= " -magic_id $magic_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system($command);
Index: trunk/ippScripts/scripts/magic_process.pl
===================================================================
--- trunk/ippScripts/scripts/magic_process.pl	(revision 23687)
+++ trunk/ippScripts/scripts/magic_process.pl	(revision 23688)
@@ -343,5 +343,5 @@
         $command .= " -magic_id $magic_id";
         $command .= " -node $node";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system($command);
Index: trunk/ippScripts/scripts/magic_tree.pl
===================================================================
--- trunk/ippScripts/scripts/magic_tree.pl	(revision 23687)
+++ trunk/ippScripts/scripts/magic_tree.pl	(revision 23688)
@@ -296,5 +296,5 @@
         my $command = "$magictool -inputtree";
         $command .= " -magic_id $magic_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system($command);
Index: trunk/ippScripts/scripts/register_exp.pl
===================================================================
--- trunk/ippScripts/scripts/register_exp.pl	(revision 23687)
+++ trunk/ippScripts/scripts/register_exp.pl	(revision 23688)
@@ -191,5 +191,5 @@
     carp($msg);
     if (defined $exp_id and not $no_update) {
-        my $command = "$regtool -addprocessedexp -exp_id $exp_id -code $exit_code";
+        my $command = "$regtool -addprocessedexp -exp_id $exp_id -fault $exit_code";
         $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
Index: trunk/ippScripts/scripts/register_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/register_imfile.pl	(revision 23687)
+++ trunk/ippScripts/scripts/register_imfile.pl	(revision 23688)
@@ -112,9 +112,9 @@
 
 # we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
-if (uc(&value_for_flag ($cmdflags, "NULL", "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
-if (uc(&value_for_flag ($cmdflags, "NULL", "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
-if (uc(&value_for_flag ($cmdflags, "NULL", "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
-if (uc(&value_for_flag ($cmdflags, "NULL", "-class_id"))  eq "NULL") { &my_die ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
-if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-class_id"))  eq "NULL") { &my_die ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
+if (uc(&value_for_flag ($cmdflags, "-exp_type"))  eq "NULL") { &my_die ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
 
 my $command = "$regtool -addprocessedimfile";
@@ -226,5 +226,5 @@
         $command .= " -inst UNKNOWN";
         $command .= " -class_id $tmp_class_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 23687)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 23688)
@@ -232,11 +232,6 @@
         &my_die("Unable to perform ppStack: $error_code", $stack_id, $error_code);
     }
-    &my_die("Couldn't find expected output file: $outputName", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
-    &my_die("Couldn't find expected output file: $outputMask", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
-    &my_die("Couldn't find expected output file: $outputWeight", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
-    &my_die("Couldn't find expected output file: $outputSources", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
-#   &my_die("Couldn't find expected output file: $bin1Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
-#   &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
-
+
+    my $quality;                # Quality flag
     if ($do_stats) {
         my $outputStatsReal = $ipprc->file_resolve($outputStats);
@@ -255,5 +250,17 @@
         }
         chomp $cmdflags;
-    }
+
+        ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+    }
+
+    if (!$quality) {
+        &my_die("Couldn't find expected output file: $outputName", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
+        &my_die("Couldn't find expected output file: $outputMask", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
+        &my_die("Couldn't find expected output file: $outputWeight", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
+        &my_die("Couldn't find expected output file: $outputSources", $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
+#       &my_die("Couldn't find expected output file: $bin1Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
+#       &my_die("Couldn't find expected output file: $bin2Name",    $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
+    }
+
 }
 
@@ -306,5 +313,5 @@
 
     if (defined $stack_id and not $no_update) {
-        my $command = "$stacktool -stack_id $stack_id -code $exit_code";
+        my $command = "$stacktool -stack_id $stack_id -fault $exit_code";
         if ($run_state eq 'new') {
             $command .= " -addsumskyfile";
Index: trunk/ippScripts/scripts/summit_copy.pl
===================================================================
--- trunk/ippScripts/scripts/summit_copy.pl	(revision 23687)
+++ trunk/ippScripts/scripts/summit_copy.pl	(revision 23688)
@@ -148,5 +148,5 @@
         $command .= " -class_id $class_id";
         $command .= " -uri $uri";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
 
Index: trunk/ippScripts/scripts/warp_overlap.pl
===================================================================
--- trunk/ippScripts/scripts/warp_overlap.pl	(revision 23687)
+++ trunk/ippScripts/scripts/warp_overlap.pl	(revision 23688)
@@ -193,5 +193,5 @@
         my $command = "$warptool -addoverlap";
         $command .= " -warp_id $warp_id";
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         system ($command);
Index: trunk/ippScripts/scripts/warp_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/warp_skycell.pl	(revision 23687)
+++ trunk/ippScripts/scripts/warp_skycell.pl	(revision 23688)
@@ -175,5 +175,4 @@
 # Run pswarp
 my $cmdflags;
-my $accept = 1;                 # Accept the skycell?
 my $do_stats;
 unless ($no_op) {
@@ -215,5 +214,5 @@
 
     if ($do_stats) {
-        # Check first for the stats file, and if the ACCEPT flag is set.
+        # Check first for the stats file
         my $outputStatsReal = $ipprc->file_resolve($outputStats);
         &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
@@ -232,5 +231,7 @@
         chomp $cmdflags;
 
-        if ($cmdflags =~ /-accept/) {
+        my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
+
+        if (!$quality) {
             &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
             &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
@@ -249,7 +250,7 @@
             $command .= " -magicked" if $magicked;
 
-            $command .= " -uri $outputImage" if $accept;
+            $command .= " -uri $outputImage" if !$quality;
             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-            $command .= " $cmdflags" if $accept;
+            $command .= " $cmdflags";
             $command .= " -hostname $host"   if defined $host;
             $command .= " -dbname $dbname"   if defined $dbname;
@@ -307,5 +308,5 @@
         $command .= " -skycell_id $skycell_id";
         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-        $command .= " -code $exit_code";
+        $command .= " -fault $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
         run(command => $command, verbose => $verbose);
Index: trunk/ippTools/configure.ac
===================================================================
--- trunk/ippTools/configure.ac	(revision 23687)
+++ trunk/ippTools/configure.ac	(revision 23688)
@@ -18,5 +18,5 @@
 PKG_CHECK_MODULES([PSLIB], [pslib >= 1.1.0])
 PKG_CHECK_MODULES([PSMODULES], [psmodules >= 1.1.0])
-PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.50]) 
+PKG_CHECK_MODULES([IPPDB], [ippdb >= 1.1.52]) 
 
 PXTOOLS_CFLAGS="${PSLIB_CFLAGS=} ${PSMODULES_CFLAGS=} ${IPPDB_CFLAGS=}"
Index: trunk/ippTools/share/chiptool_completely_processed_exp.sql
===================================================================
--- trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 23687)
+++ trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 23688)
@@ -35,3 +35,4 @@
         COUNT(rawImfile.class_id) = COUNT(chipProcessedImfile.class_id)
         AND SUM(chipProcessedImfile.fault) = 0
+        AND SUM(chipProcessedImfile.quality > 0) != COUNT(*)
     ) as Foo
Index: trunk/ippTools/share/difftool_definebyquery.sql
===================================================================
--- trunk/ippTools/share/difftool_definebyquery.sql	(revision 23687)
+++ trunk/ippTools/share/difftool_definebyquery.sql	(revision 23688)
@@ -38,5 +38,5 @@
     WHERE
         warpSkyfile.fault = 0
-        AND warpSkyfile.ignored = 0
+        AND warpSkyfile.quality = 0
     -- warpsToDiff WHERE hook %s
     ) AS warpsToDiff
@@ -51,4 +51,5 @@
     WHERE stackRun.state = 'full'
         AND stackSumSkyfile.fault = 0
+        AND stackSumSkyfile.quality = 0
     -- stacksForDiff WHERE hook %s
     GROUP BY
Index: trunk/ippTools/share/difftool_definebyquery_part1.sql
===================================================================
--- trunk/ippTools/share/difftool_definebyquery_part1.sql	(revision 23687)
+++ trunk/ippTools/share/difftool_definebyquery_part1.sql	(revision 23688)
@@ -1,22 +1,21 @@
-    SELECT
-        exp_id,
-        warp_id,
-        rawExp.filter,
-        warpRun.label,
-        warpRun.tess_id,
-        count(skycell_id) as skycell_count
-    FROM warpRun
-    JOIN warpSkyfile USING(warp_id)
-    JOIN fakeRun USING(fake_id) 
-    JOIN camRun USING(cam_id) 
-    JOIN chipRun USING (chip_id) 
-    JOIN rawExp USING(exp_id)
-    LEFT JOIN diffRun USING(exp_id)
-
-    WHERE
-        warpSkyfile.ignored = 0
-        -- warp where hook %s
-        -- exp where hook %s
-        -- diff where hook %s
-
-    GROUP BY exp_id, warp_id DESC
+SELECT
+    exp_id,
+    warp_id,
+    rawExp.filter,
+    warpRun.label,
+    warpRun.tess_id,
+    COUNT(skycell_id) as skycell_count
+FROM warpRun
+JOIN warpSkyfile USING(warp_id)
+JOIN fakeRun USING(fake_id)
+JOIN camRun USING(cam_id)
+JOIN chipRun USING(chip_id)
+JOIN rawExp USING(exp_id)
+LEFT JOIN diffRun USING(exp_id)
+WHERE
+    warpSkyfile.fault = 0
+    AND warpSkyfile.quality = 0
+    -- warp where hook %s
+    -- exp where hook %s
+    -- diff where hook %s
+GROUP BY exp_id, warp_id DESC
Index: trunk/ippTools/share/difftool_definebyquery_part2.sql
===================================================================
--- trunk/ippTools/share/difftool_definebyquery_part2.sql	(revision 23687)
+++ trunk/ippTools/share/difftool_definebyquery_part2.sql	(revision 23688)
@@ -1,36 +1,36 @@
 -- insert skycells to diff
 INSERT INTO skycellsToDiff
+SELECT
+    0,                      -- diff_id
+    warpSkyfile.skycell_id,
+    warpSkyfile.warp_id,    -- warp1
+    NULL,                   -- stack1
+    NULL,                   -- warp2
+    max_stack_id,           -- stack2
+    warpSkyfile.tess_id,
+    0
+FROM warpSkyfile
+JOIN warpRun USING(warp_id)
+LEFT JOIN (
     SELECT
-        0,                      -- diff_id
-        warpSkyfile.skycell_id,
-        warpSkyfile.warp_id,    -- warp1
-        NULL,                   -- stack1
-        NULL,                   -- warp2
-        max_stack_id,           -- stack2
-        warpSkyfile.tess_id,
-        0
-        FROM warpSkyfile
-        JOIN warpRun USING(warp_id)
-        LEFT JOIN (
-            SELECT
-                MAX(stack_id) AS max_stack_id, -- most recent stack, by virtue of auto-increment
-                stackRun.skycell_id,
-                stackRun.tess_id,
-                filter
-            FROM stackRun
-            JOIN stackSumSkyfile USING(stack_id)
-            WHERE stackSumSkyfile.fault = 0
-                AND stackRun.state = 'full'
-            -- stacks where hook %s
-            GROUP BY
-                skycell_id,
-                filter
-            ) as bestStacks
-        USING(skycell_id)
-        WHERE
-            warpSkyfile.warp_id = %lld
-            AND ignored = 0
-            AND filter = '%s'
-            AND warpSkyfile.tess_id = bestStacks.tess_id
-        -- (good fraction test goes here for example also above)
-        -- warp where hook %s
+        MAX(stack_id) AS max_stack_id, -- most recent stack, by virtue of auto-increment
+        stackRun.skycell_id,
+        stackRun.tess_id,
+        filter
+    FROM stackRun
+    JOIN stackSumSkyfile USING(stack_id)
+    WHERE stackSumSkyfile.fault = 0
+        AND stackSumSkyfile.quality = 0
+        AND stackRun.state = 'full'
+    -- stacks where hook %s
+    GROUP BY
+        skycell_id,
+        filter
+    ) as bestStacks USING(skycell_id)
+WHERE
+    warpSkyfile.warp_id = %lld
+    AND warpSkyfile.fault = 0
+    AND warpSkyfile.quality = 0
+    AND filter = '%s'
+    AND warpSkyfile.tess_id = bestStacks.tess_id
+-- warp where hook %s
Index: trunk/ippTools/share/difftool_definewarpwarp_insert.sql
===================================================================
--- trunk/ippTools/share/difftool_definewarpwarp_insert.sql	(revision 23687)
+++ trunk/ippTools/share/difftool_definewarpwarp_insert.sql	(revision 23688)
@@ -11,6 +11,6 @@
 FROM warpSkyfile AS inputWarpSkyfile
 JOIN warpSkyfile AS templateWarpSkyfile USING(skycell_id, tess_id)
-WHERE inputWarpSkyfile.ignored = 0
-    AND templateWarpSkyfile.ignored = 0
+WHERE inputWarpSkyfile.quality = 0
+    AND templateWarpSkyfile.quality = 0
     AND inputWarpSkyfile.warp_id = %s
     AND templateWarpSkyfile.warp_id = %s
Index: trunk/ippTools/share/difftool_todiffskyfile.sql
===================================================================
--- trunk/ippTools/share/difftool_todiffskyfile.sql	(revision 23687)
+++ trunk/ippTools/share/difftool_todiffskyfile.sql	(revision 23688)
@@ -63,5 +63,6 @@
     AND diffSkyfile.diff_id IS NULL)
     OR (diffRun.state = 'update'
-    AND diffSkyfile.fault = 0)
+    AND diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0)
     )
 -- Ensure input warps are available
@@ -69,18 +70,20 @@
     OR (warpRun.state = 'full'
     AND warpSkyfile.fault = 0
-    AND warpSkyfile.ignored = 0))
+    AND warpSkyfile.quality = 0))
 -- Ensure input stacks are available
     AND (diffInputSkyfile.stack1 IS NULL
     OR (stackRun.state = 'full'
-    AND stackSumSkyfile.fault = 0))
+    AND stackSumSkyfile.fault = 0
+    AND stackSumSkyfile.quality = 0))
 -- Ensure template warps are available
     AND (diffInputSkyfile.warp2 IS NULL
     OR (warpTemplateRun.state = 'full'
     AND warpTemplateSkyfile.fault = 0
-    AND warpTemplateSkyfile.ignored = 0))
+    AND warpTemplateSkyfile.quality = 0))
 -- Ensure template stacks are available
     AND (diffInputSkyfile.stack2 IS NULL
     OR (stackTemplateRun.state = 'full'
-    AND stackTemplateSkyfile.fault = 0))
+    AND stackTemplateSkyfile.fault = 0
+    AND stackTemplateSkyfile.quality = 0))
 
 
Index: trunk/ippTools/share/disttool_toadvance.sql
===================================================================
--- trunk/ippTools/share/disttool_toadvance.sql	(revision 23687)
+++ trunk/ippTools/share/disttool_toadvance.sql	(revision 23688)
@@ -7,5 +7,5 @@
     (
 -- raw stage
-SELECT 
+SELECT
     distRun.dist_id,
     stage,
@@ -29,5 +29,5 @@
 UNION
 -- chip stage
-SELECT 
+SELECT
     distRun.dist_id,
     stage,
@@ -51,5 +51,5 @@
 UNION
 -- warp stage
-SELECT 
+SELECT
     distRun.dist_id,
     stage,
@@ -66,5 +66,5 @@
         AND distRun.stage = 'warp'
 --        AND warpSkyfile.fault = 0
---        AND warpSkyfile.ignored = 0
+--        AND warpSkyfile.quality = 0
     GROUP BY
         distRun.dist_id,
@@ -99,5 +99,5 @@
 UNION
 -- stack stage
-SELECT 
+SELECT
     distRun.dist_id,
     stage,
Index: trunk/ippTools/share/flatcorr_completely_processed_chiprun.sql
===================================================================
--- trunk/ippTools/share/flatcorr_completely_processed_chiprun.sql	(revision 23687)
+++ trunk/ippTools/share/flatcorr_completely_processed_chiprun.sql	(revision 23688)
@@ -14,5 +14,5 @@
         dvodb
     FROM
-        (SELECT 
+        (SELECT
             chipRun.*,
             rawImfile.class_id as rawimfile_class_id,
@@ -33,4 +33,5 @@
             COUNT(rawImfile.class_id) = COUNT(chipProcessedImfile.class_id)
             AND SUM(chipProcessedImfile.fault) = 0
-        ) as Foo
+            AND SUM(chipProcessedImfile.quality > 0) != COUNT(*)
+       ) as Foo
     ) as Bar
Index: trunk/ippTools/share/flatcorr_pending.sql
===================================================================
--- trunk/ippTools/share/flatcorr_pending.sql	(revision 23687)
+++ trunk/ippTools/share/flatcorr_pending.sql	(revision 23688)
@@ -1,3 +1,3 @@
-SELECT 
+SELECT
     *
 FROM
@@ -21,4 +21,4 @@
 HAVING
     COUNT(rawImfile.class_id) = COUNT(chipProcessedImfile.class_id)
-    AND SUM(chipProcessedImfile.fault) = 0
+    AND SUM(chipProcessedImfile.fault > 0) = 0
 
Index: trunk/ippTools/share/magicdstool_completed_runs.sql
===================================================================
--- trunk/ippTools/share/magicdstool_completed_runs.sql	(revision 23687)
+++ trunk/ippTools/share/magicdstool_completed_runs.sql	(revision 23688)
@@ -4,5 +4,5 @@
     (
 -- raw stage
-SELECT 
+SELECT
     magicDSRun.magic_ds_id
     FROM magicDSRun
@@ -22,5 +22,5 @@
 UNION
 -- chip stage
-SELECT 
+SELECT
     magicDSRun.magic_ds_id
     FROM magicDSRun
@@ -40,5 +40,5 @@
 UNION
 -- warp stage
-SELECT 
+SELECT
     magicDSRun.magic_ds_id
     FROM magicDSRun
@@ -51,5 +51,5 @@
         AND magicDSRun.stage = 'warp'
         AND warpSkyfile.fault = 0
-        AND warpSkyfile.ignored = 0
+        AND warpSkyfile.quality = 0
     GROUP BY
         magicDSRun.magic_ds_id,
@@ -75,4 +75,5 @@
         AND magicDSRun.stage = 'diff'
         AND diffSkyfile.fault = 0
+        AND diffSkyfile.quality = 0
     GROUP BY
         magicDSRun.magic_ds_id,
Index: trunk/ippTools/share/magicdstool_getskycells.sql
===================================================================
--- trunk/ippTools/share/magicdstool_getskycells.sql	(revision 23687)
+++ trunk/ippTools/share/magicdstool_getskycells.sql	(revision 23688)
@@ -21,6 +21,7 @@
     ON warpSkyfile.warp_id = warpSkyCellMap.warp_id
     AND warpSkyfile.skycell_id = warpSkyCellMap.skycell_id
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.quality = 0
 WHERE
     diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0
     AND magic_ds_id = %lld
Index: trunk/ippTools/share/magicdstool_todestreak.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak.sql	(revision 23687)
+++ trunk/ippTools/share/magicdstool_todestreak.sql	(revision 23688)
@@ -61,4 +61,5 @@
     AND chipRun.state = 'full'
     AND chipProcessedImfile.fault = 0
+    AND chipProcessedImfile.quality = 0
     AND magicDSFile.component IS NULL
 UNION
@@ -95,5 +96,5 @@
     AND warpRun.state = 'full'
     AND warpSkyfile.fault = 0
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.quality = 0
     AND magicDSFile.component IS NULL
 UNION
@@ -130,4 +131,5 @@
     AND magicDSRun.stage = 'diff'
     AND diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0
     AND magicDSFile.component IS NULL
 ) as Foo
Index: trunk/ippTools/share/magictool_chipprocessedimfile.sql
===================================================================
--- trunk/ippTools/share/magictool_chipprocessedimfile.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_chipprocessedimfile.sql	(revision 23688)
@@ -26,4 +26,5 @@
     chipRun.state = 'full'
     AND chipProcessedImfile.fault = 0
+    AND chipProcessedImfile.quality = 0
 --   AND magicRun.state = 'full'
 --   AND magicMask.fault = 0
Index: trunk/ippTools/share/magictool_definebyquery.sql
===================================================================
--- trunk/ippTools/share/magictool_definebyquery.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_definebyquery.sql	(revision 23688)
@@ -45,7 +45,8 @@
 WHERE
     diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0
 -- WHERE hook %s
-AND exp_id = 36475
-AND diffRun.label = 'magic_2008-11-12'
+    AND exp_id = 36475
+    AND diffRun.label = 'magic_2008-11-12'
 GROUP BY
     exp_id,
@@ -79,5 +80,5 @@
     JOIN diffRun USING(diff_id)
     WHERE
-        warpSkyfile.ignored = 0
+        warpSkyfile.quality = 0
         -- magicSkycellNums WHERE hook %s
 AND exp_id = 36475
Index: trunk/ippTools/share/magictool_definebyquery_insert.sql
===================================================================
--- trunk/ippTools/share/magictool_definebyquery_insert.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_definebyquery_insert.sql	(revision 23688)
@@ -9,2 +9,3 @@
     diff_id = @DIFF_ID@ -- Update this with the appropriate diff_id
     AND fault = 0
+    AND quality = 0
Index: trunk/ippTools/share/magictool_definebyquery_select_test.sql
===================================================================
--- trunk/ippTools/share/magictool_definebyquery_select_test.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_definebyquery_select_test.sql	(revision 23688)
@@ -25,5 +25,5 @@
     JOIN warpSkyfile USING(warp_id, skycell_id)
     WHERE
-        warpSkyfile.ignored = 0
+        warpSkyfile.quality = 0
         AND warpRun.state = 'full'
     -- INSERT HERE any additional restrictions (e.g., exp_id, warpSkyfile.good_frac)
Index: trunk/ippTools/share/magictool_definebyquery_temp_insert.sql
===================================================================
--- trunk/ippTools/share/magictool_definebyquery_temp_insert.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_definebyquery_temp_insert.sql	(revision 23688)
@@ -20,4 +20,5 @@
 WHERE
     diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0
 -- WHERE hook %s
 GROUP BY
Index: trunk/ippTools/share/magictool_diffskyfile.sql
===================================================================
--- trunk/ippTools/share/magictool_diffskyfile.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_diffskyfile.sql	(revision 23688)
@@ -20,8 +20,9 @@
     ON warpSkyfile.warp_id = warpSkyCellMap.warp_id
     AND warpSkyfile.skycell_id = warpSkyCellMap.skycell_id
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.quality = 0
 WHERE
     diffRun.state = 'full'
     AND diffSkyfile.fault = 0
+    AND diffSkyfile.quality = 0
 --   AND magicRun.state = 'full'
 --   AND magicMask.fault = 0
Index: trunk/ippTools/share/magictool_inputs.sql
===================================================================
--- trunk/ippTools/share/magictool_inputs.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_inputs.sql	(revision 23688)
@@ -10,4 +10,5 @@
     diffSkyfile.path_base,
     diffSkyfile.fault
+    diffSkyfile.quality
 FROM magicRun
 JOIN magicInputSkyfile
@@ -35,2 +36,3 @@
 WHERE
     fault = 0
+    AND quality = 0
Index: trunk/ippTools/share/magictool_warpskyfile.sql
===================================================================
--- trunk/ippTools/share/magictool_warpskyfile.sql	(revision 23687)
+++ trunk/ippTools/share/magictool_warpskyfile.sql	(revision 23688)
@@ -21,4 +21,5 @@
     warpRun.state = 'full'
     AND warpSkyfile.fault = 0
+    AND warpSkyfile.quality = 0
 --   AND magicRun.state = 'full'
 --   AND magicMask.fault = 0
Index: trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_create_tables.sql	(revision 23687)
+++ trunk/ippTools/share/pxadmin_create_tables.sql	(revision 23688)
@@ -18,6 +18,6 @@
     epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     PRIMARY KEY(exp_name, camera, telescope),
-    KEY(fault))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    KEY(fault)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE summitImfile (
@@ -34,7 +34,6 @@
     PRIMARY KEY(exp_name, camera, telescope, class, class_id),
     KEY(file_id),
-    FOREIGN KEY (exp_name, camera, telescope)
-        REFERENCES  summitExp(exp_name, camera, telescope))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_name, camera, telescope) REFERENCES summitExp(exp_name, camera, telescope)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE pzDownloadExp (
@@ -46,7 +45,6 @@
     PRIMARY KEY(exp_name, camera, telescope),
     KEY(state),
-    FOREIGN KEY (exp_name, camera, telescope)
-        REFERENCES  summitExp(exp_name, camera, telescope))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_name, camera, telescope) REFERENCES summitExp(exp_name, camera, telescope)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE pzDownloadImfile (
@@ -62,8 +60,7 @@
     PRIMARY KEY(exp_name, camera, telescope, class, class_id),
     KEY(fault),
-    FOREIGN KEY (exp_name, camera, telescope)
-        REFERENCES  pzDownloadExp(exp_name, camera, telescope),
-    FOREIGN KEY (exp_name, camera, telescope, class, class_id)
-        REFERENCES  summitImfile(exp_name, camera, telescope, class, class_id)) ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY (exp_name, camera, telescope) REFERENCES pzDownloadExp(exp_name, camera, telescope),
+    FOREIGN KEY(exp_name, camera, telescope, class, class_id) REFERENCES summitImfile(exp_name, camera, telescope, class, class_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE newExp (
@@ -98,7 +95,6 @@
     epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     PRIMARY KEY(exp_id, tmp_class_id),
-    FOREIGN KEY (exp_id)
-        REFERENCES  newExp(exp_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_id) REFERENCES newExp(exp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE rawExp (
@@ -172,7 +168,6 @@
     KEY(end_stage),
     KEY(fault),
-    FOREIGN KEY (exp_id)
-        REFERENCES  newExp(exp_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_id) REFERENCES newExp(exp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE rawImfile (
@@ -237,4 +232,5 @@
     ignored TINYINT DEFAULT 0,
     hostname VARCHAR(64),
+    quality SMALLINT NOT NULL DEFAULT 0,
     fault SMALLINT NOT NULL,
     epoch TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -245,10 +241,8 @@
     KEY(fault),
     KEY(raw_image_id),
+    KEY(quality),
     UNIQUE KEY(exp_id, tmp_class_id),
-    FOREIGN KEY (exp_id, tmp_class_id)
-        REFERENCES newImfile(exp_id, tmp_class_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
-
-CREATE TABLE guidePendingExp (guide_id BIGINT AUTO_INCREMENT, exp_id BIGINT, recipe VARCHAR(64), PRIMARY KEY(guide_id), KEY(guide_id), KEY(exp_id)) ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_id, tmp_class_id) REFERENCES newImfile(exp_id, tmp_class_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE chipRun (
@@ -273,7 +267,6 @@
     KEY(end_stage),
     INDEX(chip_id, exp_id),
-    FOREIGN KEY (exp_id)
-        REFERENCES rawExp(exp_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(exp_id) REFERENCES rawExp(exp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE chipImfile (
@@ -283,6 +276,6 @@
     PRIMARY KEY(chip_id, class_id),
     KEY(chip_imfile_id),
-    FOREIGN KEY (chip_id) REFERENCES  chipRun(chip_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE chipProcessedImfile (
@@ -343,4 +336,5 @@
     n_cr INT,
     path_base VARCHAR(255),
+    quality SMALLINT NOT NULL DEFAULT 0,
     fault SMALLINT NOT NULL,
     magicked BIGINT,
@@ -348,14 +342,13 @@
     KEY(data_state),
     KEY(fault),
-    FOREIGN KEY (chip_id, exp_id)
-        REFERENCES  chipRun(chip_id, exp_id),
-    FOREIGN KEY (exp_id, class_id)
-        REFERENCES  rawImfile(exp_id, class_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    KEY(quality),
+    FOREIGN KEY(chip_id, exp_id) REFERENCES chipRun(chip_id, exp_id),
+    FOREIGN KEY(exp_id, class_id) REFERENCES rawImfile(exp_id, class_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE chipMask (
     label VARCHAR(64),
-    PRIMARY KEY(label))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    PRIMARY KEY(label)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE camRun (
@@ -380,7 +373,6 @@
     KEY(end_stage),
     INDEX(cam_id, chip_id),
-    FOREIGN KEY (chip_id)
-        REFERENCES chipRun(chip_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE camProcessedExp (
@@ -444,15 +436,16 @@
     n_astrom INT,
     path_base VARCHAR(255),
+    quality SMALLINT NOT NULL DEFAULT 0,
     fault SMALLINT NOT NULL,
     PRIMARY KEY(cam_id),
     KEY(fault),
-    FOREIGN KEY (cam_id)
-        REFERENCES camRun(cam_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    KEY(quality),
+    FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE camMask (
     label VARCHAR(64),
-    PRIMARY KEY(label))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    PRIMARY KEY(label)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE fakeRun (
@@ -475,7 +468,6 @@
     KEY(end_stage),
     INDEX(fake_id, cam_id),
-    FOREIGN KEY (cam_id)
-        REFERENCES camRun(cam_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE fakeProcessedImfile (
@@ -493,14 +485,12 @@
     PRIMARY KEY(fake_id, exp_id, class_id),
     KEY(fault),
-    FOREIGN KEY (fake_id)
-        REFERENCES fakeRun(fake_id),
-    FOREIGN KEY (exp_id, class_id)
-        REFERENCES rawImfile(exp_id, class_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(fake_id) REFERENCES fakeRun(fake_id),
+    FOREIGN KEY(exp_id, class_id) REFERENCES rawImfile(exp_id, class_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE fakeMask (
     label VARCHAR(64),
-    PRIMARY KEY(label))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    PRIMARY KEY(label)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE detRun (
@@ -535,5 +525,4 @@
     ref_det_id BIGINT,
     ref_iter INT,
-    -- parent INT, :: dropping this
     PRIMARY KEY(det_id),
     KEY(det_id),
@@ -543,21 +532,18 @@
     KEY(state),
     KEY(label),
-    -- KEY(parent), :: dropping this
-    INDEX(det_id, iteration))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    INDEX(det_id, iteration)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE detInputExp (
-det_id BIGINT,
-iteration INT,
-exp_id BIGINT,
-include TINYINT,
-PRIMARY KEY(det_id, iteration, exp_id),
-INDEX(det_id, exp_id),
-INDEX(det_id, iteration),
-FOREIGN KEY (det_id)
-REFERENCES  detRun(det_id),
-FOREIGN KEY (exp_id)
-REFERENCES  rawExp(exp_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    det_id BIGINT,
+    iteration INT,
+    exp_id BIGINT,
+    include TINYINT,
+    PRIMARY KEY(det_id, iteration, exp_id),
+    INDEX(det_id, exp_id),
+    INDEX(det_id, iteration),
+    FOREIGN KEY(det_id) REFERENCES detRun(det_id),
+    FOREIGN KEY(exp_id) REFERENCES rawExp(exp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE detProcessedImfile (
@@ -585,8 +571,6 @@
     INDEX(det_id, class_id),
     INDEX(det_id, exp_id),
-    FOREIGN KEY (det_id, exp_id)
-        REFERENCES  detInputExp(det_id, exp_id),
-    FOREIGN KEY (exp_id, class_id)
-        REFERENCES  rawImfile(exp_id, class_id)
+    FOREIGN KEY(det_id, exp_id) REFERENCES detInputExp(det_id, exp_id),
+    FOREIGN KEY(exp_id, class_id) REFERENCES rawImfile(exp_id, class_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -611,8 +595,6 @@
     PRIMARY KEY(det_id, exp_id),
     KEY(fault),
-    FOREIGN KEY (det_id, exp_id)
-        REFERENCES  detInputExp(det_id, exp_id),
-    FOREIGN KEY (det_id, exp_id)
-        REFERENCES  detProcessedImfile(det_id, exp_id)
+    FOREIGN KEY(det_id, exp_id) REFERENCES detInputExp(det_id, exp_id),
+    FOREIGN KEY(det_id, exp_id) REFERENCES detProcessedImfile(det_id, exp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -635,8 +617,6 @@
     PRIMARY KEY(det_id, iteration, class_id),
     KEY(fault),
-    FOREIGN KEY (det_id, iteration)
-        REFERENCES  detInputExp(det_id, iteration),
-    FOREIGN KEY (det_id, class_id)
-        REFERENCES  detProcessedImfile(det_id, class_id)
+    FOREIGN KEY(det_id, iteration) REFERENCES detInputExp(det_id, iteration),
+    FOREIGN KEY(det_id, class_id) REFERENCES detProcessedImfile(det_id, class_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -650,8 +630,6 @@
     PRIMARY KEY(det_id, iteration, class_id),
     KEY(fault),
-    FOREIGN KEY (det_id, iteration)
-    REFERENCES  detInputExp(det_id, iteration),
-    FOREIGN KEY (det_id, iteration, class_id)
-    REFERENCES  detStackedImfile(det_id, iteration, class_id)
+    FOREIGN KEY(det_id, iteration) REFERENCES detInputExp(det_id, iteration),
+    FOREIGN KEY(det_id, iteration, class_id) REFERENCES  detStackedImfile(det_id, iteration, class_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -675,8 +653,6 @@
     KEY(fault),
     INDEX(det_id, iteration),
-    FOREIGN KEY (det_id)
-    REFERENCES  detInputExp(det_id),
-    FOREIGN KEY (det_id, iteration, class_id)
-    REFERENCES  detNormalizedStatImfile(det_id, iteration, class_id)
+    FOREIGN KEY(det_id) REFERENCES detInputExp(det_id),
+    FOREIGN KEY(det_id, iteration, class_id) REFERENCES detNormalizedStatImfile(det_id, iteration, class_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -698,8 +674,6 @@
     PRIMARY KEY(det_id, iteration),
     KEY(fault),
-    FOREIGN KEY (det_id, iteration)
-    REFERENCES  detInputExp(det_id, iteration),
-    FOREIGN KEY (det_id, iteration)
-    REFERENCES  detNormalizedImfile(det_id, iteration)
+    FOREIGN KEY(det_id, iteration) REFERENCES detInputExp(det_id, iteration),
+    FOREIGN KEY(det_id, iteration) REFERENCES detNormalizedImfile(det_id, iteration)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -736,8 +710,6 @@
     KEY(fault),
     INDEX(det_id, iteration, exp_id),
-    FOREIGN KEY (det_id, iteration, exp_id)
-    REFERENCES  detInputExp(det_id, iteration, exp_id),
-    FOREIGN KEY (det_id, exp_id, class_id)
-    REFERENCES  detProcessedImfile(det_id, exp_id, class_id)
+    FOREIGN KEY (det_id, iteration, exp_id) REFERENCES detInputExp(det_id, iteration, exp_id),
+    FOREIGN KEY (det_id, exp_id, class_id) REFERENCES detProcessedImfile(det_id, exp_id, class_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -771,8 +743,6 @@
        KEY(fault),
        INDEX(det_id, iteration),
-       FOREIGN KEY (det_id, iteration, exp_id)
-       REFERENCES  detInputExp(det_id, iteration, exp_id),
-       FOREIGN KEY (det_id, iteration, exp_id)
-       REFERENCES  detResidImfile(det_id, iteration, exp_id)
+       FOREIGN KEY(det_id, iteration, exp_id) REFERENCES detInputExp(det_id, iteration, exp_id),
+       FOREIGN KEY(det_id, iteration, exp_id) REFERENCES detResidImfile(det_id, iteration, exp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -788,8 +758,6 @@
        PRIMARY KEY(det_id, iteration),
        KEY(fault),
-       FOREIGN KEY (det_id, iteration)
-         REFERENCES  detInputExp(det_id, iteration),
-       FOREIGN KEY (det_id, iteration)
-         REFERENCES  detResidExp(det_id, iteration)
+       FOREIGN KEY(det_id, iteration) REFERENCES detInputExp(det_id, iteration),
+       FOREIGN KEY(det_id, iteration) REFERENCES detResidExp(det_id, iteration)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -812,6 +780,5 @@
        PRIMARY KEY(det_id, iteration, class_id),
        KEY(fault),
-       FOREIGN KEY (det_id, iteration)
-         REFERENCES  detRun(det_id, iteration)
+       FOREIGN KEY(det_id, iteration) REFERENCES detRun(det_id, iteration)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -838,6 +805,5 @@
     KEY(end_stage),
     INDEX(warp_id, fake_id),
-    FOREIGN KEY (fake_id)
-        REFERENCES fakeRun(fake_id)
+    FOREIGN KEY(fake_id) REFERENCES fakeRun(fake_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -850,6 +816,5 @@
     PRIMARY KEY(warp_id, skycell_id, tess_id, class_id),
     KEY(fault),
-    FOREIGN KEY (warp_id)
-        REFERENCES warpRun(warp_id)
+    FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -860,6 +825,6 @@
     PRIMARY KEY(warp_id, skycell_id),
     KEY(warp_skyfile_id),
-    FOREIGN KEY (warp_id) REFERENCES  warpRun(warp_id))
-ENGINE=innodb DEFAULT CHARSET=latin1;
+    FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 
@@ -881,12 +846,12 @@
     ymin INT,
     ymax INT,
-    ignored TINYINT,
+    quality SMALLINT NOT NULL DEFAULT 0,
     fault SMALLINT,
     magicked TINYINT,
     PRIMARY KEY(warp_id, skycell_id, tess_id),
     KEY(good_frac),
-    KEY(ignored), KEY(fault),
-    FOREIGN KEY (warp_id, skycell_id, tess_id)
-        REFERENCES warpSkyCellMap(warp_id, skycell_id, tess_id)
+    KEY(fault),
+    KEY(quality),
+    FOREIGN KEY(warp_id, skycell_id, tess_id) REFERENCES warpSkyCellMap(warp_id, skycell_id, tess_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -918,6 +883,6 @@
         warp_id BIGINT,
         PRIMARY KEY(stack_id, warp_id),
-        FOREIGN KEY (stack_id)  REFERENCES  stackRun(stack_id),
-        FOREIGN KEY (warp_id)  REFERENCES  warpSkyfile(warp_id)
+        FOREIGN KEY(stack_id) REFERENCES stackRun(stack_id),
+        FOREIGN KEY(warp_id) REFERENCES warpSkyfile(warp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -948,4 +913,5 @@
         hostname VARCHAR(64),
         good_frac FLOAT,
+        quality SMALLINT NOT NULL DEFAULT 0,
         fault SMALLINT,
         PRIMARY KEY(stack_id),
@@ -953,5 +919,6 @@
         KEY(good_frac),
         KEY(fault),
-        FOREIGN KEY (stack_id)  REFERENCES  stackRun(stack_id)
+        KEY(quality),
+        FOREIGN KEY(stack_id) REFERENCES stackRun(stack_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -971,5 +938,5 @@
         KEY(state),
         KEY(tess_id),
-        FOREIGN KEY (exp_id) REFERENCES rawExp(exp_id)
+        FOREIGN KEY(exp_id) REFERENCES rawExp(exp_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -991,9 +958,9 @@
         KEY(skycell_id),
         KEY(tess_id),
-        FOREIGN KEY (diff_id)  REFERENCES  diffRun(diff_id),
-        FOREIGN KEY (warp1, skycell_id, tess_id)  REFERENCES  warpSkyfile(warp_id, skycell_id, tess_id),
-        FOREIGN KEY (warp2, skycell_id, tess_id)  REFERENCES  warpSkyfile(warp_id, skycell_id, tess_id),
-        FOREIGN KEY (stack1)  REFERENCES  stackSumSkyfile(stack_id),
-        FOREIGN KEY (stack2)  REFERENCES  stackSumSkyfile(stack_id)
+        FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id),
+        FOREIGN KEY(warp1, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id),
+        FOREIGN KEY(warp2, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id),
+        FOREIGN KEY(stack1) REFERENCES stackSumSkyfile(stack_id),
+        FOREIGN KEY(stack2) REFERENCES stackSumSkyfile(stack_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1022,4 +989,5 @@
         hostname VARCHAR(64),
         good_frac FLOAT,
+        quality SMALLINT NOT NULL DEFAULT 0,
         fault SMALLINT,
         magicked TINYINT,
@@ -1027,5 +995,6 @@
         KEY(good_frac),
         KEY(fault),
-        FOREIGN KEY (diff_id)  REFERENCES  diffRun(diff_id)
+        KEY(quality),
+        FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1047,6 +1016,6 @@
         KEY(label),
         KEY(fault),
-        FOREIGN KEY (exp_id)  REFERENCES rawExp(exp_id),
-        FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id)
+        FOREIGN KEY(exp_id)  REFERENCES rawExp(exp_id),
+        FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1056,6 +1025,6 @@
         node VARCHAR(64),
         PRIMARY KEY(magic_id, diff_id, node),
-        FOREIGN KEY (magic_id)  REFERENCES  magicRun(magic_id),
-        FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id)
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
+        FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1068,5 +1037,5 @@
         KEY(dep),
         INDEX(magic_id, node),
-        FOREIGN KEY (magic_id)  REFERENCES  magicRun(magic_id)
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1077,6 +1046,6 @@
         fault SMALLINT,
         PRIMARY KEY(magic_id, node),
-        FOREIGN KEY (magic_id)  REFERENCES  magicRun(magic_id),
-        FOREIGN KEY (magic_id, node)  REFERENCES  magicTree(magic_id, node),
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
+        FOREIGN KEY(magic_id, node) REFERENCES magicTree(magic_id, node),
         KEY(fault)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1088,5 +1057,5 @@
         fault SMALLINT,
         PRIMARY KEY(magic_id),
-        FOREIGN KEY (magic_id)  REFERENCES  magicRun(magic_id),
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
         KEY(fault)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
@@ -1109,5 +1078,5 @@
         KEY(magic_id),
         KEY(label),
-        FOREIGN KEY (magic_id)  REFERENCES  magicRun(magic_id)
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1120,5 +1089,5 @@
     PRIMARY KEY(magic_ds_id, component),
     KEY(fault),
-    FOREIGN KEY (magic_ds_id) REFERENCES magicDSRun(magic_ds_id)
+    FOREIGN KEY(magic_ds_id) REFERENCES magicDSRun(magic_ds_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1139,5 +1108,5 @@
         KEY(cal_id),
         KEY(last_step),
-        FOREIGN KEY (cal_id)  REFERENCES  calDB(cal_id)
+        FOREIGN KEY(cal_id) REFERENCES calDB(cal_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1167,6 +1136,6 @@
         include TINYINT,
         PRIMARY KEY(corr_id, chip_id),
-        FOREIGN KEY (corr_id)  REFERENCES  flatcorrRun(corr_id),
-        FOREIGN KEY (chip_id)  REFERENCES  chipRun(chip_id)
+        FOREIGN KEY(corr_id) REFERENCES flatcorrRun(corr_id),
+        FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1177,7 +1146,7 @@
         include TINYINT,
         PRIMARY KEY(corr_id, cam_id),
-        FOREIGN KEY (corr_id)  REFERENCES  flatcorrRun(corr_id),
-        FOREIGN KEY (chip_id)  REFERENCES  chipRun(chip_id),
-        FOREIGN KEY (cam_id)  REFERENCES  camRun(cam_id)
+        FOREIGN KEY(corr_id) REFERENCES flatcorrRun(corr_id),
+        FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id),
+        FOREIGN KEY(cam_id) REFERENCES camRun(cam_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1231,9 +1200,9 @@
         PRIMARY KEY(job_id, req_id),
         KEY(job_id),
-        FOREIGN KEY (req_id)  REFERENCES  pstampRequest(req_id)
+        FOREIGN KEY(req_id) REFERENCES pstampRequest(req_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
 CREATE TABLE distTarget (
-    target_id   BIGINT AUTO_INCREMENT, 
+    target_id   BIGINT AUTO_INCREMENT,
     obs_mode    VARCHAR(64),
     stage       VARCHAR(64),
@@ -1263,5 +1232,5 @@
 
 CREATE TABLE distComponent (
-    dist_id     BIGINT, 
+    dist_id     BIGINT,
     component   VARCHAR(64),
     bytes       INT,
@@ -1335,4 +1304,4 @@
 
 
--- This comment line is here to avoid empty query error. 
+-- This comment line is here to avoid empty query error.
 -- Another way to avoid that problem is to omit the semicolon above but I think that is untidy.
Index: trunk/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 23687)
+++ trunk/ippTools/share/pxadmin_drop_tables.sql	(revision 23688)
@@ -1,3 +1,4 @@
 SET FOREIGN_KEY_CHECKS=0;
+
 DROP TABLE IF EXISTS pzDataStore;
 DROP TABLE IF EXISTS summitExp;
@@ -9,5 +10,4 @@
 DROP TABLE IF EXISTS rawExp;
 DROP TABLE IF EXISTS rawImfile;
-DROP TABLE IF EXISTS guidePendingExp;
 DROP TABLE IF EXISTS chipRun;
 DROP TABLE IF EXISTS chipProcessedImfile;
Index: trunk/ippTools/share/stacktool_definebyquery_insert.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_insert.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_definebyquery_insert.sql	(revision 23688)
@@ -21,3 +21,3 @@
     AND rawExp.filter = '%s'
     AND warpSkyfile.fault = 0
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.quality = 0
Index: trunk/ippTools/share/stacktool_definebyquery_insert_random_part1.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_insert_random_part1.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_definebyquery_insert_random_part1.sql	(revision 23688)
@@ -28,5 +28,5 @@
         AND rawExp.filter = '%s' -- the result of the query is grouped by filter and inserted for one at a time
         AND warpSkyfile.fault = 0
-        AND warpSkyfile.ignored = 0
+        AND warpSkyfile.quality = 0
 -- Put additional constraints here
 -- stacktool_definebyquery_insert_random_part2.sql goes here
Index: trunk/ippTools/share/stacktool_definebyquery_part1.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_part1.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_definebyquery_part1.sql	(revision 23688)
@@ -17,13 +17,13 @@
         COUNT(warpSkyfile.skycell_id) AS num_warp -- number of warps that can be stacked
     FROM warpRun
-        JOIN warpSkyfile USING(warp_id)
-        JOIN fakeRun USING(fake_id)
-        JOIN camRun USING(cam_id)
-        JOIN chipRun USING(chip_id)
-        JOIN rawExp USING(exp_id)
+    JOIN warpSkyfile USING(warp_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
     WHERE
         warpRun.state = 'full'
-    AND warpSkyfile.ignored = 0
-    AND warpSkyfile.fault = 0
+        AND warpSkyfile.fault = 0
+        AND warpSkyfile.quality = 0
     -- Here should follow the SQL in stacktool_definebyquery_part2.sql,
     -- after any additional WHERE conditions have been added
Index: trunk/ippTools/share/stacktool_definebyquery_test.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_test.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_definebyquery_test.sql	(revision 23688)
@@ -31,5 +31,5 @@
     WHERE
         warpRun.state = 'full'
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.quality = 0
     AND warpSkyfile.fault = 0
     -- Any additional selection on warps/exposures goes here
Index: trunk/ippTools/share/stacktool_find_complete_warps.sql
===================================================================
--- trunk/ippTools/share/stacktool_find_complete_warps.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_find_complete_warps.sql	(revision 23688)
@@ -6,5 +6,5 @@
     COUNT(stackRun.stack_id) AS num_extant
 FROM warpRun
-JOIN warpSkyfile 
+JOIN warpSkyfile
     USING(warp_id)
 JOIN fakeRun
@@ -23,5 +23,6 @@
 WHERE
     warpRun.state = 'full'
-    AND warpSkyfile.ignored = 0
+    AND warpSkyfile.fault = 0
+    AND warpSkyfile.quality = 0
 GROUP BY
     warpSkyfile.skycell_id, stackRun.stack_id
Index: trunk/ippTools/share/stacktool_tosum.sql
===================================================================
--- trunk/ippTools/share/stacktool_tosum.sql	(revision 23687)
+++ trunk/ippTools/share/stacktool_tosum.sql	(revision 23688)
@@ -12,7 +12,4 @@
     USING(stack_id)
 WHERE
-    ((stackRun.state = 'new'
-        AND stackSumSkyfile.stack_id IS NULL)
-    OR
-    (stackRun.state = 'update'
-        AND stackSumSkyfile.fault = 0))
+    ((stackRun.state = 'new' AND stackSumSkyfile.stack_id IS NULL)
+    OR (stackRun.state = 'update' AND stackSumSkyfile.fault = 0 AND stackSumSkyfile.quality = 0))
Index: trunk/ippTools/share/warptool_finished_run_select.sql
===================================================================
--- trunk/ippTools/share/warptool_finished_run_select.sql	(revision 23687)
+++ trunk/ippTools/share/warptool_finished_run_select.sql	(revision 23688)
@@ -19,4 +19,4 @@
    HAVING
        COUNT(warpSkyCellMap.warp_id) = COUNT(warpSkyfile.warp_id)
-       AND SUM(warpSkyfile.fault) = 0
+       AND SUM(warpSkyfile.fault > 0) = 0
  ) as Foo
Index: trunk/ippTools/share/warptool_imfile.sql
===================================================================
--- trunk/ippTools/share/warptool_imfile.sql	(revision 23687)
+++ trunk/ippTools/share/warptool_imfile.sql	(revision 23688)
@@ -26,3 +26,5 @@
     AND camRun.state = 'full'
     AND chipRun.state = 'full'
+    AND chipProcessedImfile.quality = 0
+    and camProcessedExp.quality = 0
 
Index: trunk/ippTools/share/warptool_revertwarped_delete.sql
===================================================================
--- trunk/ippTools/share/warptool_revertwarped_delete.sql	(revision 23687)
+++ trunk/ippTools/share/warptool_revertwarped_delete.sql	(revision 23688)
@@ -7,2 +7,3 @@
     AND chipRun.exp_id = rawExp.exp_id
     AND warpSkyfile.fault != 0
+
Index: trunk/ippTools/src/camtool.c
===================================================================
--- trunk/ippTools/src/camtool.c	(revision 23687)
+++ trunk/ippTools/src/camtool.c	(revision 23688)
@@ -468,5 +468,6 @@
 
     PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
 
     // generate restrictions
@@ -533,15 +534,15 @@
         zpt_lq,
         zpt_uq,
-	fwhm_major,
-	fwhm_major_lq,
-	fwhm_major_uq,
-	fwhm_minor,
-	fwhm_minor_lq,
-	fwhm_minor_uq,
-
-	iq_fwhm_major,
-	iq_fwhm_major_err,
-	iq_fwhm_minor,
-	iq_fwhm_minor_err,
+        fwhm_major,
+        fwhm_major_lq,
+        fwhm_major_uq,
+        fwhm_minor,
+        fwhm_minor_lq,
+        fwhm_minor_uq,
+
+        iq_fwhm_major,
+        iq_fwhm_major_err,
+        iq_fwhm_minor,
+        iq_fwhm_minor_err,
 
         iq_m2,
@@ -576,5 +577,6 @@
         n_astrom,
         path_base,
-        code
+        fault,
+        quality
         );
 
@@ -599,7 +601,7 @@
 
     // NULL for end_stage means go as far as possible
-    // EAM : skip here if code != 0
+    // EAM : skip here if fault != 0
     // Also, we can run fake even if tess_id is not defined
-    if (code || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "cam"))) {
+    if (fault || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "cam"))) {
         psFree(row);
         psFree(pendingRow);
@@ -745,5 +747,5 @@
     PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label",          "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction",      "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "camProcessedExp.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "camProcessedExp.fault", "==");
 
     if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
@@ -833,5 +835,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
 
     psMetadata *where = psMetadataAlloc();
@@ -841,5 +843,5 @@
     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
 
-    if (!pxSetFaultCode(config->dbh, "camProcessedExp", where, code)) {
+    if (!pxSetFaultCode(config->dbh, "camProcessedExp", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         psFree (where);
@@ -1114,5 +1116,5 @@
     char sqlFilename[80];
   } ExportTable;
-  
+
   int numExportTables = 2;
 
@@ -1194,5 +1196,5 @@
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
@@ -1205,5 +1207,5 @@
   psAssert (item, "entry not in input?");
   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-  
+
   psMetadataItem *entry = psListGet (item->data.list, 0);
   assert (entry);
@@ -1214,5 +1216,5 @@
   // fprintf (stdout, "---- cam run ----\n");
   // psMetadataPrint (stderr, entry->data.md, 1);
-  
+
   item = psMetadataLookup (input, "camProcessedImfile");
   psAssert (item, "entry not in input?");
Index: trunk/ippTools/src/camtoolConfig.c
===================================================================
--- trunk/ippTools/src/camtoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/camtoolConfig.c	(revision 23688)
@@ -164,5 +164,6 @@
 
     psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-path_base", 0,            "define base output location", NULL);
-    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-quality",  0,            "set quality", 0);
     psMetadataAddBool(addprocessedexpArgs, PS_LIST_TAIL, "-faulted",  0,            "only return imfiles with a fault status set", false);
 
@@ -191,4 +192,5 @@
 
     psMetadataAddBool(revertprocessedexpArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
+    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updateprocessedexp
@@ -199,5 +201,5 @@
     psMetadataAddStr(updateprocessedexpArgs, PS_LIST_TAIL, "-class",  0,            "search by class", NULL);
     psMetadataAddStr(updateprocessedexpArgs, PS_LIST_TAIL, "-class_id",  0,            "search by class ID", NULL);
-    psMetadataAddS16(updateprocessedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code (required)", INT16_MAX);
+    psMetadataAddS16(updateprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code (required)", INT16_MAX);
 
     // -block
Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 23687)
+++ trunk/ippTools/src/chiptool.c	(revision 23688)
@@ -409,14 +409,15 @@
     PXOPT_LOOKUP_F32(dtime_script, config->args,   "-dtime_script", false, false);
     PXOPT_LOOKUP_STR(hostname, config->args,       "-hostname", false, false);
-    PXOPT_LOOKUP_F32(n_stars, config->args,    	   "-n_stars", false, false);
-    PXOPT_LOOKUP_F32(n_psfstars, config->args,	   "-n_psfstars", false, false);
-    PXOPT_LOOKUP_F32(n_iqstars, config->args, 	   "-n_iqstars", false, false);
-    PXOPT_LOOKUP_F32(n_extended, config->args, 	   "-n_extended", false, false);
-    PXOPT_LOOKUP_F32(n_cr, config->args,       	   "-n_cr", false, false);
-    PXOPT_LOOKUP_STR(path_base, config->args,  	   "-path_base", false, false);
-    PXOPT_LOOKUP_BOOL(magicked, config->args,  	   "-magicked", false);
+    PXOPT_LOOKUP_F32(n_stars, config->args,        "-n_stars", false, false);
+    PXOPT_LOOKUP_F32(n_psfstars, config->args,     "-n_psfstars", false, false);
+    PXOPT_LOOKUP_F32(n_iqstars, config->args,      "-n_iqstars", false, false);
+    PXOPT_LOOKUP_F32(n_extended, config->args,     "-n_extended", false, false);
+    PXOPT_LOOKUP_F32(n_cr, config->args,           "-n_cr", false, false);
+    PXOPT_LOOKUP_STR(path_base, config->args,      "-path_base", false, false);
+    PXOPT_LOOKUP_BOOL(magicked, config->args,      "-magicked", false);
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -449,33 +450,33 @@
                                    fwhm_minor_uq,
 
-				   iq_fwhm_major,
-				   iq_fwhm_major_err,
-				   iq_fwhm_minor,
-				   iq_fwhm_minor_err,
-
-				   iq_m2,
-				   iq_m2_err,
-				   iq_m2_lq,
-				   iq_m2_uq,
-
-				   iq_m2c,
-				   iq_m2c_err,
-				   iq_m2c_lq,
-				   iq_m2c_uq,
-
-				   iq_m2s,
-				   iq_m2s_err,
-				   iq_m2s_lq,
-				   iq_m2s_uq,
-
-				   iq_m3,
-				   iq_m3_err,
-				   iq_m3_lq,
-				   iq_m3_uq,
-
-				   iq_m4,
-				   iq_m4_err,
-				   iq_m4_lq,
-				   iq_m4_uq,
+                                   iq_fwhm_major,
+                                   iq_fwhm_major_err,
+                                   iq_fwhm_minor,
+                                   iq_fwhm_minor_err,
+
+                                   iq_m2,
+                                   iq_m2_err,
+                                   iq_m2_lq,
+                                   iq_m2_uq,
+
+                                   iq_m2c,
+                                   iq_m2c_err,
+                                   iq_m2c_lq,
+                                   iq_m2c_uq,
+
+                                   iq_m2s,
+                                   iq_m2s_err,
+                                   iq_m2s_lq,
+                                   iq_m2s_uq,
+
+                                   iq_m3,
+                                   iq_m3_err,
+                                   iq_m3_lq,
+                                   iq_m3_uq,
+
+                                   iq_m4,
+                                   iq_m4_err,
+                                   iq_m4_lq,
+                                   iq_m4_uq,
 
                                    dtime_detrend,
@@ -490,5 +491,6 @@
                                    n_cr,
                                    path_base,
-                                   code,
+                                   fault,
+                                   quality,
                                    magicked
             )) {
@@ -618,5 +620,5 @@
     PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "LIKE");
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "chipProcessedImfile.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "chipProcessedImfile.fault", "==");
 
     if (!psListLength(where->list)
@@ -659,7 +661,7 @@
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
-
-    if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, code)) {
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
+
+    if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         return false;
@@ -1280,5 +1282,5 @@
     char sqlFilename[80];
   } ExportTable;
-  
+
   int numExportTables = 3;
 
@@ -1360,11 +1362,11 @@
 {
   unsigned int nFail;
-  
+
   int numImportTables = 2;
- 
+
   char tables[2] [80] = {"chipImfile", "chipProcessedImfile"};
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
@@ -1386,10 +1388,10 @@
   // fprintf (stdout, "---- chip run ----\n");
   // psMetadataPrint (stderr, entry->data.md, 1);
-  
+
   for (int i = 0; i < numImportTables; i++) {
     psMetadataItem *item = psMetadataLookup (input, tables[i]);
     psAssert (item, "entry not in input?");
     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-  
+
     switch (i) {
       case 0:
@@ -1405,5 +1407,5 @@
         }
         break;
-        
+
       case 1:
         for (int i = 0; i < item->data.list->n; i++) {
Index: trunk/ippTools/src/chiptoolConfig.c
===================================================================
--- trunk/ippTools/src/chiptoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/chiptoolConfig.c	(revision 23688)
@@ -146,5 +146,6 @@
 
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
-    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-quality",  0,            "set quality", 0);
     psMetadataAddBool(addprocessedimfileArgs, PS_LIST_TAIL, "-magicked",  0,        "define magicked status", false);
 
@@ -171,5 +172,5 @@
     pxchipSetSearchArgs(revertprocessedimfileArgs);
     psMetadataAddBool(revertprocessedimfileArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
-    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updateprocessedimfile
@@ -177,5 +178,5 @@
     psMetadataAddS64(updateprocessedimfileArgs, PS_LIST_TAIL, "-chip_id",  0,            "search by chip ID", 0);
     psMetadataAddStr(updateprocessedimfileArgs,  PS_LIST_TAIL, "-class_id",           0, "search by class ID", NULL);
-    psMetadataAddS16(updateprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code (required)", 0);
+    psMetadataAddS16(updateprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code (required)", 0);
 
     // -advanceexp
Index: trunk/ippTools/src/dettoolConfig.c
===================================================================
--- trunk/ippTools/src/dettoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/dettoolConfig.c	(revision 23688)
@@ -254,5 +254,5 @@
     psMetadataAddS64(addprocessedimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "define exp ID (required)", 0);
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "define class ID (required)", NULL);
-    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-uri",  0,            "define URI", NULL);
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-recip",  0,            "define recipe", NULL);
@@ -287,5 +287,5 @@
     psMetadataAddS64(revertprocessedimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by exposure ID", 0);
     psMetadataAddStr(revertprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "search by class ID", NULL);
-    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updateprocessedimfile
@@ -334,5 +334,5 @@
     psMetadataAddF64(addprocessedexpArgs, PS_LIST_TAIL, "-user_5",  0,            "define user statistic (5)", NAN);
     psMetadataAddStr(addprocessedexpArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
-    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
 
     // -proccessedexp
@@ -348,5 +348,5 @@
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-det_id",  0,            "search by detrend ID (required)", 0);
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by exposure ID", 0);
-    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updateprocessedexp
@@ -380,5 +380,5 @@
     psMetadataAddS32(addstackedArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number (required)", 0);
     psMetadataAddStr(addstackedArgs, PS_LIST_TAIL, "-class_id",  0,            "define class ID (required)", NULL);
-    psMetadataAddS16(addstackedArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addstackedArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddStr(addstackedArgs, PS_LIST_TAIL, "-uri",  0,            "define URI", NULL);
     psMetadataAddStr(addstackedArgs, PS_LIST_TAIL, "-recip",  0,            "define recipe", NULL);
@@ -407,5 +407,5 @@
     psMetadataAddS32(revertstackedArgs, PS_LIST_TAIL, "-iteration",  0,            "search by iteration number", 0);
     psMetadataAddStr(revertstackedArgs, PS_LIST_TAIL, "-class_id",  0,            "search by class ID", NULL);
-    psMetadataAddS16(revertstackedArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertstackedArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updatestacked
@@ -443,5 +443,5 @@
     psMetadataAddStr(addnormstatArgs, PS_LIST_TAIL, "-class_id",  0,            "define class ID (required)", NULL);
     psMetadataAddF32(addnormstatArgs, PS_LIST_TAIL, "-norm",  0,            "define normal value (required)", NAN);
-    psMetadataAddS16(addnormstatArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addnormstatArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
 
     // -normalizedstat
@@ -459,5 +459,5 @@
     psMetadataAddS32(revertnormalizedstatArgs, PS_LIST_TAIL, "-iteration",  0,            "search by iteration number", 0);
     psMetadataAddStr(revertnormalizedstatArgs, PS_LIST_TAIL, "-class_id",  0,            "search by class ID", NULL);
-    psMetadataAddS16(revertnormalizedstatArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertnormalizedstatArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updatenormalizedstat
@@ -494,5 +494,5 @@
     psMetadataAddS32(addnormalizedimfileArgs, PS_LIST_TAIL, "-iteration", 0,            "define iteration number", 0);
     psMetadataAddStr(addnormalizedimfileArgs, PS_LIST_TAIL, "-class_id", 0,            "define class ID (required)", NULL);
-    psMetadataAddS16(addnormalizedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addnormalizedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddStr(addnormalizedimfileArgs, PS_LIST_TAIL, "-uri", 0,            "define URI", NULL);
     psMetadataAddF64(addnormalizedimfileArgs, PS_LIST_TAIL, "-bg", 0,            "define exposure background", NAN);
@@ -521,5 +521,5 @@
     psMetadataAddS32(revertnormalizedimfileArgs, PS_LIST_TAIL, "-iteration", 0,            "search by iteration number", 0);
     psMetadataAddStr(revertnormalizedimfileArgs, PS_LIST_TAIL, "-class_id", 0,            "search by class ID", NULL);
-    psMetadataAddS16(revertnormalizedimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertnormalizedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updatenormalizedimfile
@@ -555,5 +555,5 @@
     psMetadataAddS64(addnormalizedexpArgs, PS_LIST_TAIL, "-det_id",  0,            "define detrend ID (required)", 0);
     psMetadataAddS32(addnormalizedexpArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
-    psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-recip",  0,            "search for recipe", NULL);
     psMetadataAddF64(addnormalizedexpArgs, PS_LIST_TAIL, "-bg",  0,            "define exposure background", NAN);
@@ -580,5 +580,5 @@
     psMetadataAddS64(revertnormalizedexpArgs, PS_LIST_TAIL, "-det_id", 0,            "search by detrend ID (required)", 0);
     psMetadataAddS32(revertnormalizedexpArgs, PS_LIST_TAIL, "-iteration", 0,            "search by iteration number", 0);
-    psMetadataAddS16(revertnormalizedexpArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertnormalizedexpArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updatenormalizedexp
@@ -616,5 +616,5 @@
     psMetadataAddS64(addresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "define detrend ID (required)", 0);
     psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,          "define class ID (required)", NULL);
-    psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-code",  0,              "set fault code", 0);
+    psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-fault",  0,              "set fault code", 0);
     psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri",  0,               "define resid file URI", NULL);
     psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-recip",  0,             "define recipe", NULL);
@@ -658,5 +658,5 @@
     psMetadataAddS64(revertresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,         "search by detrend ID", 0);
     psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,       "search for class ID", NULL);
-    psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-code",  0,           "search by fault code", 0);
+    psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-fault",  0,           "search by fault code", 0);
 
     // -updateresidimfile
@@ -696,5 +696,5 @@
     psMetadataAddS32(addresidexpArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
     psMetadataAddS64(addresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "define detrend ID (required)", 0);
-    psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-recip",  0,            "define recipe", NULL);
     psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-bg",  0,            "define exposure background", NAN);
@@ -734,5 +734,5 @@
     psMetadataAddS32(revertresidexpArgs, PS_LIST_TAIL, "-iteration", 0,            "search by iteration number", 0);
     psMetadataAddS64(revertresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by detrend ID", 0);
-    psMetadataAddS16(revertresidexpArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertresidexpArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updateresidexp
@@ -777,5 +777,5 @@
     psMetadataAddF64(adddetrunsummaryArgs, PS_LIST_TAIL, "-bg_stdev",  0,            "define exposure background stdev", NAN);
     psMetadataAddF64(adddetrunsummaryArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,            "define exposure background mean stdev", NAN);
-    psMetadataAddS16(adddetrunsummaryArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(adddetrunsummaryArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddBool(adddetrunsummaryArgs, PS_LIST_TAIL, "-accept",  0,            "declare that this detrun iteration is accepted as a master", false);
     psMetadataAddBool(adddetrunsummaryArgs, PS_LIST_TAIL, "-again",  0,            "start a new iteration of this detrend run", false);
@@ -794,5 +794,5 @@
     psMetadataAddS64(revertdetrunsummaryArgs, PS_LIST_TAIL, "-det_id", 0,            "search by detrend ID (required)", 0);
     psMetadataAddS32(revertdetrunsummaryArgs, PS_LIST_TAIL, "-iteration", 0,            "search by iteration number", 0);
-    psMetadataAddS16(revertdetrunsummaryArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertdetrunsummaryArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -updatedetrunsummary
@@ -886,9 +886,9 @@
     PXOPT_ADD_MODE("-input",           "", DETTOOL_MODE_INPUT,         inputArgs);
 
-    PXOPT_ADD_MODE("-toprocessedimfile", "",  		  DETTOOL_MODE_TOPROCESSEDIMFILE, toprocessedimfileArgs);
-    PXOPT_ADD_MODE("-addprocessedimfile", "", 		  DETTOOL_MODE_ADDPROCESSEDIMFILE,  addprocessedimfileArgs);
-    PXOPT_ADD_MODE("-processedimfile", "",    		  DETTOOL_MODE_PROCESSEDIMFILE, processedimfileArgs);
-    PXOPT_ADD_MODE("-revertprocessedimfile", "", 	  DETTOOL_MODE_REVERTPROCESSEDIMFILE, revertprocessedimfileArgs);
-    PXOPT_ADD_MODE("-updateprocessedimfile", "", 	  DETTOOL_MODE_UPDATEPROCESSEDIMFILE, updateprocessedimfileArgs);
+    PXOPT_ADD_MODE("-toprocessedimfile", "",              DETTOOL_MODE_TOPROCESSEDIMFILE, toprocessedimfileArgs);
+    PXOPT_ADD_MODE("-addprocessedimfile", "",             DETTOOL_MODE_ADDPROCESSEDIMFILE,  addprocessedimfileArgs);
+    PXOPT_ADD_MODE("-processedimfile", "",                DETTOOL_MODE_PROCESSEDIMFILE, processedimfileArgs);
+    PXOPT_ADD_MODE("-revertprocessedimfile", "",          DETTOOL_MODE_REVERTPROCESSEDIMFILE, revertprocessedimfileArgs);
+    PXOPT_ADD_MODE("-updateprocessedimfile", "",          DETTOOL_MODE_UPDATEPROCESSEDIMFILE, updateprocessedimfileArgs);
     PXOPT_ADD_MODE("-pendingcleanup_processedimfile", "", DETTOOL_MODE_PENDINGCLEANUP_PROCESSEDIMFILE, pendingcleanup_processedimfileArgs);
     PXOPT_ADD_MODE("-donecleanup_processedimfile", "",    DETTOOL_MODE_DONECLEANUP_PROCESSEDIMFILE, donecleanup_processedimfileArgs);
Index: trunk/ippTools/src/dettool_detrunsummary.c
===================================================================
--- trunk/ippTools/src/dettool_detrunsummary.c	(revision 23687)
+++ trunk/ippTools/src/dettool_detrunsummary.c	(revision 23688)
@@ -101,5 +101,5 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
 
@@ -107,10 +107,10 @@
             det_id,
             iteration,
-	    "full",
+            "full",
             bg,
             bg_stdev,
             bg_mean_stdev,
             accept,
-            code
+            fault
         );
 }
@@ -120,5 +120,5 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-    
+
     // build a query to search by det_id, iteration, exp_id
     psMetadata *where = psMetadataAlloc();
@@ -129,6 +129,6 @@
     PXOPT_LOOKUP_BOOL(again, config->args, "-again", false);
 
-    // The values supplied as arguments on the command (eg, -bg) are parsed 
-    // by mdToDetRunSummary below. 
+    // The values supplied as arguments on the command (eg, -bg) are parsed
+    // by mdToDetRunSummary below.
     // XXX why is there ever more than one?
 
@@ -141,6 +141,6 @@
     if (psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-	psStringAppend(&query, " WHERE %s", whereClause);
-	psFree(whereClause);
+        psStringAppend(&query, " WHERE %s", whereClause);
+        psFree(whereClause);
     }
     psFree(where);
@@ -199,6 +199,6 @@
     psFree(output);
 
-    // XXX this logic does not deal with the case of -code being set
-    // XXX it should be an error for -again and -code to both be set
+    // XXX this logic does not deal with the case of -fault being set
+    // XXX it should be an error for -again and -fault to both be set
     if (again) {
         if (!startNewIteration(config, det_id)) {
@@ -306,5 +306,5 @@
     PXOPT_COPY_S64(config->args, where, "-det_id",    "det_id", "==");
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
-    PXOPT_COPY_STR(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_STR(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertdetrunsummary.sql");
@@ -340,5 +340,5 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-    
+
     PXOPT_LOOKUP_S64(det_id, config->args, "-det_id", true, false); // required
     PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
@@ -355,5 +355,5 @@
     }
 
-    char *query = "UPDATE detRunSummary SET accept = %d WHERE det_id = %"PRId64; 
+    char *query = "UPDATE detRunSummary SET accept = %d WHERE det_id = %"PRId64;
     if (!p_psDBRunQueryF(config->dbh, query, accept, det_id)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
Index: trunk/ippTools/src/dettool_normalizedexp.c
===================================================================
--- trunk/ippTools/src/dettool_normalizedexp.c	(revision 23687)
+++ trunk/ippTools/src/dettool_normalizedexp.c	(revision 23688)
@@ -72,9 +72,9 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-    
+
     PXOPT_LOOKUP_S64(det_id, config->args, "-det_id", true, false); // required
     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false); // Required if fault == 0
     PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
     PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
@@ -117,20 +117,20 @@
     // insert the new row into the detProcessedImfile table
     if (!detNormalizedExpInsert(
-	    config->dbh,
-	    det_id,
-	    iteration,
-	    recipe,
-	    bg,
-	    bg_stdev,
-	    bg_mean_stdev,
-	    user_1,
-	    user_2,
-	    user_3,
-	    user_4,
-	    user_5,
-	    path_base,
-	    "full",
-	    code
-	    )) {
+            config->dbh,
+            det_id,
+            iteration,
+            recipe,
+            bg,
+            bg_stdev,
+            bg_mean_stdev,
+            user_1,
+            user_2,
+            user_3,
+            user_4,
+            user_5,
+            path_base,
+            "full",
+            fault
+            )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -221,5 +221,5 @@
     PXOPT_COPY_S64(config->args, where, "-det_id",    "det_id", "==");
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertnormalizedexp.sql");
@@ -260,5 +260,5 @@
 
     if (!setNormExpDataState(config, det_id, iteration, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_normalizedimfile.c
===================================================================
--- trunk/ippTools/src/dettool_normalizedimfile.c	(revision 23687)
+++ trunk/ippTools/src/dettool_normalizedimfile.c	(revision 23688)
@@ -80,8 +80,8 @@
     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    // Required if code == 0
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    // Required if fault == 0
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);
 
     // optional
@@ -97,21 +97,21 @@
 
     if (!detNormalizedImfileInsert(
-	    config->dbh,
-	    det_id,
-	    iteration,
-	    class_id,
-	    uri,
-	    bg,
-	    bg_stdev,
-	    bg_mean_stdev,
-	    user_1,
-	    user_2,
-	    user_3,
-	    user_4,
-	    user_5,
-	    path_base,
-	    "full",
-	    code
-	    )) {
+            config->dbh,
+            det_id,
+            iteration,
+            class_id,
+            uri,
+            bg,
+            bg_stdev,
+            bg_mean_stdev,
+            user_1,
+            user_2,
+            user_3,
+            user_4,
+            user_5,
+            path_base,
+            "full",
+            fault
+            )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -201,5 +201,5 @@
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertnormalizedimfile.sql");
@@ -241,5 +241,5 @@
 
     if (!setNormImfileDataState(config, det_id, iteration, class_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_normalizedstat.c
===================================================================
--- trunk/ippTools/src/dettool_normalizedstat.c	(revision 23687)
+++ trunk/ippTools/src/dettool_normalizedstat.c	(revision 23688)
@@ -83,17 +83,17 @@
     // default
     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(code, config->args, "-fault", false, false);
 
     detNormalizedStatImfileRow *row = detNormalizedStatImfileRowAlloc
-	(det_id,
-	 iteration,
-	 class_id,
-	 norm,
-	 "full",
-	 code);
-									 
+        (det_id,
+         iteration,
+         class_id,
+         norm,
+         "full",
+         code);
+
     if (!detNormalizedStatImfileInsertObject(config->dbh, row)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
     }
 
@@ -181,5 +181,5 @@
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertnormalizedstat.sql");
@@ -221,5 +221,5 @@
 
     if (!setNormStatImfileDataState(config, det_id, iteration, class_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_processedexp.c
===================================================================
--- trunk/ippTools/src/dettool_processedexp.c	(revision 23687)
+++ trunk/ippTools/src/dettool_processedexp.c	(revision 23688)
@@ -80,8 +80,8 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    // Required if code == 0
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    // Required if fault == 0
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false);
 
     // optional
@@ -141,6 +141,6 @@
         user_5,
         path_base,
-	"full",
-        code
+        "full",
+        fault
     );
 
@@ -231,5 +231,5 @@
     PXOPT_COPY_S64(config->args, where, "-det_id", "det_id", "==");
     PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",   "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",   "fault", "==");
 
     psString query = pxDataGet("dettool_revertprocessedexp.sql");
@@ -269,5 +269,5 @@
     PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", true, false);
     if (!setProcessedExpDataState(config, det_id, exp_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_processedimfile.c
===================================================================
--- trunk/ippTools/src/dettool_processedimfile.c	(revision 23687)
+++ trunk/ippTools/src/dettool_processedimfile.c	(revision 23688)
@@ -92,9 +92,9 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    // Required if code == 0
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    // Required if fault == 0
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false);
 
     // optional
@@ -144,6 +144,6 @@
         user_5,
         path_base,
-	"full",
-        code
+        "full",
+        fault
     );
     psFree(rawImfiles);
@@ -190,5 +190,5 @@
         psStringAppend(&query, " %s", whereClause);
         psFree(whereClause);
-	hasWhere = true;
+        hasWhere = true;
     }
     psFree (where);
@@ -196,21 +196,21 @@
     // restrict search to included imfiles
     if (included) {
-	if (hasWhere) {
-	    psStringAppend(&query, " AND detInputExp.include = 1");
-	} else {
-	    psStringAppend(&query, " WHERE detInputExp.include = 1");
-	}
-	hasWhere = true;
+        if (hasWhere) {
+            psStringAppend(&query, " AND detInputExp.include = 1");
+        } else {
+            psStringAppend(&query, " WHERE detInputExp.include = 1");
+        }
+        hasWhere = true;
     }
 
     if (hasWhere) {
-	psStringAppend(&query, " AND");
+        psStringAppend(&query, " AND");
     } else {
-	psStringAppend(&query, " WHERE");
+        psStringAppend(&query, " WHERE");
     }
 
     if (faulted) {
         // list only faulted rows
-	psStringAppend(&query, " %s", " detProcessedImfile.fault != 0");
+        psStringAppend(&query, " %s", " detProcessedImfile.fault != 0");
     } else {
         // don't list faulted rows
@@ -263,5 +263,5 @@
     PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
 
     psString query = pxDataGet("dettool_revertprocessedimfile.sql");
@@ -303,5 +303,5 @@
 
     if (!setProcessedImfileDataState(config, det_id, exp_id, class_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_residexp.c
===================================================================
--- trunk/ippTools/src/dettool_residexp.c	(revision 23687)
+++ trunk/ippTools/src/dettool_residexp.c	(revision 23688)
@@ -95,6 +95,6 @@
     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false); // required
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false); // Required if fault == 0
     PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
     PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
@@ -124,7 +124,7 @@
 
     if (psListLength(where->list)) {
-	psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-	psStringAppend(&query, " WHERE %s", whereClause);
-	psFree(whereClause);
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, " WHERE %s", whereClause);
+        psFree(whereClause);
     }
     psFree(where);
@@ -151,5 +151,5 @@
 
     if (!detResidExpInsert(
-	    config->dbh,
+            config->dbh,
             det_id,
             iteration,
@@ -174,7 +174,7 @@
             user_5,
             path_base,
-	    "full",
+            "full",
             !reject,
-            code
+            fault
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -225,5 +225,5 @@
     if (reject) {
         psStringAppend(&query, " %s", "AND detResidExp.accept != 0");
-    } 
+    }
 
     // treat limit == 0 as "no limit"
@@ -273,5 +273,5 @@
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     PXOPT_COPY_S64(config->args, where, "-exp_id",    "exp_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertresidexp.sql");
@@ -330,5 +330,5 @@
     PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", false, false);
     if (data_state) {
-	if (!isValidDataState (data_state)) return false;
+        if (!isValidDataState (data_state)) return false;
     }
 
Index: trunk/ippTools/src/dettool_residimfile.c
===================================================================
--- trunk/ippTools/src/dettool_residimfile.c	(revision 23687)
+++ trunk/ippTools/src/dettool_residimfile.c	(revision 23688)
@@ -75,5 +75,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    
+
     PXOPT_LOOKUP_S64(det_id, config->args, "-det_id", true, false); // required
     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
@@ -84,7 +84,7 @@
     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false); // required
     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); // Required if code == 0
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false); // Required if fault == 0
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false); // Required if fault == 0
     PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
     PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
@@ -107,5 +107,5 @@
 
     if (!detResidImfileInsert(
-	    config->dbh,
+            config->dbh,
             det_id,
             iteration,
@@ -134,6 +134,6 @@
             user_5,
             path_base,
-	    "full",
-            code
+            "full",
+            fault
     )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -174,5 +174,5 @@
         psStringAppend(&query, " %s", whereClause);
         psFree(whereClause);
-	hasWhere = true;
+        hasWhere = true;
     }
     psFree(where);
@@ -180,16 +180,16 @@
     // restrict search to included imfiles
     if (included) {
-	if (hasWhere) {
-	    psStringAppend(&query, " AND detInputExp.include = 1");
-	} else {
-	    psStringAppend(&query, " WHERE detInputExp.include = 1");
-	}
-	hasWhere = true;
+        if (hasWhere) {
+            psStringAppend(&query, " AND detInputExp.include = 1");
+        } else {
+            psStringAppend(&query, " WHERE detInputExp.include = 1");
+        }
+        hasWhere = true;
     }
 
     if (hasWhere) {
-	psStringAppend(&query, " AND");
+        psStringAppend(&query, " AND");
     } else {
-	psStringAppend(&query, " WHERE");
+        psStringAppend(&query, " WHERE");
     }
 
@@ -249,5 +249,5 @@
     PXOPT_COPY_S64(config->args, where, "-exp_id",  "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertresidimfile.sql");
@@ -289,5 +289,5 @@
     PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", true, false);
     if (!setResidImfileDataState(config, det_id, iteration, exp_id, class_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/dettool_stack.c
===================================================================
--- trunk/ippTools/src/dettool_stack.c	(revision 23687)
+++ trunk/ippTools/src/dettool_stack.c	(revision 23688)
@@ -127,9 +127,9 @@
     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    // Required if code == 0
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
-    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    // Required if fault == 0
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);
+    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (fault == 0), false);
 
     // optional
@@ -188,6 +188,6 @@
             user_4,
             user_5,
-	    "full",
-            code
+            "full",
+            fault
         );
 
@@ -286,5 +286,5 @@
     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",      "fault", "==");
 
     psString query = pxDataGet("dettool_revertstacked.sql");
@@ -326,5 +326,5 @@
 
     if (!setStackedImfileDataState(config, det_id, iteration, class_id, data_state)) {
-	return false;
+        return false;
     }
     return true;
Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 23687)
+++ trunk/ippTools/src/difftool.c	(revision 23688)
@@ -485,7 +485,8 @@
     PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); // required
     PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
-    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", (code == 0), false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);
+    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", (fault == 0), false);
 
     // optional
@@ -540,5 +541,6 @@
                            hostname,
                            good_frac,
-                           code,
+                           fault,
+                           quality,
                            magicked
           )) {
@@ -578,5 +580,5 @@
     PXOPT_COPY_S64(config->args, where,  "-diff_skyfile_id", "diffInputSkyfile.diff_skyfile_id", "==");
     PXOPT_COPY_STR(config->args, where, "-tess_id", "diffSkyfile.tess_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "diffSkyfile.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "diffSkyfile.fault", "==");
     PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "==");
@@ -655,5 +657,5 @@
     PXOPT_COPY_S64(config->args, where,  "-diff_id", "diffSkyfile.diff_id", "==");
     PXOPT_COPY_STR(config->args, where,  "-label", "diffRun.label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",     "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",     "fault", "==");
 
     if (!psDBTransaction(config->dbh)) {
@@ -1269,4 +1271,6 @@
     PXOPT_COPY_S64(config->args, selectWhere, "-exp_id", "inputRawExp.exp_id", "==");
     PXOPT_COPY_STR(config->args, selectWhere, "-filter", "inputRawExp.filter", "==");
+    PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "inputRawExp.obs_mode", "==");
+    PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "templateRawExp.obs_mode", "==");
     PXOPT_COPY_STR(config->args, selectWhere, "-input_label", "inputWarpRun.label", "==");
     PXOPT_COPY_STR(config->args, selectWhere, "-template_label", "templateWarpRun.label", "==");
@@ -1662,10 +1666,10 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
 
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-diff_id",   "diff_id",   "==");
 
-    if (!pxSetFaultCode(config->dbh, "diffSkyfile", where, code)) {
+    if (!pxSetFaultCode(config->dbh, "diffSkyfile", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         psFree (where);
Index: trunk/ippTools/src/difftoolConfig.c
===================================================================
--- trunk/ippTools/src/difftoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/difftoolConfig.c	(revision 23688)
@@ -88,5 +88,6 @@
     psMetadataAddS64(adddiffskyfileArgs, PS_LIST_TAIL, "-diff_id", 0,            "define warp ID (required)", 0);
     psMetadataAddStr(adddiffskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0,       "define skycell of file (required)", 0);
-    psMetadataAddS16(adddiffskyfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(adddiffskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
+    psMetadataAddS16(adddiffskyfileArgs, PS_LIST_TAIL, "-quality",  0,            "set quality", 0);
     psMetadataAddStr(adddiffskyfileArgs, PS_LIST_TAIL, "-uri", 0,            "define URI of file", 0);
     psMetadataAddStr(adddiffskyfileArgs, PS_LIST_TAIL, "-path_base", 0,            "define base output location", 0);
@@ -123,5 +124,5 @@
     psMetadataAddU64(diffskyfileArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     psMetadataAddBool(diffskyfileArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
-    psMetadataAddS16(diffskyfileArgs, PS_LIST_TAIL, "-code",  0,            "deifine fault code", 0);
+    psMetadataAddS16(diffskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "define fault code", 0);
 
     // -revertdiffskyfile
@@ -129,5 +130,5 @@
     psMetadataAddS64(revertdiffskyfileArgs, PS_LIST_TAIL, "-diff_id", 0,            "search by diff ID", 0);
     psMetadataAddStr(revertdiffskyfileArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);
-    psMetadataAddS16(revertdiffskyfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertdiffskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -definepoprun
@@ -171,4 +172,5 @@
     psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-filter", 0, "search by filter", NULL);
     psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-distance", 0, "limit distance between input and template (deg)", NAN);
+    psMetadataAddStr(definewarpwarpArgs, PS_LIST_TAIL, "-obs_mode", 0, "search by observation mode", NULL);
     psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-timediff", 0, "limit time difference between input and template", NAN);
     psMetadataAddF32(definewarpwarpArgs, PS_LIST_TAIL, "-rotdiff", 0, "limit rotator difference between input and template", NAN);
@@ -205,5 +207,5 @@
     psMetadata *updatediffskyfileArgs = psMetadataAlloc();
     psMetadataAddS64(updatediffskyfileArgs, PS_LIST_TAIL, "-diff_id", 0,      "define diff ID (required)", 0);
-    psMetadataAddS16(updatediffskyfileArgs, PS_LIST_TAIL, "-code", 0,         "set fault code (required)", 0);
+    psMetadataAddS16(updatediffskyfileArgs, PS_LIST_TAIL, "-fault", 0,         "set fault code (required)", 0);
 
     // -exportrun
Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 23687)
+++ trunk/ippTools/src/disttool.c	(revision 23688)
@@ -106,5 +106,5 @@
 
     // TODO: should we check that stage_id actually exists for stage
-    // in magicdstool we queue off of a magic_id so the stage_id, exp_id, and cam_id get looked up 
+    // in magicdstool we queue off of a magic_id so the stage_id, exp_id, and cam_id get looked up
     // when the run is queued
 
@@ -151,8 +151,8 @@
     PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false);
     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    if ((!state) && (!label) && (!code)) {
-        psError(PXTOOLS_ERR_DATA, false, "parameters (-code or -set_state or -set_label) are required");
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    if ((!state) && (!label) && (!fault)) {
+        psError(PXTOOLS_ERR_DATA, false, "parameters (-fault or -set_state or -set_label) are required");
         psFree(where);
         return false;
@@ -169,6 +169,6 @@
     }
 
-    if (code) {
-        psStringAppend(&query, " , fault = %d", code);
+    if (fault) {
+        psStringAppend(&query, " , fault = %d", fault);
     }
 
@@ -195,5 +195,5 @@
     PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "distComponent.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "distComponent.fault", "==");
 
     // It might be useful to be able to query by the parameters of the underlying runs
@@ -402,6 +402,6 @@
     // unless fault code is set require filename, bytes, and md5sum
     bool require_fileinfo = false;
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-    if (!code) {
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    if (!fault) {
         require_fileinfo = true;
     }
@@ -410,5 +410,5 @@
     PXOPT_LOOKUP_STR(name, config->args, "-name", require_fileinfo, false);
 
-    if (!distComponentInsert(config->dbh, dist_id, component, bytes, md5sum, "full", name, code)) {
+    if (!distComponentInsert(config->dbh, dist_id, component, bytes, md5sum, "full", name, fault)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
Index: trunk/ippTools/src/disttoolConfig.c
===================================================================
--- trunk/ippTools/src/disttoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/disttoolConfig.c	(revision 23688)
@@ -46,5 +46,5 @@
     psMetadata *definerunArgs = psMetadataAlloc();
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-stage",         0, "define stage for bundle (required)", NULL);
-    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id (required)", 0); 
+    psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id (required)", 0);
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-outroot",  0, "define output destination (required)", NULL);
     psMetadataAddS64(definerunArgs, PS_LIST_TAIL, "-target_id", 0, "define stage_id", 0); 
@@ -52,8 +52,8 @@
     psMetadataAddBool(definerunArgs, PS_LIST_TAIL, "-no_magic", 0, "magic is not needed", false);
     psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-set_label",    0, "define label for run", NULL);
-    
+
     // -updaterun
     psMetadata *updaterunArgs = psMetadataAlloc();
-    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-dist_id",  0, "define dist_id", 0); 
+    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-dist_id",  0, "define dist_id", 0);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_state", 0, "new value for state", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-set_label", 0, "new value for label", NULL);
@@ -61,19 +61,19 @@
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state",     0, "value for state", NULL);
     psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label",     0, "limit updates to label", NULL);
-    psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-code",      0, "define fault code", 0); 
-    
+    psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-fault",      0, "define fault code", 0);
+
     // -revertrun
     psMetadata *revertrunArgs = psMetadataAlloc();
-    psMetadataAddS64(revertrunArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
+    psMetadataAddS64(revertrunArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
     psMetadataAddStr(revertrunArgs, PS_LIST_TAIL, "-stage",    0, "define stage", NULL);
-    psMetadataAddS64(revertrunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id", 0); 
+    psMetadataAddS64(revertrunArgs, PS_LIST_TAIL, "-stage_id", 0, "define stage_id", 0);
     psMetadataAddStr(revertrunArgs, PS_LIST_TAIL, "-state",    0, "define state", NULL);
     psMetadataAddStr(revertrunArgs, PS_LIST_TAIL, "-label",    0, "define label", NULL);
-    psMetadataAddS16(revertrunArgs, PS_LIST_TAIL, "-code", 0, "define fault code", 0); 
+    psMetadataAddS16(revertrunArgs, PS_LIST_TAIL, "-fault", 0, "define fault code", 0);
     psMetadataAddBool(revertrunArgs, PS_LIST_TAIL, "-all",    0, "revert all faulted runs", NULL);
-    
+
     // -pendingcomponent
     psMetadata *pendingcomponentArgs = psMetadataAlloc();
-    psMetadataAddS64(pendingcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
+    psMetadataAddS64(pendingcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
     psMetadataAddStr(pendingcomponentArgs, PS_LIST_TAIL, "-stage",    0, "limit results to runs for stage", NULL);
     psMetadataAddStr(pendingcomponentArgs, PS_LIST_TAIL, "-label",    0, "limit results to label", NULL);
@@ -84,14 +84,14 @@
     // -addprocessedcomponent
     psMetadata *addprocessedcomponentArgs = psMetadataAlloc();
-    psMetadataAddS64(addprocessedcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
+    psMetadataAddS64(addprocessedcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
     psMetadataAddStr(addprocessedcomponentArgs, PS_LIST_TAIL, "-component", 0, "define component (required)", NULL);
     psMetadataAddStr(addprocessedcomponentArgs, PS_LIST_TAIL, "-name", 0, "define file name", NULL);
-    psMetadataAddS32(addprocessedcomponentArgs, PS_LIST_TAIL, "-bytes", 0, "define file size", 0); 
+    psMetadataAddS32(addprocessedcomponentArgs, PS_LIST_TAIL, "-bytes", 0, "define file size", 0);
     psMetadataAddStr(addprocessedcomponentArgs, PS_LIST_TAIL, "-md5sum", 0, "define stage for bundle", NULL);
-    psMetadataAddS32(addprocessedcomponentArgs, PS_LIST_TAIL, "-code", 0, "define fault code", 0); 
+    psMetadataAddS32(addprocessedcomponentArgs, PS_LIST_TAIL, "-fault", 0, "define fault code", 0);
 
     // -processedcomponent
     psMetadata *processedcomponentArgs = psMetadataAlloc();
-    psMetadataAddS64(processedcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
+    psMetadataAddS64(processedcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
     psMetadataAddU64(processedcomponentArgs, PS_LIST_TAIL, "-limit",  0,  "limit result set to N items", 0);
     psMetadataAddBool(processedcomponentArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
@@ -99,5 +99,5 @@
     // -toadvance
     psMetadata *toadvanceArgs = psMetadataAlloc();
-    psMetadataAddS64(toadvanceArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
+    psMetadataAddS64(toadvanceArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0);
     psMetadataAddU64(toadvanceArgs, PS_LIST_TAIL, "-limit",  0,  "limit result set to N items", 0);
     psMetadataAddBool(toadvanceArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
Index: trunk/ippTools/src/faketool.c
===================================================================
--- trunk/ippTools/src/faketool.c	(revision 23687)
+++ trunk/ippTools/src/faketool.c	(revision 23688)
@@ -496,5 +496,5 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args,        "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args,        "-fault", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -513,5 +513,5 @@
                                    path_base,
                                    "full",
-                                   code,
+                                   fault,
                                    NULL         // epoch
             )) {
@@ -687,5 +687,5 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
 
     psMetadata *where = psMetadataAlloc();
@@ -693,5 +693,5 @@
     PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
 
-    if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", where, code)) {
+    if (!pxSetFaultCode(config->dbh, "fakeProcessedImfile", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         psFree(where);
@@ -1238,5 +1238,5 @@
 
   int numExportTables = 2;
-  
+
   PS_ASSERT_PTR_NON_NULL(config, NULL);
 
@@ -1316,5 +1316,5 @@
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
Index: trunk/ippTools/src/faketoolConfig.c
===================================================================
--- trunk/ippTools/src/faketoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/faketoolConfig.c	(revision 23688)
@@ -175,5 +175,5 @@
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-hostname",  0,            "define hostname", NULL);
     psMetadataAddStr(addprocessedimfileArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
-    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
 
     // -processedimfile
@@ -193,5 +193,5 @@
     psMetadataAddS64(updateprocessedimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by exposure ID", 0);
     psMetadataAddStr(updateprocessedimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "search by class ID", NULL);
-    psMetadataAddS16(updateprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code (required)", 0);
+    psMetadataAddS16(updateprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code (required)", 0);
 
     // -revertprocessedimfile
@@ -239,5 +239,5 @@
 
     psMetadataAddBool(revertprocessedimfileArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
-    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertprocessedimfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
 
Index: trunk/ippTools/src/flatcorr.c
===================================================================
--- trunk/ippTools/src/flatcorr.c	(revision 23687)
+++ trunk/ippTools/src/flatcorr.c	(revision 23688)
@@ -117,5 +117,5 @@
     }
 
-    // require the camera to be defined: this analysis does not make sense 
+    // require the camera to be defined: this analysis does not make sense
     // across multiple cameras
     PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
@@ -169,12 +169,12 @@
 
     if (pretend) {
-	for (long i = 0; i < psArrayLength(output); i++) {
-	    // negative simple so the default is true
-	    if (!ippdbPrintMetadataRaw(stdout, output->data[i], !simple)) {
-		psError(PS_ERR_UNKNOWN, false, "failed to print array");
-		psFree(output);
-		return false;
-	    }
-	}
+        for (long i = 0; i < psArrayLength(output); i++) {
+            // negative simple so the default is true
+            if (!ippdbPrintMetadataRaw(stdout, output->data[i], !simple)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to print array");
+                psFree(output);
+                return false;
+            }
+        }
         psFree(output);
         return true;
@@ -191,11 +191,11 @@
     // create a new flatcorrRun
     if (!flatcorrRunInsert(
-	    config->dbh,
+            config->dbh,
             0,      // corr_id
-	    det_type,
+            det_type,
             dvodb,
-	    camera,
-	    telescope,
-	    NULL,
+            camera,
+            telescope,
+            NULL,
             filter,
             "reg",  // state
@@ -203,7 +203,7 @@
             label,
             reduction,
-	    region,
-	    NULL,
-	    0
+            region,
+            NULL,
+            0
         )) {
         if (!psDBRollback(config->dbh)) {
@@ -304,18 +304,18 @@
     // create a new flatcorrRun
     flatcorrRunRow *row = flatcorrRunRowAlloc(
-	0,      // corr_id
-	det_type,
-	dvodb,
-	camera,
-	telescope,
-	NULL,
-	filter,
-	"reg",  // state
-	workdir,
-	label,
-	reduction,
-	region,
-	NULL, // hostname
-	0 // fault
+        0,      // corr_id
+        det_type,
+        dvodb,
+        camera,
+        telescope,
+        NULL,
+        filter,
+        "reg",  // state
+        workdir,
+        label,
+        reduction,
+        region,
+        NULL, // hostname
+        0 // fault
         );
 
@@ -328,5 +328,5 @@
         return false;
     }
-    
+
     // figure out the ID of the flatcorrRun we just created
     psS64 corr_id = psDBLastInsertID(config->dbh);
@@ -365,6 +365,6 @@
     psString query = pxDataGet("flatcorr_dropchip.sql");
     if (!query) {
-	psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-	return false;
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
     }
 
@@ -390,13 +390,13 @@
     psString query = pxDataGet("flatcorr_chiprundone.sql");
     if (!query) {
-	psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-	return false;
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
     }
 
     // treat limit == 0 as "no limit"
     if (limit) {
-	psString limitString = psDBGenerateLimitSQL(limit);
-	psStringAppend(&query, " %s", limitString);
-	psFree(limitString);
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
     }
 
@@ -459,13 +459,13 @@
         // queue the exp
         if (!pxcamQueueByChipID(
-		config,
-		row->chip_id,
-		row->workdir,
-		row->label,
-		row->reduction,
-		row->expgroup,
-		row->dvodb,
-		row->tess_id,
-		"camera")) {
+                config,
+                row->chip_id,
+                row->workdir,
+                row->label,
+                row->reduction,
+                row->expgroup,
+                row->dvodb,
+                row->tess_id,
+                "camera")) {
             if (!psDBRollback(config->dbh)) {
                 psError(PS_ERR_UNKNOWN, false, "database error");
@@ -478,8 +478,8 @@
         }
 
-	// figure out the ID of the flatcorrRun we just created
-	psS64 cam_id = psDBLastInsertID(config->dbh);
-
-	// add the camRun entry to the flatcorrCamLink table (include is TRUE)
+        // figure out the ID of the flatcorrRun we just created
+        psS64 cam_id = psDBLastInsertID(config->dbh);
+
+        // add the camRun entry to the flatcorrCamLink table (include is TRUE)
         if (!flatcorrCamLinkInsert(config->dbh, corr_id, row->chip_id, cam_id, 1)) {
             if (!psDBRollback(config->dbh)) {
@@ -489,5 +489,5 @@
             return false;
         }
-	
+
         psFree(row);
     }
@@ -513,6 +513,6 @@
     psString query = pxDataGet("flatcorr_dropcamera.sql");
     if (!query) {
-	psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-	return false;
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
     }
 
@@ -537,13 +537,13 @@
     psString query = pxDataGet("flatcorr_pendingprocess.sql");
     if (!query) {
-	psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-	return false;
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
     }
 
     // treat limit == 0 as "no limit"
     if (limit) {
-	psString limitString = psDBGenerateLimitSQL(limit);
-	psStringAppend(&query, " %s", limitString);
-	psFree(limitString);
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
     }
 
@@ -566,7 +566,7 @@
 
     if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) {
-	psError(PS_ERR_UNKNOWN, false, "failed to print array");
-	psFree(output);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
     }
 
@@ -588,7 +588,7 @@
     // treat limit == 0 as "no limit"
     if (limit) {
-	psString limitString = psDBGenerateLimitSQL(limit);
-	psStringAppend(&query, " %s", limitString);
-	psFree(limitString);
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
     }
 
@@ -611,7 +611,7 @@
 
     if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) {
-	psError(PS_ERR_UNKNOWN, false, "failed to print array");
-	psFree(output);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
     }
 
@@ -628,5 +628,5 @@
     PXOPT_LOOKUP_BOOL(simple,  config->args, "-simple",  false);
     PXOPT_LOOKUP_BOOL(limit,   config->args, "-limit",   false);
-    
+
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chipProcessedImfile.chip_id", "==");
@@ -647,7 +647,7 @@
     // treat limit == 0 as "no limit"
     if (limit) {
-	psString limitString = psDBGenerateLimitSQL(limit);
-	psStringAppend(&query, " %s", limitString);
-	psFree(limitString);
+        psString limitString = psDBGenerateLimitSQL(limit);
+        psStringAppend(&query, " %s", limitString);
+        psFree(limitString);
     }
 
@@ -670,7 +670,7 @@
 
     if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) {
-	psError(PS_ERR_UNKNOWN, false, "failed to print array");
-	psFree(output);
-	return false;
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
     }
 
@@ -685,9 +685,9 @@
     PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false);
     PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64;
 
-    if (!p_psDBRunQueryF(config->dbh, query, hostname, code, corr_id)) {
+    if (!p_psDBRunQueryF(config->dbh, query, hostname, fault, corr_id)) {
         psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id);
         return false;
@@ -721,7 +721,7 @@
 
     // check that state is a valid string value
-    if (!strcmp(state, "reg") && 
-	!strcmp(state, "new") && 
-	!strcmp(state, "full"))
+    if (!strcmp(state, "reg") &&
+        !strcmp(state, "new") &&
+        !strcmp(state, "full"))
     {
         psError(PS_ERR_UNKNOWN, false, "invalid state: %s", state);
@@ -745,5 +745,5 @@
     char sqlFilename[80];
   } ExportTable;
-  
+
   int numExportTables = 3;
 
@@ -825,11 +825,11 @@
   unsigned int nFail;
   psMetadataItem *item, *entry;
-  
+
   int numImportTables = 3;
-  
+
   char tables[3] [80] = {"flatcorrRun", "flatcorrCamLink", "flatcorrChipLink"};
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
@@ -843,9 +843,9 @@
     psAssert (item, "entry not in input?");
     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-    
+
     entry = psListGet (item->data.list, 0);
     assert (entry);
     assert (entry->type == PS_DATA_METADATA);
-  
+
     switch (i) {
       case 0:
@@ -857,5 +857,5 @@
         // psMetadataPrint (stderr, entry->data.md, 1);
         break;
-      } 
+      }
       case 1:
       {
Index: trunk/ippTools/src/flatcorrConfig.c
===================================================================
--- trunk/ippTools/src/flatcorrConfig.c	(revision 23687)
+++ trunk/ippTools/src/flatcorrConfig.c	(revision 23688)
@@ -106,5 +106,5 @@
     psMetadataAddS64 (addprocessArgs, PS_LIST_TAIL, "-corr_id",  0, "add complete run for specified corr_id (required)", 0);
     psMetadataAddStr (addprocessArgs, PS_LIST_TAIL, "-hostname", 0, "set hostname", NULL);
-    psMetadataAddS16 (addprocessArgs, PS_LIST_TAIL, "-code",     0, "set fault code", 0);
+    psMetadataAddS16 (addprocessArgs, PS_LIST_TAIL, "-fault",     0, "set fault code", 0);
 
     // -updaterun
Index: trunk/ippTools/src/magicdstool.c
===================================================================
--- trunk/ippTools/src/magicdstool.c	(revision 23687)
+++ trunk/ippTools/src/magicdstool.c	(revision 23688)
@@ -599,10 +599,10 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     PXOPT_LOOKUP_STR(backup_path_base, config->args, "-backup_path_base", false, false);
     PXOPT_LOOKUP_STR(recovery_path_base, config->args, "-recovery_path_base", false, false);
     PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false);
 
-    if (setmagicked && (code != 0)) {
+    if (setmagicked && (fault != 0)) {
         psError(PS_ERR_UNKNOWN, true, " cannot setmagicked for faulted file");
         return false;
@@ -625,5 +625,5 @@
     }
 
-    if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, code)) {
+    if (!magicDSFileInsert(config->dbh, magic_ds_id, component, backup_path_base, recovery_path_base, fault)) {
             // rollback
         if (!psDBRollback(config->dbh)) {
@@ -781,5 +781,5 @@
     PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
 
     psString query = psStringCopy("DELETE FROM magicDSFile WHERE fault != 0");
Index: trunk/ippTools/src/magicdstoolConfig.c
===================================================================
--- trunk/ippTools/src/magicdstoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/magicdstoolConfig.c	(revision 23688)
@@ -99,5 +99,5 @@
     psMetadataAddStr(adddestreakedfileArgs, PS_LIST_TAIL, "-recovery_path_base", 0, "define recovery pixels URI", NULL);
     psMetadataAddBool(adddestreakedfileArgs, PS_LIST_TAIL, "-setmagicked", 0, "update the magicked state of the file", false);
-    psMetadataAddS16(adddestreakedfileArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);
+    psMetadataAddS16(adddestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
 
     // -revertdestreakedfile
@@ -105,5 +105,5 @@
     psMetadataAddS64(revertdestreakedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magictool de-streak ID", 0);
     psMetadataAddStr(revertdestreakedfileArgs, PS_LIST_TAIL, "-component", 0, "search by component", NULL);
-    psMetadataAddS16(revertdestreakedfileArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0);
+    psMetadataAddS16(revertdestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
 
     // -getskycells
@@ -125,5 +125,5 @@
     PXOPT_ADD_MODE("-updaterun",           "update state of magic de-streak run",
                     MAGICDSTOOL_MODE_UPDATERUN,         updaterunArgs);
-    PXOPT_ADD_MODE("-todestreak",          "show pending files",    
+    PXOPT_ADD_MODE("-todestreak",          "show pending files",
                     MAGICDSTOOL_MODE_TODESTREAK,       todestreakArgs);
     PXOPT_ADD_MODE("-adddestreakedfile",   "add a de-streaked file",
Index: trunk/ippTools/src/magictool.c
===================================================================
--- trunk/ippTools/src/magictool.c	(revision 23687)
+++ trunk/ippTools/src/magictool.c	(revision 23688)
@@ -535,9 +535,9 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
-
-    if (code > 0) {
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+
+    if (fault > 0) {
         char *query = "UPDATE magicRun SET fault = %d, state = 'full' WHERE magic_id = %" PRId64;
-        if (!p_psDBRunQueryF(config->dbh, query, code, magic_id)) {
+        if (!p_psDBRunQueryF(config->dbh, query, fault, magic_id)) {
             psError(PS_ERR_UNKNOWN, false,
                     "failed to set fault for magic_id %" PRId64, magic_id);
@@ -561,5 +561,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
 
     psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'run' WHERE fault != 0");
@@ -908,5 +908,5 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     if (!magicNodeResultInsert(config->dbh,
@@ -914,5 +914,5 @@
                                node,
                                uri,
-                               code
+                               fault
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -931,5 +931,5 @@
     PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "magicNodeResult.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
 
     psString query = pxDataGet("magictool_revertnode.sql");
@@ -1037,5 +1037,5 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -1048,5 +1048,5 @@
                          uri,
                          streaks,
-                         code
+                         fault
         )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1094,5 +1094,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
 
     if (!psDBTransaction(config->dbh)) {
Index: trunk/ippTools/src/magictoolConfig.c
===================================================================
--- trunk/ippTools/src/magictoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/magictoolConfig.c	(revision 23688)
@@ -100,10 +100,10 @@
     psMetadataAddS64(inputtreeArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID (required)", 0);
     psMetadataAddStr(inputtreeArgs, PS_LIST_TAIL, "-dep_file", 0, "order of operations dep. file", NULL);
-    psMetadataAddS16(inputtreeArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);
+    psMetadataAddS16(inputtreeArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
 
     // -reverttree
     psMetadata *reverttreeArgs = psMetadataAlloc();
     psMetadataAddS64(reverttreeArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magictool ID", 0);
-    psMetadataAddS16(reverttreeArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0);
+    psMetadataAddS16(reverttreeArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
 
     // -inputs
@@ -126,5 +126,5 @@
     psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-node", 0, "define symbolic node name (required)", NULL);
     psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-uri", 0, "define URI", NULL);
-    psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);
+    psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
 
     // -revertnode
@@ -133,5 +133,5 @@
     psMetadataAddStr(revertnodeArgs, PS_LIST_TAIL, "-node", 0, "search by node name", NULL);
     psMetadataAddStr(revertnodeArgs, PS_LIST_TAIL, "-label",0, "search by label", NULL);
-    psMetadataAddS16(revertnodeArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0);
+    psMetadataAddS16(revertnodeArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
 
     // -tomask
@@ -145,10 +145,10 @@
     psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-uri", 0, "define URI", NULL);
     psMetadataAddS32(addmaskArgs, PS_LIST_TAIL, "-streaks", 0, "define number of streaks", 0);
-    psMetadataAddS16(addmaskArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);
+    psMetadataAddS16(addmaskArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
 
     // -revertmask
     psMetadata *revertmaskArgs = psMetadataAlloc();
     psMetadataAddS64(revertmaskArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magictool ID", 0);
-    psMetadataAddS16(revertmaskArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0);
+    psMetadataAddS16(revertmaskArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
 
     // -mask
Index: trunk/ippTools/src/pztool.c
===================================================================
--- trunk/ippTools/src/pztool.c	(revision 23687)
+++ trunk/ippTools/src/pztool.c	(revision 23688)
@@ -338,5 +338,5 @@
         // a lot simplier than a complicated scheme (tried that) to attempt to
         // request on the right number of rows for each camera
-        
+
         // treat limit == 0 as "no limit"
         if (limit) {
@@ -403,5 +403,5 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     // start a transaction early so it will contain any row level locks
@@ -410,5 +410,5 @@
         return false;
     }
-    
+
     // query to get an excluse lock on this exposure in
     // pzDownloadExp
@@ -421,5 +421,5 @@
         PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
         PXOPT_COPY_STR(config->args, where,  "-telescope", "telescope", "==");
-        
+
         if (psListLength(where->list)) {
             psString whereClause = psDBGenerateWhereSQL(where, NULL);
@@ -455,5 +455,5 @@
             class_id,
             uri,
-            code,
+            fault,
             NULL,    // epoch
             hostname
@@ -605,5 +605,5 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
             return false;
-        } 
+        }
 
         // sanity check: we should have inserted at least one row
@@ -675,5 +675,5 @@
             // init
             long counter = 0,   // the total number of elements zipped so far
-            i = 0,              // which array in the set 
+            i = 0,              // which array in the set
             index = 0;          // the depth into each array
             // test
@@ -782,10 +782,10 @@
     PXOPT_COPY_STR(config->args, where,  "-class_id", "class_id", "==");
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
-
-    if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", where, code)) {
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
+
+    if (!pxSetFaultCode(config->dbh, "pzDownloadImfile", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
-	psFree (where);
-	return false;
+        psFree (where);
+        return false;
     }
     psFree(where);
Index: trunk/ippTools/src/pztoolConfig.c
===================================================================
--- trunk/ippTools/src/pztoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/pztoolConfig.c	(revision 23688)
@@ -45,8 +45,8 @@
     // -adddatastore
     psMetadata *adddatastoreArgs = psMetadataAlloc();
-    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL); 
-    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL); 
+    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL);
+    psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL);
     psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-uri", 0,            "define storage uri", NULL);
-    
+
     // -datastore
     psMetadata *datastoreArgs = psMetadataAlloc();
@@ -55,16 +55,16 @@
     // -seen
     psMetadata *seenArgs = psMetadataAlloc();
-    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL); 
-    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL); 
-    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL); 
-    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL); 
+    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL);
+    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL);
+    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL);
+    psMetadataAddStr(seenArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL);
     psMetadataAddBool(seenArgs, PS_LIST_TAIL, "-simple", 0,            "use the simple output format", false);
-    
+
     // -pendingexp
     psMetadata *pendingexpArgs = psMetadataAlloc();
-    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL); 
-    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL); 
-    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL); 
-    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL); 
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL);
+    psMetadataAddStr(pendingexpArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL);
     psMetadataAddBool(pendingexpArgs, PS_LIST_TAIL, "-desc", 0,            "sort ouput in descending format", false);
     psMetadataAddU64(pendingexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
@@ -73,8 +73,8 @@
     // -pendingimfile
     psMetadata *pendingimfileArgs = psMetadataAlloc();
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL); 
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL); 
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL); 
-    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL); 
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL);
+    psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_type", 0,            "define exposure type", NULL);
     psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-desc", 0,            "sort ouput in descending format", false);
     psMetadataAddU64(pendingimfileArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
@@ -83,7 +83,7 @@
     // -copydone
     psMetadata *copydoneArgs = psMetadataAlloc();
-    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL); 
-    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL); 
-    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL); 
+    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL);
+    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL);
+    psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL);
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class", 0,            "define class", NULL);
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-class_id", 0,            "define class_id", NULL);
@@ -95,5 +95,5 @@
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-label",  0,        "define the label for the chip stage", NULL);
     psMetadataAddStr(copydoneArgs, PS_LIST_TAIL, "-hostname",  0,     "define the host that copied the image", NULL);
-    psMetadataAddS16(copydoneArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(copydoneArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
     psMetadataAddBool(copydoneArgs, PS_LIST_TAIL, "-row_lock", 0,     "lock pzDownImfile rows while advancing an exposure", false);
     // XXX: remove this once advance is fixed
@@ -102,7 +102,7 @@
     // -copied
     psMetadata *copiedArgs = psMetadataAlloc();
-    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL); 
-    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL); 
-    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL); 
+    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID", NULL);
+    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID", NULL);
+    psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID", NULL);
     psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-class", 0,            "define class", NULL);
     psMetadataAddStr(copiedArgs, PS_LIST_TAIL, "-class_id", 0,            "define class_id", NULL);
@@ -113,19 +113,19 @@
     // -updatecopied
     psMetadata *updatecopiedArgs = psMetadataAlloc();
-    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL); 
-    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL); 
-    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL); 
+    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL);
+    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL);
+    psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL);
     psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-class", 0,            "define class", NULL);
     psMetadataAddStr(updatecopiedArgs, PS_LIST_TAIL, "-class_id", 0,            "define class_id", NULL);
-    psMetadataAddS16(updatecopiedArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(updatecopiedArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -revertcopied
     psMetadata *revertcopiedArgs = psMetadataAlloc();
-    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL); 
-    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL); 
-    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL); 
+    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-exp_name", 0,            "define exposure ID (required)", NULL);
+    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-inst", 0,            "define camera ID (required)", NULL);
+    psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-telescope", 0,            "define telescope ID (required)", NULL);
     psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-class", 0,            "define class", NULL);
     psMetadataAddStr(revertcopiedArgs, PS_LIST_TAIL, "-class_id", 0,            "define class_id", NULL);
-    psMetadataAddS16(revertcopiedArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertcopiedArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -clearcommonfaults
@@ -134,7 +134,7 @@
     // -toadvance
     psMetadata *toadvanceArgs = psMetadataAlloc();
-    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-exp_name", 0,      "define exposure ID", NULL); 
-    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-inst", 0,          "define camera ID", NULL); 
-    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-telescope", 0,     "define telescope ID", NULL); 
+    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-exp_name", 0,      "define exposure ID", NULL);
+    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-inst", 0,          "define camera ID", NULL);
+    psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-telescope", 0,     "define telescope ID", NULL);
     psMetadataAddStr(toadvanceArgs, PS_LIST_TAIL, "-label",  0,        "define the label for the chip stage", NULL);
     psMetadataAddBool(toadvanceArgs, PS_LIST_TAIL, "-simple",  0,      "use the simple output format", false);
@@ -143,7 +143,7 @@
     // -advance
     psMetadata *advanceArgs = psMetadataAlloc();
-    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-exp_name", 0,   "define exposure ID (required)", NULL); 
-    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-inst", 0,       "define camera ID (required)", NULL); 
-    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-telescope", 0,  "define telescope ID (required)", NULL); 
+    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-exp_name", 0,   "define exposure ID (required)", NULL);
+    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-inst", 0,       "define camera ID (required)", NULL);
+    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-telescope", 0,  "define telescope ID (required)", NULL);
     psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-workdir",  0,   "define the \"default\" workdir for this exposure (required)", NULL);
     psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-dvodb",  0,     "define the dvodb for the next processing step", NULL);
Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 23687)
+++ trunk/ippTools/src/regtool.c	(revision 23688)
@@ -238,5 +238,7 @@
     PXOPT_LOOKUP_TIME(dateobs, config->args, "-dateobs", false, false);
     PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
 
     if (!rawImfileInsert(
@@ -302,5 +304,6 @@
         ignored,
         hostname,
-        code,
+        fault,
+        quality,
         NULL,
         0
@@ -408,5 +411,5 @@
     PXOPT_COPY_STR(config->args, where,  "-tmp_class_id", "tmp_class_id", "==");
     PXOPT_COPY_STR(config->args, where,  "-class_id",     "class_id", "==");
-    PXOPT_COPY_S16(config->args, where,  "-code",         "fault", "==");
+    PXOPT_COPY_S16(config->args, where,  "-fault",         "fault", "==");
     PXOPT_COPY_S64(config->args, where,  "-exp_id_begin", "exp_id", ">=");
     PXOPT_COPY_S64(config->args, where,  "-exp_id_end", "exp_id", "<=");
@@ -452,13 +455,13 @@
     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
     PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false);
 
-    if ((code == INT16_MAX) && !isfinite(user_1)) { 
-        psError(PS_ERR_UNKNOWN, false, "one of -code or -user_1 must be selected");
-        return false;
-    }
-    if ((code != INT16_MAX) && isfinite(user_1)) { 
-        psError(PS_ERR_UNKNOWN, false, "only one of -code or -user_1 must be selected");
+    if ((fault == INT16_MAX) && !isfinite(user_1)) { 
+        psError(PS_ERR_UNKNOWN, false, "one of -fault or -user_1 must be selected");
+        return false;
+    }
+    if ((fault != INT16_MAX) && isfinite(user_1)) { 
+        psError(PS_ERR_UNKNOWN, false, "only one of -fault or -user_1 must be selected");
         return false;
     }
@@ -468,7 +471,7 @@
     PXOPT_COPY_STR(config->args, where,  "-class_id",     "class_id", "==");
 
-    if (code != INT16_MAX) {
+    if (fault != INT16_MAX) {
 	// this is fairly dangerous : can set all if the where is not set...
-	if (!pxSetFaultCode(config->dbh, "rawImfile", where, code)) {
+	if (!pxSetFaultCode(config->dbh, "rawImfile", where, fault)) {
 	    psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
 	    psFree (where);
@@ -644,5 +647,5 @@
 
     // default
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     psString query = pxDataGet("regtool_pendingexp.sql");
@@ -801,5 +804,5 @@
         moon_phase,
         hostname,
-        code,
+        fault,
         NULL,
         0
@@ -995,5 +998,5 @@
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
-    PXOPT_COPY_S16(config->args, where,  "-code",         "fault", "==");
+    PXOPT_COPY_S16(config->args, where,  "-fault",         "fault", "==");
     PXOPT_COPY_S64(config->args, where,  "-exp_id_begin", "exp_id", ">=");
     PXOPT_COPY_S64(config->args, where,  "-exp_id_end", "exp_id", "<=");
@@ -1039,7 +1042,7 @@
     PXOPT_COPY_S64(config->args, where,  "-exp_id",       "exp_id", "==");
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
-
-    if (!pxSetFaultCode(config->dbh, "rawExp", where, code)) {
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
+
+    if (!pxSetFaultCode(config->dbh, "rawExp", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         psFree(where);
@@ -1161,5 +1164,5 @@
     char sqlFilename[80];
   } ExportTable;
-  
+
   int numExportTables = 2;
 
@@ -1241,5 +1244,5 @@
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
@@ -1252,5 +1255,5 @@
   psAssert (item, "entry not in input?");
   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-  
+
   psMetadataItem *entry = psListGet (item->data.list, 0);
   assert (entry);
Index: trunk/ippTools/src/regtoolConfig.c
===================================================================
--- trunk/ippTools/src/regtoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/regtoolConfig.c	(revision 23688)
@@ -122,5 +122,6 @@
     ADD_OPT(Time, addprocessedimfileArgs, "-dateobs",        "define observation time",         NULL);
     ADD_OPT(Str,  addprocessedimfileArgs, "-hostname",       "define host name",                NULL);
-    ADD_OPT(S16,  addprocessedimfileArgs, "-code",           "set fault code",                  0);
+    ADD_OPT(S16,  addprocessedimfileArgs, "-fault",           "set fault code",                  0);
+    ADD_OPT(S16,  addprocessedimfileArgs, "-quality",        "set quality flag", 0);
 
     // -processedimfile
@@ -140,5 +141,5 @@
     ADD_OPT(Str, revertprocessedimfileArgs, "-tmp_class_id",  "searcy by temp. class ID", NULL);
     ADD_OPT(Str, revertprocessedimfileArgs, "-class_id",      "search by class ID", NULL);
-    ADD_OPT(S16, revertprocessedimfileArgs, "-code",          "search by fault code", 0);
+    ADD_OPT(S16, revertprocessedimfileArgs, "-fault",          "search by fault code", 0);
     ADD_OPT(S64, revertprocessedimfileArgs, "-exp_id_begin",  "search by exposure ID", 0);
     ADD_OPT(S64, revertprocessedimfileArgs, "-exp_id_end",    "search by exposure ID", 0);
@@ -149,5 +150,5 @@
     ADD_OPT(Str, updateprocessedimfileArgs, "-class_id",      "search by class ID", NULL);
     ADD_OPT(F64, updateprocessedimfileArgs, "-user_1",        "set user stat (1)", NAN);
-    ADD_OPT(S16, updateprocessedimfileArgs, "-code",          "set fault code", INT16_MAX);
+    ADD_OPT(S16, updateprocessedimfileArgs, "-fault",          "set fault code (required)", INT16_MAX);
 
     // -pendingexp
@@ -226,5 +227,5 @@
     ADD_OPT(Str,  addprocessedexpArgs, "-label",            "define label for chip stage (non-detrend data only)", NULL);
     ADD_OPT(Str,  addprocessedexpArgs, "-hostname",         "define host name", NULL);
-    ADD_OPT(S16,  addprocessedexpArgs, "-code",             "set fault code", 0);
+    ADD_OPT(S16,  addprocessedexpArgs, "-fault",             "set fault code", 0);
 
     // -processedexp
@@ -276,5 +277,5 @@
     psMetadata *revertprocessedexpArgs = psMetadataAlloc();
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-exp_id",   0,            "search by exposure ID", 0);
-    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-code",     0,            "search by fault code", 0);
+    psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-fault",     0,            "search by fault code", 0);
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-exp_id_begin",   0,      "search by exposure ID", 0);
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-exp_id_end",   0,      "search by exposure ID", 0);
@@ -283,5 +284,5 @@
     psMetadata *updatedprocessedexpArgs = psMetadataAlloc();
     psMetadataAddS64(updatedprocessedexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by exposure ID", 0);
-    psMetadataAddS16(updatedprocessedexpArgs, PS_LIST_TAIL, "-code",    0,            "set fault code (required)", INT16_MAX);
+    psMetadataAddS16(updatedprocessedexpArgs, PS_LIST_TAIL, "-fault",    0,            "set fault code (required)", INT16_MAX);
 
     // -exportrun
Index: trunk/ippTools/src/stacktool.c
===================================================================
--- trunk/ippTools/src/stacktool.c	(revision 23687)
+++ trunk/ippTools/src/stacktool.c	(revision 23688)
@@ -718,5 +718,6 @@
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -754,5 +755,6 @@
                                hostname,
                                good_frac,
-                               code
+                               fault,
+                               quality
           )) {
         if (!psDBRollback(config->dbh)) {
@@ -862,5 +864,5 @@
     PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
     PXOPT_COPY_STR(config->args, where, "-label", "stackRun.label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code", "stackSumSkyfile.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
 
     if (!psDBTransaction(config->dbh)) {
@@ -1169,10 +1171,10 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
 
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_S64(config->args, where, "-stack_id",   "stack_id",   "==");
 
-    if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, code)) {
+    if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         psFree (where);
@@ -1192,5 +1194,5 @@
 
   int numExportTables = 3;
-  
+
   PS_ASSERT_PTR_NON_NULL(config, NULL);
 
@@ -1262,11 +1264,11 @@
 {
   unsigned int nFail;
-  
+
   int numImportTables = 2;
-  
+
   char tables[2] [80] = {"stackInputSkyfile", "stackSumSkyfile"};
 
   PS_ASSERT_PTR_NON_NULL(config, NULL);
-  
+
   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
 
@@ -1293,5 +1295,5 @@
     psAssert (item, "entry not in input?");
     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
-  
+
     switch (i) {
       case 0:
@@ -1307,5 +1309,5 @@
         }
         break;
-        
+
       case 1:
         for (int i = 0; i < item->data.list->n; i++) {
@@ -1322,5 +1324,5 @@
     }
   }
-  
+
   return true;
 }
Index: trunk/ippTools/src/stacktoolConfig.c
===================================================================
--- trunk/ippTools/src/stacktoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/stacktoolConfig.c	(revision 23688)
@@ -147,5 +147,6 @@
     psMetadataAddStr(addsumskyfileArgs, PS_LIST_TAIL, "-hostname", 0,            "define hostname", 0);
     psMetadataAddF32(addsumskyfileArgs, PS_LIST_TAIL, "-good_frac",  0,            "define %% of good pixels", NAN);
-    psMetadataAddS16(addsumskyfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addsumskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
+    psMetadataAddS16(addsumskyfileArgs, PS_LIST_TAIL, "-quality",  0,            "set quality", 0);
 
     // -sumskyfile
@@ -162,5 +163,5 @@
     psMetadataAddS64(revertsumskyfileArgs, PS_LIST_TAIL, "-stack_id", 0,            "search by stack ID", 0);
     psMetadataAddStr(revertsumskyfileArgs, PS_LIST_TAIL, "-label", 0, "search by label", 0);
-    psMetadataAddS16(revertsumskyfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertsumskyfileArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
 
     // -pendingcleanuprun
@@ -185,5 +186,5 @@
     psMetadata *updatesumskyfileArgs = psMetadataAlloc();
     psMetadataAddS64(updatesumskyfileArgs, PS_LIST_TAIL, "-stack_id", 0,            "define stack ID (required)", 0);
-    psMetadataAddS16(updatesumskyfileArgs, PS_LIST_TAIL, "-code", 0,            "set fault code (required)", 0);
+    psMetadataAddS16(updatesumskyfileArgs, PS_LIST_TAIL, "-fault", 0,            "set fault code (required)", 0);
 
     // -exportrun
Index: trunk/ippTools/src/warptool.c
===================================================================
--- trunk/ippTools/src/warptool.c	(revision 23687)
+++ trunk/ippTools/src/warptool.c	(revision 23688)
@@ -609,5 +609,5 @@
     PXOPT_LOOKUP_STR(mapfile, config->args, "-mapfile", false, false);
     PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", false, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -616,5 +616,5 @@
     }
 
-    if (code == 0) {
+    if (fault == 0) {
         if (!parseAndInsertSkyCellMap(config, mapfile)) {
             psError(PS_ERR_UNKNOWN, false, "failed to inject mapfile: %s into the database", mapfile);
@@ -631,5 +631,5 @@
             NULL,   // tess_id
             NULL,   // class_id
-            code    // fault
+            fault    // fault
         );
     }
@@ -896,9 +896,9 @@
     PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
     PXOPT_LOOKUP_F32(good_frac, config->args, "-good_frac", false, false);
-    PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
     PXOPT_LOOKUP_BOOL(magicked, config->args, "-magicked", false);
 
     // default values
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
+    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
 
     // we don't want to insert the last skyfile in a run but then not mark the
@@ -927,6 +927,6 @@
                            ymin,
                            ymax,
-                           !accept,
-                           code,
+                           fault,
+                           quality,
                            magicked
         )) {
@@ -1112,5 +1112,5 @@
     PXOPT_COPY_STR(config->args, where, "-reduction",  "rawExp.reduction", "==");
     PXOPT_COPY_STR(config->args, where, "-label",      "warpRun.label", "==");
-    PXOPT_COPY_S16(config->args, where, "-code",       "warpSkyfile.fault", "==");
+    PXOPT_COPY_S16(config->args, where, "-fault",       "warpSkyfile.fault", "==");
 
     if (!psListLength(where->list)
@@ -1560,12 +1560,12 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // warp_id, skycell_id, code are required
+    // warp_id, skycell_id, fault are required
     PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
     PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
-    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
+    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
 
     psString query = pxDataGet("warptool_updateskyfile.sql");
 
-    if (!p_psDBRunQueryF(config->dbh, query, code, warp_id, skycell_id)) {
+    if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
Index: trunk/ippTools/src/warptoolConfig.c
===================================================================
--- trunk/ippTools/src/warptoolConfig.c	(revision 23687)
+++ trunk/ippTools/src/warptoolConfig.c	(revision 23688)
@@ -155,5 +155,5 @@
     psMetadataAddStr(addoverlapArgs, PS_LIST_TAIL, "-mapfile", 0,            "path to skycell <-> imfile mapping file", NULL);
     psMetadataAddS64(addoverlapArgs, PS_LIST_TAIL, "-warp_id",  0,            "set warp ID", 0);
-    psMetadataAddS16(addoverlapArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addoverlapArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
 
     // -scmap
@@ -190,7 +190,7 @@
     psMetadataAddStr(addwarpedArgs, PS_LIST_TAIL, "-hostname", 0,            "define hostname", 0);
     psMetadataAddF32(addwarpedArgs, PS_LIST_TAIL, "-good_frac",  0,            "define %% of good pixels", NAN);
-    psMetadataAddBool(addwarpedArgs, PS_LIST_TAIL, "-accept",  0, "define if this skycell should be accepted", false);
     psMetadataAddBool(addwarpedArgs, PS_LIST_TAIL, "-magicked",  0, "define if this skycell has been magicked", false);
-    psMetadataAddS16(addwarpedArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
+    psMetadataAddS16(addwarpedArgs, PS_LIST_TAIL, "-fault",  0,            "set fault code", 0);
+    psMetadataAddS16(addwarpedArgs, PS_LIST_TAIL, "-quality",  0,            "set quality", 0);
 
     // -warped
@@ -216,5 +216,5 @@
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-reduction",  0,            "search by warpRun reduction class", NULL);
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-label",  0,            "search by warpRun label", NULL);
-    psMetadataAddS16(revertwarpedArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
+    psMetadataAddS16(revertwarpedArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
     psMetadataAddBool(revertwarpedArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
 
@@ -269,5 +269,5 @@
     psMetadataAddS64(updateskyfileArgs, PS_LIST_TAIL, "-warp_id", 0,    "warptool ID to update", 0);
     psMetadataAddStr(updateskyfileArgs, PS_LIST_TAIL, "-skycell_id", 0, "skycell ID to update", NULL);
-    psMetadataAddS16(updateskyfileArgs, PS_LIST_TAIL, "-code",  0,      "new fault code", 0);
+    psMetadataAddS16(updateskyfileArgs, PS_LIST_TAIL, "-fault",  0,      "new fault code", 0);
 
     // -exportrun
Index: trunk/ippconfig/recipes/ppStatsFromMetadata.config
===================================================================
--- trunk/ippconfig/recipes/ppStatsFromMetadata.config	(revision 23687)
+++ trunk/ippconfig/recipes/ppStatsFromMetadata.config	(revision 23688)
@@ -50,4 +50,5 @@
   ENTRY  VAL  ROBUST_MEDIAN    	  F32  ROBUST_STDEV      -bg_mean_stdev      
   ENTRY  VAL  ROBUST_STDEV     	  F32  RMS               -bg_stdev           
+  ENTRY  VAL  QUALITY             S32  CONSTANT          -quality             # Bad quality flag
 END
 
@@ -168,4 +169,5 @@
   ENTRY  VAL  IQ_M2S_L            F32  SAMPLE_MEAN      -iq_m2s_lq            
   ENTRY  VAL  IQ_M2S_U            F32  SAMPLE_MEAN      -iq_m2s_uq            
+  ENTRY  VAL  QUALITY             S32  CONSTANT          -quality             # Bad quality flag
 END
 
@@ -225,4 +227,6 @@
   ENTRY  VAL  iq_m2s              F32  UQ               -iq_m2s_uq            
   ENTRY  VAL  iq_m2s              F32  LQ               -iq_m2s_lq            
+
+  ENTRY  VAL  QUALITY             S32  CONSTANT          -quality             # Bad quality flag
 END
 
@@ -253,4 +257,5 @@
   ENTRY  VAL  RANGE.YMAX          S32  CONSTANT          -ymax          
   ENTRY  VAL  ACCEPT              BOOL CONSTANT          -accept
+  ENTRY  VAL  QUALITY             S32  CONSTANT          -quality             # Bad quality flag
 END
 
@@ -279,4 +284,5 @@
   ENTRY  VAL  NUM_SOURCES         S32  SUM               -sources                       
   ENTRY  VAL  GOOD_PIXEL_FRAC     F32  MEAN              -good_frac                     
+  ENTRY  VAL  QUALITY             S32  CONSTANT          -quality             # Bad quality flag
 END
 
@@ -301,4 +307,5 @@
   ENTRY  VAL  NUM_SOURCES           S32  SUM               -sources        
   ENTRY  VAL  GOOD_PIXEL_FRAC       F32  MEAN              -good_frac      
+  ENTRY  VAL  QUALITY               S32  CONSTANT          -quality             # Bad quality flag
 END
 
Index: trunk/ppImage/src/ppImage.h
===================================================================
--- trunk/ppImage/src/ppImage.h	(revision 23687)
+++ trunk/ppImage/src/ppImage.h	(revision 23688)
@@ -40,5 +40,5 @@
     bool doAstromMosaic;                // full-mosaic Astrometry
     bool doStats;                       // call ppStats on the image
-    bool checkCTE;			// measure pixel-based variance
+    bool checkCTE;                      // measure pixel-based variance
 
     // output files requested
@@ -88,5 +88,5 @@
     float remnanceThresh;               // Threshold for remnance detection
 
-    char *normClass;			// class to use for per-class normalization 
+    char *normClass;                    // class to use for per-class normalization
 } ppImageOptions;
 
@@ -146,7 +146,7 @@
 bool ppImageRebinChip (pmConfig *config, pmFPAview *view, ppImageOptions *options, char *outName);
 
-bool ppImagePhotom (pmConfig *config, pmFPAview *view);
-bool ppImageAstrom (pmConfig *config);
-bool ppImageAddstar (pmConfig *config);
+bool ppImagePhotom(psMetadata *stats, pmConfig *config, pmFPAview *view);
+bool ppImageAstrom(pmConfig *config, psMetadata *stats);
+bool ppImageAddstar(pmConfig *config);
 
 // Subtract background from the chip-mosaicked image
Index: trunk/ppImage/src/ppImageAstrom.c
===================================================================
--- trunk/ppImage/src/ppImageAstrom.c	(revision 23687)
+++ trunk/ppImage/src/ppImageAstrom.c	(revision 23688)
@@ -7,5 +7,5 @@
 // this function is mostly equivalent to the top-level of psastro, with some
 // modifications since the data has already been loaded.
-bool ppImageAstrom (pmConfig *config) {
+bool ppImageAstrom (pmConfig *config, psMetadata *stats) {
 
     bool status;
@@ -27,5 +27,5 @@
     }
 
-    if (!psastroAnalysis (config)) {
+    if (!psastroAnalysis(config, stats)) {
         psError (PSASTRO_ERR_UNKNOWN, false, "failure in psastro analysis\n");
         return false;
Index: trunk/ppImage/src/ppImageLoop.c
===================================================================
--- trunk/ppImage/src/ppImageLoop.c	(revision 23687)
+++ trunk/ppImage/src/ppImageLoop.c	(revision 23688)
@@ -13,7 +13,12 @@
 bool ppImageLoop(pmConfig *config, ppImageOptions *options)
 {
-    psMetadata *stats = options->doStats ? psMetadataAlloc() : NULL; // Statistics to output
+    psMetadata *stats = NULL;           // Statistics to output
     float timeDetrend = 0;              // Amount of time spent in detrend
     float timePhot = 0;                 // Amount of time spent in photometry
+
+    if (options->doStats) {
+        stats = psMetadataAlloc();
+        psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
+    }
 
     bool status;                        // Status of MD lookup
@@ -139,5 +144,5 @@
         psTimerStart(TIMER_PHOT);
         if (options->doPhotom) {
-            if (!ppImagePhotom(config, view)) {
+            if (!ppImagePhotom(stats, config, view)) {
                 ESCAPE("error running photometry.");
             }
@@ -200,5 +205,5 @@
     // this also performs the psastro file IO
     if (options->doAstromChip || options->doAstromMosaic) {
-        if (!ppImageAstrom(config)) {
+        if (!ppImageAstrom(config, stats)) {
             ESCAPE("error running astrometry.");
         }
Index: trunk/ppImage/src/ppImagePhotom.c
===================================================================
--- trunk/ppImage/src/ppImagePhotom.c	(revision 23687)
+++ trunk/ppImage/src/ppImagePhotom.c	(revision 23688)
@@ -6,5 +6,5 @@
 
 // In this function, we perform the psphot analysis routine for the chip-mosaicked images
-bool ppImagePhotom (pmConfig *config, pmFPAview *view) {
+bool ppImagePhotom(psMetadata *stats, pmConfig *config, pmFPAview *view) {
 
     bool status;
@@ -12,5 +12,5 @@
     pmReadout *readout;
 
-    psphotInit ();
+    psphotInit();
 
     // find or define a pmFPAfile PSPHOT.INPUT
@@ -37,14 +37,22 @@
             // run the actual photometry analysis
             if (!psphotReadout (config, view)) {
-                psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
-                return false;
+                // This is likely a data quality issue
+                // XXX Split into multiple cases using error codes?
+                psErrorStackPrint(stderr, "Unable to perform photometry on image");
+                psWarning("Unable to perform photometry on image --- suspect bad data quality.");
+                if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
+                    psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                                     "Unable to perform photometry on image", psErrorCodeLast());
+                }
+                psErrorClear();
+                psphotFilesActivate(config, false);
             }
 
-	    // we want to save the MASK as modified by psphot, but not the data or weight
-	    // free the old mask and replace with a memory copy of the new mask
-	    pmReadout *oldReadout = pmFPAviewThisReadout (view, input->src);
-	    pmReadout *newReadout = pmFPAviewThisReadout (view, input->fpa);
-	    psFree (oldReadout->mask);
-	    oldReadout->mask = psMemIncrRefCounter (newReadout->mask);
+            // we want to save the MASK as modified by psphot, but not the data or weight
+            // free the old mask and replace with a memory copy of the new mask
+            pmReadout *oldReadout = pmFPAviewThisReadout(view, input->src);
+            pmReadout *newReadout = pmFPAviewThisReadout(view, input->fpa);
+            psFree (oldReadout->mask);
+            oldReadout->mask = psMemIncrRefCounter(newReadout->mask);
         }
     }
Index: trunk/ppStack/src/ppStackPhotometry.c
===================================================================
--- trunk/ppStack/src/ppStackPhotometry.c	(revision 23687)
+++ trunk/ppStack/src/ppStackPhotometry.c	(revision 23688)
@@ -69,8 +69,14 @@
 
     if (!psphotReadoutKnownSources(config, photView, inSources)) {
-        // Clear the error, so that the output files are written.
-        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on stacked image.");
-        psFree(photView);
-        return false;
+        // This is likely a data quality issue
+        // XXX Split into multiple cases using error codes?
+        psErrorStackPrint(stderr, "Unable to perform photometry on image");
+        psWarning("Unable to perform photometry on image --- suspect bad data quality.");
+        if (options->stats && psMetadataLookupS32(NULL, options->stats, "QUALITY") == 0) {
+            psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                             "Unable to perform photometry on image", psErrorCodeLast());
+        }
+        psErrorClear();
+        psphotFilesActivate(config, false);
     }
 
Index: trunk/ppStack/src/ppStackSetup.c
===================================================================
--- trunk/ppStack/src/ppStackSetup.c	(revision 23687)
+++ trunk/ppStack/src/ppStackSetup.c	(revision 23688)
@@ -43,4 +43,5 @@
         psFree(resolved);
         options->stats = psMetadataAlloc();
+        psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
     }
 
Index: trunk/ppSub/src/Makefile.am
===================================================================
--- trunk/ppSub/src/Makefile.am	(revision 23687)
+++ trunk/ppSub/src/Makefile.am	(revision 23688)
@@ -19,4 +19,5 @@
 	ppSubBackground.c	 \
 	ppSubCamera.c		 \
+	ppSubData.c		 \
 	ppSubLoop.c		 \
 	ppSubReadout.c		 \
Index: trunk/ppSub/src/ppSub.h
===================================================================
--- trunk/ppSub/src/ppSub.h	(revision 23687)
+++ trunk/ppSub/src/ppSub.h	(revision 23688)
@@ -22,4 +22,20 @@
 #define PPSUB_RECIPE "PPSUB"            /// Name of the recipe to use
 
+// Output files, for activation/deactivation
+typedef enum {
+    PPSUB_FILES_IMAGE = 0x01,           // Image files
+    PPSUB_FILES_PHOT  = 0x02,           // Photometry files
+    PPSUB_FILES_ALL   = 0xFF,           // All files
+} ppSubFiles;
+
+/// Data for processing
+typedef struct {
+    psErrorCode quality;                /// Quality code; 0 for no problem
+    psMetadata *stats;                  /// Statistics
+} ppSubData;
+
+/// Constructor
+ppSubData *ppSubDataAlloc(void);
+
 /// Setup the arguments parsing
 bool ppSubArgumentsSetup(int argc, char *argv[], ///< Command-line arguments
@@ -41,5 +57,5 @@
 /// Perform PSF-matched image subtraction on the readout
 bool ppSubReadout(pmConfig *config,     ///< Configuration
-                  psMetadata *stats,    ///< Statistics, for output
+                  ppSubData *data,      ///< Processing data
                   const pmFPAview *view ///< View of readout to subtract
     );
@@ -53,4 +69,5 @@
 /// looking up the parameters in the recipe and supplying them to the function pmSubtractionMatch()
 bool ppSubMatchPSFs(pmConfig *config,    ///< Configuration
+                    ppSubData *data,    ///< Processing data
                     const pmFPAview *view ///< View of active readout
     );
@@ -63,4 +80,5 @@
 /// Photometry stage 1: measure the PSF from the minuend image
 bool ppSubMakePSF(pmConfig *config,       ///< Configuration
+                  ppSubData *data,    ///< Processing data
                   const pmFPAview *view ///< View of active readout
     );
@@ -74,5 +92,5 @@
 /// Photometry stage 2: find and measure sources on the subtracted image
 bool ppSubReadoutPhotometry(pmConfig *config,     ///< Configuration
-                            psMetadata *stats,    ///< Statistics, for output
+                            ppSubData *data,    ///< Processing data
                             const pmFPAview *view ///< View of active readout
     );
@@ -80,5 +98,5 @@
 /// Renormalize, update headers and generate JPEGs
 bool ppSubReadoutUpdate(pmConfig *config, ///< Configuration
-                        psMetadata *stats, ///< Statistics for output, or NULL
+                        ppSubData *data,    ///< Processing data
                         const pmFPAview *view ///< View of active readout
     );
@@ -96,4 +114,10 @@
 void ppSubVersionPrint(void);
 
+/// Mark the data quality as bad and prepare to suspend processing
+void ppSubDataQuality(pmConfig *config, ///< Configuration
+                      ppSubData *data,  ///< Processing data
+                      psErrorCode error,///< Error code
+                      ppSubFiles files  ///< Files to deactivate
+    );
 
 // Copy every instance of a single keyword from one metadata to another
Index: trunk/ppSub/src/ppSubCamera.c
===================================================================
--- trunk/ppSub/src/ppSubCamera.c	(revision 23687)
+++ trunk/ppSub/src/ppSubCamera.c	(revision 23688)
@@ -285,2 +285,4 @@
     return true;
 }
+
+
Index: trunk/ppSub/src/ppSubData.c
===================================================================
--- trunk/ppSub/src/ppSubData.c	(revision 23688)
+++ trunk/ppSub/src/ppSubData.c	(revision 23688)
@@ -0,0 +1,63 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+#include <psmodules.h>
+#include <psphot.h>
+
+#include "ppSub.h"
+
+
+// Image files to activate/deactivate
+static const char *imageFiles[] = { "PPSUB.OUTPUT", "PPSUB.OUTPUT.MASK", "PPSUB.OUTPUT.VARIANCE",
+                                    "PPSUB.OUTPUT.KERNELS", "PPSUB.OUTPUT.JPEG1", "PPSUB.OUTPUT.JPEG2",
+                                    "PPSUB.INPUT.CONV", "PPSUB.INPUT.CONV.MASK", "PPSUB.INPUT.CONV.VARIANCE",
+                                    "PPSUB.REF.CONV", "PPSUB.REF.CONV.MASK", "PPSUB.REF.CONV.VARIANCE",
+                                    NULL };
+
+
+
+static void subOptionsFree(ppSubData *options)
+{
+    psFree(options->stats);
+    return;
+}
+
+ppSubData *ppSubDataAlloc(void)
+{
+    ppSubData *options = psAlloc(sizeof(ppSubData)); // Processing data, to return
+    psMemSetDeallocator(options, (psFreeFunc)subOptionsFree);
+
+    options->quality = 0;
+    options->stats = psMetadataAlloc();
+    psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", 0, "Data quality", 0);
+
+    return options;
+}
+
+
+void ppSubDataQuality(pmConfig *config, ppSubData *data, psErrorCode error, ppSubFiles files)
+{
+    psAssert(config, "Require configuration");
+    psAssert(data, "Require processing data");
+
+    if (psMetadataLookupS32(NULL, data->stats, "QUALITY") == 0) {
+        data->quality = error;
+        psMetadataAddS32(data->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Data quality", error);
+    }
+
+    if (files & PPSUB_FILES_IMAGE) {
+        for (int i = 0; imageFiles[i]; i++) {
+            pmFPAfileActivate(config->files, imageFiles[i], false);
+        }
+    }
+    if (files & PPSUB_FILES_PHOT) {
+        psphotFilesActivate(config, false);
+    }
+
+    psErrorClear();
+
+    return;
+}
Index: trunk/ppSub/src/ppSubLoop.c
===================================================================
--- trunk/ppSub/src/ppSubLoop.c	(revision 23687)
+++ trunk/ppSub/src/ppSubLoop.c	(revision 23688)
@@ -28,7 +28,8 @@
     pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,MASKS,JPEG");
 
+    ppSubData *data = ppSubDataAlloc(); // Processing data
+
     bool mdok;                          // Status of MD lookup
     const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); // Filename for statistics
-    psMetadata *stats = NULL;           // Container for statistics
     FILE *statsFile = NULL;             // File stream for statistics
     if (statsName && strlen(statsName) > 0) {
@@ -38,7 +39,5 @@
             psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
             psFree(resolved);
-            return false;
-        } else {
-            stats = psMetadataAlloc();
+            goto ERROR;
         }
         psFree(resolved);
@@ -48,5 +47,5 @@
     if (!input) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find input data!\n");
-        return false;
+        goto ERROR;
     }
 
@@ -54,5 +53,5 @@
     if (!reference) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find reference data!\n");
-        return false;
+        goto ERROR;
     }
 
@@ -60,5 +59,5 @@
     if (!output) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find output data!\n");
-        return false;
+        goto ERROR;
     }
 
@@ -67,5 +66,5 @@
     // Iterate over the FPA hierarchy
     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-        return false;
+        goto ERROR;
     }
 
@@ -77,5 +76,5 @@
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "FPA format discrepency between input and reference");
             psFree(view);
-            return false;
+            goto ERROR;
         }
 
@@ -85,5 +84,5 @@
 
         if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-            return false;
+            goto ERROR;
         }
 
@@ -96,5 +95,5 @@
                         "FPA format discrepency between input and reference");
                 psFree(view);
-                return false;
+                goto ERROR;
             }
             if (!inCell->file_exists) {
@@ -102,5 +101,5 @@
             }
             if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                return false;
+                goto ERROR;
             }
 
@@ -108,5 +107,5 @@
             while ((inRO = pmFPAviewNextReadout(view, input->fpa, 1))) {
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                    return false;
+                    goto ERROR;
                 }
                 pmReadout *refRO = pmFPAviewThisReadout(view, reference->fpa);// Reference readout of interest
@@ -116,5 +115,5 @@
                             "FPA format discrepency between input and reference");
                     psFree(view);
-                    return false;
+                    goto ERROR;
                 }
                 if (!inRO->data_exists) {
@@ -123,37 +122,37 @@
 
                 // Perform the analysis
-                if (!ppSubReadout(config, stats, view)) {
+                if (!ppSubReadout(config, data, view)) {
                     psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.\n");
-                    return false;
+                    goto ERROR;
                 }
 
                 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
-                    return false;
+                    goto ERROR;
                 }
             }
 
             // Perform statistics on the cell
-            if (stats) {
+            if (statsFile) {
                 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file
                 if (!output) {
                     psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n");
-                    return false;
+                    goto ERROR;
                 }
                 psImageMaskType maskValue = pmConfigMaskGet("MASK.VALUE", config);
-                ppStatsFPA(stats, output->fpa, view, maskValue, config);
+                ppStatsFPA(data->stats, output->fpa, view, maskValue, config);
             }
 
             if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-                return false;
+                goto ERROR;
             }
         }
 
         if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-            return false;
+            goto ERROR;
         }
     }
 
     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
-        return false;
+        goto ERROR;
     }
 
@@ -161,9 +160,9 @@
 
     // Write out summary statistics
-    if (stats) {
-        psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_SUB", 0, "Time for subtraction completion",
+    if (statsFile) {
+        psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_SUB", 0, "Time for subtraction completion",
                          psTimerMark("ppSub"));
 
-        const char *statsMDC = psMetadataConfigFormat(stats);
+        const char *statsMDC = psMetadataConfigFormat(data->stats);
         if (!statsMDC || strlen(statsMDC) == 0) {
             psWarning("Unable to generate statistics MDC file.\n");
@@ -173,15 +172,17 @@
         psFree((void *)statsMDC);
         fclose(statsFile);
-
-        psFree(stats);
     }
 
     psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig");
     if (dump_file) {
-
         pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
         pmConfigDump(config, input->fpa, dump_file);
     }
 
+    psFree(data);
     return true;
+
+ERROR:
+    psFree(data);
+    return false;
 }
Index: trunk/ppSub/src/ppSubMakePSF.c
===================================================================
--- trunk/ppSub/src/ppSubMakePSF.c	(revision 23687)
+++ trunk/ppSub/src/ppSubMakePSF.c	(revision 23688)
@@ -22,5 +22,5 @@
 #include "ppSub.h"
 
-bool ppSubMakePSF(pmConfig *config, const pmFPAview *view)
+bool ppSubMakePSF(pmConfig *config, ppSubData *data, const pmFPAview *view)
 {
     psAssert(config, "Require configuration");
@@ -83,6 +83,10 @@
     psArray *sources = psMetadataLookupPtr(&mdok, minuend->analysis, "PSPHOT.SOURCES");
     if (!psphotReadoutFindPSF(config, view, sources)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on subtracted image.");
-        return false;
+        // This is likely a data quality issue
+        // XXX Split into multiple cases using error codes?
+        psErrorStackPrint(stderr, "Unable to determine PSF");
+        psWarning("Unable to determine PSF --- suspect bad data quality.");
+        ppSubDataQuality(config, data, PSPHOT_ERR_PSF, PPSUB_FILES_PHOT);
+        return true;
     }
 
@@ -98,21 +102,2 @@
     return true;
 }
-
-// XXX we used to need this, is it still needed?
-
-// pmCell *photCell = pmFPAfileThisCell(config->files, view, "PSPHOT.INPUT");
-// pmCellFreeReadouts(photCell);
-
-// if (!pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL") ||
-//     !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||
-//     !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {
-//     psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");
-//     return false;
-// }
-
-// Blow away the sources psphot found --- they're irrelevant for the subtraction
-// XXX is this still needed?  These are now probably not being set
-// pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with sources
-// psMetadataRemoveKey(photRO->analysis, "PSPHOT.SOURCES");
-// psMetadataRemoveKey(photRO->analysis, "PSPHOT.HEADER");
-
Index: trunk/ppSub/src/ppSubMatchPSFs.c
===================================================================
--- trunk/ppSub/src/ppSubMatchPSFs.c	(revision 23687)
+++ trunk/ppSub/src/ppSubMatchPSFs.c	(revision 23688)
@@ -22,5 +22,5 @@
 #include "ppSub.h"
 
-bool ppSubMatchPSFs(pmConfig *config, const pmFPAview *view)
+bool ppSubMatchPSFs(pmConfig *config, ppSubData *data, const pmFPAview *view)
 {
     psAssert(config, "Require configuration");
@@ -136,15 +136,27 @@
 
     // Match the PSFs
+    bool success = false;               // Operation was successful?
     if (kernelRO) {
-        if (!pmSubtractionMatchPrecalc(inConv, refConv, inRO, refRO, kernelRO->analysis,
-                                       stride, sys, maskVal, maskBad, maskPoor, poorFrac, badFrac)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to convolve images.");
-            return false;
-        }
+        success = pmSubtractionMatchPrecalc(inConv, refConv, inRO, refRO, kernelRO->analysis,
+                                            stride, sys, maskVal, maskBad, maskPoor, poorFrac, badFrac);
     } else {
-        if (!pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, stride, regionSize, spacing,
-                                threshold, sources, stampsName, type, size, order, widths, orders, inner,
-                                ringsOrder, binning, penalty, optimum, optWidths, optOrder, optThresh, iter,
-                                rej, sys, maskVal, maskBad, maskPoor, poorFrac, badFrac, subMode)) {
+        success = pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, stride, regionSize,
+                                     spacing, threshold, sources, stampsName, type, size, order,
+                                     widths, orders, inner, ringsOrder, binning, penalty, optimum,
+                                     optWidths, optOrder, optThresh, iter, rej, sys, maskVal,
+                                     maskBad, maskPoor, poorFrac, badFrac, subMode);
+    }
+
+    psFree(optWidths);
+    pmSubtractionThreadsFinalize(inRO, refRO);
+
+    if (!success) {
+        psErrorCode error = psErrorCodeLast(); // Error code
+        if (error == PM_ERR_STAMPS) {
+            psErrorStackPrint(stderr, "Unable to find stamps");
+            psWarning("Unable to find stamps --- suspect bad data quality.");
+            ppSubDataQuality(config, data, error, PPSUB_FILES_ALL);
+            return true;
+        } else {
             psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
             return false;
@@ -152,19 +164,7 @@
     }
 
-    psFree(optWidths);
-
-    pmSubtractionThreadsFinalize(inRO, refRO);
-
     psImageCovarianceTransfer(inConv->variance, inConv->covariance);
     psImageCovarianceTransfer(refConv->variance, refConv->covariance);
 
-    // XXX drop the pixels associated with inRO and refRO (now that we have inConv and refConf)
-#ifdef TESTING
-    psphotSaveImage (NULL, inRO->image, "inRO.fits");
-    psphotSaveImage (NULL, refRO->image, "refRO.fits");
-    psphotSaveImage (NULL, inConv->image, "inConv.fits");
-    psphotSaveImage (NULL, refConv->image, "refConv.fits");
-#endif
-
     return true;
 }
Index: trunk/ppSub/src/ppSubReadout.c
===================================================================
--- trunk/ppSub/src/ppSubReadout.c	(revision 23687)
+++ trunk/ppSub/src/ppSubReadout.c	(revision 23688)
@@ -21,5 +21,5 @@
 #include "ppSub.h"
 
-bool ppSubReadout(pmConfig *config, psMetadata *stats, const pmFPAview *view)
+bool ppSubReadout(pmConfig *config, ppSubData *data, const pmFPAview *view)
 {
     psTimerStart("PPSUB_MATCH");
@@ -30,7 +30,10 @@
     }
 
-    if (!ppSubMatchPSFs(config, view)) {
+    if (!ppSubMatchPSFs(config, data, view)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs.");
         return false;
+    } else if (data->quality) {
+        // Can't do anything at all
+        return true;
     }
 
@@ -40,5 +43,5 @@
     }
 
-    if (!ppSubMakePSF(config, view)) {
+    if (!data->quality && !ppSubMakePSF(config, data, view)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
         return false;
@@ -56,10 +59,10 @@
     }
 
-    if (!ppSubReadoutPhotometry(config, stats, view)) {
+    if (!data->quality && !ppSubReadoutPhotometry(config, data, view)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
         return false;
     }
 
-    if (!ppSubReadoutUpdate(config, stats, view)) {
+    if (!ppSubReadoutUpdate(config, data, view)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
         return false;
Index: trunk/ppSub/src/ppSubReadoutPhotometry.c
===================================================================
--- trunk/ppSub/src/ppSubReadoutPhotometry.c	(revision 23687)
+++ trunk/ppSub/src/ppSubReadoutPhotometry.c	(revision 23688)
@@ -22,5 +22,5 @@
 #include "ppSub.h"
 
-bool ppSubReadoutPhotometry (pmConfig *config, psMetadata *stats, const pmFPAview *view)
+bool ppSubReadoutPhotometry (pmConfig *config, ppSubData *data, const pmFPAview *view)
 {
     psAssert(config, "Require configuration");
@@ -45,6 +45,8 @@
     pmPSF *psf = psMetadataLookupPtr(NULL, psfInputChip->analysis, "PSPHOT.PSF"); // PSF for photometry
     if (!psf) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF from psphot");
-        return false;
+        psErrorStackPrint(stderr, "No PSF available");
+        psWarning("No PSF available --- suspect bad data quality.");
+        ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT);
+        return true;
     }
     psMetadataAddPtr(psfLoadChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN | PS_META_REPLACE,
@@ -80,25 +82,21 @@
     }
 
-#if 0
-    psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_REPLACE,
-                     "psphot input: view on another pmFPAfile", photFile);
-#endif
+    if (!psphotReadoutMinimal(config, view)) {
+        // This is likely a data quality issue
+        // XXX Split into multiple cases using error codes?
+        psErrorStackPrint(stderr, "Unable to perform photometry on image");
+        psWarning("Unable to perform photometry on image --- suspect bad data quality.");
+        ppSubDataQuality(config, data, psErrorCodeLast(), PPSUB_FILES_PHOT);
+    }
 
-    if (!psphotReadoutMinimal(config, view)) {
-        psWarning("Unable to perform photometry on subtracted image.");
-        psErrorStackPrint(stderr, "Error stack from photometry:");
-        psErrorClear();
-    }
-#if 1
     photRO->data_exists = true;
     photRO->parent->data_exists = true;
     photRO->parent->parent->data_exists = true;
-#endif
 
-    if (stats) {
+    if (data->stats) {
         psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
-        psMetadataAddS32(stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
+        psMetadataAddS32(data->stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected",
                          sources ? sources->n : 0);
-        psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
+        psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry",
                          psTimerClear("PPSUB_PHOT"));
     }
Index: trunk/ppSub/src/ppSubReadoutUpdate.c
===================================================================
--- trunk/ppSub/src/ppSubReadoutUpdate.c	(revision 23687)
+++ trunk/ppSub/src/ppSubReadoutUpdate.c	(revision 23688)
@@ -21,5 +21,5 @@
 #include "ppSub.h"
 
-bool ppSubReadoutUpdate(pmConfig *config, psMetadata *stats, const pmFPAview *view)
+bool ppSubReadoutUpdate(pmConfig *config, ppSubData *data, const pmFPAview *view)
 {
     psAssert(config, "Require configuration");
@@ -47,18 +47,18 @@
 
     // Statistics on the matching
-    if (stats) {
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);
-        psMetadataCopySingle(stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);
+    if (data->stats) {
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MODE);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_STAMPS);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_MEAN);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_DEV_RMS);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_NORM);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_BGDIFF);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MX);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MY);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXX);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MXY);
+        psMetadataCopySingle(data->stats, outRO->analysis, PM_SUBTRACTION_ANALYSIS_MYY);
 
-        psMetadataAddF32(stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
+        psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
                          psTimerClear("PPSUB_MATCH"));
     }
Index: trunk/psModules/src/config/pmConfigRecipes.c
===================================================================
--- trunk/psModules/src/config/pmConfigRecipes.c	(revision 23687)
+++ trunk/psModules/src/config/pmConfigRecipes.c	(revision 23688)
@@ -81,5 +81,5 @@
             psTrace ("psModules.config", 3, "read recipes from camera config");
         } else {
-            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");
+            psTrace ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");
         }
     }
@@ -97,5 +97,5 @@
             psTrace ("psModules.config", 3, "read recipes from symbolic references");
         } else {
-            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
+            psTrace ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
         }
 
@@ -105,5 +105,5 @@
             return false;
         }
-        psLogMsg ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes");
+        psTrace ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes");
 
         // load recipe-files specified on the command line
@@ -115,5 +115,5 @@
             psTrace ("psModules.config", 3, "read recipes from command-line arguments");
         } else {
-            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
+            psTrace ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
         }
 
@@ -126,5 +126,5 @@
             psTrace ("psModules.config", 3, "read recipes from symbolic references");
         } else {
-            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
+            psTrace ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");
         }
 
@@ -137,5 +137,5 @@
             psTrace ("psModules.config", 3, "read recipes from command-line arguments");
         } else {
-            psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
+            psTrace ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");
         }
     }
@@ -348,5 +348,5 @@
             psFree(recipesIter);
             return false;
-	}
+        }
     }
     psFree(recipesIter);
Index: trunk/psModules/src/config/pmErrorCodes.dat
===================================================================
--- trunk/psModules/src/config/pmErrorCodes.dat	(revision 23687)
+++ trunk/psModules/src/config/pmErrorCodes.dat	(revision 23688)
@@ -11,4 +11,5 @@
 OBJECTS			Problem in objects
 SKY			Problem in sky
+STAMPS			Unable to select stamps for PSF-matching
 # these errors correspond to standard exit conditions
 ARGUMENTS               Incorrect arguments
Index: trunk/psModules/src/imcombine/pmSubtractionMatch.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 23687)
+++ trunk/psModules/src/imcombine/pmSubtractionMatch.c	(revision 23688)
@@ -18,6 +18,8 @@
 #include "pmSubtractionMask.h"
 #include "pmSubtractionThreads.h"
+#include "pmSubtractionVisual.h"
+#include "pmErrorCodes.h"
+
 #include "pmSubtractionMatch.h"
-#include "pmSubtractionVisual.h"
 
 #define BG_STAT PS_STAT_ROBUST_MEDIAN   // Statistic to use for background
@@ -73,5 +75,5 @@
                                       stampSpacing, mode);
     if (!*stamps) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to find stamps.");
+        psError(psErrorCodeLast(), false, "Unable to find stamps.");
         return false;
     }
Index: trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 23687)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 23688)
@@ -20,5 +20,5 @@
 #include "pmModel.h"
 #include "pmSource.h"
-
+#include "pmErrorCodes.h"
 
 #include "pmSubtraction.h"
@@ -355,4 +355,5 @@
     if (numGood == 0 && numFound == 0) {
         // No good stamps
+        psError(PM_ERR_STAMPS, true, "Unable to find suitable stamps");
         psFree(stamps);
         return NULL;
Index: trunk/psastro/src/psastro.c
===================================================================
--- trunk/psastro/src/psastro.c	(revision 23687)
+++ trunk/psastro/src/psastro.c	(revision 23688)
@@ -13,13 +13,11 @@
 # include "psastroStandAlone.h"
 
-static void usage (void) {
-    fprintf (stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
-    exit (2);
+static void usage(void) {
+    fprintf(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
+    exit(PS_EXIT_CONFIG_ERROR);
 }
 
-int main (int argc, char **argv) {
-
-    pmConfig *config = NULL;
-
+int main (int argc, char **argv)
+{
     psTimerStart ("complete");
 
@@ -28,9 +26,11 @@
     // model inits are needed in pmSourceIO
     // models defined in psphot/src/models are not available in psastro
-    pmModelClassInit ();
+    pmModelClassInit();
 
     // load configuration information
-    config = psastroArguments (argc, argv);
-    if (!config) usage ();
+    pmConfig *config = config = psastroArguments(argc, argv);
+    if (!config) {
+        usage();
+    }
 
     psastroVersionPrint();
@@ -39,5 +39,6 @@
     if (!psastroParseCamera (config)) {
         psErrorStackPrint(stderr, "error setting up the camera\n");
-        exit (1);
+        psFree(config);
+        exit(PS_EXIT_CONFIG_ERROR);
     }
 
@@ -46,22 +47,30 @@
     if (!psastroDataLoad (config)) {
         psErrorStackPrint(stderr, "error loading input data\n");
-        exit (1);
+        psFree(config);
+        exit(PS_EXIT_DATA_ERROR);
     }
 
+    psMetadata *stats = psMetadataAlloc(); // Statistics, for output
+    psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
+
     // run the full astrometry analysis (chip and/or mosaic)
-    if (!psastroAnalysis (config)) {
+    if (!psastroAnalysis(config, stats)) {
         psErrorStackPrint(stderr, "failure in psastro analysis\n");
-        exit (1);
+        psFree(config);
+        psFree(stats);
+        exit(PS_EXIT_SYS_ERROR);
     }
 
     // write out the results
-    if (!psastroDataSave (config)) {
+    if (!psastroDataSave(config, stats)) {
         psErrorStackPrint(stderr, "failed to write out data\n");
-        exit (1);
+        psFree(config);
+        psFree(stats);
+        exit(PS_EXIT_DATA_ERROR);
     }
 
-    psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
+    psLogMsg("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
 
-    psastroCleanup (config);
-    exit (EXIT_SUCCESS);
+    psastroCleanup(config);
+    exit(PS_EXIT_SUCCESS);
 }
Index: trunk/psastro/src/psastro.h
===================================================================
--- trunk/psastro/src/psastro.h	(revision 23687)
+++ trunk/psastro/src/psastro.h	(revision 23688)
@@ -46,8 +46,8 @@
 #endif
 
-bool              psastroDataSave (pmConfig *config);
+bool              psastroDataSave (pmConfig *config, psMetadata *stats);
 bool              psastroDefineFiles (pmConfig *config, pmFPAfile *input);
 bool              psastroDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType);
-bool              psastroAnalysis (pmConfig *config);
+bool              psastroAnalysis (pmConfig *config, psMetadata *stats);
 
 bool              psastroConvertFPA (pmFPA *fpa, psMetadata *recipe);
@@ -125,5 +125,5 @@
 bool              psastroAstromGuessSetChip (pmFPA *fpa, pmChip *chip, const pmFPAview *view, double pixelScale, bool bilevelAstrometry);
 bool              psastroAstromGuessSetFPA (pmFPA *fpa, bool *bilevelAstrometry);
-bool              psastroMetadataStats (pmConfig *config);
+bool              psastroMetadataStats (pmConfig *config, psMetadata *stats);
 
 bool 		  psastroZeroPoint (pmConfig *config);
Index: trunk/psastro/src/psastroAnalysis.c
===================================================================
--- trunk/psastro/src/psastroAnalysis.c	(revision 23687)
+++ trunk/psastro/src/psastroAnalysis.c	(revision 23688)
@@ -1,5 +1,5 @@
 /** @file psastroAnalysis.c
  *
- *  @brief 
+ *  @brief
  *
  *  @ingroup libpsastro
@@ -13,5 +13,21 @@
 # include "psastroInternal.h"
 
-bool psastroAnalysis (pmConfig *config) {
+/// Turn save on/off for a file
+static void fileSave(pmConfig *config,  // Configuration
+                     const char *name,  // Name of file
+                     bool save          // Save file?
+    )
+{
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, name, 0); // File of interest
+    if (!file) {
+        psErrorClear();
+        return;
+    }
+    file->save = save;
+    return;
+}
+
+
+bool psastroAnalysis (pmConfig *config, psMetadata *stats) {
 
     bool status;
@@ -40,6 +56,15 @@
     }
     if (nStars == 0) {
-        psLogMsg ("psastro", 2, "skipping astrometry analysis : no stars\n");
-        return false;
+        // This is likely a data quality issue
+        psWarning("No stars for astrometry analysis --- suspect bad data quality");
+        if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
+            psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                             "No stars for astrometry", PSASTRO_ERR_DATA);
+        }
+        fileSave(config, "PSASTRO.OUTPUT", false);
+        fileSave(config, "PSASTRO.OUTPUT.MASK", false);
+        fileSave(config, "PSASTRO.OUT.REFSTARS", false);
+        psErrorClear();
+        return true;
     }
 
Index: trunk/psastro/src/psastroDataSave.c
===================================================================
--- trunk/psastro/src/psastroDataSave.c	(revision 23687)
+++ trunk/psastro/src/psastroDataSave.c	(revision 23688)
@@ -22,5 +22,5 @@
  * this loop saves the photometry/astrometry data files
  */
-bool psastroDataSave (pmConfig *config) {
+bool psastroDataSave (pmConfig *config, psMetadata *stats) {
 
     pmChip *chip;
@@ -84,5 +84,5 @@
 
     // Write out summary statistics
-    if (!psastroMetadataStats (config)) ESCAPE;
+    if (!psastroMetadataStats (config, stats)) ESCAPE;
 
     // activate all files except PSASTRO.OUTPUT
Index: trunk/psastro/src/psastroMetadataStats.c
===================================================================
--- trunk/psastro/src/psastroMetadataStats.c	(revision 23687)
+++ trunk/psastro/src/psastroMetadataStats.c	(revision 23688)
@@ -13,5 +13,5 @@
 # include "psastroInternal.h"
 
-bool psastroMetadataStats (pmConfig *config) {
+bool psastroMetadataStats (pmConfig *config, psMetadata *stats) {
 
     bool status;
@@ -24,27 +24,24 @@
 
     if (!output) {
-	psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find output file (PSASTRO.OUTPUT).");
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find output file (PSASTRO.OUTPUT).");
+        return false;
     }
 
-    // create output stats metadata
-    psMetadata *stats = psMetadataAlloc ();
-
-    // extract stats for the complete fpa 
+    // extract stats for the complete fpa
     pmFPAview *view = pmFPAviewAlloc(0);
 
     if (!ppStatsMetadata(stats, output->fpa, view, 0, config)) {
-	psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
-	psFree(view);
-	psFree(stats);
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
+        psFree(view);
+        psFree(stats);
+        return false;
     }
 
     // if we did not request any specific stats, the structure is empty
     if (stats && stats->list->n == 0) {
-	psWarning ("stats output specified, but no requested stats entries in headers");
-	psFree(view);
-	psFree(stats);
-	return true;
+        psWarning ("stats output specified, but no requested stats entries in headers");
+        psFree(view);
+        psFree(stats);
+        return true;
     }
 
@@ -52,7 +49,7 @@
     char *statsMDC = psMetadataConfigFormat(stats);
     if (!statsMDC || strlen(statsMDC) == 0) {
-	psError(PS_ERR_IO, false, "Unable to serialize stats metadata.\n");
-	return false;
-    } 
+        psError(PS_ERR_IO, false, "Unable to serialize stats metadata.\n");
+        return false;
+    }
 
     // convert to a real UNIX filename
@@ -60,10 +57,10 @@
     FILE *statsFile = fopen (resolved, "w");
     if (!statsFile) {
-	psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
-	psFree(stats);
-	psFree(view);
-	psFree(statsMDC);
-	psFree(resolved);
-	return false;
+        psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
+        psFree(stats);
+        psFree(view);
+        psFree(statsMDC);
+        psFree(resolved);
+        return false;
     }
 
Index: trunk/psphot/src/psphot.h
===================================================================
--- trunk/psphot/src/psphot.h	(revision 23687)
+++ trunk/psphot/src/psphot.h	(revision 23688)
@@ -31,4 +31,6 @@
 bool            psphotReadoutCleanup (pmConfig *config, pmReadout *readout, psMetadata *recipe, pmDetections *detections, pmPSF *psf, psArray *sources);
 bool            psphotDefineFiles (pmConfig *config, pmFPAfile *input);
+void            psphotFilesActivate(pmConfig *config, bool state);
+
 bool            psphotSetMaskBits (pmConfig *config);
 bool            psphotSetMaskRecipe (pmConfig *config, psImageMaskType maskValue, psImageMaskType markValue);
Index: trunk/psphot/src/psphotDefineFiles.c
===================================================================
--- trunk/psphot/src/psphotDefineFiles.c	(revision 23687)
+++ trunk/psphot/src/psphotDefineFiles.c	(revision 23688)
@@ -1,3 +1,9 @@
 # include "psphotInternal.h"
+
+// List of output files
+static const char *outputFiles[] = { "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL",
+                                     "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",
+                                     "PSPHOT.PSF.SAVE", "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL",
+                                     "SOURCE.PLOT.APRESID", NULL };
 
 // XXX we need to be able to distinguish several cases:
@@ -133,2 +139,13 @@
     return true;
 }
+
+void psphotFilesActivate(pmConfig *config, bool state)
+{
+    for (int i = 0; outputFiles[i]; i++) {
+        if (!pmFPAfileActivate(config->files, state, outputFiles[i])) {
+            psErrorClear();
+        }
+    }
+
+    return;
+}
Index: trunk/psphot/src/psphotMaskReadout.c
===================================================================
--- trunk/psphot/src/psphotMaskReadout.c	(revision 23687)
+++ trunk/psphot/src/psphotMaskReadout.c	(revision 23688)
@@ -39,8 +39,8 @@
       psImage *mk = readout->mask;
       for (int j = 0; j < im->numRows; j++) {
-	for (int i = 0; i < im->numCols; i++) {
-	  if (isfinite(im->data.F32[j][i]) && isfinite(wt->data.F32[j][i])) continue;
-	  mk->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskBad;
-	}
+        for (int i = 0; i < im->numCols; i++) {
+          if (isfinite(im->data.F32[j][i]) && isfinite(wt->data.F32[j][i])) continue;
+          mk->data.PS_TYPE_IMAGE_MASK_DATA[j][i] |= maskBad;
+        }
       }
     }
Index: trunk/pswarp/src/Makefile.am
===================================================================
--- trunk/pswarp/src/Makefile.am	(revision 23687)
+++ trunk/pswarp/src/Makefile.am	(revision 23688)
@@ -24,5 +24,5 @@
 	pswarpMatchRange.c		\
 	pswarpParseCamera.c		\
-	pswarpPixelFraction.c		\
+	pswarpPixelsLit.c		\
 	pswarpSetMaskBits.c		\
 	pswarpSetThreads.c	        \
Index: trunk/pswarp/src/pswarp.h
===================================================================
--- trunk/pswarp/src/pswarp.h	(revision 23687)
+++ trunk/pswarp/src/pswarp.h	(revision 23688)
@@ -102,8 +102,8 @@
                           const char *filename, const char *argname);
 
-/// Check to see if the readout has a minimum fraction of "lit" pixels
-bool pswarpPixelFraction(const pmReadout *readout, ///< Readout to inspect
-                         psMetadata *stats, ///< Statistics to update with the result
-                         const pmConfig *config ///< Configuration
+/// Get the range of lit pixels
+bool pswarpPixelsLit(const pmReadout *readout, ///< Readout to inspect
+                     psMetadata *stats, ///< Statistics to update with the result
+                     const pmConfig *config ///< Configuration
     );
 
Index: trunk/pswarp/src/pswarpArguments.c
===================================================================
--- trunk/pswarp/src/pswarpArguments.c	(revision 23687)
+++ trunk/pswarp/src/pswarpArguments.c	(revision 23688)
@@ -163,10 +163,4 @@
     }
 
-    float acceptFrac = psMetadataLookupF32(&status, recipe, "ACCEPT.FRAC"); ///< Min fraction of good pixels
-    if (!status) {
-        acceptFrac = 0.0;
-        psWarning("ACCEPT.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac);
-    }
-
     // Set recipe values in the recipe (since we've possibly altered some)
     psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE,
@@ -180,6 +174,4 @@
     psMetadataAddF32(recipe, PS_LIST_TAIL, "POOR.FRAC", PS_META_REPLACE,
                      "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
-    psMetadataAddF32(recipe, PS_LIST_TAIL, "ACCEPT.FRAC", PS_META_REPLACE,
-                     "Minimum fraction of good pixels for result to be accepted", acceptFrac);
 
     // Set recipe values in the arguments
@@ -194,6 +186,4 @@
     psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0,
                      "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
-    psMetadataAddF32(config->arguments, PS_LIST_TAIL, "ACCEPT.FRAC", 0,
-                     "Minimum fraction of good pixels for result to be accepted", acceptFrac);
 
     psTrace("pswarp", 1, "Done with pswarpArguments...\n");
Index: trunk/pswarp/src/pswarpErrorCodes.dat
===================================================================
--- trunk/pswarp/src/pswarpErrorCodes.dat	(revision 23687)
+++ trunk/pswarp/src/pswarpErrorCodes.dat	(revision 23688)
@@ -9,2 +9,3 @@
 IO			Problem in FITS I/O
 DATA                    Problem in data values
+NO_OVERLAP		No overlap between input and skycell
Index: trunk/pswarp/src/pswarpLoop.c
===================================================================
--- trunk/pswarp/src/pswarpLoop.c	(revision 23687)
+++ trunk/pswarp/src/pswarpLoop.c	(revision 23688)
@@ -142,4 +142,5 @@
         psFree(resolved);
         stats = psMetadataAlloc();
+        psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
     }
 
@@ -273,14 +274,25 @@
     }
 
+    if (!output->data_exists) {
+        psWarning("No overlap between input and skycell.");
+        if (stats) {
+            psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                             "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP);
+        }
+        psphotFilesActivate(config, false);
+        psFree(cells);
+        psFree(view);
+        return true;
+    }
+
     pmCell *outCell = output->parent;   ///< Output cell
     pmChip *outChip = outCell->parent;  ///< Output chip
     pmFPA *outFPA = outChip->parent;    ///< Output FP
 
-    if (!pswarpPixelFraction(output, stats, config)) {
-        // Don't write output images, and don't bother about anything else
-        output->data_exists = outCell->data_exists = outChip->data_exists = false;
+    if (!pswarpPixelsLit(output, stats, config)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to calculate pixel regions.");
         psFree(cells);
         psFree(view);
-        goto COMPLETED;
+        return false;
     }
 
@@ -363,6 +375,6 @@
     fileActivation(config, independentFiles, false);
 
-    // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but that's going to be tricky.
-    // We have a list of sources, so we use those to redetermine the PSF model.
+    // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
+    // that's going to be tricky.  We have a list of sources, so we use those to redetermine the PSF model.
 
     if (psMetadataLookupBool(&mdok, config->arguments, "PSF")) {
@@ -393,6 +405,14 @@
         // measure the PSF using these sources
         if (!psphotReadoutFindPSF(config, view, sources)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to determine PSF for warped image.");
-            return false;
+            // This is likely a data quality issue
+            // XXX Split into multiple cases using error codes?
+            psErrorStackPrint(stderr, "Unable to determine PSF");
+            psWarning("Unable to determine PSF --- suspect bad data quality.");
+            if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
+                psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                                 "Unable to determine PSF", psErrorCodeLast());
+            }
+            psErrorClear();
+            psphotFilesActivate(config, false);
         }
 
@@ -447,5 +467,4 @@
     // Now done with the skycell side of things
 
-    COMPLETED:
     // Write out summary statistics
     if (stats) {
Index: trunk/pswarp/src/pswarpPixelFraction.c
===================================================================
--- trunk/pswarp/src/pswarpPixelFraction.c	(revision 23687)
+++ 	(revision )
@@ -1,102 +1,0 @@
-/** @file pswarpPixelFraction.c
- *
- *  @brief
- *
- *  @ingroup pswarp
- *
- *  @author IfA
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-02-05 20:44:04 $
- *  Copyright 2009 Institute for Astronomy, University of Hawaii
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <pslib.h>
-#include <psmodules.h>
-
-#include "pswarp.h"
-
-bool pswarpPixelFraction(const pmReadout *readout, psMetadata *stats, const pmConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(readout, false);
-    PS_ASSERT_IMAGE_NON_NULL(readout->image, false);
-    PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, false);
-    if (!readout->mask) {
-        // Can't do anything
-        return true;
-    }
-    PS_ASSERT_IMAGE_NON_NULL(readout->mask, false);
-    PS_ASSERT_IMAGES_SIZE_EQUAL(readout->mask, readout->image, false);
-    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, false);
-
-    if (stats) {
-        PS_ASSERT_METADATA_NON_NULL(stats, false);
-    }
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    PS_ASSERT_METADATA_NON_NULL(config->arguments, false);
-
-    bool status; 
-
-    float minFrac = psMetadataLookupF32(NULL, config->arguments, "ACCEPT.FRAC"); ///< Minimum fraction
-
-    // load the recipe
-    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
-    if (!recipe) {
-        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
-        return false;
-    }
-
-    // output mask bits
-    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT"); 
-    psAssert (status, "MASK.OUTPUT was not defined");
-
-    psImage *image = readout->image;    ///< Image of interest
-    psImage *mask = readout->mask;      ///< Mask image
-
-    int numCols = image->numCols, numRows = image->numRows; ///< Size of image
-    long numPix = numCols * numRows;
-
-    // Range of valid pixels
-    int xMin = INT_MAX, xMax = -INT_MAX, yMin = INT_MAX, yMax = -INT_MAX;
-
-    long numBad = 0;                     ///< Number of bad pixels
-    for (int y = 0; y < numRows; y++) {
-        for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue) {
-                numBad++;
-            } else {
-                if (y > yMax) {
-                    yMax = y;
-                }
-                if (y < yMin) {
-                    yMin = y;
-                }
-                if (x > xMax) {
-                    xMax = x;
-                }
-                if (x < xMin) {
-                    xMin = x;
-                }
-            }
-        }
-    }
-
-    float goodFrac = (numPix - numBad) / (float)numPix; ///< Fraction of good pixels
-    bool accept = (goodFrac >= minFrac ? true : false); ///< Accept this readout?
-
-    if (stats) {
-        psMetadataAddBool(stats, PS_LIST_HEAD, "ACCEPT", 0, "Accept this readout?", accept);
-
-        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMIN", 0, "Minimum valid x value", xMin);
-        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMAX", 0, "Maximum valid x value", xMax);
-        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMIN", 0, "Minimum valid y value", yMin);
-        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMAX", 0, "Maximum valid y value", yMax);
-    }
-
-    return accept;
-}
-
Index: trunk/pswarp/src/pswarpPixelsLit.c
===================================================================
--- trunk/pswarp/src/pswarpPixelsLit.c	(revision 23688)
+++ trunk/pswarp/src/pswarpPixelsLit.c	(revision 23688)
@@ -0,0 +1,92 @@
+/** @file pswarpPixelFraction.c
+ *
+ *  @brief
+ *
+ *  @ingroup pswarp
+ *
+ *  @author IfA
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-02-05 20:44:04 $
+ *  Copyright 2009 Institute for Astronomy, University of Hawaii
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <pslib.h>
+#include <psmodules.h>
+
+#include "pswarp.h"
+
+bool pswarpPixelsLit(const pmReadout *readout, psMetadata *stats, const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(readout, false);
+    PS_ASSERT_IMAGE_NON_NULL(readout->image, false);
+    PS_ASSERT_IMAGE_TYPE(readout->image, PS_TYPE_F32, false);
+    if (!readout->mask) {
+        // Can't do anything
+        return true;
+    }
+    PS_ASSERT_IMAGE_NON_NULL(readout->mask, false);
+    PS_ASSERT_IMAGES_SIZE_EQUAL(readout->mask, readout->image, false);
+    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, false);
+
+    if (!stats) {
+        // No point in continuing --- we record results to the statistics
+        return true;
+    }
+    PS_ASSERT_PTR_NON_NULL(config, false);
+    PS_ASSERT_METADATA_NON_NULL(config->arguments, false);
+
+    bool status;
+
+    // load the recipe
+    psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
+    if (!recipe) {
+        psError(PSPHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
+        return false;
+    }
+
+    // output mask bits
+    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT");
+    psAssert(status, "MASK.OUTPUT was not defined");
+
+    psImage *image = readout->image;    ///< Image of interest
+    psImage *mask = readout->mask;      ///< Mask image
+
+    int numCols = image->numCols, numRows = image->numRows; ///< Size of image
+
+    // Range of valid pixels
+    int xMin = INT_MAX, xMax = -INT_MAX, yMin = INT_MAX, yMax = -INT_MAX;
+
+    for (int y = 0; y < numRows; y++) {
+        for (int x = 0; x < numCols; x++) {
+            if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue)) {
+                if (y > yMax) {
+                    yMax = y;
+                }
+                if (y < yMin) {
+                    yMin = y;
+                }
+                if (x > xMax) {
+                    xMax = x;
+                }
+                if (x < xMin) {
+                    xMin = x;
+                }
+            }
+        }
+    }
+
+    if (stats) {
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMIN", 0, "Minimum valid x value", xMin);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMAX", 0, "Maximum valid x value", xMax);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMIN", 0, "Minimum valid y value", yMin);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMAX", 0, "Maximum valid y value", yMax);
+    }
+
+    return true;
+}
+
