Index: trunk/psastro/src/psastroChooseRefstars.c
===================================================================
--- trunk/psastro/src/psastroChooseRefstars.c	(revision 15963)
+++ trunk/psastro/src/psastroChooseRefstars.c	(revision 17037)
@@ -1,3 +1,10 @@
 # include "psastroInternal.h"
+
+# define ESCAPE { \
+  psError(PS_ERR_UNKNOWN, false, "Failure in psastroChooseRefstars"); \
+  psFree (index); \
+  psFree (view); \
+  return false; \
+}
 
 bool psastroChooseRefstars (pmConfig *config, psArray *refs) {
@@ -35,4 +42,8 @@
 
     int nMax = psMetadataLookupS32 (&status, recipe, "PSASTRO.MAX.NREF");
+
+    // de-activate all files except PSASTRO.REFSTARS
+    pmFPAfileActivate (config->files, false, NULL);
+    pmFPAfileActivate (config->files, true, "PSASTRO.REFSTARS");
 
     // this loop selects the matched stars for all chips
@@ -101,5 +112,11 @@
             }
         }
+	if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
     }
+    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE;
+
+    // activate all files except PSASTRO.OUTPUT
+    if (!pmFPAfileActivate (config->files, true, NULL)) ESCAPE;
+    if (!pmFPAfileActivate (config->files, false, "PSASTRO.REFSTARS")) ESCAPE;
 
     psFree (index);
