Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 13849)
+++ trunk/ippTools/src/dettool.c	(revision 13937)
@@ -449,4 +449,10 @@
     }
 
+    psString reduction = psMetadataLookupStr(&status, config->args, "-reduction");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -reduction");
+        return false;
+    }
+
     psString label = psMetadataLookupStr(&status, config->args, "-label");
     if (!status) {
@@ -528,32 +534,33 @@
     // XXX det_id
     detRunInsert(config->dbh,
-            0,
-            0,
-            det_type,
-            mode,
-            "run",
-            filelevel,
-            workdir,
-            camera,
-            telescope,
-            exp_type,
-            filter,
-            airmass_min,
-            airmass_max,
-            exp_time_min,
-            exp_time_max,
-            ccd_temp_min,
-            ccd_temp_max,
-            posang_min,
-            posang_max,
-            registered,
-            time_begin,
-            time_end,
-            use_begin,
-            use_end,
-	    solang_min,
-            solang_max,
-            label,
-            0       // parent
+                 0,
+                 0,
+                 det_type,
+                 mode,
+                 "run",
+                 filelevel,
+                 workdir,
+                 camera,
+                 telescope,
+                 exp_type,
+                 reduction,
+                 filter,
+                 airmass_min,
+                 airmass_max,
+                 exp_time_min,
+                 exp_time_max,
+                 ccd_temp_min,
+                 ccd_temp_max,
+                 posang_min,
+                 posang_max,
+                 registered,
+                 time_begin,
+                 time_end,
+                 use_begin,
+                 use_end,
+                 solang_min,
+                 solang_max,
+                 label,
+                 0       // parent
         );
     psFree(registered);
@@ -1172,4 +1179,10 @@
     }
 
+    psString reduction = psMetadataLookupStr(&status, config->args, "-reduction");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -reduction");
+        return false;
+    }
+
     psString label = psMetadataLookupStr(&status, config->args, "-label");
     if (!status) {
@@ -1251,32 +1264,33 @@
     // XXX det_id
     detRunInsert(config->dbh,
-            0,      // det_id
-            0,      // iteration
-            det_type,
-            mode,
-            "run",  // state
-            filelevel,
-            workdir,
-            camera,
-            telescope,
-            "NA",
-            filter,
-            airmass_min,
-            airmass_max,
-            exp_time_min,
-            exp_time_max,
-            ccd_temp_min,
-            ccd_temp_max,
-            posang_min,
-            posang_max,
-            registered,
-            time_begin,
-            time_end,
-            use_begin,
-            use_end,
-	    solang_min,
-            solang_max,
-            label,
-            0       // parent
+                 0,      // det_id
+                 0,      // iteration
+                 det_type,
+                 mode,
+                 "run",  // state
+                 filelevel,
+                 workdir,
+                 camera,
+                 telescope,
+                 "NA",
+                 reduction,
+                 filter,
+                 airmass_min,
+                 airmass_max,
+                 exp_time_min,
+                 exp_time_max,
+                 ccd_temp_min,
+                 ccd_temp_max,
+                 posang_min,
+                 posang_max,
+                 registered,
+                 time_begin,
+                 time_end,
+                 use_begin,
+                 use_end,
+                 solang_min,
+                 solang_max,
+                 label,
+                 0       // parent
         );
     psFree(registered);
@@ -1671,4 +1685,14 @@
             psFree(use_end);
         }
+    }
+
+    psString reduction = psMetadataLookupStr(&status, config->args, "-set_reduction");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_reduction");
+        return false;
+    }
+    if (reduction) {
+        psFree(detRun->reduction);
+        detRun->reduction = psStringCopy(reduction);
     }
 
@@ -2115,4 +2139,5 @@
             "   detRun.det_type,"
             "   detRun.workdir,"
+            "   detRun.reduction,"
             "   rawImfile.*,"
             "   rawExp.camera"
@@ -2862,4 +2887,5 @@
         "    detRun.det_type,\n"
         "    detRun.workdir,\n"
+        "    detRun.reduction,\n"
         "    detProcessedImfile.class_id,\n"
         "    rawExp.camera\n"
@@ -2987,12 +3013,12 @@
     // add the two required restrictions: detRun.state and detRun.mode
     if ((value = psMetadataLookupStr(&status, config->args, "-select_state"))) {
-	psStringAppend(&query, " detRun.state = '%s'", value);
+        psStringAppend(&query, " detRun.state = '%s'", value);
     } else {
-	psStringAppend(&query, " detRun.state = 'run'");
+        psStringAppend(&query, " detRun.state = 'run'");
     }
     if ((value = psMetadataLookupStr(&status, config->args, "-select_mode"))) {
-	psStringAppend(&query, " AND detRun.mode = '%s'", value);
+        psStringAppend(&query, " AND detRun.mode = '%s'", value);
     } else {
-	psStringAppend(&query, " AND detRun.mode = 'master'");
+        psStringAppend(&query, " AND detRun.mode = 'master'");
     }
 
@@ -4407,4 +4433,5 @@
         "   detRun.mode,\n"
         "   detRun.workdir,\n"
+        "   detRun.reduction,\n"
         "   detProcessedImfile.exp_tag,\n"
         "   detProcessedImfile.class_id,\n"
@@ -4444,4 +4471,5 @@
         "   detRun.mode,\n"
         "   detRun.workdir,\n"
+        "   detRun.reduction,\n"
         "   rawImfile.exp_tag,\n"
         "   rawImfile.class_id,\n"
@@ -6774,33 +6802,34 @@
 
     if (!detRunInsert(config->dbh,
-            0,          // det_id
-            0,          // the iteration is fixed at 0
-            det_type,
-            mode,
-            "reg",      // state
-            filelevel,
-            workdir,
-            camera,
-            telescope,
-            exp_type,
-            filter,
-            airmass_min,
-            airmass_max,
-            exp_time_min,
-            exp_time_max,
-            ccd_temp_min,
-            ccd_temp_max,
-            posang_min,
-            posang_max,
-            registered,
-            time_begin,
-            time_end,
-            use_begin,
-            use_end,
-            solang_min,
-            solang_max,
-            label,      // label
-            parent ? (psS64)atoll(parent) : 0
-    )) {
+                      0,          // det_id
+                      0,          // the iteration is fixed at 0
+                      det_type,
+                      mode,
+                      "reg",      // state
+                      filelevel,
+                      workdir,
+                      camera,
+                      telescope,
+                      exp_type,
+                      NULL,
+                      filter,
+                      airmass_min,
+                      airmass_max,
+                      exp_time_min,
+                      exp_time_max,
+                      ccd_temp_min,
+                      ccd_temp_max,
+                      posang_min,
+                      posang_max,
+                      registered,
+                      time_begin,
+                      time_end,
+                      use_begin,
+                      use_end,
+                      solang_min,
+                      solang_max,
+                      label,      // label
+                      parent ? (psS64)atoll(parent) : 0
+            )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         // rollback
