Index: trunk/psModules/src/concepts/pmConceptsPhotcode.c
===================================================================
--- trunk/psModules/src/concepts/pmConceptsPhotcode.c	(revision 8815)
+++ trunk/psModules/src/concepts/pmConceptsPhotcode.c	(revision 9572)
@@ -4,26 +4,31 @@
 
 #include <stdio.h>
+#include <string.h>
 #include <pslib.h>
 
 #include "pmConceptsPhotcode.h"
 
-char *pmConceptsPhotcodeForView (pmConfig *config, pmFPAfile *file, pmFPAview *view)
+psString pmConceptsPhotcodeForView(pmConfig *config, pmFPAfile *file, pmFPAview *view)
 {
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(file, NULL);
+    PS_ASSERT_PTR_NON_NULL(view, NULL);
 
     if (view->chip < -1) {
-        psError(PS_ERR_IO, true, "photcodes undefined for FPA: defined by chip\n");
+        psError(PS_ERR_IO, true, "Photcodes undefined for FPA: defined by chip\n");
         return NULL;
     }
 
     // select recipe options supplied on command line
-    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, "PHASE2");
-    if (recipe == NULL) {
-        psError(PS_ERR_IO, true, "recipe PHASE2 not found\n");
+    bool mdok;                          // Status of MD lookup
+    psMetadata *recipe  = psMetadataLookupPtr(&mdok, config->recipes, "PHASE2");
+    if (!mdok || !recipe) {
+        psError(PS_ERR_IO, true, "Recipe PHASE2 not found\n");
         return NULL;
     }
 
     // select photcode rule from recipe
-    char *rule = psMetadataLookupStr (NULL, recipe, "PHOTCODE.RULE");
-    if (rule == NULL) {
+    char *rule = psMetadataLookupStr(&mdok, recipe, "PHOTCODE.RULE");
+    if (!mdok || !rule || strlen(rule) == 0) {
         psError(PS_ERR_IO, true, "PHOTCODE.RULE not found in PHASE2 recipe\n");
         return NULL;
@@ -31,5 +36,5 @@
 
     // convert rule to real photcode
-    char *photcode = pmFPAfileNameFromRule (rule, file, view);
+    psString photcode = pmFPAfileNameFromRule(rule, file, view);
 
     return photcode;
