Index: trunk/ppImage/src/ppImageDetrendReadout.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendReadout.c	(revision 16084)
+++ trunk/ppImage/src/ppImageDetrendReadout.c	(revision 16844)
@@ -32,6 +32,6 @@
 # endif
 
-    // set up the readouts for dark and bias
-    pmReadout  *dark = NULL;
+    // set up the dark and bias
+    pmCell *dark = NULL;
     pmReadout  *bias = NULL;
     if (options->doBias) {
@@ -39,11 +39,11 @@
     }
     if (options->doDark) {
-        dark = pmFPAfileThisReadout(config->files, detview, "PPIMAGE.DARK");
+        dark = pmFPAfileThisCell(config->files, detview, "PPIMAGE.DARK");
     }
 
     // Bias, dark and overscan subtraction are all merged.
-    if (options->doBias || options->doDark || options->doOverscan) {
-        if (!pmBiasSubtract(input, options->overscan, bias, dark, view)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to subtract bias.\n");
+    if (options->doBias || options->doOverscan) {
+        if (!pmBiasSubtract(input, options->overscan, bias, NULL, view)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to subtract bias.");
             return false;
         }
@@ -54,4 +54,11 @@
         // create the target mask and weight images
         pmReadoutGenerateWeight(input, true);
+    }
+
+    if (options->doDark) {
+        if (!pmDarkApply(input, dark, options->maskValue)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to subtract dark.");
+            return false;
+        }
     }
 
