Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 8285)
+++ /trunk/ippTools/src/dettool.c	(revision 8286)
@@ -10,20 +10,27 @@
 
 static bool pendingMode(pxConfig *config);
-static bool defineMode(pxConfig *config);
+static bool definebyexpMode(pxConfig *config);
+static bool definebyqueryMode(pxConfig *config);
 static bool runsMode(pxConfig *config);
-static bool selectrunMode(pxConfig *config);
-static bool selectMode(pxConfig *config);
 static bool inputMode(pxConfig *config);
 static bool rawMode(pxConfig *config);
-static bool addprocMode(pxConfig *config);
-static bool procMode(pxConfig *config);
-static bool addstacMode(pxConfig *config);
-static bool stacMode(pxConfig *config);
-static bool stacframeMode(pxConfig *config);
+//static bool selectrunMode(pxConfig *config);
+//static bool selectMode(pxConfig *config);
+static bool addprocessedMode(pxConfig *config);
+static bool tostackMode(pxConfig *config);
+static bool processedMode(pxConfig *config);
+static bool addstackedMode(pxConfig *config);
+static bool stackedMode(pxConfig *config);
+static bool stacframeMode(pxConfig *config); // needed?
+static bool tonormalizeMode(pxConfig *config);
+static bool addnormstatMode(pxConfig *config);
+static bool normstatMode(pxConfig *config);
 static bool addnormalizedMode(pxConfig *config);
-static bool normalizedMode(pxConfig *config);
-static bool normalizedframeMode(pxConfig *config);
-static bool addresidMode(pxConfig *config);
-static bool residMode(pxConfig *config);
+static bool toresidMode(pxConfig *config);
+static bool addresidimfileMode(pxConfig *config);
+static bool normalizedMode(pxConfig *config); // needed?
+static bool toresidexpMode(pxConfig *config);
+static bool normalizedframeMode(pxConfig *config);// neede?
+static bool residimfileMode(pxConfig *config);
 static bool addresidexpMode(pxConfig *config);
 static bool residexpMode(pxConfig *config);
