Index: trunk/ppImage/src/ppImageOptions.c
===================================================================
--- trunk/ppImage/src/ppImageOptions.c	(revision 5858)
+++ trunk/ppImage/src/ppImageOptions.c	(revision 5976)
@@ -1,119 +1,126 @@
-# include "ppImage.h"
+#include "ppImage.h"
 
 // XXX EAM : this needs signficant work to choose the detrend images based on the detrend database
 
-bool ppImageOptions (ppData *data, ppOptions *options, ppConfig *config) {
+bool ppImageOptions(ppData *data, ppOptions *options, ppConfig *config)
+{
 
-    bool status;
-
-    // default initial values
-    options->doMask = false;		// Mask bad pixels
-    options->doNonLin = false;		// Non-linearity correction
-    options->doBias = false;		// Bias subtraction
-    options->doDark = false;		// Dark subtraction
-    options->doOverscan = false;	// Overscan subtraction
-    options->doFlat = false;		// Flat-field normalisation
-    options->doFringe = false;		// Fringe subtraction
-    options->doSource = false;		// Source identification and photometry
-    options->doAstrom = false;		// Astrometry
-    options->overscanBins = 1;		// Number of pixels per bin for overscan
+    // Flags for various activities
+    options->doMask = false;            // Mask bad pixels
+    options->doNonLin = false;          // Non-linearity correction
+    options->doBias = false;            // Bias subtraction
+    options->doDark = false;            // Dark subtraction
+    options->doOverscan = false;        // Overscan subtraction
+    options->doFlat = false;            // Flat-field normalisation
+    options->doFringe = false;          // Fringe subtraction
+    options->doSource = false;          // Source identification and photometry
+    options->doAstrom = false;          // Astrometry
+    // Overscan options
+    options->overscanBins = 1;          // Number of pixels per bin for overscan
     options->overscanStats = NULL;      // Statistics for overscan
-    options->overscanFit = NULL;	// Overscan fit (polynomial or spline)
+    options->overscanFit = NULL;        // Overscan fit (polynomial or spline)
     options->overscanFitType = PM_FIT_NONE; // Fit type for overscan
     options->overscanMode = PM_OVERSCAN_NONE; // Axis for overscan
+    // Non-linearity options
+    options->nonLinearType = 0;         // Type of non-linearity data (vector, string or metadata)
+    options->nonLinearData = NULL;      // The non-linearity data
+    options->nonLinearSource = NULL;    // If the non-linearity data is a menu, this provides the key
+    // Various others
+    options->imageLoadDepth = PP_LOAD_NONE; // No load depth specified yet
 
-    options->doNonLin = false;
-    options->nonLinearType = false;
-    options->nonLinearData = NULL;
-    options->nonLinearSource = NULL;
-
-    options->imageLoadDepth = PP_LOAD_NONE;
-    char *depth = psMetadataLookupPtr(NULL, config->recipe, "LOAD.DEPTH");
-    if (depth == NULL) {
-	psAbort ("phase2", "load depth not specified");
+    bool mdStatus = false;              // Result of MD lookup
+    const char *depth = psMetadataLookupStr(&mdStatus, config->recipe, "LOAD.DEPTH");
+    if (! mdStatus || ! depth || strlen(depth) == 0) {
+        psLogMsg("ppImage", PS_LOG_ERROR, "LOAD.DEPTH not specified in recipe.");
+        exit(EXIT_FAILURE);
     }
     if (!strcasecmp(depth, "FPA")) {
-	options->imageLoadDepth = PP_LOAD_FPA;
-    }
-    if (!strcasecmp(depth, "CHIP")) {
-	options->imageLoadDepth = PP_LOAD_CHIP;
-    }
-    if (!strcasecmp(depth, "CELL")) {
-	options->imageLoadDepth = PP_LOAD_CELL;
-    }
-    if (options->imageLoadDepth == PP_LOAD_NONE) {
-	psAbort ("phase2", "load depth not specified");
+        options->imageLoadDepth = PP_LOAD_FPA;
+    } else if (!strcasecmp(depth, "CHIP")) {
+        options->imageLoadDepth = PP_LOAD_CHIP;
+    } else if (!strcasecmp(depth, "CELL")) {
+        options->imageLoadDepth = PP_LOAD_CELL;
+    } else {
+        psLogMsg(__func__, PS_LOG_ERROR, "LOAD.DEPTH in recipe is not FPA, CHIP or CELL.");
+        exit(EXIT_FAILURE);
     }
 
-    // mask - recipe options
+    // Mask recipe options
     if (psMetadataLookupBool(NULL, config->recipe, "MASK")) {
-	data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
-        if (strlen(data->mask->filename) > 0) {
+        data->mask->filename = psMetadataLookupStr(NULL, config->arguments, "-mask");
+        if (data->mask->filename && strlen(data->mask->filename) > 0) {
             options->doMask = true;
         } else {
-            psLogMsg("phase2", PS_LOG_WARN, "Masking is desired, but no mask was supplied"
-		     " --- no masking will be performed.\n");
+            psLogMsg(__func__, PS_LOG_WARN, "Masking is desired, but no mask was supplied"
+                     " --- no masking will be performed.\n");
         }
     }
 
-    // non-linear - recipe options
+    // Non-linearity recipe options
     if (psMetadataLookupBool(NULL, config->recipe, "NONLIN")) {
-	psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA");
-	if (! dataItem) {
-	    psAbort("phase2", "Non-linearity correction desired, but unable to "
-		     "find NONLIN.DATA in recipe");
-	} 
+        psMetadataItem *dataItem = psMetadataLookup(config->recipe, "NONLIN.DATA");
+        if (! dataItem) {
+            psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to "
+                     "find NONLIN.DATA in recipe.");
+            exit(EXIT_FAILURE);
+        }
 
         options->doNonLin = true;
-	options->nonLinearType = dataItem->type;
-	options->nonLinearData = dataItem;
+        options->nonLinearType = dataItem->type;
+        options->nonLinearData = dataItem;
 
-	switch (dataItem->type) {
-	  case PS_DATA_VECTOR:
-	  case PS_DATA_STRING:
-	    break;
+        switch (dataItem->type) {
+            // No immediate action required
+          case PS_DATA_VECTOR:
+          case PS_DATA_STRING:
+            break;
 
-	  case PS_DATA_METADATA:
-	    // This is a menu
-	    options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE");
-	    if (! status || ! options->nonLinearSource) {
-		psAbort("phase2", "Non-linearity correction desired, but unable to "
-			 "find NONLIN.SOURCE in recipe");
-	    } 
-	    break;
-
-	  default:
-	    psAbort("phase2", "Non-linearity correction desired, but "
-		    "NONLIN.DATA is of invalid type.");
-	}
-
+            // This is a menu; we need the key
+          case PS_DATA_METADATA:
+            {
+                bool status;
+                options->nonLinearSource = psMetadataLookupStr(&status, config->recipe, "NONLIN.SOURCE");
+                if (! status || ! options->nonLinearSource) {
+                    psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but unable to "
+                            "find NONLIN.SOURCE in recipe");
+                    exit(EXIT_FAILURE);
+                }
+            }
+            break;
+          default:
+            psLogMsg(__func__, PS_LOG_ERROR, "Non-linearity correction desired, but "
+                    "NONLIN.DATA is of invalid type.");
+            exit(EXIT_FAILURE);
+        }
     }
 
-    // bias - recipe options
+    // Bias recipe options
     if (psMetadataLookupBool(NULL, config->recipe, "BIAS")) {
-	data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");
-        if (strlen(data->bias->filename) > 0) {
+        data->bias->filename = psMetadataLookupStr(NULL, config->arguments, "-bias");
+        if (data->bias->filename && strlen(data->bias->filename) > 0) {
             options->doBias = true;
         } else {
-            psLogMsg("phase2", PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- "
+            psLogMsg(__func__, PS_LOG_WARN, "Bias subtraction is desired, but no bias was supplied --- "
                      "no bias subtraction will be performed.\n");
         }
     }
 
-    // dark - recipe options
+    // Dark recipe options
     if (psMetadataLookupBool(NULL, config->recipe, "DARK")) {
-	data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");
-        if (strlen(data->dark->filename) > 0) {
+        data->dark->filename = psMetadataLookupStr(NULL, config->arguments, "-dark");
+        if (data->dark->filename && strlen(data->dark->filename) > 0) {
             options->doDark = true;
         } else {
-            psLogMsg("phase2", PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- "
+            psLogMsg(__func__, PS_LOG_WARN, "Dark subtraction is desired, but no dark was supplied --- "
                      "no dark subtraction will be performed.\n");
         }
     }
 
-    // overscan - recipe options
+    // XXX PAP: The overscan stuff needs to be updated following the reworked API
+
+    // Overscan recipe options
     // XXX EAM : we should abort on invalid options. default options?
     if (psMetadataLookupBool(NULL, config->recipe, "OVERSCAN")) {
-	// XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?
+        // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?
         options->doOverscan = true;
         psString mode = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.MODE");
@@ -123,5 +130,5 @@
             options->overscanMode = PM_OVERSCAN_ALL;
         } else if (strcasecmp(mode, "NONE")) {
-            psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"
+            psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"
                      " assuming NONE.\n", mode);
         }
@@ -135,7 +142,7 @@
             options->overscanFitType = PM_FIT_SPLINE;
             // int order = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
-	    // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();
+            // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();
         } else if (strcasecmp(fit, "NONE")) {
-            psLogMsg("phase2", PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
+            psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
                      " assuming NONE.\n", fit);
         }
@@ -158,9 +165,9 @@
     // flat-field - recipe options
     if (psMetadataLookupBool(NULL, config->recipe, "FLAT")) {
-	data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");
+        data->flat->filename = psMetadataLookupStr(NULL, config->arguments, "-flat");
         if (strlen(data->flat->filename) > 0) {
             options->doFlat = true;
         } else {
-            psLogMsg("phase2", PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- "
+            psLogMsg(__func__, PS_LOG_WARN, "Flat-fielding is desired, but no flat was supplied --- "
                      "no flat-fielding will be performed.\n");
         }
