Index: trunk/ppStack/src/ppStack.h
===================================================================
--- trunk/ppStack/src/ppStack.h	(revision 36717)
+++ trunk/ppStack/src/ppStack.h	(revision 36855)
@@ -108,5 +108,6 @@
                          const psVector *addVariance, // Additional variance for rejection
                          bool safety,                 // Enable safety switch?
-                         const psVector *norm         // Normalisations to apply
+                         const psVector *norm,         // Normalisations to apply
+                         const psVector *bscaleApplyOffset  // hack for offset based on bscale
     );
 
Index: trunk/ppStack/src/ppStackCombineFinal.c
===================================================================
--- trunk/ppStack/src/ppStackCombineFinal.c	(revision 36717)
+++ trunk/ppStack/src/ppStackCombineFinal.c	(revision 36855)
@@ -44,5 +44,5 @@
 
 bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
-                         pmConfig *config, bool safe, bool normalise, bool grow)
+                         pmConfig *config, bool safe, bool normalise, bool grow, bool bscaleoffset)
 {
     psAssert(stack, "Require stack");
@@ -107,4 +107,5 @@
         PS_ARRAY_ADD_SCALAR(job->args, safe, PS_TYPE_U8);
         PS_ARRAY_ADD_SCALAR(job->args, normalise, PS_TYPE_U8);
+        PS_ARRAY_ADD_SCALAR(job->args, bscaleoffset, PS_TYPE_U8);
         if (!psThreadJobAddPending(job)) {
             psFree(reject);
Index: trunk/ppStack/src/ppStackLoop.c
===================================================================
--- trunk/ppStack/src/ppStackLoop.c	(revision 36717)
+++ trunk/ppStack/src/ppStackLoop.c	(revision 36855)
@@ -120,5 +120,5 @@
     psTrace("ppStack", 2, "Final stack of convolved images....\n");
     if (options->convolve) {
-      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true)) {
+      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, false, true, false)) {
         psError(psErrorCodeLast(), false, "Unable to perform final combination.");
         psFree(stack);
@@ -128,5 +128,6 @@
     else {
       // Since we haven't convolved, I believe we do need to normalize here.
-      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true)) {
+      //MEH -- see below for comment on ppStackCombineFinal and bscaleOffset
+      if (!ppStackCombineFinal(stack, options->convCovars, options, config, false, true, true, true)) {
         psError(psErrorCodeLast(), false, "Unable to perform final combination.");
         psFree(stack);
@@ -207,5 +208,8 @@
 	// generate the unconvolved stack. NOTE: this one must be normalized since the inputs have not been
         psTrace("ppStack", 2, "Stack of unconvolved images....\n");
-        if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false)) {
+        //MEH -- terrible hack for bscale offset to input warps -- treat like normalization 
+        // -- if BSCALEOFFSET TRUE, 0.5*bscale for offset values, otherwise value 0.0
+        // -- bscaleOffset set when files read in and applied in CombineFinal (if arg true, only valid for unconv case)
+        if (!ppStackCombineFinal(stack, options->origCovars, options, config, false, true, false, true)) {
             psError(psErrorCodeLast(), false, "Unable to perform unconvolved combination.");
             psFree(stack);
Index: trunk/ppStack/src/ppStackLoop.h
===================================================================
--- trunk/ppStack/src/ppStackLoop.h	(revision 36717)
+++ trunk/ppStack/src/ppStackLoop.h	(revision 36855)
@@ -65,5 +65,6 @@
     bool safe,                          // Allow safe combination?
     bool norm,                          // Normalise images?
-    bool grow                           // Grow rejection masks?
+    bool grow,                           // Grow rejection masks?
+    bool bscaleoffset                   // Apply bscale offset?
     );
 
Index: trunk/ppStack/src/ppStackOptions.c
===================================================================
--- trunk/ppStack/src/ppStackOptions.c	(revision 36717)
+++ trunk/ppStack/src/ppStackOptions.c	(revision 36855)
@@ -19,4 +19,5 @@
     psFree(options->inputMask);
     psFree(options->sourceLists);
+    psFree(options->bscaleOffset);
     psFree(options->norm);
     psFree(options->sources);
@@ -65,4 +66,5 @@
     options->inputMask = NULL;
     options->sourceLists = NULL;
+    options->bscaleOffset = NULL;
     options->norm = NULL;
     options->sources = NULL;
Index: trunk/ppStack/src/ppStackOptions.h
===================================================================
--- trunk/ppStack/src/ppStackOptions.h	(revision 36717)
+++ trunk/ppStack/src/ppStackOptions.h	(revision 36855)
@@ -35,4 +35,5 @@
     float clippedMean;                  // clipped mean of input fwhm
     float clippedStdev;                 // clipped stdev of input fwhm 
+    psVector *bscaleOffset;             // hack offset of bzero using 0.5*bscale if option, 0.0 if not
     // Convolve
     psArray *cells;                     // Cells for convolved images --- a handle for reading again
Index: trunk/ppStack/src/ppStackPrepare.c
===================================================================
--- trunk/ppStack/src/ppStackPrepare.c	(revision 36717)
+++ trunk/ppStack/src/ppStackPrepare.c	(revision 36855)
@@ -148,4 +148,9 @@
     }
 
