Index: trunk/pswarp/src/pswarpDataLoad.c
===================================================================
--- trunk/pswarp/src/pswarpDataLoad.c	(revision 10958)
+++ trunk/pswarp/src/pswarpDataLoad.c	(revision 12505)
@@ -9,8 +9,23 @@
 bool pswarpDataLoad (pmConfig *config) {
 
+    bool status;
     pmChip *chip;
     pmCell *cell;
     pmReadout *readout;
     pmFPAview *view;
+
+    // select the current recipe
+    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);
+    if (!recipe) {
+	psError(PSWARP_ERR_CONFIG, false, "Can't find PSASTRO recipe needed for pixel scale!\n");
+	return false;
+    }
+
+    // physical pixel scale in microns per pixel
+    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
+    if (!status) {
+	psError(PS_ERR_IO, false, "Failed to lookup pixel scale"); 
+	return false; 
+    } 
 
     // select the input data sources
@@ -21,4 +36,11 @@
     }
 
+    // use the external astrometry source if supplied
+    pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSWARP.ASTROM");
+    if (!astrom) {
+	fprintf (stderr, "*** using header astrometry\n");
+	astrom = input;
+    }
+ 
     // select the output readout
     view = pmFPAviewAlloc (0);
@@ -44,5 +66,5 @@
     // XXX need to optionally load the astrometry datafile
     bool bilevelAstrometry = false;
-    pmHDU *phu = pmFPAviewThisPHU (view, input->fpa);
+    pmHDU *phu = pmFPAviewThisPHU (view, astrom->fpa);
     if (phu) {
       char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
@@ -52,5 +74,5 @@
     }
     if (bilevelAstrometry) {
-      pmAstromReadBilevelMosaic (input->fpa, phu->header);
+      pmAstromReadBilevelMosaic (input->fpa, phu->header, pixelScale);
     } 
 
@@ -64,10 +86,8 @@
 
         // read WCS data from the corresponding header
-	pmHDU *hdu = pmFPAviewThisHDU (view, input->fpa);
+	pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
 	if (bilevelAstrometry) {
 	  pmAstromReadBilevelChip (chip, hdu->header); 
 	} else {
-	  // XXX get pixelScale from recipes.  does it matter?
-	  float pixelScale = 13.5;
 	  pmAstromReadWCS (input->fpa, chip, hdu->header, pixelScale);
 	}
