Index: /branches/eam_branches/20090522/Nebulous-Server/Changes
===================================================================
--- /branches/eam_branches/20090522/Nebulous-Server/Changes	(revision 24564)
+++ /branches/eam_branches/20090522/Nebulous-Server/Changes	(revision 24565)
@@ -29,4 +29,6 @@
     - infinitely try to get a db handle if the connection fails
     - add --mountpoint param to neb-voladd
+    - change Nebulous::Server->find_objects() to return dirs and to sort it's
+      output 
       
 0.16
Index: /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server.pm
===================================================================
--- /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24564)
+++ /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server.pm	(revision 24565)
@@ -1449,6 +1449,27 @@
     }
 
-    eval {
-        $log->debug("trying for a directory match under dir: $dir_id");
+    # find dirs under dir
+    my @dir_keys;
+    eval {
+        $log->debug("looking for directories under dir: $dir_id");
+        my $query = $db->prepare_cached( $sql->find_dir_by_parent_id);
+        $query->execute( $dir_id );
+
+        while ( my $row = $query->fetchrow_hashref ) {
+            next if $row->{'dir_id'} == 1;
+            my $dir = $row->{'dirname'};
+            if ($dir_id == 1) {
+                push @dir_keys, $dir . '/' if $dir;
+            } else {
+                push @dir_keys, $key->path . '/' . $dir . '/' if $dir;
+            }
+            $log->debug( "matched $dir" ) if $dir;
+        }
+    };
+    $log->logdie("database error: $@") if $@;
+
+    # find files under dir
+    eval {
+        $log->debug("looking for objects under dir: $dir_id");
         my $query = $db->prepare_cached( $sql->find_object_by_dir_id );
         $query->execute( $dir_id );
@@ -1463,6 +1484,6 @@
 
     $log->debug( "leaving" );
-
-    return \@keys;
+    
+    return [sort(@dir_keys), sort(@keys)];
 }
 
Index: /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server/SQL.pm
===================================================================
--- /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24564)
+++ /branches/eam_branches/20090522/Nebulous-Server/lib/Nebulous/Server/SQL.pm	(revision 24565)
@@ -317,4 +317,9 @@
         FROM storage_object
         WHERE dir_id = ?
+    },
+    find_dir_by_parent_id => qq{
+        SELECT dir_id, dirname
+        FROM directory
+        WHERE parent_id = ?
     },
     rename_object => qq{
Index: /branches/eam_branches/20090522/Nebulous-Server/t/13_server_find_objects.t
===================================================================
--- /branches/eam_branches/20090522/Nebulous-Server/t/13_server_find_objects.t	(revision 24564)
+++ /branches/eam_branches/20090522/Nebulous-Server/t/13_server_find_objects.t	(revision 24565)
@@ -8,5 +8,5 @@
 use warnings FATAL => qw( all );
 
-use Test::More tests => 28;
+use Test::More tests => 36;
 
 use lib qw( ./t ./lib );
@@ -100,6 +100,7 @@
     my $keys = $neb->find_objects("a");
 
-    is(scalar @$keys, 1, 'number of keys found');
-    is($keys->[0], "a/foo", "key name");
+    is(scalar @$keys, 2, 'number of keys found');
+    is($keys->[0], "a/b/", "key name");
+    is($keys->[1], "a/foo", "key name");
 }
 
@@ -113,6 +114,6 @@
 
     is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "a/foo", "key name");
-    is($keys->[1], "a/bar", "key name");
+    is($keys->[0], "a/bar", "key name");
+    is($keys->[1], "a/foo", "key name");
 }
 
@@ -138,7 +139,8 @@
     my $keys = $neb->find_objects("/");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
@@ -152,7 +154,8 @@
     my $keys = $neb->find_objects(".");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
@@ -166,7 +169,23 @@
     my $keys = $neb->find_objects("..");
 
-    is(scalar @$keys, 2, 'number of keys found');
-    is($keys->[0], "foo", "key name");
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
     is($keys->[1], "bar", "key name");
