Index: /trunk/psastro/src/psastroUseModel.c
===================================================================
--- /trunk/psastro/src/psastroUseModel.c	(revision 27045)
+++ /trunk/psastro/src/psastroUseModel.c	(revision 27046)
@@ -1,5 +1,5 @@
 /** @file psastroMosiacAstrom.c
  *
- *  @brief 
+ *  @brief
  *
  *  @ingroup libpsastro
@@ -17,5 +17,5 @@
 /**
  * Apply the generic astrometry model to this image.  This assumes the WCS i
- * terms either do not exist or are invalid 
+ * terms either do not exist or are invalid
  */
 bool psastroUseModel (pmConfig *config, psMetadata *recipe) {
@@ -29,5 +29,5 @@
   if (!useModel) return true;
 
-  // identify reference astrometry table.  
+  // identify reference astrometry table.
   // if not defined, correction was not requested; skip step
   pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.MODEL");
@@ -69,23 +69,23 @@
       pmFPAview *myView = pmFPAviewAlloc (0);
 
-      // loop over all chips, replace input astrometry elements with those from astrom 
+      // loop over all chips, replace input astrometry elements with those from astrom
       pmChip *obsChip = NULL;
       while ((obsChip = pmFPAviewNextChip (myView, input->fpa, 1)) != NULL) {
-	  psTrace ("psastro", 4, "Chip %d: %x %x\n", myView->chip, obsChip->file_exists, obsChip->process);
-	  if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }
+          psTrace ("psastro", 4, "Chip %d: %x %x\n", myView->chip, obsChip->file_exists, obsChip->process);
+          if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }
 
-	  // set the chip astrometry using the astrom file
-	  pmChip *refChip = pmFPAviewThisChip (myView, astrom->fpa);
+          // set the chip astrometry using the astrom file
+          pmChip *refChip = pmFPAviewThisChip (myView, astrom->fpa);
 
-	  psFree (obsChip->toFPA);
-	  psFree (obsChip->fromFPA);
+          psFree (obsChip->toFPA);
+          psFree (obsChip->fromFPA);
 
-	  // supply astrometry from model 
-	  obsChip->toFPA   = psMemIncrRefCounter (refChip->toFPA);
-	  obsChip->fromFPA = psMemIncrRefCounter (refChip->fromFPA);
+          // supply astrometry from model
+          obsChip->toFPA   = psMemIncrRefCounter (refChip->toFPA);
+          obsChip->fromFPA = psMemIncrRefCounter (refChip->fromFPA);
 
-	  // XXX if we want to write out the result, update the header here.  this needs to be
-	  // updated with the correct HDU selection.  obsChip->hdu may not exist.
-	  // pmAstromWriteBilevelChip (obsChip->hdu->header, obsChip, NONLIN_TOL);
+          // XXX if we want to write out the result, update the header here.  this needs to be
+          // updated with the correct HDU selection.  obsChip->hdu may not exist.
+          // pmAstromWriteBilevelChip (obsChip->hdu->header, obsChip, NONLIN_TOL);
       }
 
@@ -108,5 +108,5 @@
   if (DEBUG) psastroDumpCorners ("corners.up.ast2.dat", "corners.dn.ast2.dat", astrom->fpa);
 
-  // loop over all chips, replace input astrometry elements with those from astrom 
+  // loop over all chips, replace input astrometry elements with those from astrom
   pmChip *obsChip = NULL;
   while ((obsChip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
@@ -120,5 +120,5 @@
     psFree (obsChip->fromFPA);
 
-    // supply astrometry from model 
+    // supply astrometry from model
     obsChip->toFPA   = psMemIncrRefCounter (refChip->toFPA);
     obsChip->fromFPA = psMemIncrRefCounter (refChip->fromFPA);
@@ -147,4 +147,10 @@
   // psFree (updates);
 
+  // files associated with the science image
+  if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
+      psError (PS_ERR_IO, false, "Can't close the astrometry model file");
+      return false;
+  }
+
   psFree (view);
   return true;