+    //MEH -- bscale offset hack for warps 
+    options->bscaleOffset = psVectorAlloc(options->num, PS_TYPE_F32);
+    psVectorInit(options->bscaleOffset, 0.0);
+    bool setbscaleoffset = psMetadataLookupBool(NULL,recipe, "BSCALEOFFSET");
+
     psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope
     int numCols = 0, numRows = 0;   // Size of image
@@ -162,4 +167,13 @@
 	}
         options->sumExposure += options->exposures->data.F32[i];
+
+        //MEH -- hdu get redefn again below if conv (lots of this happening..) 
+        if (setbscaleoffset) {
+            pmHDU *hdu = pmHDUFromCell(cell);
+            assert(hdu && hdu->header);
+            float bscale = psMetadataLookupF32(NULL, hdu->header, "BSCALE");
+            options->bscaleOffset->data.F32[i] = 0.5*bscale;
+        }
+        psLogMsg("ppStack", PS_LOG_INFO, "bscaleOffset: %d %f", i,options->bscaleOffset->data.F32[i]);
 
         // Get list of PSFs, to determine target PSF
Index: trunk/ppStack/src/ppStackReadout.c
===================================================================
--- trunk/ppStack/src/ppStackReadout.c	(revision 36717)
+++ trunk/ppStack/src/ppStackReadout.c	(revision 36855)
@@ -34,4 +34,5 @@
     bool safety = PS_SCALAR_VALUE(args->data[4], U8);    // Safety switch on?
     bool normalise = PS_SCALAR_VALUE(args->data[5], U8); // Normalise images?
+    bool bscaleoffset = PS_SCALAR_VALUE(args->data[6], U8); // Apply bscale offset?
 
     psVector *mask = options->inputMask; // Mask for inputs
@@ -40,7 +41,8 @@
     psVector *addVariance = options->matchChi2; // Additional variance when rejecting
     psVector *norm = normalise ? options->norm : NULL; // Normalisations to apply to images
+    psVector *bscaleApplyOffset = bscaleoffset ? options->bscaleOffset : NULL; // BSCALE offset to apply to images
 
     bool status = ppStackReadoutFinal(config, options->outRO, options->expRO, thread->readouts, mask, reject,
-                                      weightings, exposures, addVariance, safety, norm); // Status of operation
+                                      weightings, exposures, addVariance, safety, norm, bscaleApplyOffset); // Status of operation
 
     thread->busy = false;
@@ -201,5 +203,5 @@
                          const psVector *mask, const psArray *rejected, const psVector *weightings,
                          const psVector *exposures, const psVector *addVariance, bool safety,
-                         const psVector *norm)
+                         const psVector *norm, const psVector *bscaleApplyOffset)
 {
     assert(config);
@@ -271,4 +273,10 @@
         stack->data[i] = data;
 
+        //MEH -- apply bscale offset before norm   
+        if (bscaleApplyOffset) {
+            psLogMsg("ppStack", PS_LOG_INFO, "bscaleApplyOffset: %d %f", i, bscaleApplyOffset->data.F32[i]);
+            psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(bscaleApplyOffset->data.F32[i], PS_TYPE_F32));
+        }
+
         if (norm) {
             float normalise = powf(10.0, -0.4 * norm->data.F32[i]); // Normalisation
Index: trunk/ppStack/src/ppStackThread.c
===================================================================
--- trunk/ppStack/src/ppStackThread.c	(revision 36717)
+++ trunk/ppStack/src/ppStackThread.c	(revision 36855)
@@ -277,5 +277,5 @@
 
     {
-        psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 6);
+        psThreadTask *task = psThreadTaskAlloc("PPSTACK_FINAL_COMBINE", 7);
         task->function = &ppStackReadoutFinalThread;
         psThreadTaskAdd(task);
