Index: /trunk/psastro/src/Makefile.am
===================================================================
--- /trunk/psastro/src/Makefile.am	(revision 9573)
+++ /trunk/psastro/src/Makefile.am	(revision 9574)
@@ -31,5 +31,6 @@
 psastroMosaicHeaders.c	    \
 psastroMosaicRescaleChips.c \
-psastroWCS.c	   
+psastroWCS.c	            \
+psastroErrorCodes.c
 
 include_HEADERS = \
@@ -44,10 +45,10 @@
 
 ### Error codes.
-#BUILT_SOURCES = psastroErrorCodes.h psastroErrorCodes.c
-#CLEANFILES = psastroErrorCodes.h psastroErrorCodes.c
+BUILT_SOURCES = psastroErrorCodes.h psastroErrorCodes.c
+CLEANFILES = psastroErrorCodes.h psastroErrorCodes.c
 
-#psastroErrorCodes.h : psastroErrorCodes.dat psastroErrorCodes.h.in
-#	$(ERRORCODES) --data=psastroErrorCodes.dat --outdir=. psastroErrorCodes.h
+psastroErrorCodes.h : psastroErrorCodes.dat psastroErrorCodes.h.in
+	$(ERRORCODES) --data=psastroErrorCodes.dat --outdir=. psastroErrorCodes.h
 
-#psastroErrorCodes.c : psastroErrorCodes.dat psastroErrorCodes.c.in psastroErrorCodes.h
-#	$(ERRORCODES) --data=psastroEerrorCodes.dat --outdir=. psastroErrorCodes.c
+psastroErrorCodes.c : psastroErrorCodes.dat psastroErrorCodes.c.in psastroErrorCodes.h
+	$(ERRORCODES) --data=psastroErrorCodes.dat --outdir=. psastroErrorCodes.c
Index: /trunk/psastro/src/psastro.c
===================================================================
--- /trunk/psastro/src/psastro.c	(revision 9573)
+++ /trunk/psastro/src/psastro.c	(revision 9574)
@@ -1,3 +1,8 @@
 # include "psastro.h"
+
+static void usage (void) {
+    psErrorStackPrint(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)");
+    exit (2);
+}
 
 int main (int argc, char **argv) {
@@ -11,26 +16,47 @@
     // load configuration information
     pmConfig *config = psastroArguments (argc, argv);
+    if (!config) usage ();
 
     // load identify the data sources
-    psastroParseCamera (config);
+    if (!psastroParseCamera (config)) {
+	psErrorStackPrint(stderr, "error setting up the camera");
+	exit (1);
+    }
 
     // load the raw pixel data (from PSPHOT.SOURCES)
     // select subset of stars for astrometry
-    psastroDataLoad (config);
+    if (!psastroDataLoad (config)) {
+	psErrorStackPrint(stderr, "error loading input data");
+	exit (1);
+    }
 
     // interpret the available initial astrometric information
     // apply the initial guess
-    psastroAstromGuess (config);
+    if (!psastroAstromGuess (config)) {
+	psErrorStackPrint(stderr, "failed to determine initial astrometry guess");
+	exit (1);
+    }
 
     // load the reference stars overlapping the data stars
     psArray *refs = psastroLoadReferences (config);
+    if (!refs) {
+	psErrorStackPrint(stderr, "failed to load reference data");
+	exit (1);
+    }
 
+    // XXX ?? what does this do ??
     psastroMosaicGetRefstars (config, refs);
 
     char *mosastro = psMetadataLookupStr (NULL, config->arguments, "MOSASTRO");
     if (mosastro == NULL) {
-        psastroChipAstrom (config, refs);
+        if (!psastroChipAstrom (config, refs)) {
+	    psErrorStackPrint(stderr, "failed to perform single chip astrometry");
+	    exit (1);
+	}
     } else {
-        psastroMosaicAstrom (config, refs);
+	if (!psastroMosaicAstrom (config, refs)) {
+	    psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry");
+	    exit (1);
+	}
     }
 
@@ -39,5 +65,8 @@
 
     // write out the results
-    psastroDataSave (config);
+    if (!psastroDataSave (config)) {
+	psErrorStackPrint(stderr, "failed to write out data");
+	exit (1);
+    }
 
     psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
Index: /trunk/psastro/src/psastro.h
===================================================================
--- /trunk/psastro/src/psastro.h	(revision 9573)
+++ /trunk/psastro/src/psastro.h	(revision 9574)
@@ -9,4 +9,6 @@
 # include <pslib.h>
 # include <psmodules.h>
+
+# include "psastroErrorCodes.h"
 
 # define psMemCopy(A)(psMemIncrRefCounter((A)))
@@ -37,6 +39,4 @@
 bool              psastroOneChip (pmFPA *fpa, pmChip *chip, psArray *refset, psArray *rawset, psMetadata *recipe, psMetadata *updates);
 
-// bool              psVectorSmooth (psVector *vector, double sigma, double Nsigma);
-
 // utility functions:
 bool              psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip, psArray *rawstars, psArray *refstars);
