Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 7127)
+++ /trunk/ippTools/src/dettool.c	(revision 7128)
@@ -16,4 +16,5 @@
 
 static detInputExpRow *rawDetrenTodetInputExpRow(rawDetrendExpRow *rawExp, psS32 det_id);
+static psArray *searchRawImfiles(pxConfig *config);
 
 int main(int argc, char **argv)
@@ -157,4 +158,27 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    // search from rawImfiles
+    psArray *rawImfiles = searchRawImfiles(config);
+
+    // print imfile list
+    psMetadata *output = psMetadataAlloc();
+    for (long i = 0; i < psArrayLength(rawImfiles); i++) {
+        psMetadata *md = rawImfileMetadataFromObject(rawImfiles->data[i]);
+        psMetadataAddMetadata(
+            output, PS_LIST_TAIL, "rawImfile",  PS_META_DUPLICATE_OK, NULL, md);
+    }
+
+    psString str = psMetadataConfigFormat(output); 
+    psFree(output);
+    fprintf(stdout, "%s\n", str);
+    psFree(str);
+
+    return true;
+}
+
+static psArray *searchRawImfiles(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
     // select exp_ids from detInputExp matching det_idp
     // where query should be pre-generated
@@ -163,5 +187,5 @@
     if (!detInputExp) {
         psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found");
-        return false;
+        return NULL;
     }
 
@@ -176,5 +200,5 @@
             psFree(detInputExp);
             psFree(where_exp_ids);
-            return false;
+            return NULL;
         }
     }
@@ -187,21 +211,8 @@
     if (!rawImfiles) {
         psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found");
-        return false;
-    }
-
-    // print imfile list
-    psMetadata *output = psMetadataAlloc();
-    for (long i = 0; i < psArrayLength(rawImfiles); i++) {
-        psMetadata *md = rawImfileMetadataFromObject(rawImfiles->data[i]);
-        psMetadataAddMetadata(
-            output, PS_LIST_TAIL, "rawImfile",  PS_META_DUPLICATE_OK, NULL, md);
-    }
-
-    psString str = psMetadataConfigFormat(output); 
-    psFree(output);
-    fprintf(stdout, "%s\n", str);
-    psFree(str);
-
-    return true;
+        return NULL;
+    }
+
+    return rawImfiles;
 }
 
@@ -310,4 +321,62 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    // det_id, class_id, uri, & recipe are required
+    bool status = false;
+    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
+        return false;
+    }
+    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
+        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 recipe = psMetadataLookupStr(&status, config->args, "-recipe");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -recipe");
+        return false;
+    }
+    psString stats = psMetadataLookupStr(&status, config->args, "-stats");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
+        return false;
+    }
+
+    // correlate the class_id against the input exposure(s)
+    psArray *rawImfiles = searchRawImfiles(config);
+
+    bool valid_class_id = false;
+    for (long i = 0; i < psArrayLength(rawImfiles); i++) {
+        if (class_id == ((rawImfileRow *)rawImfiles->data[i])->class_id) {
+            valid_class_id = true;
+            break;
+        }
+    }
+    psFree(rawImfiles);
+
+    if (!valid_class_id) {
+        psError(PS_ERR_UNKNOWN, true, 
+            "class_id can not be correlated with the input exposures");
+        return false;
+    }
+
+    // create a new detStackedImfile object
+    detStackedImfileRow *stackedImfile = detStackedImfileRowAlloc(
+        (psS32)atol(det_id), class_id, uri, stats, recipe
+    );   
+    psFree(rawImfiles);
+
+    // insert the new row into the detProcessedImfile table
+    if (!detStackedImfileInsertObject(config->dbh, stackedImfile)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false; 
+    }
+
     return true;
 }