@@ -53,33 +60,38 @@
 
     switch (config->mode) {
-        MODECASE(DETTOOL_MODE_PENDING, pendingMode);
-        MODECASE(DETTOOL_MODE_DEFINE, defineMode);
-        MODECASE(DETTOOL_MODE_RUNS, runsMode);
-        MODECASE(DETTOOL_MODE_SELECTRUN, selectrunMode);
-        MODECASE(DETTOOL_MODE_SELECT, selectMode);
-        MODECASE(DETTOOL_MODE_INPUT, inputMode);
-        MODECASE(DETTOOL_MODE_RAW, rawMode);
-        MODECASE(DETTOOL_MODE_ADDPROCESSED, addprocMode);
-        MODECASE(DETTOOL_MODE_PROCESSED, procMode);
-        MODECASE(DETTOOL_MODE_ADDSTACKED, addstacMode);
-        MODECASE(DETTOOL_MODE_STACKED, stacMode);
-        MODECASE(DETTOOL_MODE_STACKEDFRAME, stacframeMode);
-        MODECASE(DETTOOL_MODE_ADDNORMALIZED, addnormalizedMode);
-        MODECASE(DETTOOL_MODE_NORMALIZED, normalizedMode);
-        MODECASE(DETTOOL_MODE_NORMALIZEDFRAME, normalizedframeMode);
-        MODECASE(DETTOOL_MODE_ADDRESID, addresidMode);
-        MODECASE(DETTOOL_MODE_RESID, residMode);
-        MODECASE(DETTOOL_MODE_ADDRESIDEXP, addresidexpMode);
-        MODECASE(DETTOOL_MODE_RESIDEXP, residexpMode);
+        MODECASE(DETTOOL_MODE_PENDING,          pendingMode);
+        MODECASE(DETTOOL_MODE_DEFINEBYEXP,      definebyexpMode);
+        MODECASE(DETTOOL_MODE_DEFINEBYQUERY,    definebyqueryMode);
+        MODECASE(DETTOOL_MODE_RUNS,             runsMode);
+        MODECASE(DETTOOL_MODE_INPUT,            inputMode);
+        MODECASE(DETTOOL_MODE_RAW,              rawMode);
+//        MODECASE(DETTOOL_MODE_SELECTRUN, selectrunMode);
+//        MODECASE(DETTOOL_MODE_SELECT, selectMode);
+        MODECASE(DETTOOL_MODE_ADDPROCESSED,     addprocessedMode);
+        MODECASE(DETTOOL_MODE_TOSTACK,          tostackMode);
+        MODECASE(DETTOOL_MODE_PROCESSED,        processedMode);
+        MODECASE(DETTOOL_MODE_ADDSTACKED,       addstackedMode);
+        MODECASE(DETTOOL_MODE_STACKED,          stackedMode);
+        MODECASE(DETTOOL_MODE_STACKEDFRAME,     stacframeMode); // needed?
+        MODECASE(DETTOOL_MODE_TONORMALIZE,      tonormalizeMode);
+        MODECASE(DETTOOL_MODE_ADDNORMSTAT,      addnormstatMode);
+        MODECASE(DETTOOL_MODE_NORMSTAT,         normstatMode);
+        MODECASE(DETTOOL_MODE_ADDNORMALIZED,    addnormalizedMode);
+        MODECASE(DETTOOL_MODE_NORMALIZED,       normalizedMode);
+        MODECASE(DETTOOL_MODE_TORESID,          toresidMode);
+        MODECASE(DETTOOL_MODE_ADDRESIDIMFILE,   addresidimfileMode);
+        MODECASE(DETTOOL_MODE_TORESIDEXP,       toresidexpMode);
+        MODECASE(DETTOOL_MODE_NORMALIZEDFRAME,  normalizedframeMode); // needed?
+        MODECASE(DETTOOL_MODE_RESIDIMFILE,      residimfileMode);
+        MODECASE(DETTOOL_MODE_ADDRESIDEXP,      addresidexpMode);
+        MODECASE(DETTOOL_MODE_RESIDEXP,         residexpMode);
         MODECASE(DETTOOL_MODE_DECLAREMASTERFRAME, declaremasterframeMode);
-        MODECASE(DETTOOL_MODE_MASTERFRAME, masterframeMode);
-        MODECASE(DETTOOL_MODE_MASTER, masterMode);
-        MODECASE(DETTOOL_MODE_RERUN, rerunMode);
+        MODECASE(DETTOOL_MODE_MASTERFRAME,      masterframeMode);
+        MODECASE(DETTOOL_MODE_MASTER,           masterMode);
+        MODECASE(DETTOOL_MODE_RERUN,            rerunMode);
         default:
             psAbort(argv[0], "invalid option (this should not happen)");
     }
-
-    psFree(config);
-    pmConfigDone();
+psFree(config); pmConfigDone();
     psLibFinalize();
 
@@ -136,5 +148,5 @@
 }
 
-static bool defineMode(pxConfig *config)
+static bool definebyexpMode(pxConfig *config)
 {
     bool status     = false;
@@ -262,4 +274,9 @@
     printf("%ld\n", det_id);
 
+    return true;
+}
+
+static bool definebyqueryMode(pxConfig *config)
+{
     return true;
 }
@@ -347,4 +364,5 @@
 }
 
+#if 0
 static bool selectrunMode(pxConfig *config)
 {
@@ -466,4 +484,7 @@
     return true;
 }
+
+#endif
+
 static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id, psS32 iteration)
 {
@@ -620,5 +641,5 @@
 }
 
-static bool addprocMode(pxConfig *config)
+static bool addprocessedMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -710,5 +731,10 @@
 }
 
-static bool procMode(pxConfig *config)
+static bool tostackMode(pxConfig *config)
+{
+    return true;
+}
+
+static bool processedMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -967,5 +993,5 @@
 }
 
-static bool addstacMode(pxConfig *config)
+static bool addstackedMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -1066,5 +1092,5 @@
 }
 
-static bool stacMode(pxConfig *config)
+static bool stackedMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -1224,4 +1250,19 @@
 }
 
