Index: /trunk/ippTools/src/pztool.c
===================================================================
--- /trunk/ippTools/src/pztool.c	(revision 15152)
+++ /trunk/ippTools/src/pztool.c	(revision 15153)
@@ -38,5 +38,5 @@
 static bool copydoneCompleteExp(pxConfig *config);
 static psArray *pzGetKnownCameras(pxConfig *config);
-static psArray *pzArrayAddArray(psArray *array, psArray *input);
+static psArray *pzArrayZip(psArray *arraySet);
 
 # define MODECASE(caseName, func) \
@@ -227,5 +227,5 @@
 
     // array to hold the aggregate results
-    psArray *output = psArrayAlloc(0);
+    psArray *cameraImfiles = psArrayAlloc(0);
 
     for (long i = 0; i < psArrayLength(cameras); i++) {
@@ -233,5 +233,5 @@
         if (!query) {
             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
-            psFree(output);
+            psFree(cameraImfiles);
             return false;
         }
@@ -273,5 +273,5 @@
             psError(PS_ERR_UNKNOWN, false, "database error");
             psFree(query);
-            psFree(output);
+            psFree(cameraImfiles);
             return false;
         }
@@ -281,5 +281,5 @@
         if (!result) {
             psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(output);
+            psFree(cameraImfiles);
             return false;
         }
@@ -287,12 +287,16 @@
             psTrace("pztool", PS_LOG_INFO, "no rows found");
             psFree(result);
-            psFree(output);
+            psFree(cameraImfiles);
             return true;
         }
 
-        // merge this query into the result set
-        pzArrayAddArray(output, result);
+        // add this query into the array of result set
+        psArrayAdd(cameraImfiles, 0, result);
         psFree(result);
     }
+
+    // stitch the arrays of imfiles together
+    psArray *output = pzArrayZip(cameraImfiles);
+    psFree(cameraImfiles);
 
     bool simple = false;
@@ -620,4 +624,35 @@
 }
 
+static psArray *pzArrayZip(psArray *arraySet)
+{
+    long setSize = 0;
+
+    // figure out the size of the combined arrays
+    for (long i = 0; i < psArrayLength(arraySet); i++) {
+        setSize += psArrayLength(arraySet->data[i]);
+    }
+
+    psArray *output = psArrayAllocEmpty(setSize);
+    // loop over each array in the set forever
+    long index = 0; // the depth into each array
+    long counter; // counter - the total number of elements zipped so far
+    long i; // i - which array in the set 
+    for (counter = 0, i = 0;
+            (counter < setSize) && (i < psArrayLength(arraySet));
+            counter++, ++i, i = i % psArrayLength(arraySet)) {
+
+        psArray *array = arraySet->data[i];
+        // make sure that this array has not run out of elements
+        if (index > (psArrayLength(arraySet) - 1)) {
+            continue;
+        }
+
+        psArrayAdd(output, 0, array->data[index]);
+    }
+
+    return output;
+}
+
+#if 0
 static psArray *pzArrayAddArray(psArray *array, psArray *input)
 {
@@ -628,2 +663,3 @@
     return array;
 }
+#endif
