Index: trunk/ppImage/src/ppImageAstrom.c
===================================================================
--- trunk/ppImage/src/ppImageAstrom.c	(revision 10439)
+++ trunk/ppImage/src/ppImageAstrom.c	(revision 11352)
@@ -5,4 +5,6 @@
 # include "ppImage.h"
 
+// this function is mostly equivalent to the top-level of psastro, with some
+// modifications since the data has already been loaded.
 bool ppImageAstrom (pmConfig *config) {
 
@@ -16,5 +18,4 @@
     pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSASTRO.INPUT");
     if (!status) {
-
 	// psphotReadout requires a pmFPAfile supplied with the name PSASTRO.INPUT
 	// create a pmFPAfile which points at PSPHOT.OUTPUT
@@ -27,22 +28,51 @@
     }
 
-    psastroConvertFPA (input->fpa, recipe);
+    // convert the output sources created by psphot into astrometry objects
+    if (!psastroConvertFPA (input->fpa, recipe)) {
+	psErrorStackPrint(stderr, "error loading input data\n");
+	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\n");
+	exit (1);
+    }
 
     // load the reference stars overlapping the data stars
     psArray *refs = psastroLoadRefstars(config);
-
-    psastroChooseRefstars(config, refs); 
-
-    if (psMetadataLookupBool (NULL, recipe, "ASTROM.CHIP")) {
-	psastroChipAstrom (config, refs);
-    } 
-    if (psMetadataLookupBool (NULL, recipe, "ASTROM.MOSAIC")) {
-	psastroMosaicAstrom (config, refs);
+    if (!refs) {
+	psErrorStackPrint(stderr, "failed to load reference data\n");
+	exit (1);
     }
 
+    if (!psastroChooseRefstars (config, refs)) {
+	psErrorStackPrint(stderr, "failed to select reference data for chips\n");
+	exit (1);
+    }
+
+    // XXX does this check the recipe??
+    bool chipastro = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.CHIP.MODE");
+    bool mosastro  = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.MOSAIC.MODE");
+    if (!chipastro && !mosastro) {
+	psLogMsg ("psastro", 3, "no astrometry mode selected, assuming chip mode\n");
+	chipastro= true;
+    }
+
+    if (chipastro) {
+      if (!psastroChipAstrom (config, refs)) {
+	    psErrorStackPrint(stderr, "failed to perform single chip astrometry\n");
+	    exit (1);
+	}
+    } 
+    if (mosastro) {
+	if (!psastroMosaicAstrom (config, refs)) {
+	    psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry\n");
+	    exit (1);
+	}
+    }
+
+    // XXX should this be left to the ppImageLoop?
     psastroDataSave (config);
 