+static bool tonormalizeMode(pxConfig *config)
+{
+    return true;
+}
+
+static bool addnormstatMode(pxConfig *config)
+{
+    return true;
+}
+
+static bool normstatMode(pxConfig *config)
+{
+    return true;
+}
+
 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id)
 {
@@ -1415,4 +1456,9 @@
     psFree(masterImfile);
 
+    return true;
+}
+
+static bool toresidMode(pxConfig *config)
+{
     return true;
 }
@@ -1497,4 +1543,9 @@
 }
 
+static bool toresidexpMode(pxConfig *config)
+{
+    return true;
+}
+
 static bool normalizedframeMode(pxConfig *config)
 {
@@ -1580,5 +1631,5 @@
 }
 
-static bool addresidMode(pxConfig *config)
+static bool addresidimfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -1720,5 +1771,5 @@
 }
 
-static bool residMode(pxConfig *config)
+static bool residimfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
Index: /trunk/ippTools/src/dettool.h
===================================================================
--- /trunk/ippTools/src/dettool.h	(revision 8285)
+++ /trunk/ippTools/src/dettool.h	(revision 8286)
@@ -7,20 +7,27 @@
     DETTOOL_MODE_NONE           = 0x0,
     DETTOOL_MODE_PENDING,
-    DETTOOL_MODE_DEFINE,
+    DETTOOL_MODE_DEFINEBYEXP,
+    DETTOOL_MODE_DEFINEBYQUERY,
     DETTOOL_MODE_RUNS,
-    DETTOOL_MODE_SELECTRUN,
-    DETTOOL_MODE_SELECT,
     DETTOOL_MODE_INPUT,
     DETTOOL_MODE_RAW,
+//    DETTOOL_MODE_SELECTRUN,
+//    DETTOOL_MODE_SELECT,
     DETTOOL_MODE_ADDPROCESSED,
+    DETTOOL_MODE_TOSTACK,
     DETTOOL_MODE_PROCESSED,
     DETTOOL_MODE_ADDSTACKED,
     DETTOOL_MODE_STACKED,
     DETTOOL_MODE_STACKEDFRAME,
+    DETTOOL_MODE_TONORMALIZE,
+    DETTOOL_MODE_ADDNORMSTAT,
+    DETTOOL_MODE_NORMSTAT,
     DETTOOL_MODE_ADDNORMALIZED,
     DETTOOL_MODE_NORMALIZED,
+    DETTOOL_MODE_TORESID,
+    DETTOOL_MODE_ADDRESIDIMFILE,
+    DETTOOL_MODE_TORESIDEXP,
     DETTOOL_MODE_NORMALIZEDFRAME,
-    DETTOOL_MODE_ADDRESID,
-    DETTOOL_MODE_RESID,
+    DETTOOL_MODE_RESIDIMFILE,
     DETTOOL_MODE_ADDRESIDEXP,
     DETTOOL_MODE_RESIDEXP,
Index: /trunk/ippTools/src/dettoolConfig.c
===================================================================
--- /trunk/ippTools/src/dettoolConfig.c	(revision 8285)
+++ /trunk/ippTools/src/dettoolConfig.c	(revision 8286)
@@ -38,10 +38,11 @@
             "use the simple output format", false);
 
-    // -define 
-    psMetadata *defineArgs = psMetadataAlloc();
-    psMetadataAddStr(defineArgs, PS_LIST_TAIL, "-exp_id",  PS_META_DUPLICATE_OK,
-        "include this exposure (multiple OK, required)", NULL);
-    psMetadataAddStr(defineArgs, PS_LIST_TAIL, "-det_type",  0,
-        "define the type of detrend run (required)", NULL);
+    // -definebyexp 
+    psMetadata *definebyexpArgs = psMetadataAlloc();
+    psMetadataAddStr(definebyexpArgs, PS_LIST_TAIL, "-exp_id",
+            PS_META_DUPLICATE_OK,
+            "include this exposure (multiple OK, required)", NULL);
+    psMetadataAddStr(definebyexpArgs, PS_LIST_TAIL, "-det_type",  0,
+            "define the type of detrend run (required)", NULL);
 
     // -runs
