Index: /trunk/pswarp/src/pswarpLoop.c
===================================================================
--- /trunk/pswarp/src/pswarpLoop.c	(revision 41395)
+++ /trunk/pswarp/src/pswarpLoop.c	(revision 41396)
@@ -123,16 +123,27 @@
 			}
 
-			// Determine the reference catalog used
-			if ((!refcat)&&(astromRO)) {
-			  if ((astromRO->parent->parent->hdu->header)&&(output->fpa->analysis)) {
-			    psMetadataItem *refItem = psMetadataLookup(astromRO->parent->parent->hdu->header, "PSREFCAT");
-			    if (refItem) {
-			      refcat = psMetadataLookupStr(NULL, astromRO->parent->parent->hdu->header, "PSREFCAT");
-			      psMetadataAddStr(output->fpa->analysis, PS_LIST_TAIL, "REFERENCE_CATALOG", PS_META_REPLACE,
-					       "Reference catalog used for calibration.", refcat);
+			// Determine the reference catalog used for the astrometry
+			if (!refcat && astromRO) {
+
+			    // find the HDU for this readout
+			    pmHDU *hdu = pmHDUFromReadout (astromRO);
+			    if (! hdu) {
+				psWarning ("unable to find HDU for astrometry source, cannot save PSREFCAT");
+			    } 
+			    if (!output->fpa->analysis) {
+				psWarning ("analysis metadata not defined for output, cannot save PSREFCAT");
 			    }
-			  }
+
+			    psMetadataItem *refItem = psMetadataLookup(hdu->header, "PSREFCAT");
+			    if (!refItem) {
+				psWarning ("PSREFCAT not found in astrometry HDU, cannot save PSREFCAT");
+			    }
+
+			    if (refItem && hdu && output->fpa->analysis) {
+				refcat = psMetadataLookupStr(NULL, hdu->header, "PSREFCAT");
+				psMetadataAddStr(output->fpa->analysis, PS_LIST_TAIL, "REFERENCE_CATALOG", PS_META_REPLACE,
+						 "Reference catalog used for calibration.", refcat);
+			    }
 			}
-			
 		    }
 
