Index: /branches/end_stage/ippTools/src/warptool.c
===================================================================
--- /branches/end_stage/ippTools/src/warptool.c	(revision 16095)
+++ /branches/end_stage/ippTools/src/warptool.c	(revision 16096)
@@ -108,14 +108,5 @@
 
     // required options
-    bool status = false;
-    psString mode = psMetadataLookupStr(&status, config->args, "-mode");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -survey_mode");
-        return false;
-    }
-    if (!mode) {
-        psError(PS_ERR_UNKNOWN, true, "-mode is required");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(mode, config->args, "-mode", true, false);
     // check mode
     if (mode && !isValidMode(config, mode)) {
@@ -123,35 +114,15 @@
         return false;
     }
-
-    psString workdir = psMetadataLookupStr(&status, config->args, "-workdir");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -workdir");
-        return false;
-    }
-    if (!workdir) {
-        psError(PS_ERR_UNKNOWN, true, "-workdir is required");
-        return false;
-    }
-
-    psString dvodb = psMetadataLookupStr(&status, config->args, "-dvodb");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dvodb");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-
-    psString end_stage = psMetadataLookupStr(&status, config->args, "-end_stage");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -end_stage");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
+
+    // optional
+    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
+    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false);
+    PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psTime *registered = NULL;
     {
+        bool status;
         psString registeredStr = psMetadataLookupStr(&status, config->args, "-registered");
         if (!status) {
@@ -193,15 +164,4 @@
     warpRun->warp_id = warp_id;
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            psFree(warpRun);
-            return false;
-        }
-    }
-
     if (!warpRunPrintObject(stdout, warpRun, !simple)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print object");
@@ -276,24 +236,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString warp_id = psMetadataLookupStr(&status, config->args, "-warp_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -warpt_id");
-        return false;
-    }
-    if (!warp_id) {
-        psError(PS_ERR_UNKNOWN, true, "-warp_id is required");
-        return false;
-    }
-
-    psString state = psMetadataLookupStr(&status, config->args, "-state");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
-        return false;
-    }
-    if (!state) {
-        psError(PS_ERR_UNKNOWN, true, "-state is required");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", true, false);
+    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
 
     if (state) {
@@ -310,35 +252,10 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString warp_id = psMetadataLookupStr(&status, config->args, "-warp_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -warp_id");
-        return false;
-    }
-    if (!warp_id) {
-        psError(PS_ERR_UNKNOWN, true, "-warp_id is required");
-        return false;
-    }
-
-    psString cam_id = psMetadataLookupStr(&status, config->args, "-cam_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -cam_id");
-        return false;
-    }
-    if (!cam_id) {
-        psError(PS_ERR_UNKNOWN, true, "-cam_id is required");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", true, false);
+    PXOPT_LOOKUP_STR(cam_id, config->args, "-cam_id", true, false);
 
     // defaults to false
-    bool magiced = psMetadataLookupBool(&status, config->args, "-magiced");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -magiced");
-        return false;
-    }
-
-    // XXX need to validate the warp_id here
-    // XXX instead of validiting it here we should just use forgein key
-    // constrants
+    PXOPT_LOOKUP_BOOL(magiced, config->args, "-magiced", false);
+
     if (!warpInputExpInsert(config->dbh,
             (psS64)atoll(warp_id),
@@ -358,10 +275,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -412,14 +325,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
@@ -447,10 +350,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -501,14 +400,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
@@ -536,10 +425,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -590,14 +475,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
@@ -620,19 +495,10 @@
 }
 
-
+    
 static bool addoverlapMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString mapfile = psMetadataLookupStr(&status, config->args, "-mapfile");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -mapfile");
-        return false;
-    }
-    if (!mapfile) {
-        psError(PS_ERR_UNKNOWN, true, "-mapfile is required");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(mapfile, config->args, "-mapfile", false, false);
 
     if (!psDBTransaction(config->dbh)) {
@@ -724,10 +590,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -778,14 +640,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
@@ -813,10 +665,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -867,14 +715,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
@@ -902,78 +740,18 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString warp_id = psMetadataLookupStr(&status, config->args, "-warp_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -warp_id");
-        return false;
-    }
-    if (!warp_id) {
-        psError(PS_ERR_UNKNOWN, true, "-warp_id is required");
-        return false;
-    }
-
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
-        return false;
-    }
-
-    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
-        return false;
-    }
-
-    psString path_base = psMetadataLookupStr(&status, config->args, "-path_base");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -path_base");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(warp_id, config->args, "-warp_id", true, false);
+    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
+    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
 
     // optional
-    psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");
-        return false;
-    }
-
-    psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev");
-        return false;
-    }
-
-    psF64 good_frac = psMetadataLookupF64(&status, config->args, "-good_frac");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -good_frac");
-        return false;
-    }
-
-    bool ignore = psMetadataLookupBool(&status, config->args, "-ignore");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ignore");
-        return false;
-    }
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);
+    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
+    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
+    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
+    PXOPT_LOOKUP_F64(good_frac, config->args, "-good_frac", false, false);
+    PXOPT_LOOKUP_BOOL(ignore, config->args, "-ignore", false);
 
     // default values
-    psS16 code = psMetadataLookupS16(&status, config->args, "-code");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
-        return false;
-    }
+    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
 
     // we don't want to insert the last skyfile in a run but then not mark the
@@ -1132,10 +910,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     // find all rawImfiles matching the default query
@@ -1186,14 +960,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     if (psArrayLength(output)) {
         if (!convertIdToStr(output)) {