@@ -52,4 +53,5 @@
             "use the simple output format", false);
 
+#if 0
     // XXX temporary
     // -selectrun
@@ -71,4 +73,5 @@
     psMetadataAddStr(selectArgs, PS_LIST_TAIL, "-classID",  0,
         "defined class ID (required)", NULL);
+#endif
 
     // -input
@@ -204,36 +207,36 @@
         "use the simple output format", false);
 
-    // -addresid
-    psMetadata *addresidArgs = psMetadataAlloc();
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-det_id",  0,
-        "define detrend ID (required)", NULL);
-    psMetadataAddS32(addresidArgs, PS_LIST_TAIL, "-iteration",  0,
+    // -addresidimfile
+    psMetadata *addresidimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-det_id",  0,
+        "define detrend ID (required)", NULL);
+    psMetadataAddS32(addresidimfileArgs, PS_LIST_TAIL, "-iteration",  0,
         "define iteration number", 0);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-exp_id",  0,
-        "define detrend ID (required)", NULL);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-class_id",  0,
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,
+        "define detrend ID (required)", NULL);
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,
         "define class ID (required)", NULL);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-recip",  0,
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-recip",  0,
         "define recipe (required)", NULL);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-uri",  0,
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri",  0,
         "define resid file URI (required)", NULL);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-b1_uri",  0,
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-b1_uri",  0,
         "define banana 1", NULL);
-    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-b2_uri",  0,
+    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-b2_uri",  0,
         "define banana 2", NULL);
 
-    // -resid
-    psMetadata *residArgs = psMetadataAlloc();
-    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-det_id",  0,
+    // -residimfile
+    psMetadata *residimfileArgs = psMetadataAlloc();
+    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-det_id",  0,
         "search for detrend ID (required)", NULL);
-    psMetadataAddS32(residArgs, PS_LIST_TAIL, "-iteration",  0,
+    psMetadataAddS32(residimfileArgs, PS_LIST_TAIL, "-iteration",  0,
         "search for iteration number", 0);
-    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-exp_id",  0,
-        "define detrend ID (required)", NULL);
-    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-class_id",  0,
-        "search for class ID", NULL);
-    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-recip",  0,
+    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-exp_id",  0,
+        "define detrend ID (required)", NULL);
+    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-class_id",  0,
+        "search for class ID", NULL);
+    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-recip",  0,
         "search for recipe", NULL);
