Index: /trunk/psLib/test/astronomy/tst_psAstrometry.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2002)
+++ /trunk/psLib/test/astronomy/tst_psAstrometry.c	(revision 2002)
@@ -0,0 +1,165 @@
+/** @file  tst_psAstrometry.c
+ *
+ *  @brief Contains the tests for psAstrometry.[ch]
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-07 19:17:23 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include <math.h>
+#include <string.h>
+
+#include "psTest.h"
+#include "pslib.h"
+
+static int testExposureAlloc(void);
+static int testObservatoryAlloc(void);
+
+testDescription tests[] = {
+                              {testExposureAlloc,735,"psExposureAlloc",0,false},
+                              {testObservatoryAlloc,736,"psObservatoryAlloc",0,false},
+                              {NULL}
+                          };
+
+int main(int argc, char* argv[])
+{
+    psLogSetLevel(PS_LOG_INFO);
+
+    return ! runTestSuite(stderr,"psImage",tests,argc,argv);
+}
+
+static int testExposureAlloc(void)
+{
+    psTime* now = psTimeGetTime(PS_TIME_UTC);
+    char* name = "The Kaiser Royal Observatory";
+
+    psObservatory* obs = psObservatoryAlloc(name,
+                                            20.7, 156.3, 3055.0, 9.0);
+
+    psExposure* exp = psExposureAlloc(1.0, 2.0, 3.0, 4.0, 5.0,
+                                      now, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, obs);
+
+
+    if (fabs(exp->ra - 1.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set ra.");
+        return 1;
+    }
+
+    if (fabs(exp->dec - 2.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set dec.");
+        return 2;
+    }
+
+    if (fabs(exp->hourAngle - 3.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set hourAngle.");
+        return 3;
+    }
+
+    if (fabs(exp->zenithDistance - 4.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set zenithDistance.");
+        return 4;
+    }
+
+    if (fabs(exp->azimuth - 5.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set azimuth.");
+        return 5;
+    }
+    if (exp->time != now) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set time.");
+        return 6;
+    }
+
+    if (fabsf(exp->rotAngle - 6.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set rotAngle.");
+        return 7;
+    }
+
+    if (fabsf(exp->temperature - 7.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set temperature.");
+        return 8;
+    }
+
+    if (fabsf(exp->pressure - 8.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set pressure.");
+        return 9;
+    }
+
+    if (fabsf(exp->humidity - 9.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set humidity.");
+        return 10;
+    }
+
+    if (fabsf(exp->exposureTime - 10.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set exposureTime.");
+        return 11;
+    }
+
+    if (fabsf(exp->wavelength - 11.0f) > FLT_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set wavelength.");
+        return 12;
+    }
+
+    if (exp->observatory != obs) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psExposureAlloc did not set wavelength.");
+        return 12;
+    }
+
+    psFree(obs);
+    psFree(now);
+    psFree(exp);
+    return 0;
+}
+
+static int testObservatoryAlloc(void)
+{
+    char* name = "The Kaiser Royal Observatory";
+    psObservatory* obs = psObservatoryAlloc(name,
+                                            20.7, 156.3, 3055.0, 9.0);
+
+    if (fabs(obs->latitude - 20.7) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set latitude.");
+        return 1;
+    }
+
+    if (fabs(obs->longitude - 156.3) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set longitude.");
+        return 2;
+    }
+
+    if (fabs(obs->height - 3055.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set height.");
+        return 3;
+    }
+
+    if (fabs(obs->tlr - 9.0) > DBL_EPSILON) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set tlr.");
+        return 4;
+    }
+
+    if (strcmp(obs->name,name) != 0) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not set name.");
+        return 5;
+    }
+
+    if (obs->name == name) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not copy name.");
+        return 6;
+    }
+
+    psObservatory* obs2 = psObservatoryAlloc(NULL,
+                          20.7, 156.3, 3055.0, 9.0);
+
+    if (obs2->name != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,"psObservatoryAlloc did not handle NULL name.");
+        return 7;
+    }
+
+    psFree(obs);
+    psFree(obs2);
+
+    return 0;
+}
Index: /trunk/psLib/test/astronomy/tst_psImageConvolve.c
===================================================================
--- /trunk/psLib/test/astronomy/tst_psImageConvolve.c	(revision 2002)
+++ /trunk/psLib/test/astronomy/tst_psImageConvolve.c	(revision 2002)
@@ -0,0 +1,453 @@
+/** @file  tst_psImageConvolve.c
+ *
+ *  @brief Contains the tests for psImageConvolve.[ch]
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-07 19:17:23 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include <math.h>
+#include <float.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "psTest.h"
+#include "pslib.h"
+#include "psType.h"
+
+static int testKernelAlloc(void);
+static int testKernelGenerate(void);
+static int testImageConvolve(void);
+
+testDescription tests[] = {
+                              {testKernelAlloc,731,"psKernelAlloc",0,false},
+                              {testKernelGenerate,732,"psKernelGenerate",0,false},
+                              {testImageConvolve,733,"psImageConvolve",0,false},
+                              {NULL}
+                          };
+
+int main(int argc, char* argv[])
+{
+    psLogSetLevel(PS_LOG_INFO);
+
+    return ! runTestSuite(stderr,"psImage",tests,argc,argv);
+}
+
+static int testKernelAlloc(void)
+{
+    int numCases = 4;
+    int xMin[] = { -5,  0,-10,  5};
+    int xMax[] = {  0,  5, -5, 10};
+    int yMin[] = { -4,  0, -8,  4};
+    int yMax[] = {  0,  4, -4,  8};
+    int i;
+    psKernel* k;
+
+    for (i=0;i<numCases;i++) {
+        k = psKernelAlloc(xMin[i],xMax[i],yMin[i],yMax[i]);
+
+        if (k == NULL) {
+            psError(__func__,"psKernelAlloc returned NULL for [%d:%d,%d:%d].",
+                    xMin[i], xMax[i], yMin[i], yMax[i]);
+            return i*10+1;
+        }
+
+        if (k->xMin != xMin[i] || k->xMax != xMax[i] ||
+                k->yMin != yMin[i] || k->yMax != yMax[i]) {
+            psError(__func__,"Min/max members, [%d:%d,%d:%d], of psKernel wrong. Should be [%d:%d,%d:%d].",
+                    k->xMin,k->xMax, k->yMin, k->yMax,
+                    xMin[i], xMax[i], yMin[i], yMax[i]);
+            return i*10+2;
+        }
+
+        if (k->image->numCols != xMax[i]-xMin[i]+1 ||
+                k->image->numRows != yMax[i]-yMin[i]+1) {
+            psError(__func__,"Size of the kernel image is wrong (%dx%d vs %dx%d).",
+                    xMax[i]-xMin[i]+1, yMax[i]-yMin[i]+1,
+                    k->image->numCols, k->image->numRows);
+            return i*10+2;
+        }
+
+        for (int j=yMin[i]; j<yMax[i]; j++) {
+            if (k->kernel[j]+xMin[i] != k->image->data.PS_TYPE_KERNEL_DATA[j-yMin[i]]) {
+                psError(__func__,"The kernel pointer was set wrong for row %d.",
+                        j);
+                return i*10+4;
+            }
+        }
+
+        psFree(k);
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning (xMin > xMax)");
+    k = psKernelAlloc(5, -5, -2, 2);
+    if (k == NULL) {
+        psError(__func__,"psKernelAlloc returned NULL for xMin > xMax.");
+        return i*10+5;
+    }
+
+    if (k->xMin != -5 || k->xMax != 5) {
+        psError(__func__,"psKernelAlloc didn't swap xMin & xMax.");
+        return i*10+6;
+    }
+
+    psFree(k);
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning (yMin > yMax)");
+    k = psKernelAlloc(-2, 2, 5, -5);
+    if (k == NULL) {
+        psError(__func__,"psKernelAlloc returned NULL for yMin > yMax.");
+        return i*10+7;
+    }
+
+    if (k->yMin != -5 || k->yMax != 5) {
+        psError(__func__,"psKernelAlloc didn't swap yMin & yMax.");
+        return i*10+8;
+    }
+
+    psFree(k);
+
+    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;
+}
+
+static int testImageConvolve(void)
+{
+    const int r = 200;
+    const int c = 300;
+    int sum;
+
+    // approximate a normalized gaussian kernel.
+    psKernel* g = psKernelAlloc(-1,1,-1,1);
+    g->kernel[-1][-1] =
+        g->kernel[-1][1] =
+            g->kernel[1][-1] =
+                g->kernel[1][1] = 0.0113;
+    g->kernel[1][0] =
+        g->kernel[-1][0] =
+            g->kernel[0][-1] =
+                g->kernel[0][1] = 0.0838;
+    g->kernel[0][0] = 0.6193;
+
+    // create a normalized non-symetric kernel.
+    psKernel* nsk = psKernelAlloc(0,2,0,2);
+    sum = 0.0;
+    for (int i=0;i<2;i++) {
+        for (int j=0;j<2;j++) {
+            nsk->kernel[i][j] = i+j;
+            sum = i+j;
+        }
+    }
+    for (int i=0;i<2;i++) {
+        for (int j=0;j<2;j++) {
+            nsk->kernel[i][j] /= sum;
+        }
+    }
+
+
+    psImage* img = psImageAlloc(c,r,PS_TYPE_F32);
+    memset(img->data.F32[0],0,c*r*PSELEMTYPE_SIZEOF(PS_TYPE_F32));
+    img->data.F32[0][0] = 1.0f;
+    img->data.F32[r/2][c/2] = 1.0f;
+    img->data.F32[r-1][c/2] = 1.0f;
+
+    // test spacial convolution of gaussian
+    psLogMsg(__func__,PS_LOG_INFO,"Testing direct gaussian convolution");
+    psImage* out = psImageConvolve(NULL, img, g, true);
+
+    if (out == NULL) {
+        psError(__func__, "psImageConvolve returned a NULL for direct gaussian case.");
+        return 1;
+    }
+
+    if (out->numCols != c || out->numRows != r) {
+        psError(__func__, "psImageConvolve result image is %dx%d, but expected %dx%d.",
+                out->numCols, out->numRows,
+                c,r);
+        return 2;
+    }
+
+    if (out->type.type != PS_TYPE_F32) {
+        char* typeStr;
+        PS_TYPE_NAME(typeStr,out->type.type);
+        psError(__func__, "psImageConvolve result image is of type %s, not psF32.",
+                typeStr);
+        return 3;
+    }
+
+    // test values
+    for (int i=-1;i<1;i++) {
+        for (int j=-1;j<1;j++) {
+            if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        c/2+j,r/2+i,
+                        out->data.F32[r/2+i][c/2+j], g->kernel[i][j]);
+                return 4;
+            }
+            if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        j,i,
+                        out->data.F32[i][j], g->kernel[i][j]);
+                return 5;
+            }
+            if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        c/2+j,r-1+i,
+                        out->data.F32[r-1+i][c/2+j], g->kernel[i][j]);
+                return 6;
+            }
+        }
+    }
+
+    // test fourier convolution of gaussian
+    psLogMsg(__func__,PS_LOG_INFO,"Testing fourier gaussian convolution");
+    psKernel* gg = psKernelAlloc(1,3,1,3);
+    gg->kernel[1][1] =
+        gg->kernel[1][3] =
+            gg->kernel[3][1] =
+                gg->kernel[3][3] = 0.0113;
+    gg->kernel[3][2] =
+        gg->kernel[1][2] =
+            gg->kernel[2][1] =
+                gg->kernel[2][3] = 0.0838;
+    gg->kernel[2][2] = 0.6193;
+    img->data.F32[0][0] = 0.0f;
+    img->data.F32[r/2][c/2] = 1.0f;
+    img->data.F32[r-1][c/2] = 0.0f;
+    psImage* out2 = psImageConvolve(out, img, gg, false);
+
+    if (out == NULL) {
+        psError(__func__, "psImageConvolve returned a NULL for gaussian case.");
+        return 10;
+    }
+
+    if (out != out2) {
+        psError(__func__, "psImageConvolve didn't recycle the supplied out image struct.");
+        return 11;
+    }
+
+    if (out->numCols != c || out->numRows != r) {
+        psError(__func__, "psImageConvolve result image is %dx%d, but expected %dx%d.",
+                out->numCols, out->numRows,
+                c,r);
+        return 12;
+    }
+
+    if (out->type.type != PS_TYPE_F32) {
+        char* typeStr;
+        PS_TYPE_NAME(typeStr,out->type.type);
+        psError(__func__, "psImageConvolve result image is of type %s, not psF32.",
+                typeStr);
+        return 13;
+    }
+
+    psImageWriteSection(out2,0,0,0,NULL,0,"out2.fits");
+    // test values
+    for (int i=-1;i<1;i++) {
+        for (int j=-1;j<1;j++) {
+            if (fabsf(out->data.F32[r/2+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        c/2+j,r/2+i,
+                        out->data.F32[r/2+i][c/2+j], g->kernel[i][j]);
+                psImageWriteSection(out,0,0,0,NULL,0,"problem.fits");
+                return 14;
+            }
+            if (i >= 0 && j >= 0 && fabsf(out->data.F32[i][j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        j,i,
+                        out->data.F32[i][j], g->kernel[i][j]);
+                return 15;
+            }
+            if (i <= 0 && fabsf(out->data.F32[r-1+i][c/2+j] - g->kernel[i][j]) > 0.0001) {
+                psError(__func__,"Convolved image wrong at %d,%d.  Value is %g, expected %g.",
+                        c/2+j,r-1+i,
+                        out->data.F32[r-1+i][c/2+j], g->kernel[i][j]);
+                return 16;
+            }
+        }
+    }
+
+    psFree(g);
+    psFree(img);
+    psFree(nsk);
+    psFree(out);
+    return 0;
+}