Index: /trunk/psastro/src/psastroArguments.c
===================================================================
--- /trunk/psastro/src/psastroArguments.c	(revision 9573)
+++ /trunk/psastro/src/psastroArguments.c	(revision 9574)
@@ -1,10 +1,4 @@
 # include "psastro.h"
 # include <glob.h>
-// XXX leak free 2006.04.27
-
-static void usage (void) {
-    fprintf (stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
-    exit (2);
-}
 
 pmConfig *psastroArguments (int argc, char **argv) {
@@ -13,5 +7,8 @@
     int N;
 
-    if (argc == 1) usage ();
+    if (argc == 1) {
+	psError(PSASTRO_ERR_ARGUMENTS, true, "No arguments supplied");
+	return NULL;
+    }
 
     // basic pslib options
@@ -50,12 +47,18 @@
 
     status = pmConfigFileSetsMD (config->arguments, config, "INPUT", "-file", "-list");
-    if (!status) { usage ();}
-
-    if (argc != 2) usage ();
-
+    if (!status) {
+	psError(PSASTRO_ERR_ARGUMENTS, true, "Missing -file (input) or -list (input)");
+	return NULL;
+    }
+    
+    if (argc != 2) {
+	psError(PSASTRO_ERR_ARGUMENTS, true, "Incorrect arguments supplied");
+	return NULL;
+    }
+    
     // output positions is fixed
     psMetadataAddStr (config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "", argv[1]);
 
-    psTrace(__func__, 1, "Done with psastroArguments...\n");
+    psTrace("psastro", 1, "Done with psastroArguments...\n");
     return (config);
 }
Index: /trunk/psastro/src/psastroAstromGuess.c
===================================================================
--- /trunk/psastro/src/psastroAstromGuess.c	(revision 9573)
+++ /trunk/psastro/src/psastroAstromGuess.c	(revision 9574)
@@ -26,6 +26,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-        psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-        exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!");
+	return false;
     }
 
@@ -33,6 +33,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-        psErrorStackPrint(stderr, "Can't find input data!\n");
-        exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
+	return false;
     }
 
@@ -45,5 +45,5 @@
 
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 
@@ -63,5 +63,5 @@
         // XXX should this go into a different function? this would separate WCS interpretation from application
         while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
@@ -80,5 +80,5 @@
                     p_psDeproject (raw->sky, raw->TP, fpa->projection);
 
-                    if (i < 0) {
+		    if ((i < 10) && (psTraceGetLevel("psastro.guess") > 5)) {
                         fprintf (stderr, "up: %f,%f -> %f,%f -> %f,%f -> %f,%f\n",
                                  raw->chip->x, raw->chip->y,
Index: /trunk/psastro/src/psastroChipAstrom.c
===================================================================
--- /trunk/psastro/src/psastroChipAstrom.c	(revision 9573)
+++ /trunk/psastro/src/psastroChipAstrom.c	(revision 9574)
@@ -11,6 +11,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe");
+	return false;
     }
 
@@ -18,6 +18,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psErrorStackPrint(stderr, "Can't find input data!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");
+	return false;
     }
 
@@ -29,9 +29,9 @@
 
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroConvert.c
===================================================================
--- /trunk/psastro/src/psastroConvert.c	(revision 9573)
+++ /trunk/psastro/src/psastroConvert.c	(revision 9574)
@@ -10,9 +10,9 @@
  
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroDataLoad.c
===================================================================
--- /trunk/psastro/src/psastroDataLoad.c	(revision 9573)
+++ /trunk/psastro/src/psastroDataLoad.c	(revision 9574)
@@ -1,10 +1,8 @@
 # include "psastro.h"
-// XXX leak free 2006.04.27
-
 // this loop loads the data from the input files and selects the
 // brighter stars for astrometry
 // at the end of this function, the complete stellar data is loaded
 // into the correct fpa structure locations (readout.analysis:PSPHOT.SOURCES)
-// 
+
 // all of the different astrometry analysis modes use the same data load loop
 bool psastroDataLoad (pmConfig *config) {
@@ -17,6 +15,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");
+	return false;
     }
 
@@ -24,7 +22,8 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psErrorStackPrint(stderr, "Can't find input data!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
     }
+
     // de-activate all files except PSASTRO.INPUT
     pmFPAfileActivate (config->files, false, NULL);
@@ -37,10 +36,10 @@
 
     while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
 	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
Index: /trunk/psastro/src/psastroDataSave.c
===================================================================
--- /trunk/psastro/src/psastroDataSave.c	(revision 9573)
+++ /trunk/psastro/src/psastroDataSave.c	(revision 9574)
@@ -12,6 +12,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");
+	return false;
     }
 