-    psMetadataAddBool(residArgs, PS_LIST_TAIL, "-simple",  0,
+    psMetadataAddBool(residimfileArgs, PS_LIST_TAIL, "-simple",  0,
         "use the simple output format", false);
  
@@ -313,9 +316,9 @@
     // find which mode we're running under
     PXTOOL_MODE("-pending",         DETTOOL_MODE_PENDING,       pendingArgs);
-    PXTOOL_MODE("-define",          DETTOOL_MODE_DEFINE,        defineArgs);
+    PXTOOL_MODE("-definebyexp",     DETTOOL_MODE_DEFINEBYEXP,   definebyexpArgs);
     PXTOOL_MODE("-raw",             DETTOOL_MODE_RAW,           rawArgs);
     PXTOOL_MODE("-runs",            DETTOOL_MODE_RUNS,          runsArgs);
-    PXTOOL_MODE("-selectrun",       DETTOOL_MODE_SELECTRUN,     selectrunArgs);
-    PXTOOL_MODE("-select",          DETTOOL_MODE_SELECT,        selectArgs);
+//    PXTOOL_MODE("-selectrun",       DETTOOL_MODE_SELECTRUN,     selectrunArgs);
+//    PXTOOL_MODE("-select",          DETTOOL_MODE_SELECT,        selectArgs);
     PXTOOL_MODE("-input",           DETTOOL_MODE_INPUT,         inputArgs);
     PXTOOL_MODE("-addprocessed",    DETTOOL_MODE_ADDPROCESSED,  addprocArgs);
@@ -327,6 +330,6 @@
     PXTOOL_MODE("-normalized",      DETTOOL_MODE_NORMALIZED,    normalizedArgs);
     PXTOOL_MODE("-normalizedframe", DETTOOL_MODE_NORMALIZEDFRAME,normalizedframeArgs);
-    PXTOOL_MODE("-addresid",        DETTOOL_MODE_ADDRESID,      addresidArgs);
-    PXTOOL_MODE("-resid",           DETTOOL_MODE_RESID,         residArgs);
+    PXTOOL_MODE("-addresidimfile",  DETTOOL_MODE_ADDRESIDIMFILE,  addresidimfileArgs);
+    PXTOOL_MODE("-residimfile",     DETTOOL_MODE_RESIDIMFILE,    residimfileArgs);
     PXTOOL_MODE("-addresidexp",     DETTOOL_MODE_ADDRESIDEXP,  addresidexpArgs);
     PXTOOL_MODE("-residexp",        DETTOOL_MODE_RESIDEXP,     residexpArgs);
@@ -348,14 +351,15 @@
         printf("\nPan-STARRS Detrend Tool\n");
         printf("Usage: %s <mode> [<options>]\n\n", argv[0]);
-        printf(" <mode> : [-pending|-define|-runs|-selectrun|-select|-raw|-addprocessed|-processed|-addstacked|-stacked|-stackedframe|-addnormalized|-normalized|-normalizedframe|-addresid|-resid|-addresidexp|-residexp|-declaremasterframe|-masterframe|-master|-rerun]\n\n");
+        printf(" <mode> : [-pending|-definebyexp|-runs|-selectrun|-select|-raw|-addprocessed|-processed|-addstacked|-stacked|-stackedframe|-addnormalized|-normalized|-normalizedframe|-addresidimfile|-residimfile|-addresidexp|-residexp|-declaremasterframe|-masterframe|-master|-rerun]\n\n");
         fprintf (stdout, "-pending ");
         psArgumentHelp(pendingArgs);
         psFree(pendingArgs);
-        fprintf (stdout, "-define ");
-        psArgumentHelp(defineArgs);
-        psFree(defineArgs);
+        fprintf (stdout, "-definebyexp ");
+        psArgumentHelp(definebyexpArgs);
+        psFree(definebyexpArgs);
         fprintf (stdout, "-runs ");
         psArgumentHelp(runsArgs);
         psFree(runsArgs);
+#if 0
         fprintf (stdout, "-selectrun ");
         psArgumentHelp(selectrunArgs);
@@ -364,4 +368,5 @@
         psArgumentHelp(selectArgs);
         psFree(selectArgs);
+#endif
         fprintf (stdout, "-input ");
         psArgumentHelp(inputArgs);
@@ -395,9 +400,9 @@
         psFree(normalizedframeArgs);
         fprintf (stdout, "-addresid ");
-        psArgumentHelp(addresidArgs);
-        psFree(addresidArgs);
-        fprintf (stdout, "-resid ");
-        psArgumentHelp(residArgs);
-        psFree(residArgs);
+        psArgumentHelp(addresidimfileArgs);
+        psFree(addresidimfileArgs);
+        fprintf (stdout, "-residimfile ");
+        psArgumentHelp(residimfileArgs);
+        psFree(residimfileArgs);
         fprintf (stdout, "-addresidexp ");
         psArgumentHelp(addresidexpArgs);
@@ -423,8 +428,8 @@
 
     psFree(pendingArgs);
-    psFree(defineArgs);
+    psFree(definebyexpArgs);
     psFree(runsArgs);
-    psFree(selectrunArgs);
-    psFree(selectArgs);
+//    psFree(selectrunArgs);
+//    psFree(selectArgs);
     psFree(inputArgs);
     psFree(rawArgs);
@@ -437,6 +442,6 @@
     psFree(normalizedArgs);
     psFree(normalizedframeArgs);
-    psFree(addresidArgs);
-    psFree(residArgs);
+    psFree(addresidimfileArgs);
+    psFree(residimfileArgs);
     psFree(addresidexpArgs);
     psFree(residexpArgs);
