Index: trunk/ppSub/src/ppSubCamera.c
===================================================================
--- trunk/ppSub/src/ppSubCamera.c	(revision 42295)
+++ trunk/ppSub/src/ppSubCamera.c	(revision 42463)
@@ -180,4 +180,68 @@
 }
 
+bool pmConfigFixSkycellCamera (pmConfig *config) {
+
+    // We have some static MDC files used for update for which we are missing PSCAMERA.
+    // (This was an attempt to address cross-camera diffs, but was only a partial solution)
+    // Here we need to check for -SKYCELL entries and re-instate the PSCAMERA entries
+
+    bool mdok = false;
+    psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
+    psAssert(cameras, "missing cameras in system config info");
+    
+    // iterate over the cameras and find ones with names like _*-SKYCELLS
+    // psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, "^_.+-SKYCELL$");
+    psMetadataIterator *camerasIter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL);
+    psAssert(camerasIter, "unable to generate iterator?");
+
+    psMetadataItem *camerasItem = NULL; // Item from the metadata
+    while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
+      psAssert(camerasItem->type == PS_DATA_METADATA, "camerasItem has invalid type");
+      
+      char *name = camerasItem->name;
+      psAssert (name, "NULL name for item");
+
+      int nameLen = strlen(name);
+      if (name[0] != '_') continue;
+      if (nameLen <= 9) continue;
+      char *p = &name[nameLen - 8];
+      if (strcmp(p, "-SKYCELL")) continue;
+
+      // we have found a -SKYCELL camera.  does it already have PSCAMERA?
+
+      // remove PSCAMERA entries from *-SKYCELL cameras
+      psMetadata *formats = psMetadataLookupMetadata(&mdok, camerasItem->data.md, "FORMATS"); // List of formats
+      psAssert (formats, "missing FORMATS in camera.config ");
+
+      psMetadata *format = psMetadataLookupMetadata(&mdok, formats, "SKYCELL"); // one true format for skycells
+      psAssert (format, "missing SKYCELL metaformat for -SKYCELL entry ");
+
+      psMetadata *rule = psMetadataLookupMetadata(&mdok, format, "RULE"); // one true format for skycells
+      psAssert (rule, "missing RULE in SKYCELL metaformat for -SKYCELL entry ");
+
+      psString pscamera = psMetadataLookupStr(&mdok, rule, "PSCAMERA"); // one true format for skycells
+      if (pscamera) continue; // PSCAMERA exists, we are good
+
+      // the name of this camera is encoded in the portion of the word skipped above
+      // name[1] to name[nameLen - 8] : number of bytes to copy is : nameLen - 8 - 1:
+
+      // _GPC2-SKYCELL
+      // 0123456789012
+      // nameLen = 13
+      // nameLen - 8 - 1 = 4
+      char cameraName[64];
+
+      int nByte = nameLen - 8 - 1;
+      psAssert (nByte < 64 - 1, "camera name is too long");
+      
+      strncpy (cameraName, &name[1], nByte); cameraName[nByte] = 0;
+
+      psMetadataAddStr (rule, PS_LIST_TAIL, "PSCAMERA", PS_META_REPLACE, "", cameraName);
+    }
+    psFree (camerasIter);
+
+    return true;
+}
+
 pmConfig *pmConfigMakeTemp (pmConfig *config) {
     pmConfig *altconfig = pmConfigAlloc();
@@ -268,4 +332,6 @@
     psAssert(config, "Require configuration");
 
+    pmConfigFixSkycellCamera (config);
+
     // Input image
     pmFPAfile *input = defineInputFile(&success, config, NULL, "PPSUB.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
@@ -334,5 +400,5 @@
 	return false;
     }
-    // XXX do we need to copy the PSCAMERA across to src?  
+    // copy src->format(RULE) PSCAMERA from input->format(RULE)
     ppSubCopyPSCamera (src, input);
     psFree (srcconfig);
@@ -504,11 +570,18 @@
     checkFileruleFileSave(jpeg3, config);
 
+    // The reference sources may not be from the same origin as the reference image, so
+    // use another temporary camera.
+    pmConfig *kernel_config = pmConfigMakeTemp(config);
+
     // Output subtraction kernel
-    pmFPAfile *kernel = defineCalcFile(config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL",
-                                       PM_FPA_FILE_SUBKERNEL);
+    pmFPAfile *kernel = defineCalcFile(kernel_config, output, "PPSUB.OUTPUT.KERNELS", "KERNEL", PM_FPA_FILE_SUBKERNEL);
     if (!kernel) {
         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to define file PPSUB.OUTPUT.KERNELS");
         return false;
     }
+
+    // copy kernel->format(RULE) PSCAMERA from input->format(RULE)
+    ppSubCopyPSCamera (kernel, input);
+    psFree (kernel_config);
 
     // psPhot input