@@ -19,6 +19,6 @@
     pmFPAfile *output = psMetadataLookupPtr (NULL, config->files, "PSASTRO.OUTPUT");
     if (!output) {
-	psErrorStackPrint(stderr, "Can't find output data!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find output data!\n");
+	return false;
     }
 
@@ -33,10 +33,10 @@
 
     while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
 	while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
Index: /trunk/psastro/src/psastroLoadReferences.c
===================================================================
--- /trunk/psastro/src/psastroLoadReferences.c	(revision 9573)
+++ /trunk/psastro/src/psastroLoadReferences.c	(revision 9574)
@@ -42,17 +42,17 @@
     # if ELIXIR_MODE
     if (CATDIR) {
-	sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT elixir -D CATMODE mef -region %f %f %f %f > %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);
+	sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT elixir -D CATMODE mef -region %f %f %f %f -o %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);
     } else {
-	sprintf (tempLine, "getstar -D CATFORMAT elixir -D CATMODE mef -region %f %f %f %f > %s", RAmin, DECmin, RAmax, DECmax, tempFile);
+	sprintf (tempLine, "getstar -D CATFORMAT elixir -D CATMODE mef -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
     }
     # else
     if (CATDIR) {
-	sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT panstarrs -D CATMODE mef -region %f %f %f %f > %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);
+	sprintf (tempLine, "getstar -D CATDIR %s -D CATFORMAT panstarrs -D CATMODE mef -region %f %f %f %f -o %s", CATDIR, RAmin, DECmin, RAmax, DECmax, tempFile);
     } else {
-	sprintf (tempLine, "getstar -D CATFORMAT panstarrs -D CATMODE mef -region %f %f %f %f > %s", RAmin, DECmin, RAmax, DECmax, tempFile);
+	sprintf (tempLine, "getstar -D CATFORMAT panstarrs -D CATMODE mef -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
     }
     # endif
 
-    psTrace (__func__, 3, "%s\n", tempLine);
+    psTrace ("psastro", 3, "%s\n", tempLine);
     status = system (tempLine);
     if (status) {
@@ -99,5 +99,5 @@
     psFree (table);
 
-    psTrace (__func__, 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
+    psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
              refs->n, RAmin, DECmin, RAmax, DECmax);
     return refs;
Index: /trunk/psastro/src/psastroMosaicAstrom.c
===================================================================
--- /trunk/psastro/src/psastroMosaicAstrom.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicAstrom.c	(revision 9574)
@@ -9,6 +9,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");
+	return false;
     }
 
@@ -16,6 +16,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psErrorStackPrint(stderr, "Can't find input data!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
     }
 
Index: /trunk/psastro/src/psastroMosaicChipAstrom.c
===================================================================
--- /trunk/psastro/src/psastroMosaicChipAstrom.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicChipAstrom.c	(revision 9574)
@@ -10,9 +10,9 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroMosaicGetGrads.c
===================================================================
--- /trunk/psastro/src/psastroMosaicGetGrads.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicGetGrads.c	(revision 9574)
@@ -12,9 +12,9 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroMosaicGetRefstars.c
===================================================================
--- /trunk/psastro/src/psastroMosaicGetRefstars.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicGetRefstars.c	(revision 9574)
@@ -11,6 +11,6 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-	psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");
+	return false;
     }
 
