Index: trunk/psastro/src/psastroDefineFiles.c
===================================================================
--- trunk/psastro/src/psastroDefineFiles.c	(revision 36441)
+++ trunk/psastro/src/psastroDefineFiles.c	(revision 36837)
@@ -43,7 +43,44 @@
         if (!psastroDefineFile (config, input->fpa, "PSASTRO.MODEL", "ASTROM.MODEL", PM_FPA_FILE_ASTROM_MODEL, PM_DETREND_TYPE_ASTROM)) {
             psError (PS_ERR_IO, false, "Can't find an astrometry model file");
-            return NULL;
-        }
-    }
+            return false;
+        }
+    }
+
+    bool KHapply = psMetadataLookupBool (&status, recipe, "KH.CORRECT.APPLY");
+    if (KHapply) {
+	// Get the time from FPA.TIME
+	psTime *time = psMetadataLookupPtr(NULL, input->fpa->concepts, "FPA.TIME");
+	if (time->sec == 0 && time->nsec == 0) {
+	    psError (PM_ERR_CONFIG, false, "KH.CORRECT.APPLY requested, but date/time of exposure not found");
+	    return false;
+	}
+	// what is the appropriate date range for the correction
+	char *KHendDate = psMetadataLookupStr (&status, recipe, "KH.CORRECT.ENDDATE");
+	if (!KHendDate) {
+	    psError (PM_ERR_CONFIG, false, "KH.CORRECT.APPLY requested, but KH.CORRECT.ENDDATE not in recipe");
+	    return false;
+	}
+	psTime *endtime = psTimeFromString (KHendDate, PS_TIME_TAI);
+	if (!endtime) {
+	    psError (PM_ERR_CONFIG, false, "KH.CORRECT.APPLY requested, KH.CORRECT.ENDDATE has an invalid date/time");
+	    return false;
+	}
+	if (psTimeDelta (endtime, time) < 0) {
+	    KHapply = false;
+	    psLogMsg ("psastro", PS_LOG_INFO, "Koppenhoefer correction requested, but exposure after end date, correction skipped");
+	} else {
+	    psLogMsg ("psastro", PS_LOG_INFO, "Koppenhoefer correction requested, exposure in valid date range, correction may be applied");
+	}   
+	psFree (endtime);
+    }
+    if (KHapply) {
+        if (!psastroDefineFile (config, input->fpa, "PSASTRO.KH.CORRECT", "KH.CORRECT", PM_FPA_FILE_KH_CORRECT, PM_DETREND_TYPE_KH_CORRECT)) {
+            psError (PS_ERR_IO, false, "Can't find a Koppenhoefer Correction file");
+            return NULL;
+        }
+    }
+    // the bool above in the recipe says "apply generally for this camera".  here we are asserting that
+    // we can and should apply for this exposure XXX change the name?
+    psMetadataAddBool (recipe, PS_LIST_TAIL, "KH.CORRECT.APPLY.EXP", PS_META_REPLACE, "", KHapply);
 
     // this step is optional
