Index: trunk/psastro/src/psastro.c
===================================================================
--- trunk/psastro/src/psastro.c	(revision 23195)
+++ 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);
 }
