Index: trunk/psastro/src/psastroDefineFiles.c
===================================================================
--- trunk/psastro/src/psastroDefineFiles.c	(revision 20640)
+++ trunk/psastro/src/psastroDefineFiles.c	(revision 20641)
@@ -33,4 +33,39 @@
             return NULL;
         }
+    }
+
+    // this step is optional
+    bool REFSTAR_MASK = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK");
+    if (REFSTAR_MASK) {
+
+        if (!psastroDefineFile (config, input->fpa, "PSASTRO.REFMASK", "REFMASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+            psError (PS_ERR_IO, false, "Can't find an input mask file");
+            return NULL;
+        }
+
+        if (!psastroDefineFile (config, input->fpa, "PSASTRO.INPUT.MASK", "INPUT.MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
+            psError (PS_ERR_IO, false, "Can't find an input mask file");
+            return NULL;
+        }
+
+	pmFPAfile *inMask = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT.MASK");
+	if (!inMask) {
+            psError (PS_ERR_IO, false, "Can't find an input mask file");
+            return NULL;
+        }
+
+	// XXX not yet sure if we need to mosaic or not...
+	pmFPAfile *outMask = pmFPAfileDefineOutputFromFile  (config, inMask, "PSASTRO.OUTPUT.MASK");
+	// pmFPAfile *outMask = pmFPAfileDefineChipMosaic(config, inMask->fpa, "PSASTRO.OUTPUT.MASK");
+	if (!outMask) {
+	    psError (PS_ERR_IO, false, "Can't find the astrometry refstars file definition");
+	    return NULL;
+	}
+	if (outMask->type != PM_FPA_FILE_MASK) {
+	    psError(PS_ERR_IO, true, "%s is not of type %s", "PSASTRO.OUTPUT.MASK", pmFPAfileStringFromType (PM_FPA_FILE_MASK));
+	    return NULL;
+	}
+	outMask->save = true;
+	inMask->freeLevel = outMask->dataLevel;
     }
 