@@ -18,6 +18,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-	psErrorStackPrint(stderr, "Can't find input data!\n");
-	exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
     }
 
@@ -30,9 +30,9 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
@@ -75,5 +75,5 @@
 		    psFree (ref);
 		}
-		psTrace (__func__, 4, "Added %ld refstars\n", refstars->n);
+		psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);
 		psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.REFSTARS", PS_DATA_ARRAY, "astrometry matches", refstars);
 
Index: /trunk/psastro/src/psastroMosaicHeaders.c
===================================================================
--- /trunk/psastro/src/psastroMosaicHeaders.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicHeaders.c	(revision 9574)
@@ -9,13 +9,14 @@
     psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PSASTRO");
     if (!recipe) {
-        psErrorStackPrint(stderr, "Can't find PSASTRO recipe!\n");
-        exit(EXIT_FAILURE);
+ 	psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");
+	return false;
     }
+
 
     // select the input data sources
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
     if (!input) {
-        psErrorStackPrint(stderr, "Can't find input data!\n");
-        exit(EXIT_FAILURE);
+	psError(PSASTRO_ERR_CONFIG, true, "Can't find input data!\n");
+	return false;
     }
 
@@ -29,5 +30,5 @@
 
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroMosaicRescaleChips.c
===================================================================
--- /trunk/psastro/src/psastroMosaicRescaleChips.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicRescaleChips.c	(revision 9574)
@@ -8,5 +8,5 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
Index: /trunk/psastro/src/psastroMosaicSetAstrom.c
===================================================================
--- /trunk/psastro/src/psastroMosaicSetAstrom.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicSetAstrom.c	(revision 9574)
@@ -10,9 +10,9 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
Index: /trunk/psastro/src/psastroMosaicSetMatch.c
===================================================================
--- /trunk/psastro/src/psastroMosaicSetMatch.c	(revision 9573)
+++ /trunk/psastro/src/psastroMosaicSetMatch.c	(revision 9574)
@@ -16,9 +16,9 @@
     // this loop selects the matched stars for all chips
     while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
-        psTrace (__func__, 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
+        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
 	
 	while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
-            psTrace (__func__, 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
+            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
 
@@ -35,10 +35,10 @@
 		psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");
 		if (refstars == NULL) { continue; }
-		psTrace (__func__, 4, "Trying %ld refstars\n", refstars->n);
+		psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n);
 
 		// use small radius to match stars (assume starting astrometry is good)
 		// XXX should this take a (double radius)?
 		psArray *matches = pmAstromRadiusMatchChip (rawstars, refstars, recipe);
-		psTrace (__func__, 4, "Matched %ld refstars\n", matches->n);
+		psTrace ("psastro", 4, "Matched %ld refstars\n", matches->n);
 
 		sprintf (name, "raw.%02d.dat", view->chip);
Index: /trunk/psastro/src/psastroOneChip.c
===================================================================
--- /trunk/psastro/src/psastroOneChip.c	(revision 9573)
+++ /trunk/psastro/src/psastroOneChip.c	(revision 9574)
@@ -13,5 +13,5 @@
     pmAstromStats stats = pmAstromGridMatch (rawstars, refstars, recipe);
     stats = pmAstromGridTweak (rawstars, refstars, recipe, stats);
-    psLogMsg (__func__, 3, "grid search result: %f,%f @ %f deg\n", stats.offset.x, stats.offset.y, DEG_RAD*stats.angle);
+    psLogMsg ("psastro", 3, "grid search result: %f,%f @ %f deg\n", stats.offset.x, stats.offset.y, DEG_RAD*stats.angle);
 
     // adjust the chip.toFPA terms only
Index: /trunk/psastro/src/psastroParseCamera.c
===================================================================
--- /trunk/psastro/src/psastroParseCamera.c	(revision 9573)
+++ /trunk/psastro/src/psastroParseCamera.c	(revision 9574)
@@ -1,4 +1,3 @@
 # include "psastro.h"
-// XXX leak free 2006.04.27
 
 bool psastroParseCamera (pmConfig *config) {
@@ -8,5 +7,8 @@
     // the input image(s) are required arguments; they define the camera
     pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PSASTRO.INPUT", "INPUT");
-    if (!status) { psAbort (__func__, "missing INPUT entry"); }
+    if (!status) {
+	psError(PSASTRO_ERR_CONFIG, false, "Failed to build FPA from PSASTRO.INPUT");
+	return false;
+    }
 
     // select recipe options supplied on command line
@@ -30,6 +32,6 @@
 	    int chipNum = atoi(chips->data[i]);
 	    if (! pmFPASelectChip(input->fpa, chipNum, false)) {
-		psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum);
-		exit(EXIT_FAILURE);
+		psError(PSASTRO_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum);
+		return false;
 	    }
         }
