Index: trunk/psastro/src/psastro.c
===================================================================
--- trunk/psastro/src/psastro.c	(revision 23669)
+++ trunk/psastro/src/psastro.c	(revision 23688)
@@ -13,13 +13,11 @@
 # include "psastroStandAlone.h"
 
-static void usage (void) {
-    fprintf (stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
-    exit (2);
+static void usage(void) {
+    fprintf(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
+    exit(PS_EXIT_CONFIG_ERROR);
 }
 
-int main (int argc, char **argv) {
-
-    pmConfig *config = NULL;
-
+int main (int argc, char **argv)
+{
     psTimerStart ("complete");
 
@@ -28,9 +26,11 @@
     // model inits are needed in pmSourceIO
     // models defined in psphot/src/models are not available in psastro
-    pmModelClassInit ();
+    pmModelClassInit();
 
     // load configuration information
-    config = psastroArguments (argc, argv);
-    if (!config) usage ();
+    pmConfig *config = config = psastroArguments(argc, argv);
+    if (!config) {
+        usage();
+    }
 
     psastroVersionPrint();
@@ -39,5 +39,6 @@
     if (!psastroParseCamera (config)) {
         psErrorStackPrint(stderr, "error setting up the camera\n");
-        exit (1);
+        psFree(config);
+        exit(PS_EXIT_CONFIG_ERROR);
     }
 
@@ -46,22 +47,30 @@
     if (!psastroDataLoad (config)) {
         psErrorStackPrint(stderr, "error loading input data\n");
-        exit (1);
+        psFree(config);
+        exit(PS_EXIT_DATA_ERROR);
     }
 
+    psMetadata *stats = psMetadataAlloc(); // Statistics, for output
+    psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
+
     // run the full astrometry analysis (chip and/or mosaic)
-    if (!psastroAnalysis (config)) {
+    if (!psastroAnalysis(config, stats)) {
         psErrorStackPrint(stderr, "failure in psastro analysis\n");
-        exit (1);
+        psFree(config);
+        psFree(stats);
+        exit(PS_EXIT_SYS_ERROR);
     }
 
     // write out the results
-    if (!psastroDataSave (config)) {
+    if (!psastroDataSave(config, stats)) {
         psErrorStackPrint(stderr, "failed to write out data\n");
-        exit (1);
+        psFree(config);
+        psFree(stats);
+        exit(PS_EXIT_DATA_ERROR);
     }
 
-    psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
+    psLogMsg("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
 
-    psastroCleanup (config);
-    exit (EXIT_SUCCESS);
+    psastroCleanup(config);
+    exit(PS_EXIT_SUCCESS);
 }
Index: trunk/psastro/src/psastro.h
===================================================================
--- trunk/psastro/src/psastro.h	(revision 23669)
+++ trunk/psastro/src/psastro.h	(revision 23688)
@@ -46,8 +46,8 @@
 #endif
 
-bool              psastroDataSave (pmConfig *config);
+bool              psastroDataSave (pmConfig *config, psMetadata *stats);
 bool              psastroDefineFiles (pmConfig *config, pmFPAfile *input);
 bool              psastroDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType);
-bool              psastroAnalysis (pmConfig *config);
+bool              psastroAnalysis (pmConfig *config, psMetadata *stats);
 
 bool              psastroConvertFPA (pmFPA *fpa, psMetadata *recipe);
@@ -125,5 +125,5 @@
 bool              psastroAstromGuessSetChip (pmFPA *fpa, pmChip *chip, const pmFPAview *view, double pixelScale, bool bilevelAstrometry);
 bool              psastroAstromGuessSetFPA (pmFPA *fpa, bool *bilevelAstrometry);
-bool              psastroMetadataStats (pmConfig *config);
+bool              psastroMetadataStats (pmConfig *config, psMetadata *stats);
 
 bool 		  psastroZeroPoint (pmConfig *config);
Index: trunk/psastro/src/psastroAnalysis.c
===================================================================
--- trunk/psastro/src/psastroAnalysis.c	(revision 23669)
+++ trunk/psastro/src/psastroAnalysis.c	(revision 23688)
@@ -1,5 +1,5 @@
 /** @file psastroAnalysis.c
  *
- *  @brief 
+ *  @brief
  *
  *  @ingroup libpsastro
@@ -13,5 +13,21 @@
 # include "psastroInternal.h"
 
-bool psastroAnalysis (pmConfig *config) {
+/// Turn save on/off for a file
+static void fileSave(pmConfig *config,  // Configuration
+                     const char *name,  // Name of file
+                     bool save          // Save file?
+    )
+{
+    pmFPAfile *file = pmFPAfileSelectSingle(config->files, name, 0); // File of interest
+    if (!file) {
+        psErrorClear();
+        return;
+    }
+    file->save = save;
+    return;
+}
+
+
+bool psastroAnalysis (pmConfig *config, psMetadata *stats) {
 
     bool status;
@@ -40,6 +56,15 @@
     }
     if (nStars == 0) {
-        psLogMsg ("psastro", 2, "skipping astrometry analysis : no stars\n");
-        return false;
+        // This is likely a data quality issue
+        psWarning("No stars for astrometry analysis --- suspect bad data quality");
+        if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
+            psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
+                             "No stars for astrometry", PSASTRO_ERR_DATA);
+        }
+        fileSave(config, "PSASTRO.OUTPUT", false);
+        fileSave(config, "PSASTRO.OUTPUT.MASK", false);
+        fileSave(config, "PSASTRO.OUT.REFSTARS", false);
+        psErrorClear();
+        return true;
     }
 
Index: trunk/psastro/src/psastroDataSave.c
===================================================================
--- trunk/psastro/src/psastroDataSave.c	(revision 23669)
+++ trunk/psastro/src/psastroDataSave.c	(revision 23688)
@@ -22,5 +22,5 @@
  * this loop saves the photometry/astrometry data files
  */
-bool psastroDataSave (pmConfig *config) {
+bool psastroDataSave (pmConfig *config, psMetadata *stats) {
 
     pmChip *chip;
@@ -84,5 +84,5 @@
 
     // Write out summary statistics
-    if (!psastroMetadataStats (config)) ESCAPE;
+    if (!psastroMetadataStats (config, stats)) ESCAPE;
 
     // activate all files except PSASTRO.OUTPUT
Index: trunk/psastro/src/psastroMetadataStats.c
===================================================================
--- trunk/psastro/src/psastroMetadataStats.c	(revision 23669)
+++ trunk/psastro/src/psastroMetadataStats.c	(revision 23688)
@@ -13,5 +13,5 @@
 # include "psastroInternal.h"
 
-bool psastroMetadataStats (pmConfig *config) {
+bool psastroMetadataStats (pmConfig *config, psMetadata *stats) {
 
     bool status;
@@ -24,27 +24,24 @@
 
     if (!output) {
-	psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find output file (PSASTRO.OUTPUT).");
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find output file (PSASTRO.OUTPUT).");
+        return false;
     }
 
-    // create output stats metadata
-    psMetadata *stats = psMetadataAlloc ();
-
-    // extract stats for the complete fpa 
+    // extract stats for the complete fpa
     pmFPAview *view = pmFPAviewAlloc(0);
 
     if (!ppStatsMetadata(stats, output->fpa, view, 0, config)) {
-	psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
-	psFree(view);
-	psFree(stats);
-	return false;
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate stats for image.");
+        psFree(view);
+        psFree(stats);
+        return false;
     }
 
     // if we did not request any specific stats, the structure is empty
     if (stats && stats->list->n == 0) {
-	psWarning ("stats output specified, but no requested stats entries in headers");
-	psFree(view);
-	psFree(stats);
-	return true;
+        psWarning ("stats output specified, but no requested stats entries in headers");
+        psFree(view);
+        psFree(stats);
+        return true;
     }
 
@@ -52,7 +49,7 @@
     char *statsMDC = psMetadataConfigFormat(stats);
     if (!statsMDC || strlen(statsMDC) == 0) {
-	psError(PS_ERR_IO, false, "Unable to serialize stats metadata.\n");
-	return false;
-    } 
+        psError(PS_ERR_IO, false, "Unable to serialize stats metadata.\n");
+        return false;
+    }
 
     // convert to a real UNIX filename
@@ -60,10 +57,10 @@
     FILE *statsFile = fopen (resolved, "w");
     if (!statsFile) {
-	psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
-	psFree(stats);
-	psFree(view);
-	psFree(statsMDC);
-	psFree(resolved);
-	return false;
+        psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
+        psFree(stats);
+        psFree(view);
+        psFree(statsMDC);
+        psFree(resolved);
+        return false;
     }
 
