Index: /trunk/psastro/src/psastroExtractAnalysis.c
===================================================================
--- /trunk/psastro/src/psastroExtractAnalysis.c	(revision 23583)
+++ /trunk/psastro/src/psastroExtractAnalysis.c	(revision 23584)
@@ -13,11 +13,11 @@
 # include "psastroInternal.h"
 
-# define ESCAPE {							\
-	psError(PS_ERR_UNKNOWN, false, "I/O failure in psastroMaskUpdate"); \
+# define ESCAPE(MSG) {							\
+	psError(PS_ERR_UNKNOWN, false, "I/O failure in psastroMaskUpdate: %s", MSG); \
 	psFree (view);							\
 	return false;							\
     }
 
-# define TEST_OUTPUT 1
+# define TEST_OUTPUT 0
 
 psImage *psastroExtractStar (psImage *input, float x, float y, float dX, float dY);
@@ -117,6 +117,18 @@
     pmFPAview *view = pmFPAviewAlloc (0);
 
+    // generate a (very) basic header:
+    psMetadata *phu = psMetadataAlloc ();
+    // select the filter; default to fixed photcode and mag limit otherwise
+    char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID");
+    if (!status) ESCAPE("missing FPA.FILTER in concepts");
+
+    psMetadataAddStr (phu, PS_LIST_TAIL, "FILTER",  0, "filter", filter);
+    psMetadataAddF32 (phu, PS_LIST_TAIL, "EXPTIME", 0, "exptime", exptime);
+    psMetadataAddF32 (phu, PS_LIST_TAIL, "ZEROPT",  0, "zeropt", zeropt);
+    psFitsWriteBlank (outStars, phu, NULL);
+    psFree (phu);
+
     // open/load files as needed
-    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE("failed on FPA BEFORE");
 
     // this loop selects the matched stars for all chips
@@ -126,5 +138,5 @@
         if (!chip->fromFPA) { continue; }
 
-        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE;
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE("failed on Chip BEFORE");
 
         // text output file for testing
@@ -164,22 +176,31 @@
 
 		    pmReadout *inReadout = pmFPAviewThisReadout (view, input->fpa);
-		    psImage *subraster = psastroExtractStar (inReadout->image, ref->chip->x, ref->chip->y, 100.0, 100.0);
+		    psImage *subraster = psastroExtractStar (inReadout->image, ref->chip->x, ref->chip->y, 200.0, 200.0);
 		    if (!subraster) continue;
 		    
+                    // generate a (very) basic header:
+                    psMetadata *header = psMetadataAlloc ();
+                    psMetadataAddF32 (header, PS_LIST_TAIL, "CHIP_X",  0, "chip coordinate",        ref->chip->x);
+                    psMetadataAddF32 (header, PS_LIST_TAIL, "CHIP_Y",  0, "chip coordinate",        ref->chip->y);
+                    psMetadataAddF32 (header, PS_LIST_TAIL, "FPA_X",   0, "focal-plane coordinate", ref->FP->x);
+                    psMetadataAddF32 (header, PS_LIST_TAIL, "FPA_Y",   0, "focal-plane coordinate", ref->FP->y);
+                    psMetadataAddF32 (header, PS_LIST_TAIL, "MAG",     0, "magnitude",              ref->Mag);
+
 		    snprintf (extname, 80, "extname.%05d", nExt);
-		    psFitsWriteImage (outStars, NULL, subraster, 0, extname);
+		    psFitsWriteImage (outStars, header, subraster, 0, extname);
 		    nExt ++;
 		    
+		    psFree (header);
 		    psFree (subraster);
                 }
-                if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+                if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Readout AFTER");;
             }
-            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Cell AFTER");;
         }
-        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
-
-	fclose (f);
-    }
-    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on Chip AFTER");;
+
+	if (f) fclose (f);
+    }
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE("failed on FPA AFTER");;
 
     psFitsClose (outStars);
