IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2812


Ignore:
Timestamp:
Dec 23, 2004, 1:16:36 PM (22 years ago)
Author:
gusciora
Message:

Added tests for input parameters.

Location:
trunk/psModules
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/pmReadoutCombine.c

    r2810 r2812  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-12-23 20:27:51 $
     7 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-12-23 23:16:36 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2727psCombineParams;
    2828
    29 
    30 int p_psDetermineNumBits(unsigned int data)
     29/******************************************************************************
     30p_psDetermineNumBits(data): This routine takes an enum psStatsOptions as an
     31argument and returns the number of non-zero bits.
     32 *****************************************************************************/
     33psStatsOptions p_psDetermineNumBits(psStatsOptions data)
    3134{
    32     int i;
    33     unsigned int tmpData = data;
    34     int numBits = 0;
    35 
    36     for (i=0;i<sizeof(unsigned int);i++) {
    37         if (0x0001 && tmpData) {
     35    psS32 i;
     36    psU64 tmpData = data;
     37    psS32 numBits = 0;
     38
     39    for (i=0;i<4 * sizeof(psStatsOptions);i++) {
     40        if (0x0001 & tmpData) {
    3841            numBits++;
    3942        }
     
    4346}
    4447
     48// XXX: Whats this?
    4549#define MAX_INT 10000
    4650psImage *pmReadoutCombine(psImage *output,
     
    5559    PS_PTR_CHECK_NULL(inputs, NULL);
    5660    PS_PTR_CHECK_NULL(params, NULL);
     61    PS_PTR_CHECK_NULL(params->stats, NULL);
     62    if (zero != NULL) {
     63        PS_VECTOR_CHECK_TYPE(zero, PS_TYPE_F32, NULL);
     64    }
     65    if (scale != NULL) {
     66        PS_VECTOR_CHECK_TYPE(scale, PS_TYPE_F32, NULL);
     67    }
     68    if ((zero != NULL) && (scale != NULL)) {
     69        PS_VECTOR_CHECK_TYPE_EQUAL(zero, scale, NULL);
     70        // XXX: Currently only type F32 is implemented.
     71        // PS_VECTOR_CHECK_TYPE_S16_S32_F32(scale, NULL);
     72    }
     73
    5774    psStats *stats = params->stats;
    5875    int i;
     
    6683    int numInputs = 0;
    6784    int tmpI;
     85    psElemType outputType = PS_TYPE_F32;
     86
     87    if (1 < p_psDetermineNumBits(params->stats->options)) {
     88        psError(PS_ERR_UNKNOWN, true,
     89                "Multiple statistical options have been requested.\n");
     90        return(NULL);
     91    }
    6892
    6993    //
     
    86110        PS_READOUT_CHECK_EMPTY(tmpReadout, output);
    87111        PS_READOUT_CHECK_TYPE(tmpReadout, PS_TYPE_F32, output);
     112        outputType = tmpReadout->image->type.type;
    88113
    89114        minInputRows = PS_MIN(minInputRows,
     
    105130
    106131    // We ensure that the zero vector is of the proper size.
     132
    107133    if (zero != NULL) {
    108134        PS_VECTOR_CHECK_TYPE(zero, PS_TYPE_F32, NULL);
    109135        if (numInputs > zero->n) {
    110             // XXX: ERROR: the zero vector does not have enough elements.
     136            psError(PS_ERR_UNKNOWN, true, "zero vector has incorrect size (%d)\n", zero->n);
    111137            return(NULL);
    112138        } else if (numInputs < zero->n) {
    113             // XXX: WARNING: the zero vector too many elements.
     139            psLogMsg(__func__, PS_LOG_WARN,
     140                     "WARNING: the zero vector too many elements (%d)\n", zero->n);
    114141        }
    115142    }
     
    119146        PS_VECTOR_CHECK_TYPE(scale, PS_TYPE_F32, NULL);
    120147        if (numInputs > scale->n) {
    121             // XXX: ERROR: the scale vector does not have enough elements.
     148            psError(PS_ERR_UNKNOWN, true, "scale vector has incorrect size (%d)\n", scale->n);
    122149            return(NULL);
    123150        } else if (numInputs < scale->n) {
    124             // XXX: WARNING: the scale vector too many elements.
     151            psLogMsg(__func__, PS_LOG_WARN,
     152                     "WARNING: the scale vector too many elements (%d)\n", scale->n);
    125153        }
    126154    }
     
    134162    if (output == NULL) {
    135163        output = psImageAlloc(maxInputCols-minInputCols,
    136                               maxInputRows-minInputRows, PS_TYPE_F32);
     164                              maxInputRows-minInputRows, outputType);
    137165        *(int *) &(output->col0) = minInputCols;
    138166        *(int *) &(output->row0) = minInputRows;
     
    140168        if (((output->col0 + output->numCols) < maxInputCols) ||
    141169                ((output->row0 + output->numRows) < maxInputRows)) {
    142             //XXX ERROR: "Output image (%d, %d) is too small to hold combined images.\n",
    143             //                    output->row0 + output->numRows,
    144             //                    output->col0 + output->numCols);
     170            psError(PS_ERR_UNKNOWN, true,
     171                    "Output image (%d, %d) is too small to hold combined images.\n",
     172                    output->row0 + output->numRows,
     173                    output->col0 + output->numCols);
    145174            return(NULL);
    146175        }
     
    150179            return(NULL);
    151180        }
    152     }
    153 
    154     if (1 < p_psDetermineNumBits(params->stats->options)) {
    155         //XXX        psError(PS_ERR_UNKNOWN,true, "Multiple statistical options have been requested.\n");
    156         return(NULL);
    157181    }
    158182
     
    254278            // XXX: Is this correct?
    255279            // We add the zero vector, if non-NULL.
     280
    256281            if (zero != NULL) {
    257282                for (int r = 0; r < numInputs ; r++) {
  • trunk/psModules/src/pmSubtractSky.c

    r2810 r2812  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-23 20:27:51 $
     8 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-12-23 23:16:36 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    12  *
     12xd *
    1313 */
    1414
     
    2020
    2121/******************************************************************************
    22 p_psDetermineNumBits(data): This routine takes an insigned int as an argument
    23 and returns the number of non-zero bits.
    24  *****************************************************************************/
    25 psS32 p_psDetermineNumBits(psU32 data)
     22p_psDetermineNumBits(data): This routine takes an enum psStatsOptions as an
     23argument and returns the number of non-zero bits.
     24 *****************************************************************************/
     25psStatsOptions p_psDetermineNumBits(psStatsOptions data)
    2626{
    2727    psS32 i;
    28     psU32 tmpData = data;
     28    psU64 tmpData = data;
    2929    psS32 numBits = 0;
    3030
    31     for (i=0;i<sizeof(psU32);i++) {
    32         if (0x0001 && tmpData) {
     31    for (i=0;i<4 * sizeof(psStatsOptions);i++) {
     32        if (0x0001 & tmpData) {
    3333            numBits++;
    3434        }
  • trunk/psModules/test/tst_pmReadoutCombine.c

    r2590 r2812  
    55 *  @author GLG, MHPCC
    66 *
    7  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-12-01 22:08:32 $
     7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-12-23 23:16:36 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1515#include "pmReadoutCombine.h"
    1616static int test00(void);
     17static int test01(void);
    1718testDescription tests[] = {
    1819                              {test00, 000, "pmSubtractBias", 0, false},
     20                              {test01, 000, "pmSubtractBias(): input parameter error conditions", 0, false},
    1921                              {NULL}
    2022                          };
     
    3436int doit()
    3537{
     38    return(0);
    3639    int i;
    3740    int j;
     
    238241    return(testStatus);
    239242}
     243
     244psS32 VerifyTheOutput(psImage *output)
     245{
     246    bool testStatus = true;
     247
     248    for (psS32 i = 0 ; i < output->numRows ; i++) {
     249        for (psS32 j = 0 ; j < output->numCols ; j++) {
     250            if (output->data.F32[i][j] != 45.0) {
     251                printf("ERROR: output[%d][%d] is %.2f, should be 45.0\n", i, j, output->data.F32[i][j]);
     252                testStatus = false;
     253            }
     254        }
     255    }
     256    return(testStatus);
     257}
     258
     259
     260int test01()
     261{
     262    int i;
     263    int j;
     264    int r;
     265    psList *list = NULL;
     266    int baseRowsReadout[NUM_READOUTS];
     267    int baseColsReadout[NUM_READOUTS];
     268    int baseRows[NUM_READOUTS];
     269    int baseCols[NUM_READOUTS];
     270    int numRows[NUM_READOUTS];
     271    int numCols[NUM_READOUTS];
     272    int minOutRow = 10000;
     273    int minOutCol = 10000;
     274    int maxOutRow = -1;
     275    int maxOutCol = -1;
     276    psImage *output = NULL;
     277    psImage *rc = NULL;
     278    psCombineParams *params = (psCombineParams *) psAlloc(sizeof(psCombineParams));
     279    psVector *zero = psVectorAlloc(NUM_READOUTS, PS_TYPE_F32);
     280    psVector *zeroHalf = psVectorAlloc(NUM_READOUTS/2, PS_TYPE_F32);
     281    psVector *zeroBig = psVectorAlloc(NUM_READOUTS+1, PS_TYPE_F32);
     282    psVector *zeroF64 = psVectorAlloc(NUM_READOUTS, PS_TYPE_F64);
     283    psVector *scale = psVectorAlloc(NUM_READOUTS, PS_TYPE_F32);
     284    psVector *scaleHalf = psVectorAlloc(NUM_READOUTS/2, PS_TYPE_F32);
     285    psVector *scaleBig = psVectorAlloc(NUM_READOUTS*2, PS_TYPE_F32);
     286    psVector *scaleF64 = psVectorAlloc(NUM_READOUTS, PS_TYPE_F64);
     287    int testStatus = true;
     288    for (i=0;i<NUM_READOUTS;i++) {
     289        zero->data.F32[i] = 3.0;
     290        zeroBig->data.F32[i] = 3.0;
     291    }
     292    for (i=0;i<NUM_READOUTS;i++) {
     293        scale->data.F32[i] = 6.0;
     294        scaleBig->data.F32[i] = 6.0;
     295    }
     296
     297    params->stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     298    params->maskVal = 1;
     299    params->fracLow = 0.0;
     300    params->fracHigh = 10000.0;
     301    params->nKeep = 0;
     302
     303    for (r=0;r<NUM_READOUTS;r++) {
     304        baseRowsReadout[r] = r + 40;
     305        baseColsReadout[r] = r + 42;
     306        baseRows[r] = r;
     307        baseCols[r] = r+2;
     308        numRows[r] = 4 + (2 * r);
     309        numCols[r] = 8 + (2 * r);
     310
     311        baseRowsReadout[r] = 0;
     312        baseColsReadout[r] = 0;
     313        baseRows[r] = 0;
     314        baseCols[r] = 0;
     315        numRows[r] = 10;
     316        numCols[r] = 10;
     317
     318        psImage *tmpImage = psImageAlloc(numCols[r], numRows[r], PS_TYPE_F32);
     319        for (i=0;i<numRows[r];i++) {
     320            for (j=0;j<numCols[r];j++) {
     321                tmpImage->data.F32[i][j] = (float) (i + j);
     322                tmpImage->data.F32[i][j] = 1.0;
     323                tmpImage->data.F32[i][j] = (float) r;
     324            }
     325        }
     326
     327        *(int *) (& (tmpImage->row0)) = baseRows[r];
     328        *(int *) (& (tmpImage->col0)) = baseCols[r];
     329        psReadout *tmpReadout = psReadoutAlloc(baseColsReadout[r],
     330                                               baseRowsReadout[r],
     331                                               tmpImage);
     332        minOutRow = PS_MIN(minOutRow, (baseRowsReadout[r] + baseRows[r]));
     333        minOutCol = PS_MIN(minOutCol, (baseColsReadout[r] + baseCols[r]));
     334        maxOutRow = PS_MAX(maxOutRow, (baseRowsReadout[r] + baseRows[r] + numRows[r]));
     335        maxOutCol = PS_MAX(maxOutCol, (baseColsReadout[r] + baseCols[r] + numCols[r]));
     336
     337        if (r == 0) {
     338            list = psListAlloc(tmpReadout);
     339        } else {
     340            psListAdd(list, PS_LIST_HEAD, tmpReadout);
     341        }
     342    }
     343
     344    printf("----------------------------------------------------------------------------\n");
     345    printf("Calling pmReadoutCombine() with NULL zero vector.\n");
     346    rc = pmReadoutCombine(NULL, list, params, NULL, scale, true, 1.0, 0.0);
     347    if (rc == NULL) {
     348        //XXX: We should verify the output image here.
     349        printf("ERROR: pmReadoutCombine() returned NULL\n");
     350        testStatus = false;
     351    }
     352    if (rc->type.type != scale->type.type) {
     353        printf("ERROR: output readout->image has incorrect type.\n");
     354        testStatus = false;
     355    }
     356    psFree(rc);
     357
     358    printf("----------------------------------------------------------------------------\n");
     359    printf("Calling pmReadoutCombine() with incorrect length zero vector (too small).  Should generate error.\n");
     360    rc = pmReadoutCombine(NULL, list, params, zeroHalf, scale, true, 1.0, 0.0);
     361    if (rc != NULL) {
     362        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     363        testStatus = false;
     364    }
     365
     366    printf("----------------------------------------------------------------------------\n");
     367    printf("Calling pmReadoutCombine() with incorrect type zero vector.  Should generate error.\n");
     368    rc = pmReadoutCombine(NULL, list, params, zeroF64, scale, true, 1.0, 0.0);
     369    if (rc != NULL) {
     370        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     371        testStatus = false;
     372    }
     373
     374    printf("----------------------------------------------------------------------------\n");
     375    printf("Calling pmReadoutCombine() with incorrect length zero vector (too big).  Should generate warning.\n");
     376    rc = pmReadoutCombine(output, list, params, zeroBig, scale, true, 1.0, 0.0);
     377    if (rc != NULL) {
     378        if (false == VerifyTheOutput(rc)) {
     379            testStatus = false;
     380        }
     381        psFree(rc);
     382        rc = NULL;
     383    } else {
     384        printf("ERROR: pmReadoutCombine() returned NULL\n");
     385        testStatus = false;
     386    }
     387
     388    printf("----------------------------------------------------------------------------\n");
     389    printf("Calling pmReadoutCombine() with NULL scale vector.\n");
     390    rc = pmReadoutCombine(output, list, params, zero, NULL, true, 1.0, 0.0);
     391    if (rc == NULL) {
     392        //XXX: We should verify the output image here.
     393        printf("ERROR: pmReadoutCombine() returned NULL\n");
     394        testStatus = false;
     395    }
     396    psFree(rc);
     397
     398    printf("----------------------------------------------------------------------------\n");
     399    printf("Calling pmReadoutCombine() with incorrect length scale vector (too small).  Should generate error.\n");
     400    rc = pmReadoutCombine(output, list, params, zero, scaleHalf, true, 1.0, 0.0);
     401    if (rc != NULL) {
     402        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     403        testStatus = false;
     404    }
     405
     406    printf("----------------------------------------------------------------------------\n");
     407    printf("Calling pmReadoutCombine() with incorrect type scale vector.  Should generate error.\n");
     408    rc = pmReadoutCombine(output, list, params, zero, scaleF64, true, 1.0, 0.0);
     409    if (rc != NULL) {
     410        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     411        testStatus = false;
     412    }
     413
     414    printf("----------------------------------------------------------------------------\n");
     415    printf("Calling pmReadoutCombine() with incorrect length scale vector (too big).  Should generate warning.\n");
     416    rc = pmReadoutCombine(output, list, params, zero, scaleBig, true, 1.0, 0.0);
     417    if (rc != NULL) {
     418        if (false == VerifyTheOutput(rc)) {
     419            testStatus = false;
     420        }
     421        psFree(rc);
     422        rc = NULL;
     423    } else {
     424        printf("ERROR: pmReadoutCombine() returned NULL\n");
     425        testStatus = false;
     426    }
     427
     428    printf("----------------------------------------------------------------------------\n");
     429    printf("Calling pmReadoutCombine() insufficient size output image.  Should generate error, return NULL.\n");
     430    output = psImageAlloc(1, 1, PS_TYPE_F32);
     431    rc = pmReadoutCombine(output, list, params, zero, scale, true, 1.0, 0.0);
     432    if (rc != NULL) {
     433        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     434        testStatus = false;
     435    }
     436    psFree(output);
     437    output = NULL;
     438
     439    printf("----------------------------------------------------------------------------\n");
     440    printf("Calling pmReadoutCombine() with NULL input list.  Should generate error, return NULL.\n");
     441    rc = pmReadoutCombine(output, NULL, params, zero, scale, true, 1.0, 0.0);
     442    if (rc != NULL) {
     443        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     444        testStatus = false;
     445    }
     446
     447    printf("----------------------------------------------------------------------------\n");
     448    printf("Calling pmReadoutCombine() with NULL params.  Should generate error, return NULL.\n");
     449    rc = pmReadoutCombine(output, list, NULL, zero, scale, true, 1.0, 0.0);
     450    if (rc != NULL) {
     451        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     452        testStatus = false;
     453    }
     454
     455    printf("----------------------------------------------------------------------------\n");
     456    psStatsOptions oldStatsOpts = params->stats->options |= PS_STAT_MIN;
     457    printf("Calling pmReadoutCombine() with multiple stats->options.  Should generate error, return NULL.\n");
     458    rc = pmReadoutCombine(output, list, params, zero, scale, true, 1.0, 0.0);
     459    if (rc != NULL) {
     460        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     461        testStatus = false;
     462    }
     463    params->stats->options = oldStatsOpts;
     464
     465    printf("----------------------------------------------------------------------------\n");
     466    psStats *oldStats = params->stats;
     467    printf("Calling pmReadoutCombine() with NULL param->stats.  Should generate error, return NULL.\n");
     468    rc = pmReadoutCombine(output, list, params, zero, scale, true, 1.0, 0.0);
     469    if (rc != NULL) {
     470        printf("ERROR: pmReadoutCombine() did not return NULL\n");
     471        testStatus = false;
     472    }
     473    params->stats = oldStats;
     474
     475    printf("----------------------------------------------------------------------------\n");
     476    printf("============================================================================\n");
     477
     478    psFree(params->stats);
     479    psFree(params);
     480    //    psFree(output);
     481    //    psFree(rc);
     482    psFree(zero);
     483    psFree(zeroHalf);
     484    psFree(zeroBig);
     485    psFree(zeroF64);
     486    psFree(scale);
     487    psFree(scaleHalf);
     488    psFree(scaleBig);
     489    psFree(scaleF64);
     490    psListElem *tmpInput = (psListElem *) list->head;
     491    while (NULL != tmpInput) {
     492        psReadout *tmpReadout = (psReadout *) tmpInput->data;
     493        psFree(tmpReadout);
     494        tmpInput = tmpInput->next;
     495    }
     496    psFree(list);
     497
     498    return(!testStatus);
     499}
     500// This code will
Note: See TracChangeset for help on using the changeset viewer.