+    is($keys->[2], "foo", "key name");
+}
+
+Test::Nebulous->setup;
+
+{
+    $neb->create_object("a/bar");
+    $neb->create_object("b/foo");
+    $neb->create_object("foo");
+
+    my $keys = $neb->find_objects("/");
+
+    is(scalar @$keys, 3, 'number of keys found');
+    is($keys->[0], "a/", "key name");
+    is($keys->[1], "b/", "key name");
+    is($keys->[2], "foo", "key name");
 }
 
Index: /branches/eam_branches/20090522/Nebulous/t/70_neb-ls.t
===================================================================
--- /branches/eam_branches/20090522/Nebulous/t/70_neb-ls.t	(revision 24564)
+++ /branches/eam_branches/20090522/Nebulous/t/70_neb-ls.t	(revision 24565)
@@ -83,5 +83,5 @@
 
     is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^foo\nbar$/,  "stdout");
+    like($test->stdout, qr/^bar\nfoo$/,  "stdout");
     like($test->stderr, qr/^$/,         "stderr");
 }
@@ -99,5 +99,5 @@
 
     is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^foo\nbar\n$/,   "stdout");
+    like($test->stdout, qr/^bar\nfoo\n$/,   "stdout");
     like($test->stderr, qr/^$/,             "stderr");
 }
@@ -115,5 +115,5 @@
 
     is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^foo\nbar\n$/,   "stdout");
+    like($test->stdout, qr/^bar\nfoo\n$/,   "stdout");
     like($test->stderr, qr/^$/,             "stderr");
 }
@@ -161,5 +161,5 @@
 
     is($? >> 8, 0, "exit code");
-    like($test->stdout, qr|^a/foo\na/bar$|,  "stdout");
+    like($test->stdout, qr|^a/bar\na/foo$|,  "stdout");
     like($test->stderr, qr/^$/,             "stderr");
 }
@@ -193,5 +193,5 @@
 
     is($? >> 8, 0, "exit code");
-    like($test->stdout, qr|^a/foo$|,        "stdout");
+    like($test->stdout, qr|^a/b/\na/foo$|,        "stdout");
     like($test->stderr, qr/^$/,             "stderr");
 }
Index: /branches/eam_branches/20090522/ippTools/src/camtool.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/camtool.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/camtool.c	(revision 24565)
@@ -766,5 +766,5 @@
     pxcamGetSearchArgs (config, where);
     PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",         "==");
-    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label",          "==");
+    pxAddLabelSearchArgs (config, where, "-label",    "camRun.label",     "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction",      "==");
     PXOPT_COPY_S16(config->args, where, "-fault", "camProcessedExp.fault", "==");
Index: /branches/eam_branches/20090522/ippTools/src/camtoolConfig.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/camtoolConfig.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/camtoolConfig.c	(revision 24565)
@@ -187,5 +187,5 @@
     pxcamSetSearchArgs(revertprocessedexpArgs);
     psMetadataAddS64(revertprocessedexpArgs, PS_LIST_TAIL, "-cam_id",   0,            "search by cam_id", 0);
-    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-label",    0,            "search by camRun label", NULL);
+    psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-label",    PS_META_DUPLICATE_OK, "search by camRun label", NULL);
     psMetadataAddStr(revertprocessedexpArgs, PS_LIST_TAIL, "-reduction",0,            "search by camRun reduction class", NULL);
     psMetadataAddS16(revertprocessedexpArgs, PS_LIST_TAIL, "-code",     0,            "search by fault code", 0);
Index: /branches/eam_branches/20090522/ippTools/src/chiptool.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/chiptool.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/chiptool.c	(revision 24565)
@@ -676,6 +676,5 @@
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
-    // require a single label 
-    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "==");
+    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     PXOPT_COPY_S16(config->args, where, "-fault", "chipProcessedImfile.fault", "==");
Index: /branches/eam_branches/20090522/ippTools/src/chiptoolConfig.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/chiptoolConfig.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/chiptoolConfig.c	(revision 24565)
@@ -169,5 +169,5 @@
     psMetadataAddStr(revertprocessedimfileArgs,  PS_LIST_TAIL, "-class_id",           0, "search by class ID", NULL);
     psMetadataAddStr(revertprocessedimfileArgs,  PS_LIST_TAIL, "-reduction",          0, "search by reduction class", NULL);
