Index: trunk/ppSim/src/ppSimUtils.c
===================================================================
--- trunk/ppSim/src/ppSimUtils.c	(revision 14463)
+++ trunk/ppSim/src/ppSimUtils.c	(revision 14531)
@@ -2,4 +2,5 @@
 
 // Generate a header containing WCS keywords
+// this function is called with only one of fpa, chip, cell not NULL
 bool ppSimInitHeader(pmConfig *config,
 		     pmFPA *fpa,
@@ -11,16 +12,6 @@
     float dec0 = psMetadataLookupF32(NULL, config->arguments, "DEC"); // Boresight Dec (radians)
     float pa = psMetadataLookupF32(NULL, config->arguments, "PA"); // Position angle (radians)
-    float scale = psMetadataLookupF32(NULL, config->arguments, "SCALE") *
-        M_PI / 3600.0 / 180.0; // Plate scale (radians/pixel)
-
-    int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0");
-    int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0");
-    int xParityChip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.XPARITY");
-    int yParityChip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.YPARITY");
-
-    int x0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0");
-    int y0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0");
-    int xParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.XPARITY");
-    int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY");
+    float scale = psMetadataLookupF32(NULL, config->arguments, "SCALE"); // plate scale in arcsec / pixel
+    scale *= M_PI / 3600.0 / 180.0; // convert plate scale to radians/pixel
 
     int binning = psMetadataLookupS32(NULL, config->arguments, "BINNING"); // Binning in x and y
@@ -29,4 +20,14 @@
     int xParity, yParity;
     if (cell) {
+	int x0Chip = psMetadataLookupS32(NULL, cell->parent->concepts, "CHIP.X0");
+	int y0Chip = psMetadataLookupS32(NULL, cell->parent->concepts, "CHIP.Y0");
+	int xParityChip = psMetadataLookupS32(NULL, cell->parent->concepts, "CHIP.XPARITY");
+	int yParityChip = psMetadataLookupS32(NULL, cell->parent->concepts, "CHIP.YPARITY");
+
+	int x0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0");
+	int y0Cell = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0");
+	int xParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.XPARITY");
+	int yParityCell = psMetadataLookupS32(NULL, cell->concepts, "CELL.YPARITY");
+
 	x0 = PPSIM_FPA_TO_CELL(0.0, x0Cell, xParityCell, binning, x0Chip, xParityChip);
 	y0 = PPSIM_FPA_TO_CELL(0.0, y0Cell, yParityCell, binning, y0Chip, yParityChip);
@@ -35,4 +36,9 @@
     }
     if (chip) {
+	int x0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.X0");
+	int y0Chip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.Y0");
+	int xParityChip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.XPARITY");
+	int yParityChip = psMetadataLookupS32(NULL, chip->concepts, "CHIP.YPARITY");
+
 	x0 = PPSIM_FPA_TO_CELL(0.0, 0, 1, binning, x0Chip, xParityChip);
 	y0 = PPSIM_FPA_TO_CELL(0.0, 0, 1, binning, y0Chip, yParityChip);