@@ -37,5 +39,5 @@
     psFree (chips);
 
-    psTrace(__func__, 1, "Done with psastroParseCamera...\n");
+    psTrace("psastro", 1, "Done with psastroParseCamera...\n");
     return true;
 }
Index: /trunk/psastro/src/psastroTestFuncs.c
===================================================================
--- /trunk/psastro/src/psastroTestFuncs.c	(revision 9573)
+++ /trunk/psastro/src/psastroTestFuncs.c	(revision 9574)
@@ -32,5 +32,5 @@
 	for (int j = 0; j < map->x->nY + 1; j++) {
 	    if (map->x->mask[i][j]) continue;
-	    psLogMsg (__func__, 4, "x term %d,%d: %f +/- %f\n", i, j, map->x->coeff[i][j], map->x->coeffErr[i][j]);
+	    psLogMsg ("psastro", 4, "x term %d,%d: %f +/- %f\n", i, j, map->x->coeff[i][j], map->x->coeffErr[i][j]);
 	}
     }
@@ -39,5 +39,5 @@
 	for (int j = 0; j < map->y->nY + 1; j++) {
 	    if (map->y->mask[i][j]) continue;
-	    psLogMsg (__func__, 4, "y term %d,%d: %f +/- %f\n", i, j, map->y->coeff[i][j], map->y->coeffErr[i][j]);
+	    psLogMsg ("psastro", 4, "y term %d,%d: %f +/- %f\n", i, j, map->y->coeff[i][j], map->y->coeffErr[i][j]);
 	}
     }
Index: /trunk/psastro/src/psastroWCS.c
===================================================================
--- /trunk/psastro/src/psastroWCS.c	(revision 9573)
+++ /trunk/psastro/src/psastroWCS.c	(revision 9574)
@@ -6,5 +6,5 @@
 
     psProjectionType type;
-    bool status;
+    bool status, pcKeys, cdKeys;
     float crval1, crval2, crpix1, crpix2, cdelt1, cdelt2;
     float pc1_1, pc1_2, pc2_1, pc2_2;
@@ -29,4 +29,17 @@
     }
 
+    // what type of WCS keywords are available?
+    psMetadataLookupF32 (&pcKeys, header, "PC001001");
+    psMetadataLookupF32 (&cdKeys, header, "CD1_1");
+
+    if (cdKeys && pcKeys) {
+	psLogMsg ("psastro", 2, "warning: both CDi_j and PC00i00j defined in headers, using CDi_j terms\n");
+    }
+    if (!cdKeys && !pcKeys) {
+        psError(PS_ERR_UNKNOWN, true, "missing both CDi_j and PC00i00j WCS terms");
+	// XXX we could default here to RA, DEC, ROTANGLE
+	return false;
+    }
+
     crval1 = psMetadataLookupF32 (&status, header, "CRVAL1");
     crval2 = psMetadataLookupF32 (&status, header, "CRVAL2");
@@ -35,6 +48,6 @@
     
     // test the CDELTi varient
-    cdelt1 = psMetadataLookupF32 (&status, header, "CDELT1");
-    if (status) {
+    if (pcKeys) {
+	cdelt1 = psMetadataLookupF32 (&status, header, "CDELT1");
 	cdelt2 = psMetadataLookupF32 (&status, header, "CDELT2");
 
@@ -65,6 +78,6 @@
 
     // test the CDi_j varient
-    pc1_1 = psMetadataLookupF32 (&status, header, "CD1_1");
-    if (status) {
+    if (cdKeys) {
+	pc1_1 = psMetadataLookupF32 (&status, header, "CD1_1");
 	pc1_2 = psMetadataLookupF32 (&status, header, "CD1_2");
 	pc2_1 = psMetadataLookupF32 (&status, header, "CD2_1");