-    psMetadataAddStr(revertprocessedimfileArgs,  PS_LIST_TAIL, "-label",              0, "search by chipRun label (LIKE comparison)", NULL);
+    psMetadataAddStr(revertprocessedimfileArgs,  PS_LIST_TAIL, "-label",              PS_META_DUPLICATE_OK, "search by chipRun label (LIKE comparison)", NULL);
     pxchipSetSearchArgs(revertprocessedimfileArgs);
     psMetadataAddBool(revertprocessedimfileArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
Index: /branches/eam_branches/20090522/ippTools/src/faketool.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/faketool.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/faketool.c	(revision 24565)
@@ -632,6 +632,6 @@
 
     psMetadata *where = psMetadataAlloc();
+    pxAddLabelSearchArgs (config, where, "-label", "fakeRun.label", "==");
     PXOPT_COPY_S64(config->args, where, "-fake_id", "fake_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-label", "fakeRun.label", "==");
     PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
Index: /branches/eam_branches/20090522/ippTools/src/faketoolConfig.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/faketoolConfig.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/faketoolConfig.c	(revision 24565)
@@ -198,5 +198,5 @@
     psMetadata *revertprocessedimfileArgs = psMetadataAlloc();
     psMetadataAddS64(revertprocessedimfileArgs, PS_LIST_TAIL, "-fake_id", 0,            "search by fake ID", 0);
-    psMetadataAddStr(revertprocessedimfileArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);
+    psMetadataAddStr(revertprocessedimfileArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by label", NULL);
     psMetadataAddS64(revertprocessedimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by exp_id", 0);
     psMetadataAddStr(revertprocessedimfileArgs, PS_LIST_TAIL, "-exp_name",  0,            "search by exp_name", NULL);
Index: /branches/eam_branches/20090522/ippTools/src/warptool.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/warptool.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/warptool.c	(revision 24565)
@@ -680,5 +680,6 @@
     PXOPT_COPY_STR(config->args, where, "-skycell_id", "warpSkyCellMap.skycell_id", "==");
     PXOPT_COPY_STR(config->args, where, "-tess_id",    "warpSkyCellMap.tess_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-label",      "warpRun.label", "==");
+    // PXOPT_COPY_STR(config->args, where, "-label",      "warpRun.label", "==");
+    pxAddLabelSearchArgs (config, where, "-label",     "warpRun.label", "==");
     PXOPT_COPY_S16(config->args, where, "-fault",      "warpSkyCellMap.fault", "==");
 
@@ -1269,5 +1270,6 @@
     PXOPT_COPY_STR(config->args, where, "-tess_id",    "warpSkyfile.tess_id", "==");
     PXOPT_COPY_STR(config->args, where, "-reduction",  "rawExp.reduction", "==");
-    PXOPT_COPY_STR(config->args, where, "-label",      "warpRun.label", "==");
+    // PXOPT_COPY_STR(config->args, where, "-label",      "warpRun.label", "==");
+    pxAddLabelSearchArgs (config, where, "-label",     "warpRun.label", "==");
     PXOPT_COPY_S16(config->args, where, "-fault",       "warpSkyfile.fault", "==");
 
Index: /branches/eam_branches/20090522/ippTools/src/warptoolConfig.c
===================================================================
--- /branches/eam_branches/20090522/ippTools/src/warptoolConfig.c	(revision 24564)
+++ /branches/eam_branches/20090522/ippTools/src/warptoolConfig.c	(revision 24565)
@@ -164,5 +164,5 @@
     psMetadataAddStr(revertoverlapArgs, PS_LIST_TAIL, "-skycell_id",  0,            "search by skycell ID", NULL);
     psMetadataAddStr(revertoverlapArgs, PS_LIST_TAIL, "-tess_id",  0,            "search by tessellation ID", NULL);
-    psMetadataAddStr(revertoverlapArgs, PS_LIST_TAIL, "-label",  0,            "search by warpRun label", NULL);
+    psMetadataAddStr(revertoverlapArgs, PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by warpRun label", NULL);
     psMetadataAddS16(revertoverlapArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
     psMetadataAddBool(revertoverlapArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
@@ -227,5 +227,5 @@
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-tess_id",  0,            "search by tessellation ID", NULL);
     psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-reduction",  0,            "search by warpRun reduction class", NULL);
-    psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-label",  0,            "search by warpRun label", NULL);
+    psMetadataAddStr(revertwarpedArgs, PS_LIST_TAIL, "-label",  PS_META_DUPLICATE_OK, "search by warpRun label", NULL);
     psMetadataAddS16(revertwarpedArgs, PS_LIST_TAIL, "-fault",  0,            "search by fault code", 0);
     psMetadataAddBool(revertwarpedArgs, PS_LIST_TAIL, "-all",  0,            "allow everything to be queued without search terms", false);
Index: /branches/eam_branches/20090522/ppImage/src/ppImageReplaceBackground.c
===================================================================
--- /branches/eam_branches/20090522/ppImage/src/ppImageReplaceBackground.c	(revision 24564)
+++ /branches/eam_branches/20090522/ppImage/src/ppImageReplaceBackground.c	(revision 24565)
@@ -144,11 +144,15 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            float value = backData[y][x];
-            if (!isfinite(value)) {
-                image->data.F32[y][x] = NAN;
-                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->lowMask;
+            if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
+                image->data.F32[y][x] = 0.0;
             } else {
-                image->data.F32[y][x] -= value;
-            }
+		float value = backData[y][x];
+		if (!isfinite(value)) {
+		    image->data.F32[y][x] = NAN;
+		    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= options->lowMask;
+		} else {
+		    image->data.F32[y][x] -= value;
+		}
+	    }
         }
     }
Index: /branches/eam_branches/20090522/psLib/src/mathtypes/psVector.c
===================================================================
--- /branches/eam_branches/20090522/psLib/src/mathtypes/psVector.c	(revision 24564)
+++ /branches/eam_branches/20090522/psLib/src/mathtypes/psVector.c	(revision 24565)
@@ -77,4 +77,5 @@
     // Create vector data array
     vector->data.U8 = psAlloc(nalloc * elementSize);
+    memset (vector->data.U8, 0, nalloc * elementSize);
 
     return vector;
@@ -119,13 +120,27 @@
                 _("psVectorRealloc must a given a non-NULL psVector to resize.  Desired datatype unknown."));
         return NULL;
-    } else if (vector->nalloc != nalloc) {     // No need to realloc to same size
-        elemType = vector->type.type;
-        elementSize = PSELEMTYPE_SIZEOF(elemType);
-        if (nalloc < vector->n) {
-            vector->n = nalloc;
-        }
-        // Realloc after decrementation to avoid accessing freed array elements
-        vector->data.U8 = psRealloc(vector->data.U8, nalloc * elementSize);
-        P_PSVECTOR_SET_NALLOC(vector,nalloc);
+    } 
+
+    
+    if (vector->nalloc == nalloc) {     
+	// No need to realloc to same size
+	return vector;
+    }
+     
+    elemType = vector->type.type;
+    elementSize = PSELEMTYPE_SIZEOF(elemType);
+
+    long nstart = vector->n;
+    if (nalloc < vector->n) {
+	vector->n = nalloc;
+    }
+    // Realloc after decrementation to avoid accessing freed array elements
+    vector->data.U8 = psRealloc(vector->data.U8, nalloc * elementSize);
+    P_PSVECTOR_SET_NALLOC(vector,nalloc);
+
+    // fill newly allocated range with zeros:
+    if (nstart < nalloc) {
+	long nNew = nalloc - nstart;
+	memset (&vector->data.U8[nstart*elementSize], 0, nNew*elementSize);
     }
 
@@ -165,4 +180,8 @@
     vector->type.type = type;
     vector->n = nalloc;
+
+    // zero the vector
+    memset (vector->data.U8, 0, byteSize);
+
     return vector;
 }
