Index: /trunk/psLib/src/image/psImageConvolve.c
===================================================================
--- /trunk/psLib/src/image/psImageConvolve.c	(revision 1939)
+++ /trunk/psLib/src/image/psImageConvolve.c	(revision 1940)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-30 21:01:09 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-01 20:58:32 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,4 +64,5 @@
     result->yMax = yMax;
     result->image = psImageAlloc(numCols,numRows,PS_TYPE_KERNEL);
+    memset(result->image->rawDataBuffer,0,numCols*numRows*PSELEMTYPE_SIZEOF(PS_TYPE_KERNEL));
     result->p_kernelRows = psAlloc(sizeof(psKernelType*)*numRows);
 
@@ -94,5 +95,7 @@
     int y = 0;
     int t = 0;
-    int deltaT = 0;
+    int deltaT;
+    int oldX;
+    int oldY;
     int xMin = 0;
     int xMax = 0;
@@ -105,5 +108,5 @@
 
     // got non-NULL vectors?
-    if (xShifts == NULL || yShifts == NULL) {
+    if (tShifts == NULL || xShifts == NULL || yShifts == NULL) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psKernelGenerate",
                    PS_ERR_BAD_PARAMETER_NULL, true,
@@ -146,11 +149,16 @@
         ps##TYPE *xShiftData = xShifts->data.TYPE; \
         ps##TYPE *yShiftData = yShifts->data.TYPE; \
+        x = 0; \
+        y = 0; \
+        t = 0; \
         for (int lcv = 0; lcv < length; lcv++) { \
             if (relative) { \
                 x += xShiftData[lcv]; \
                 y += yShiftData[lcv]; \
+                t += tShiftData[lcv]; \
             } else { \
                 x = xShiftData[lcv]; \
                 y = yShiftData[lcv]; \
+                t = tShiftData[lcv]; \
             } \
             if (x < xMin) { \
@@ -168,10 +176,12 @@
         kernel = result->kernel; \
         \
-        x = xShiftData[0]; \
-        y = yShiftData[0]; \
-        t = tShiftData[0]; \
-        normalizeTime = 1.0 / (psKernelType)(tShiftData[length-1]-t); \
-        for (int i = 1; i < length; i++) { \
+        normalizeTime = 1.0 / (psKernelType)(t); \
+        x = 0; \
+        y = 0; \
+        t = 0; \
+        for (int i = 0; i < length; i++) { \
             deltaT = t; \
+            oldX = x; \
+            oldY = y; \
             if (relative) { \
                 t += tShiftData[i]; \
@@ -185,6 +195,7 @@
             deltaT = t - deltaT; \
             \
-            kernel[y][x] += deltaT * normalizeTime; \
+            kernel[oldY][oldX] += deltaT * normalizeTime; \
         } \
+        break; \
     }
 
Index: /trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- /trunk/psLib/src/imageops/psImageConvolve.c	(revision 1939)
+++ /trunk/psLib/src/imageops/psImageConvolve.c	(revision 1940)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-30 21:01:09 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-01 20:58:32 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -64,4 +64,5 @@
     result->yMax = yMax;
     result->image = psImageAlloc(numCols,numRows,PS_TYPE_KERNEL);
+    memset(result->image->rawDataBuffer,0,numCols*numRows*PSELEMTYPE_SIZEOF(PS_TYPE_KERNEL));
     result->p_kernelRows = psAlloc(sizeof(psKernelType*)*numRows);
 
@@ -94,5 +95,7 @@
     int y = 0;
     int t = 0;
-    int deltaT = 0;
+    int deltaT;
+    int oldX;
+    int oldY;
     int xMin = 0;
     int xMax = 0;
@@ -105,5 +108,5 @@
 
     // got non-NULL vectors?
-    if (xShifts == NULL || yShifts == NULL) {
+    if (tShifts == NULL || xShifts == NULL || yShifts == NULL) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psKernelGenerate",
                    PS_ERR_BAD_PARAMETER_NULL, true,
@@ -146,11 +149,16 @@
         ps##TYPE *xShiftData = xShifts->data.TYPE; \
         ps##TYPE *yShiftData = yShifts->data.TYPE; \
+        x = 0; \
+        y = 0; \
+        t = 0; \
         for (int lcv = 0; lcv < length; lcv++) { \
             if (relative) { \
                 x += xShiftData[lcv]; \
                 y += yShiftData[lcv]; \
+                t += tShiftData[lcv]; \
             } else { \
                 x = xShiftData[lcv]; \
                 y = yShiftData[lcv]; \
+                t = tShiftData[lcv]; \
             } \
             if (x < xMin) { \
@@ -168,10 +176,12 @@
         kernel = result->kernel; \
         \
-        x = xShiftData[0]; \
-        y = yShiftData[0]; \
-        t = tShiftData[0]; \
-        normalizeTime = 1.0 / (psKernelType)(tShiftData[length-1]-t); \
-        for (int i = 1; i < length; i++) { \
+        normalizeTime = 1.0 / (psKernelType)(t); \
+        x = 0; \
+        y = 0; \
+        t = 0; \
+        for (int i = 0; i < length; i++) { \
             deltaT = t; \
+            oldX = x; \
+            oldY = y; \
             if (relative) { \
                 t += tShiftData[i]; \
@@ -185,6 +195,7 @@
             deltaT = t - deltaT; \
             \
-            kernel[y][x] += deltaT * normalizeTime; \
+            kernel[oldY][oldX] += deltaT * normalizeTime; \
         } \
+        break; \
     }
 
Index: /trunk/psLib/test/image/tst_psImageConvolve.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageConvolve.c	(revision 1939)
+++ /trunk/psLib/test/image/tst_psImageConvolve.c	(revision 1940)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-30 21:04:15 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-01 20:58:32 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -21,7 +21,9 @@
 
 static int testKernelAlloc(void);
+static int testKernelGenerate(void);
 
 testDescription tests[] = {
                               {testKernelAlloc,731,"psKernelAlloc",0,false},
+                              {testKernelGenerate,732,"psKernelGenerate",0,false},
                               {NULL}
                           };
@@ -110,2 +112,177 @@
     return 0;
 }
+
+static int testKernelGenerate(void)
+{
+    int size = 4;
+    int t[] = { 1, 2, 8, 10 };
+    int x[] = { 0, 1, 0, -1 };
+    int y[] = { 2, 1, -1, -2 };
+    psKernelType sum;
+
+    psVector* xVec = psVectorAlloc(size,PS_TYPE_U32);
+    psVector* yVec = psVectorAlloc(size,PS_TYPE_U32);
+    psVector* tVec = psVectorAlloc(size,PS_TYPE_U32);
+
+    for (int i = 0; i < size; i++) {
+        xVec->data.U32[i] = x[i];
+        yVec->data.U32[i] = y[i];
+        tVec->data.U32[i] = t[i];
+    }
+
+    psKernel* result = psKernelGenerate(tVec, xVec, yVec, false);
+
+    if (result == NULL) {
+        psError(__func__,"psKernelGenerate returned NULL.");
+        return 1;
+    }
+
+    if (result->xMin != -1 || result->xMax != 1 ||
+            result->yMin != -2 || result->yMax != 2) {
+        psError(__func__,"psKernelGenerate result had a range of [%d:%d,%d:%d].  Suppose to be [0:1,1:2].",
+                result->xMin, result->xMax, result->yMin, result->yMax);
+        return 2;
+    }
+
+    sum = 0.0;
+    for (int y = result->yMin; y <= result->yMax; y++) {
+        for (int x = result->xMin; x <= result->xMax; x++) {
+            sum += result->kernel[y][x];
+        }
+    }
+    if (fabsf(1.0 - sum) > FLT_EPSILON) {
+        psError(__func__,"psKernelGenerate result is not normalized (sum=%g).",
+                sum);
+
+        return 3;
+
+    }
+
+    if (fabsf(result->kernel[2][0] - 1.0/10.0) > FLT_EPSILON ||
+            fabsf(result->kernel[ 1][ 1] - 6.0/10.0) > FLT_EPSILON ||
+            fabsf(result->kernel[ 0][ 0] - 1.0/10.0) > FLT_EPSILON ||
+            fabsf(result->kernel[-1][ 0] - 2.0/10.0) > FLT_EPSILON ||
+            fabsf(result->kernel[-2][-1] - 0.0/10.0) > FLT_EPSILON) {
+        psError(__func__,"psKernelGenerate result values, %g,%g;%g,%g, are wrong. Suppose to be 2,6;1,0.",
+                result->kernel[-1][0], result->kernel[1][1],
+                result->kernel[2][0], result->kernel[-2][-1]);
+
+        return 4;
+    }
+
+    psFree(result);
+    psFree(xVec);
+    psFree(yVec);
+    psFree(tVec);
+
+    xVec = psVectorAlloc(size,PS_TYPE_S16);
+    yVec = psVectorAlloc(size,PS_TYPE_S16);
+    tVec = psVectorAlloc(size,PS_TYPE_S16);
+
+    for (int i = 0; i < size; i++) {
+        xVec->data.S16[i] = x[i];
+        yVec->data.S16[i] = y[i];
+        tVec->data.S16[i] = t[i];
+    }
+
+    result = psKernelGenerate(tVec, xVec, yVec, true);
+
+    if (result == NULL) {
+        psError(__func__,"psKernelGenerate returned NULL.");
+        return 5;
+    }
+
+    if (result->xMin != 0 || result->xMax != 1 ||
+            result->yMin != 0 || result->yMax != 3) {
+        psError(__func__,"psKernelGenerate result had a range of [%d:%d,%d:%d].  Suppose to be [0:1,1:2].",
+                result->xMin, result->xMax, result->yMin, result->yMax);
+        return 6;
+    }
+
+    sum = 0.0;
+    for (int y = result->yMin; y <= result->yMax; y++) {
+        for (int x = result->xMin; x <= result->xMax; x++) {
+            sum += result->kernel[y][x];
+        }
+    }
+    if (fabsf(1.0 - sum) > FLT_EPSILON) {
+        psError(__func__,"psKernelGenerate result is not normalized (sum=%g).",
+                sum);
+
+        return 7;
+
+    }
+
+    if (fabsf(result->kernel[0][0] - 1.0/21.0) > FLT_EPSILON ||
+            fabsf(result->kernel[2][0] - 2.0/21.0) > FLT_EPSILON ||
+            fabsf(result->kernel[3][1] - 8.0/21.0) > FLT_EPSILON ||
+            fabsf(result->kernel[2][1] - 10.0/21.0) > FLT_EPSILON) {
+        psError(__func__,"psKernelGenerate result values, %g,%g;%g,%g, are wrong. Suppose to be 2,6;1,0.",
+                result->kernel[1][0], result->kernel[1][1],
+                result->kernel[2][0], result->kernel[2][1]);
+
+        return 8;
+    }
+
+    psFree(result);
+    psFree(xVec);
+    psFree(yVec);
+    psFree(tVec);
+
+    xVec = psVectorAlloc(size,PS_TYPE_F32);
+    yVec = psVectorAlloc(size,PS_TYPE_F32);
+    tVec = psVectorAlloc(size,PS_TYPE_F32);
+
+    for (int i = 0; i < size; i++) {
+        xVec->data.F32[i] = x[i]+0.1;
+        yVec->data.F32[i] = y[i]+0.2;
+        tVec->data.F32[i] = t[i]+0.3;
+    }
+
+    tVec->n--; // decrease size by one to make vectors unequal in length.
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be a warning - not automatically tested.");
+    result = psKernelGenerate(tVec, xVec, yVec, false);
+    if (result == NULL) {
+        psError(__func__,"psKernelGenerate returned NULL.");
+        return 9;
+    }
+
+    // make sure last sample is not used
+    if (fabsf(result->kernel[2][0] - 1.0/8.0) > FLT_EPSILON ||
+            fabsf(result->kernel[ 1][ 1] - 6.0/8.0) > FLT_EPSILON ||
+            fabsf(result->kernel[ 0][ 0] - 1.0/8.0) > FLT_EPSILON) {
+        psError(__func__,"psKernelGenerate result values wrong for truncated time vector.");
+
+        return 10;
+    }
+
+    psFree(result);
+
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be a error (time vector NULL).");
+    result = psKernelGenerate(NULL, xVec, yVec, true);
+    if (result != NULL) {
+        psError(__func__,"psKernelGenerate returned a kernel with no time vector.");
+        return 11;
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be a error (x vector NULL).");
+    result = psKernelGenerate(tVec, NULL, yVec, true);
+    if (result != NULL) {
+        psError(__func__,"psKernelGenerate returned a kernel with no x vector.");
+        return 11;
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO, "Following should be a error (y vector NULL).");
+    result = psKernelGenerate(tVec, xVec, NULL, true);
+    if (result != NULL) {
+        psError(__func__,"psKernelGenerate returned a kernel with no y vector.");
+        return 11;
+    }
+
+    psFree(xVec);
+    psFree(yVec);
+    psFree(tVec);
+    psFree(result);
+
+    return 0;
+}
