IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 3, 2004, 3:05:00 PM (22 years ago)
Author:
desonia
Message:

changed the psError signature to match SDRS. Also made misc. cleanups as
I was combing the files.

Location:
trunk/psLib/src/dataManip
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psConstants.h

    r2272 r2273  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-11-03 22:58:53 $
     8 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-11-04 01:04:57 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    3232#define PS_INT_CHECK_NON_NEGATIVE(NAME, RVAL) \
    3333if (NAME < 0) { \
    34     psError(__func__,"Error: %s is less than 0.", #NAME); \
     34    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     35            "Error: %s is less than 0.", #NAME); \
    3536    return(RVAL); \
    3637}
    … …  
    3839#define PS_INT_CHECK_POSITIVE(NAME, RVAL) \
    3940if (NAME < 1) { \
    40     psError(__func__,"Error: %s is 0 or less.", #NAME); \
    41     return(RVAL); \
    42 }
    43 
    44 // Produce an error if ((NAME1 > NAME2)
     41    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     42            "Error: %s is 0 or less.", #NAME); \
     43    return(RVAL); \
     44}
     45
     46#define PS_INT_CHECK_RANGE(NAME, LOWER, UPPER, RVAL) \
     47if ((int)NAME < LOWER || (int)NAME > UPPER) { \
     48    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     49            "Error: %s, %d, is out of range.  Must be between %d and %d.", \
     50            #NAME,(int)NAME,LOWER,UPPER); \
     51    return RVAL; \
     52}
     53
     54// Produce an error if (NAME1 > NAME2)
    4555#define PS_INT_COMPARE(NAME1, NAME2, RVAL) \
    4656if (NAME1 > NAME2) { \
    47     psError(__func__,"Error: (%s > %s) (%d %d).", #NAME1, #NAME2, NAME1, NAME2); \
     57    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     58            "Error: (%s > %s) (%d %d).", \
     59            #NAME1, #NAME2, NAME1, NAME2); \
    4860    return(RVAL); \
    4961}
    … …  
    5365#define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
    5466if (NAME1 > NAME2) { \
    55     psError(__func__,"Error: (%s > %s) (%f %f)", #NAME1, #NAME2, NAME1, NAME2); \
     67    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     68            "Error: (%s > %s) (%f %f)", \
     69            #NAME1, #NAME2, NAME1, NAME2); \
    5670    return(RVAL); \
    5771}
    … …  
    5973#define PS_FLOAT_CHECK_NON_EQUAL(NAME1, NAME2, RVAL) \
    6074if (fabs(NAME2 - NAME1) < FLT_EPSILON) { \
    61     psError(__func__,"Error: %s and %s are equal.", #NAME1, #NAME2); \
     75    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     76            "Error: %s and %s are equal.", \
     77            #NAME1, #NAME2); \
    6278    return(RVAL); \
    6379}
    … …  
    6783the wrong type.
    6884*****************************************************************************/
    69 #define PS_PTR_CHECK_NULL(NAME, RVAL) \
     85#define PS_PTR_CHECK_NULL(NAME, RVAL) PS_PTR_CHECK_NULL_GENERAL(NAME, return RVAL)
     86#define PS_PTR_CHECK_NULL_GENERAL(NAME, CLEANUP) \
    7087if (NAME == NULL) { \
    71     psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
    72     return(RVAL); \
     88    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
     89            "Unallowable operation: %s is NULL.", \
     90            #NAME); \
     91    CLEANUP; \
    7392}
    7493
    7594#define PS_PTR_CHECK_TYPE(NAME, TYPE, RVAL) \
    7695if (NAME->type.type != TYPE) { \
    77     psError(__func__,"Unallowable operation: %s has incorrect type.", #NAME); \
    78     return(RVAL); \
    79 }
     96    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     97            "Unallowable operation: %s has incorrect type.", \
     98            #NAME); \
     99    return(RVAL); \
     100}
     101
     102#define PS_PTR_CHECK_DIMEN(NAME, DIMEN, RVAL) PS_PTR_CHECK_DIMEN_GENERAL(NAME, DIMEN, return RVAL)
     103#define PS_PTR_CHECK_DIMEN_GENERAL(NAME, DIMEN, CLEANUP) \
     104if (NAME->type.dimen != DIMEN) { \
     105    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     106            "Unallowable operation: %s has incorrect dimensionality.", \
     107            #NAME); \
     108    CLEANUP; \
     109}
     110
    80111
    81112#define PS_PTR_CHECK_SIZE_EQUAL(PTR1, PTR2, RVAL) \
    82113if (PTR1->n != PTR2->n) { \
    83     psError(__func__,"ptr %s has size %d, ptr %s has size %d.", #PTR1, PTR1->n, #PTR2, PTR2->n); \
    84     return(RVAL); \
    85 }
    86 
    87 #define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) \
     114    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
     115            "ptr %s has size %d, ptr %s has size %d.", \
     116            #PTR1, PTR1->n, #PTR2, PTR2->n); \
     117    return(RVAL); \
     118}
     119
     120#define PS_PTR_CHECK_TYPE_EQUAL(PTR1, PTR2, RVAL) PS_PTR_CHECK_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL)
     121
     122#define PS_PTR_CHECK_TYPE_EQUAL_GENERAL(PTR1, PTR2, CLEANUP) \
    88123if (PTR1->type.type != PTR2->type.type) { \
    89     psError(__func__,"ptr %s has type %d, ptr %s has type %d.", #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
    90     return(RVAL); \
     124    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     125            "ptr %s has type %d, ptr %s has type %d.", \
     126            #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
     127    CLEANUP; \
    91128}
    92129
    … …  
    95132    PS_VECTOR macros:
    96133 *****************************************************************************/
    97 #define PS_VECTOR_CHECK_NULL(NAME, RVAL) \
     134#define PS_VECTOR_CHECK_NULL(NAME, RVAL) PS_VECTOR_CHECK_NULL_GENERAL(NAME, return RVAL)
     135#define PS_VECTOR_CHECK_NULL_GENERAL(NAME, CLEANUP) \
    98136if (NAME == NULL || NAME->data.V == NULL) { \
    99     psError(__func__,"Unallowable operation: psVector %s or its data is NULL.", #NAME); \
    100     return(RVAL); \
     137    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
     138            "Unallowable operation: psVector %s or its data is NULL.", \
     139            #NAME); \
     140    CLEANUP; \
    101141} \
    102142
    103143#define PS_VECTOR_CHECK_EMPTY(NAME, RVAL) \
    104144if (NAME->n < 1) { \
    105     psError(__func__,"Unallowable operation: psVector %s has no elements.", #NAME); \
     145    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
     146            "Unallowable operation: psVector %s has no elements.", \
     147            #NAME); \
    106148    return(RVAL); \
    107149} \
    … …  
    109151#define PS_VECTOR_CHECK_TYPE_F32_OR_F64(NAME, RVAL) \
    110152if ((NAME->type.type != PS_TYPE_F32) && (NAME->type.type != PS_TYPE_F64)) { \
    111     psError(__func__, "psVector %s: bad type(%d)", #NAME, NAME->type.type); \
     153    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     154            "psVector %s: bad type(%d)", \
     155            #NAME, NAME->type.type); \
    112156    return(RVAL); \
    113157} \
    … …  
    115159#define PS_VECTOR_CHECK_TYPE(NAME, TYPE, RVAL) \
    116160if (NAME->type.type != TYPE) { \
    117     psError(__func__,"Unallowable operation: psVector %s has incorrect type.", #NAME); \
     161    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     162            "Unallowable operation: psVector %s has incorrect type.", \
     163            #NAME); \
    118164    return(RVAL); \
    119165}
    … …  
    121167#define PS_VECTOR_CHECK_SIZE_EQUAL(VEC1, VEC2, RVAL) \
    122168if (VEC1->n != VEC2->n) { \
    123     psError(__func__,"psVector %s has size %d, psVector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
     169    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
     170            "psVector %s has size %d, psVector %s has size %d.", \
     171            #VEC1, VEC1->n, #VEC2, VEC2->n); \
    124172    return(RVAL); \
    125173}
    … …  
    221269#define PS_POLY_CHECK_NULL(NAME, RVAL) \
    222270if (NAME == NULL || NAME->coeff == NULL) { \
    223     psError(__func__,"Unallowable operation: polynomial %s or its coeffs is NULL.", #NAME); \
     271    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
     272            "Unallowable operation: polynomial %s or its coeffs is NULL.", \
     273            #NAME); \
    224274    return(RVAL); \
    225275} \
    … …  
    227277#define PS_POLY_CHECK_TYPE(NAME, TYPE, RVAL) \
    228278if (NAME->type != TYPE) { \
    229     psError(__func__,"Unallowable operation: polynomial %s has wrong type.", #NAME); \
     279    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     280            "Unallowable operation: polynomial %s has wrong type.", #NAME); \
    230281    return(RVAL); \
    231282} \
    … …  
    234285    PS_IMAGE macros:
    235286*****************************************************************************/
    236 #define PS_IMAGE_CHECK_NULL(NAME, RVAL) \
     287#define PS_IMAGE_CHECK_NULL(NAME, RVAL) PS_IMAGE_CHECK_NULL_GENERAL(NAME, return RVAL)
     288#define PS_IMAGE_CHECK_NULL_GENERAL(NAME, CLEANUP) \
    237289if (NAME == NULL || NAME->data.V == NULL) { \
    238     psError(__func__,"Unallowable operation: psImage %s or its data is NULL.", #NAME); \
    239     return(RVAL); \
    240 }
    241 
    242 #define PS_IMAGE_CHECK_EMPTY(NAME, RVAL) \
     290    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
     291            "Unallowable operation: psImage %s or its data is NULL.", \
     292            #NAME); \
     293    CLEANUP; \
     294}
     295
     296#define PS_IMAGE_CHECK_EMPTY(NAME, RVAL) PS_IMAGE_CHECK_EMPTY_GENERAL(NAME, return RVAL)
     297#define PS_IMAGE_CHECK_EMPTY_GENERAL(NAME, CLEANUP) \
    243298if (NAME->numCols < 1 || NAME->numRows < 1) { \
    244     psError(__func__,"Unallowable operation: psImage %s has zero rows or columns (%dx%d).", #NAME, \
    245             NAME->numCols, NAME->numRows); \
    246     return(RVAL); \
     299    psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
     300            "Unallowable operation: psImage %s has zero rows or columns (%dx%d).", \
     301            #NAME, NAME->numCols, NAME->numRows); \
     302    CLEANUP; \
    247303}
    248304
    249305#define PS_IMAGE_CHECK_TYPE(NAME, TYPE, RVAL) \
    250306if (NAME->type.type != TYPE) { \
    251     psError(__func__,"Unallowable operation: psImage %s has incorrect type.", #NAME); \
     307    psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
     308            "Unallowable operation: psImage %s has incorrect type.", \
     309            #NAME); \
    252310    return(RVAL); \
    253311}
    … …  
    260318#define PS_READOUT_CHECK_NULL(NAME, RVAL) \
    261319if (NAME == NULL || NAME->image == NULL) { \
    262     psError(__func__,"Unallowable operation: psReadout %s or its data is NULL.", #NAME); \
     320    psError(PS_ERR_BAD_PARAMETER_NULL, true, \
     321            "Unallowable operation: psReadout %s or its data is NULL.", \
     322            #NAME); \
    263323    return(RVAL); \
    264324}
  • trunk/psLib/src/dataManip/psDataManipErrors.dat

    r2080 r2273  
    88####################################################################
    99#
    10 psVectorFFT_IMAGE_TYPE_UNSUPPORTED     Input psVector type, %s, is not supported. Valid data types are psF32 and psC32.
     10psVectorFFT_TYPE_NOT_F32_C32           Input psVector type, %s, is not supported. Valid data types are psF32 and psC32.
    1111psVectorFFT_REVERSE_NOT_COMPLEX        Input psVector (%s) is not complex.  Reverse FFT operation requires a complex input.
    1212psVectorFFT_FORWARD_NOT_REAL           Input psVector (%s) is not real.  Forward FFT operation requires a real input.
    … …  
    1818psVectorFFT_NONCOMPLEX_NOTSUPPORTED    Input psVector type, %s, is required to be either psC32 or psC64.
    1919psVectorFFT_DIRECTION_NOTSET           Must specify the direction as either PS_FFT_FORWARD or PS_FFT_REVERSE.
     20#
     21psStats_NOT_F32_F64                    Invalid data type, %s.  Only psF32 and psF64 data types are supported.
     22psStats_VECTOR_TYPE_UNSUPPORTED        Input psVector type, %s, is not supported.
     23psStats_YVAL_OUT_OF_RANGE              Specified yVal, %g, is not within y-range, %g to %g.
     24psStats_ROBUST_QUARTILE_BINS_FAILED    Could not determine the robust lower/upper quartile bin numbers.
     25psStats_STATS_FAILED                   Failed to calculate the specified statistic.
     26#
     27psFunctions_INVALID_POLYNOMIAL_TYPE    Unknown polynomial type 0x%x found.  Evaluation failed.
     28psFunctions_TYPE_NOT_SUPPORTED         Input psVector type, %s, is not supported.
     29psFunctions_NOT_ENOUGH_DATAPOINTS      Given vector does not have enough data points for %d-order interpolation.
     30#
     31psMatrix_COUNT_DIFFERS                 Number of elements inconsistent, %d vs %d.  Number of elements must match.
     32psMatrix_IMAGE_SIZE_DIFFERS            Specified psImage dimensions differed, %dx%d vs %dx%d.
     33psMatrix_TYPE_MISMATCH                 Specified data type, %s, is not supported.
     34psMatrix_MIN_COMPLEX_SUPPORT           The minimum operation is not supported with complex data.
     35psMatrix_MAX_COMPLEX_SUPPORT           The maximum operation is not supported with complex data.
     36psMatrix_OPERATION_UNSUPPORTED         Specified operation, %s, is not supported.
     37psMatrix_DIMEN_OTHER_FOUND             %s's dimensionality is PS_DIMEN_OTHER, which is  not allowed.
     38psMatrix_OUTPUT_VECTOR_NOT_CREATED     Couldn't create a proper output psVector.
     39psMatrix_OUTPUT_IMAGE_NOT_CREATED      Couldn't create a proper output psImage.
     40psMatrix_DIMEN_INVALID                 Specified parameter, %s, has invalid dimensionality, %d.
     41psMatrix_VECTOR_EMPTY                  Input psVector contains no elements.  No data to perform operation with.
     42psMatrix_IMAGE_EMPTY                   Input psImage contains no pixels.  No data to perform operation with.
  • trunk/psLib/src/dataManip/psDataManipErrors.h

    r2080 r2273  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-13 20:46:57 $
     9 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-11-04 01:04:59 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    3030
    3131//~Start #define PS_ERRORTEXT_$1 "$2"
    32 #define PS_ERRORTEXT_psVectorFFT_IMAGE_TYPE_UNSUPPORTED "Input psVector type, %s, is not supported. Valid data types are psF32 and psC32."
     32#define PS_ERRORTEXT_psVectorFFT_TYPE_NOT_F32_C32 "Input psVector type, %s, is not supported. Valid data types are psF32 and psC32."
    3333#define PS_ERRORTEXT_psVectorFFT_REVERSE_NOT_COMPLEX "Input psVector (%s) is not complex.  Reverse FFT operation requires a complex input."
    3434#define PS_ERRORTEXT_psVectorFFT_FORWARD_NOT_REAL "Input psVector (%s) is not real.  Forward FFT operation requires a real input."
    … …  
    4040#define PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED "Input psVector type, %s, is required to be either psC32 or psC64."
    4141#define PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET "Must specify the direction as either PS_FFT_FORWARD or PS_FFT_REVERSE."
     42#define PS_ERRORTEXT_psStats_NOT_F32_F64 "Invalid data type, %s.  Only psF32 and psF64 data types are supported."
     43#define PS_ERRORTEXT_psStats_VECTOR_TYPE_UNSUPPORTED "Input psVector type, %s, is not supported."
     44#define PS_ERRORTEXT_psStats_YVAL_OUT_OF_RANGE "Specified yVal, %g, is not within y-range, %g to %g."
     45#define PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED "Could not determine the robust lower/upper quartile bin numbers."
     46#define PS_ERRORTEXT_psStats_STATS_FAILED "Failed to calculate the specified statistic."
     47#define PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE "Unknown polynomial type 0x%x found.  Evaluation failed."
     48#define PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED "Input psVector type, %s, is not supported."
     49#define PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS "Given vector does not have enough data points for %d-order interpolation."
     50#define PS_ERRORTEXT_psMatrix_COUNT_DIFFERS "Number of elements inconsistent, %d vs %d.  Number of elements must match."
     51#define PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS "Specified psImage dimensions differed, %dx%d vs %dx%d."
     52#define PS_ERRORTEXT_psMatrix_TYPE_MISMATCH "Specified data type, %s, is not supported."
     53#define PS_ERRORTEXT_psMatrix_MIN_COMPLEX_SUPPORT "The minimum operation is not supported with complex data."
     54#define PS_ERRORTEXT_psMatrix_MAX_COMPLEX_SUPPORT "The maximum operation is not supported with complex data."
     55#define PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED "Specified operation, %s, is not supported."
     56#define PS_ERRORTEXT_psMatrix_DIMEN_OTHER_FOUND "%s's dimensionality is PS_DIMEN_OTHER, which is  not allowed."
     57#define PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED "Couldn't create a proper output psVector."
     58#define PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED "Couldn't create a proper output psImage."
     59#define PS_ERRORTEXT_psMatrix_DIMEN_INVALID "Specified parameter, %s, has invalid dimensionality, %d."
     60#define PS_ERRORTEXT_psMatrix_VECTOR_EMPTY "Input psVector contains no elements.  No data to perform operation with."
     61#define PS_ERRORTEXT_psMatrix_IMAGE_EMPTY "Input psImage contains no pixels.  No data to perform operation with."
    4262//~End
    4363
  • trunk/psLib/src/dataManip/psFunctions.c

    r2224 r2273  
    77 *  polynomials.  It also contains a Gaussian functions.
    88 *
    9  *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-28 00:22:53 $
     9 *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-11-04 01:04:59 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    3535#include "psFunctions.h"
    3636#include "psConstants.h"
     37
     38#include "psDataManipErrors.h"
     39
    3740/*****************************************************************************/
    3841/* DEFINE STATEMENTS                                                         */
    … …  
    5053static void dPolynomial3DFree(psDPolynomial3D* myPoly);
    5154static void dPolynomial4DFree(psDPolynomial4D* myPoly);
     55static void spline1DFree(psSpline1D *tmpSpline);
     56static psS32 vectorBinDisectF32(float *bins,psS32 numBins,float x);
     57static psS32 vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x);
    5258
    5359/*****************************************************************************/
    … …  
    6773/*****************************************************************************/
    6874
     75static void spline1DFree(psSpline1D *tmpSpline)
     76{
     77    psS32 i;
     78
     79    if (tmpSpline == NULL) {
     80        return;
     81    }
     82
     83    if (tmpSpline->spline != NULL) {
     84        for (i=0;i<tmpSpline->n;i++) {
     85            psFree((tmpSpline->spline)[i]);
     86        }
     87        psFree(tmpSpline->spline);
     88    }
     89
     90    if (tmpSpline->p_psDeriv2 != NULL) {
     91        psFree(tmpSpline->p_psDeriv2);
     92    }
     93    psFree(tmpSpline->domains);
     94
     95    return;
     96}
     97
     98static void polynomial1DFree(psPolynomial1D* myPoly)
     99{
     100    psFree(myPoly->coeff);
     101    psFree(myPoly->coeffErr);
     102    psFree(myPoly->mask);
     103}
     104
     105static void polynomial2DFree(psPolynomial2D* myPoly)
     106{
     107    psS32 x = 0;
     108
     109    for (x = 0; x < myPoly->nX; x++) {
     110        psFree(myPoly->coeff[x]);
     111        psFree(myPoly->coeffErr[x]);
     112        psFree(myPoly->mask[x]);
     113    }
     114    psFree(myPoly->coeff);
     115    psFree(myPoly->coeffErr);
     116    psFree(myPoly->mask);
     117}
     118
     119static void polynomial3DFree(psPolynomial3D* myPoly)
     120{
     121    psS32 x = 0;
     122    psS32 y = 0;
     123
     124    for (x = 0; x < myPoly->nX; x++) {
     125        for (y = 0; y < myPoly->nY; y++) {
     126            psFree(myPoly->coeff[x][y]);
     127            psFree(myPoly->coeffErr[x][y]);
     128            psFree(myPoly->mask[x][y]);
     129        }
     130        psFree(myPoly->coeff[x]);
     131        psFree(myPoly->coeffErr[x]);
     132        psFree(myPoly->mask[x]);
     133    }
     134
     135    psFree(myPoly->coeff);
     136    psFree(myPoly->coeffErr);
     137    psFree(myPoly->mask);
     138}
     139
     140static void polynomial4DFree(psPolynomial4D* myPoly)
     141{
     142    psS32 w = 0;
     143    psS32 x = 0;
     144    psS32 y = 0;
     145
     146    for (w = 0; w < myPoly->nW; w++) {
     147        for (x = 0; x < myPoly->nX; x++) {
     148            for (y = 0; y < myPoly->nY; y++) {
     149                psFree(myPoly->coeff[w][x][y]);
     150                psFree(myPoly->coeffErr[w][x][y]);
     151                psFree(myPoly->mask[w][x][y]);
     152            }
     153            psFree(myPoly->coeff[w][x]);
     154            psFree(myPoly->coeffErr[w][x]);
     155            psFree(myPoly->mask[w][x]);
     156        }
     157        psFree(myPoly->coeff[w]);
     158        psFree(myPoly->coeffErr[w]);
     159        psFree(myPoly->mask[w]);
     160    }
     161
     162    psFree(myPoly->coeff);
     163    psFree(myPoly->coeffErr);
     164    psFree(myPoly->mask);
     165}
     166
     167static void dPolynomial1DFree(psDPolynomial1D* myPoly)
     168{
     169    psFree(myPoly->coeff);
     170    psFree(myPoly->coeffErr);
     171    psFree(myPoly->mask);
     172}
     173
     174static void dPolynomial2DFree(psDPolynomial2D* myPoly)
     175{
     176    psS32 x = 0;
     177
     178    for (x = 0; x < myPoly->nX; x++) {
     179        psFree(myPoly->coeff[x]);
     180        psFree(myPoly->coeffErr[x]);
     181        psFree(myPoly->mask[x]);
     182    }
     183    psFree(myPoly->coeff);
     184    psFree(myPoly->coeffErr);
     185    psFree(myPoly->mask);
     186}
     187
     188static void dPolynomial3DFree(psDPolynomial3D* myPoly)
     189{
     190    psS32 x = 0;
     191    psS32 y = 0;
     192
     193    for (x = 0; x < myPoly->nX; x++) {
     194        for (y = 0; y < myPoly->nY; y++) {
     195            psFree(myPoly->coeff[x][y]);
     196            psFree(myPoly->coeffErr[x][y]);
     197            psFree(myPoly->mask[x][y]);
     198        }
     199        psFree(myPoly->coeff[x]);
     200        psFree(myPoly->coeffErr[x]);
     201        psFree(myPoly->mask[x]);
     202    }
     203
     204    psFree(myPoly->coeff);
     205    psFree(myPoly->coeffErr);
     206    psFree(myPoly->mask);
     207}
     208
     209static void dPolynomial4DFree(psDPolynomial4D* myPoly)
     210{
     211    psS32 w = 0;
     212    psS32 x = 0;
     213    psS32 y = 0;
     214
     215    for (w = 0; w < myPoly->nW; w++) {
     216        for (x = 0; x < myPoly->nX; x++) {
     217            for (y = 0; y < myPoly->nY; y++) {
     218                psFree(myPoly->coeff[w][x][y]);
     219                psFree(myPoly->coeffErr[w][x][y]);
     220                psFree(myPoly->mask[w][x][y]);
     221            }
     222            psFree(myPoly->coeff[w][x]);
     223            psFree(myPoly->coeffErr[w][x]);
     224            psFree(myPoly->mask[w][x]);
     225        }
     226        psFree(myPoly->coeff[w]);
     227        psFree(myPoly->coeffErr[w]);
     228        psFree(myPoly->mask[w]);
     229    }
     230
     231    psFree(myPoly->coeff);
     232    psFree(myPoly->coeffErr);
     233    psFree(myPoly->mask);
     234}
     235
    69236/*****************************************************************************
    70 CreateChebyshevPolys(n): this routine takes as input the required order n,
     237createChebyshevPolys(n): this routine takes as input the required order n,
    71238and returns as output as a pointer to an array of n psPolynomial1D
    72239structures, corresponding to the first n Chebyshev polynomials.
    … …  
    76243outer coefficients of the Chebyshev polynomials.
    77244 *****************************************************************************/
    78 static psPolynomial1D **CreateChebyshevPolys(psS32 maxChebyPoly)
     245static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
    79246{
    80247    PS_INT_CHECK_NON_NEGATIVE(maxChebyPoly, NULL);
    … …  
    103270
    104271    return (chebPolys);
     272}
     273
     274/*****************************************************************************
     275    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
     276 
     277    XXX: Should the "coeffErr[]" should be used as well?
     278 *****************************************************************************/
     279static float ordPolynomial1DEval(float x, const psPolynomial1D* myPoly)
     280{
     281    psS32 loop_x = 0;
     282    float polySum = 0.0;
     283    float xSum = 1.0;
     284
     285    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
     286            "---- Calling ordPolynomial1DEval(%f)\n", x);
     287    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
     288            "Polynomial order is %d\n", myPoly->n);
     289    for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
     290        psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
     291                "Polynomial coeff[%d] is %f\n", loop_x, myPoly->coeff[loop_x]);
     292    }
     293
     294    for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
     295        if (myPoly->mask[loop_x] == 0) {
     296            psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 10,
     297                    "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, myPoly->coeff[loop_x]);
     298            polySum += xSum * myPoly->coeff[loop_x];
     299            xSum *= x;
     300        }
     301    }
     302
     303    return(polySum);
     304}
     305
     306// XXX: You can do this without having to psAlloc() vector d.
     307// XXX: How does the mask vector effect Crenshaw's formula?
     308static float chebPolynomial1DEval(float x, const psPolynomial1D* myPoly)
     309{
     310    psVector *d;
     311    psS32 n;
     312    psS32 i;
     313    float tmp;
     314
     315    n = myPoly->n;
     316    d = psVectorAlloc(n, PS_TYPE_F32);
     317    d->data.F32[n-1] = myPoly->coeff[n-1];
     318    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]) + myPoly->coeff[n-2];
     319    for (i=n-3;i>=1;i--) {
     320        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
     321                         (d->data.F32[i+2]) +
     322                         (myPoly->coeff[i]);
     323    }
     324
     325    tmp = (x * d->data.F32[1]) -
     326          (d->data.F32[2]) +
     327          (0.5 * myPoly->coeff[0]);
     328
     329    psFree(d);
     330    return(tmp);
     331    /*
     332
     333    psS32 n;
     334    psS32 i;
     335    float tmp;
     336    psPolynomial1D **chebPolys = NULL;
     337
     338    n = myPoly->n;
     339    chebPolys = createChebyshevPolys(n);
     340
     341    tmp = 0.0;
     342    for (i=0;i<myPoly->n;i++) {
     343        tmp+= (myPoly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
     344        //            printf("HMMM: psPolynomial1DEval(%f, chebPolys[%d]) is %f\n", x, i, psPolynomial1DEval(x, chebPolys[i]));
     345    }
     346    tmp-= (myPoly->coeff[0]/2.0);
     347
     348
     349    return(tmp);
     350    */
     351}
     352
     353static float ordPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
     354{
     355    PS_POLY_CHECK_NULL(myPoly, NAN);
     356
     357    psS32 loop_x = 0;
     358    psS32 loop_y = 0;
     359    float polySum = 0.0;
     360    float xSum = 1.0;
     361    float ySum = 1.0;
     362
     363    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     364        ySum = xSum;
     365        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     366            if (myPoly->mask[loop_x][loop_y] == 0) {
     367                polySum += ySum * myPoly->coeff[loop_x][loop_y];
     368                ySum *= y;
     369            }
     370        }
     371        xSum *= x;
     372    }
     373
     374    return(polySum);
     375}
     376
     377static float chebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
     378{
     379    PS_POLY_CHECK_NULL(myPoly, NAN);
     380
     381    psS32 loop_x = 0;
     382    psS32 loop_y = 0;
     383    psS32 i = 0;
     384    float polySum = 0.0;
     385    psPolynomial1D* *chebPolys = NULL;
     386    psS32 maxChebyPoly = 0;
     387
     388    // Determine how many Chebyshev polynomials
     389    // are needed, then create them.
     390    maxChebyPoly = myPoly->nX;
     391    if (myPoly->nY > maxChebyPoly) {
     392        maxChebyPoly = myPoly->nY;
     393    }
     394    chebPolys = createChebyshevPolys(maxChebyPoly);
     395
     396    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     397        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     398            if (myPoly->mask[loop_x][loop_y] == 0) {
     399                polySum += myPoly->coeff[loop_x][loop_y] *
     400                           psPolynomial1DEval(x, chebPolys[loop_x]) *
     401                           psPolynomial1DEval(y, chebPolys[loop_y]);
     402            }
     403        }
     404    }
     405    for (i=0;i<maxChebyPoly;i++) {
     406        psFree(chebPolys[i]);
     407    }
     408    psFree(chebPolys);
     409    return(polySum);
     410}
     411
     412static float ordPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)
     413{
     414    psS32 loop_x = 0;
     415    psS32 loop_y = 0;
     416    psS32 loop_z = 0;
     417    float polySum = 0.0;
     418    float xSum = 1.0;
     419    float ySum = 1.0;
     420    float zSum = 1.0;
     421
     422    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     423        ySum = xSum;
     424        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     425            zSum = ySum;
     426            for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     427                if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
     428                    polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];
     429                    zSum *= z;
     430                }
     431            }
     432            ySum *= y;
     433        }
     434        xSum *= x;
     435    }
     436
     437    return(polySum);
     438}
     439
     440static float chebPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)
     441{
     442    psS32 loop_x = 0;
     443    psS32 loop_y = 0;
     444    psS32 loop_z = 0;
     445    psS32 i = 0;
     446    float polySum = 0.0;
     447    psPolynomial1D* *chebPolys = NULL;
     448    psS32 maxChebyPoly = 0;
     449
     450    // Determine how many Chebyshev polynomials
     451    // are needed, then create them.
     452    maxChebyPoly = myPoly->nX;
     453    if (myPoly->nY > maxChebyPoly) {
     454        maxChebyPoly = myPoly->nY;
     455    }
     456    if (myPoly->nZ > maxChebyPoly) {
     457        maxChebyPoly = myPoly->nZ;
     458    }
     459    chebPolys = createChebyshevPolys(maxChebyPoly);
     460
     461    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     462        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     463            for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     464                if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
     465                    polySum += myPoly->coeff[loop_x][loop_y][loop_z] *
     466                               psPolynomial1DEval(x, chebPolys[loop_x]) *
     467                               psPolynomial1DEval(y, chebPolys[loop_y]) *
     468                               psPolynomial1DEval(z, chebPolys[loop_z]);
     469                }
     470            }
     471        }
     472    }
     473
     474    for (i=0;i<maxChebyPoly;i++) {
     475        psFree(chebPolys[i]);
     476    }
     477    psFree(chebPolys);
     478    return(polySum);
     479}
     480
     481static float ordPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)
     482{
     483    psS32 loop_w = 0;
     484    psS32 loop_x = 0;
     485    psS32 loop_y = 0;
     486    psS32 loop_z = 0;
     487    float polySum = 0.0;
     488    float wSum = 1.0;
     489    float xSum = 1.0;
     490    float ySum = 1.0;
     491    float zSum = 1.0;
     492
     493    for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
     494        xSum = wSum;
     495        for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     496            ySum = xSum;
     497            for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     498                zSum = ySum;
     499                for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     500                    if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
     501                        polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];
     502                        zSum *= z;
     503                    }
     504                }
     505                ySum *= y;
     506            }
     507            xSum *= x;
     508        }
     509        wSum *= w;
     510    }
     511
     512    return(polySum);
     513}
     514
     515static float chebPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)
     516{
     517    psS32 loop_w = 0;
     518    psS32 loop_x = 0;
     519    psS32 loop_y = 0;
     520    psS32 loop_z = 0;
     521    psS32 i = 0;
     522    float polySum = 0.0;
     523    psPolynomial1D* *chebPolys = NULL;
     524    psS32 maxChebyPoly = 0;
     525
     526    // Determine how many Chebyshev polynomials
     527    // are needed, then create them.
     528    maxChebyPoly = myPoly->nW;
     529    if (myPoly->nX > maxChebyPoly) {
     530        maxChebyPoly = myPoly->nX;
     531    }
     532    if (myPoly->nY > maxChebyPoly) {
     533        maxChebyPoly = myPoly->nY;
     534    }
     535    if (myPoly->nZ > maxChebyPoly) {
     536        maxChebyPoly = myPoly->nZ;
     537    }
     538    chebPolys = createChebyshevPolys(maxChebyPoly);
     539
     540    for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
     541        for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     542            for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     543                for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     544                    if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
     545                        polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *
     546                                   psPolynomial1DEval(w, chebPolys[loop_w]) *
     547                                   psPolynomial1DEval(x, chebPolys[loop_x]) *
     548                                   psPolynomial1DEval(y, chebPolys[loop_y]) *
     549                                   psPolynomial1DEval(z, chebPolys[loop_z]);
     550                    }
     551                }
     552            }
     553        }
     554    }
     555
     556    for (i=0;i<maxChebyPoly;i++) {
     557        psFree(chebPolys[i]);
     558    }
     559    psFree(chebPolys);
     560    return(polySum);
     561}
     562
     563/*****************************************************************************
     564    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
     565 *****************************************************************************/
     566static double dOrdPolynomial1DEval(double x, const psDPolynomial1D* myPoly)
     567{
     568    psS32 loop_x = 0;
     569    double polySum = 0.0;
     570    double xSum = 1.0;
     571
     572    for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
     573        if (myPoly->mask[loop_x] == 0) {
     574            polySum += xSum * myPoly->coeff[loop_x];
     575            xSum *= x;
     576        }
     577    }
     578
     579    return(polySum);
     580}
     581
     582// XXX: You can do this without having to psAlloc() vector d.
     583// XXX: How does the mask vector effect Crenshaw's formula?
     584static double dChebPolynomial1DEval(double x, const psDPolynomial1D* myPoly)
     585{
     586    psVector *d;
     587    psS32 n;
     588    psS32 i;
     589    double tmp;
     590
     591    n = myPoly->n;
     592    d = psVectorAlloc(n, PS_TYPE_F64);
     593    d->data.F64[n-1] = myPoly->coeff[n-1];
     594    d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]) + myPoly->coeff[n-2];
     595    for (i=n-3;i>=1;i--) {
     596        d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -
     597                         (d->data.F64[i+2]) +
     598                         (myPoly->coeff[i]);
     599    }
     600
     601    tmp = (x * d->data.F64[1]) -
     602          (d->data.F64[2]) +
     603          (0.5 * myPoly->coeff[0]);
     604
     605    psFree(d);
     606    return(tmp);
     607}
     608
     609static double dOrdPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)
     610{
     611    psS32 loop_x = 0;
     612    psS32 loop_y = 0;
     613    double polySum = 0.0;
     614    double xSum = 1.0;
     615    double ySum = 1.0;
     616
     617    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     618        ySum = xSum;
     619        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     620            if (myPoly->mask[loop_x][loop_y] == 0) {
     621                polySum += ySum * myPoly->coeff[loop_x][loop_y];
     622                ySum *= y;
     623            }
     624        }
     625        xSum *= x;
     626    }
     627
     628    return(polySum);
     629}
     630
     631static double dChebPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)
     632{
     633    psS32 loop_x = 0;
     634    psS32 loop_y = 0;
     635    psS32 i = 0;
     636    double polySum = 0.0;
     637    psPolynomial1D* *chebPolys = NULL;
     638    psS32 maxChebyPoly = 0;
     639
     640    // Determine how many Chebyshev polynomials
     641    // are needed, then create them.
     642    maxChebyPoly = myPoly->nX;
     643    if (myPoly->nY > maxChebyPoly) {
     644        maxChebyPoly = myPoly->nY;
     645    }
     646    chebPolys = createChebyshevPolys(maxChebyPoly);
     647
     648    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     649        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     650            if (myPoly->mask[loop_x][loop_y] == 0) {
     651                polySum += myPoly->coeff[loop_x][loop_y] *
     652                           psPolynomial1DEval(x, chebPolys[loop_x]) *
     653                           psPolynomial1DEval(y, chebPolys[loop_y]);
     654            }
     655        }
     656    }
     657
     658    for (i=0;i<maxChebyPoly;i++) {
     659        psFree(chebPolys[i]);
     660    }
     661    psFree(chebPolys);
     662    return(polySum);
     663}
     664
     665static double dOrdPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)
     666{
     667    psS32 loop_x = 0;
     668    psS32 loop_y = 0;
     669    psS32 loop_z = 0;
     670    double polySum = 0.0;
     671    double xSum = 1.0;
     672    double ySum = 1.0;
     673    double zSum = 1.0;
     674
     675    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     676        ySum = xSum;
     677        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     678            zSum = ySum;
     679            for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     680                if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
     681                    polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];
     682                    zSum *= z;
     683                }
     684            }
     685            ySum *= y;
     686        }
     687        xSum *= x;
     688    }
     689
     690    return(polySum);
     691}
     692
     693static double dChebPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)
     694{
     695    psS32 loop_x = 0;
     696    psS32 loop_y = 0;
     697    psS32 loop_z = 0;
     698    psS32 i = 0;
     699    double polySum = 0.0;
     700    psPolynomial1D* *chebPolys = NULL;
     701    psS32 maxChebyPoly = 0;
     702
     703    // Determine how many Chebyshev polynomials
     704    // are needed, then create them.
     705    maxChebyPoly = myPoly->nX;
     706    if (myPoly->nY > maxChebyPoly) {
     707        maxChebyPoly = myPoly->nY;
     708    }
     709    if (myPoly->nZ > maxChebyPoly) {
     710        maxChebyPoly = myPoly->nZ;
     711    }
     712    chebPolys = createChebyshevPolys(maxChebyPoly);
     713
     714    for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     715        for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     716            for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     717                if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
     718                    polySum += myPoly->coeff[loop_x][loop_y][loop_z] *
     719                               psPolynomial1DEval(x, chebPolys[loop_x]) *
     720                               psPolynomial1DEval(y, chebPolys[loop_y]) *
     721                               psPolynomial1DEval(z, chebPolys[loop_z]);
     722                }
     723            }
     724        }
     725    }
     726
     727    for (i=0;i<maxChebyPoly;i++) {
     728        psFree(chebPolys[i]);
     729    }
     730    psFree(chebPolys);
     731    return(polySum);
     732}
     733
     734static double dOrdPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)
     735{
     736    psS32 loop_w = 0;
     737    psS32 loop_x = 0;
     738    psS32 loop_y = 0;
     739    psS32 loop_z = 0;
     740    double polySum = 0.0;
     741    double wSum = 1.0;
     742    double xSum = 1.0;
     743    double ySum = 1.0;
     744    double zSum = 1.0;
     745
     746    for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
     747        xSum = wSum;
     748        for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     749            ySum = xSum;
     750            for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     751                zSum = ySum;
     752                for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     753                    if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
     754                        polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];
     755                        zSum *= z;
     756                    }
     757                }
     758                ySum *= y;
     759            }
     760            xSum *= x;
     761        }
     762        wSum *= w;
     763    }
     764
     765    return(polySum);
     766}
     767
     768static double dChebPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)
     769{
     770    psS32 loop_w = 0;
     771    psS32 loop_x = 0;
     772    psS32 loop_y = 0;
     773    psS32 loop_z = 0;
     774    psS32 i = 0;
     775    double polySum = 0.0;
     776    psPolynomial1D* *chebPolys = NULL;
     777    psS32 maxChebyPoly = 0;
     778
     779    // Determine how many Chebyshev polynomials
     780    // are needed, then create them.
     781    maxChebyPoly = myPoly->nW;
     782    if (myPoly->nX > maxChebyPoly) {
     783        maxChebyPoly = myPoly->nX;
     784    }
     785    if (myPoly->nY > maxChebyPoly) {
     786        maxChebyPoly = myPoly->nY;
     787    }
     788    if (myPoly->nZ > maxChebyPoly) {
     789        maxChebyPoly = myPoly->nZ;
     790    }
     791    chebPolys = createChebyshevPolys(maxChebyPoly);
     792
     793    for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
     794        for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
     795            for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
     796                for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
     797                    if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
     798                        polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *
     799                                   psPolynomial1DEval(w, chebPolys[loop_w]) *
     800                                   psPolynomial1DEval(x, chebPolys[loop_x]) *
     801                                   psPolynomial1DEval(y, chebPolys[loop_y]) *
     802                                   psPolynomial1DEval(z, chebPolys[loop_z]);
     803                    }
     804                }
     805            }
     806        }
     807    }
     808
     809    for (i=0;i<maxChebyPoly;i++) {
     810        psFree(chebPolys[i]);
     811    }
     812    psFree(chebPolys);
     813    return(polySum);
     814}
     815
     816
     817/*****************************************************************************
     818p_psInterpolate1D(): This routine will take as input n-element floating
     819point arrays domain and range, and the x value, assumed to lie with the
     820domain vector.  It produces as output the (n-1)-order LaGrange interpolated
     821value of x.
     822 
     823XXX: do we error check for non-distinct domain values?
     824 *****************************************************************************/
     825static float fullInterpolate1DF32(float *domain,
     826                                  float *range,
     827                                  psS32 n,
     828                                  float x)
     829{
     830    PS_INT_CHECK_NON_NEGATIVE(n, NAN);
     831    PS_PTR_CHECK_NULL(domain, NAN);
     832    PS_PTR_CHECK_NULL(range, NAN);
     833
     834    psS32 i;
     835    psS32 m;
     836    static psVector *p = NULL;
     837    p = psVectorRecycle(p, n, PS_TYPE_F32);
     838    p_psMemSetPersistent(p, true);
     839    p_psMemSetPersistent(p->data.F32, true);
     840    /*
     841        psVector *p = psVectorAlloc(n, PS_TYPE_F32);
     842        float tmp;
     843    */
     844
     845    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 4,
     846            "---- fullInterpolate1DF32() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n);
     847
     848    for (i=0;i<n;i++) {
     849        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6,
     850                "domain/range is (%f %f)\n", domain[i], range[i]);
     851    }
     852
     853    for (i=0;i<n;i++) {
     854        p->data.F32[i] = range[i];
     855        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6,
     856                "p->data.F32[%d] is %f\n", i, p->data.F32[i]);
     857
     858    }
     859
     860    // From NR, during each iteration of the m loop, we are computing the
     861    // p_{i ... i+m} terms.
     862    for (m=1;m<n;m++) {
     863        for (i=0;i<n-m;i++) {
     864            // From NR: we are computing P_{i ... i+m}
     865            p->data.F32[i] = (((x-domain[i+m]) * p->data.F32[i]) +
     866                              ((domain[i]-x) * p->data.F32[i+1])) /
     867                             (domain[i] - domain[i+m]);
     868            //printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.F32[i], domain[i], x, p->data.F32[i+1], domain[i], domain[i+m]);
     869            psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 6,
     870                    "p->data.F32[%d] is %f\n", i, p->data.F32[i]);
     871        }
     872    }
     873    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1DF32", 4,
     874            "---- fullInterpolate1DF32() end ----\n");
     875
     876    /*
     877        tmp = p->data.F32[0];
     878        psFree(p);
     879        return(tmp);
     880    */
     881    return(p->data.F32[0]);
     882}
     883
     884
     885/*****************************************************************************
     886interpolate1DF32(): this is the base 1-D flat memory routine to perform
     887LaGrange interpolation.
     888 *****************************************************************************/
     889static float interpolate1DF32(float *domain,
     890                              float *range,
     891                              psS32 n,
     892                              psS32 order,
     893                              float x)
     894{
     895    psS32 binNum;
     896    psS32 numIntPoints = order+1;
     897    psS32 origin;
     898
     899    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
     900            "---- interpolate1DF32() begin ----\n");
     901
     902    binNum = vectorBinDisectF32(domain, n, x);
     903
     904    if (0 == numIntPoints%2) {
     905        origin = binNum - ((numIntPoints/2) - 1);
     906    } else {
     907        origin = binNum - (numIntPoints/2);
     908        if ((x-domain[binNum]) > (domain[binNum+1]-x)) {
     909            // x is closer to binNum+1.
     910            origin = 1 + (binNum - (numIntPoints/2));
     911        }
     912    }
     913    if (origin < 0) {
     914        origin = 0;
     915    }
     916    if ((origin + numIntPoints) > n) {
     917        origin = n - numIntPoints;
     918    }
     919
     920    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
     921            "---- interpolate1DF32() end ----\n");
     922    return(fullInterpolate1DF32(&domain[origin], &range[origin], order+1, x));
    105923}
    106924
    … …  
    3361154}
    3371155
    338 static void polynomial1DFree(psPolynomial1D* myPoly)
    339 {
    340     psFree(myPoly->coeff);
    341     psFree(myPoly->coeffErr);
    342     psFree(myPoly->mask);
    343 }
    344 
    345 static void polynomial2DFree(psPolynomial2D* myPoly)
    346 {
    347     psS32 x = 0;
    348 
    349     for (x = 0; x < myPoly->nX; x++) {
    350         psFree(myPoly->coeff[x]);
    351         psFree(myPoly->coeffErr[x]);
    352         psFree(myPoly->mask[x]);
    353     }
    354     psFree(myPoly->coeff);
    355     psFree(myPoly->coeffErr);
    356     psFree(myPoly->mask);
    357 }
    358 
    359 static void polynomial3DFree(psPolynomial3D* myPoly)
    360 {
    361     psS32 x = 0;
    362     psS32 y = 0;
    363 
    364     for (x = 0; x < myPoly->nX; x++) {
    365         for (y = 0; y < myPoly->nY; y++) {
    366             psFree(myPoly->coeff[x][y]);
    367             psFree(myPoly->coeffErr[x][y]);
    368             psFree(myPoly->mask[x][y]);
    369         }
    370         psFree(myPoly->coeff[x]);
    371         psFree(myPoly->coeffErr[x]);
    372         psFree(myPoly->mask[x]);
    373     }
    374 
    375     psFree(myPoly->coeff);
    376     psFree(myPoly->coeffErr);
    377     psFree(myPoly->mask);
    378 }
    379 
    380 static void polynomial4DFree(psPolynomial4D* myPoly)
    381 {
    382     psS32 w = 0;
    383     psS32 x = 0;
    384     psS32 y = 0;
    385 
    386     for (w = 0; w < myPoly->nW; w++) {
    387         for (x = 0; x < myPoly->nX; x++) {
    388             for (y = 0; y < myPoly->nY; y++) {
    389                 psFree(myPoly->coeff[w][x][y]);
    390                 psFree(myPoly->coeffErr[w][x][y]);
    391                 psFree(myPoly->mask[w][x][y]);
    392             }
    393             psFree(myPoly->coeff[w][x]);
    394             psFree(myPoly->coeffErr[w][x]);
    395             psFree(myPoly->mask[w][x]);
    396         }
    397         psFree(myPoly->coeff[w]);
    398         psFree(myPoly->coeffErr[w]);
    399         psFree(myPoly->mask[w]);
    400     }
    401 
    402     psFree(myPoly->coeff);
    403     psFree(myPoly->coeffErr);
    404     psFree(myPoly->mask);
    405 }
    406 
    407 /*****************************************************************************
    408     Polynomial coefficients will be accessed in [w][x][y][z] fashion.
    409  
    410     XXX: Should the "coeffErr[]" should be used as well?
    411  *****************************************************************************/
    412 float p_psOrdPolynomial1DEval(float x, const psPolynomial1D* myPoly)
    413 {
    414     psS32 loop_x = 0;
    415     float polySum = 0.0;
    416     float xSum = 1.0;
    417 
    418     psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,
    419             "---- Calling p_psOrdPolynomial1DEval(%f)\n", x);
    420     psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,
    421             "Polynomial order is %d\n", myPoly->n);
    422     for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
    423         psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 4,
    424                 "Polynomial coeff[%d] is %f\n", loop_x, myPoly->coeff[loop_x]);
    425     }
    426 
    427     for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
    428         if (myPoly->mask[loop_x] == 0) {
    429             psTrace(".psLib.dataManip.psFunctions.p_psOrdPolynomial1DEval", 10,
    430                     "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, myPoly->coeff[loop_x]);
    431             polySum += xSum * myPoly->coeff[loop_x];
    432             xSum *= x;
    433         }
    434     }
    435 
    436     return(polySum);
    437 }
    438 
    439 // XXX: You can do this without having to psAlloc() vector d.
    440 // XXX: How does the mask vector effect Crenshaw's formula?
    441 float p_psChebPolynomial1DEval(float x, const psPolynomial1D* myPoly)
    442 {
    443     psVector *d;
    444     psS32 n;
    445     psS32 i;
    446     float tmp;
    447 
    448     n = myPoly->n;
    449     d = psVectorAlloc(n, PS_TYPE_F32);
    450     d->data.F32[n-1] = myPoly->coeff[n-1];
    451     d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]) + myPoly->coeff[n-2];
    452     for (i=n-3;i>=1;i--) {
    453         d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
    454                          (d->data.F32[i+2]) +
    455                          (myPoly->coeff[i]);
    456     }
    457 
    458     tmp = (x * d->data.F32[1]) -
    459           (d->data.F32[2]) +
    460           (0.5 * myPoly->coeff[0]);
    461 
    462     psFree(d);
    463     return(tmp);
    464     /*
    465 
    466     psS32 n;
    467     psS32 i;
    468     float tmp;
    469     psPolynomial1D **chebPolys = NULL;
    470 
    471     n = myPoly->n;
    472     chebPolys = CreateChebyshevPolys(n);
    473 
    474     tmp = 0.0;
    475     for (i=0;i<myPoly->n;i++) {
    476         tmp+= (myPoly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
    477         //            printf("HMMM: psPolynomial1DEval(%f, chebPolys[%d]) is %f\n", x, i, psPolynomial1DEval(x, chebPolys[i]));
    478     }
    479     tmp-= (myPoly->coeff[0]/2.0);
    480 
    481 
    482     return(tmp);
    483     */
    484 }
    485 
    4861156float psPolynomial1DEval(float x, const psPolynomial1D* myPoly)
    4871157{
    … …  
    4891159
    4901160    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    491         return(p_psOrdPolynomial1DEval(x, myPoly));
     1161        return(ordPolynomial1DEval(x, myPoly));
    4921162    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    493         return(p_psChebPolynomial1DEval(x, myPoly));
     1163        return(chebPolynomial1DEval(x, myPoly));
    4941164    } else {
    495         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1165        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1166                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1167                myPoly->type);
    4961168    }
    4971169    return(0.0);
    … …  
    5201192}
    5211193
    522 
    523 float p_psOrdPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
     1194float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
    5241195{
    5251196    PS_POLY_CHECK_NULL(myPoly, NAN);
    5261197
    527     psS32 loop_x = 0;
    528     psS32 loop_y = 0;
    529     float polySum = 0.0;
    530     float xSum = 1.0;
    531     float ySum = 1.0;
    532 
    533     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    534         ySum = xSum;
    535         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    536             if (myPoly->mask[loop_x][loop_y] == 0) {
    537                 polySum += ySum * myPoly->coeff[loop_x][loop_y];
    538                 ySum *= y;
    539             }
    540         }
    541         xSum *= x;
    542     }
    543 
    544     return(polySum);
    545 }
    546 
    547 float p_psChebPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
    548 {
    549     PS_POLY_CHECK_NULL(myPoly, NAN);
    550 
    551     psS32 loop_x = 0;
    552     psS32 loop_y = 0;
    553     psS32 i = 0;
    554     float polySum = 0.0;
    555     psPolynomial1D* *chebPolys = NULL;
    556     psS32 maxChebyPoly = 0;
    557 
    558     // Determine how many Chebyshev polynomials
    559     // are needed, then create them.
    560     maxChebyPoly = myPoly->nX;
    561     if (myPoly->nY > maxChebyPoly) {
    562         maxChebyPoly = myPoly->nY;
    563     }
    564     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    565 
    566     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    567         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    568             if (myPoly->mask[loop_x][loop_y] == 0) {
    569                 polySum += myPoly->coeff[loop_x][loop_y] *
    570                            psPolynomial1DEval(x, chebPolys[loop_x]) *
    571                            psPolynomial1DEval(y, chebPolys[loop_y]);
    572             }
    573         }
    574     }
    575     for (i=0;i<maxChebyPoly;i++) {
    576         psFree(chebPolys[i]);
    577     }
    578     psFree(chebPolys);
    579     return(polySum);
    580 }
    581 
    582 float psPolynomial2DEval(float x, float y, const psPolynomial2D* myPoly)
    583 {
    584     PS_POLY_CHECK_NULL(myPoly, NAN);
    585 
    5861198    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    587         return(p_psOrdPolynomial2DEval(x, y, myPoly));
     1199        return(ordPolynomial2DEval(x, y, myPoly));
    5881200    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    589         return(p_psChebPolynomial2DEval(x, y, myPoly));
     1201        return(chebPolynomial2DEval(x, y, myPoly));
    5901202    } else {
    591         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1203        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1204                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1205                myPoly->type);
    5921206    }
    5931207    return(0.0);
    5941208}
    595 
    5961209
    5971210psVector *psPolynomial2DEvalVector(const psVector *x,
    … …  
    6321245}
    6331246
    634 
    635 
    636 float p_psOrdPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)
    637 {
    638     psS32 loop_x = 0;
    639     psS32 loop_y = 0;
    640     psS32 loop_z = 0;
    641     float polySum = 0.0;
    642     float xSum = 1.0;
    643     float ySum = 1.0;
    644     float zSum = 1.0;
    645 
    646     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    647         ySum = xSum;
    648         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    649             zSum = ySum;
    650             for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    651                 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
    652                     polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];
    653                     zSum *= z;
    654                 }
    655             }
    656             ySum *= y;
    657         }
    658         xSum *= x;
    659     }
    660 
    661     return(polySum);
    662 }
    663 
    664 float p_psChebPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)
    665 {
    666     psS32 loop_x = 0;
    667     psS32 loop_y = 0;
    668     psS32 loop_z = 0;
    669     psS32 i = 0;
    670     float polySum = 0.0;
    671     psPolynomial1D* *chebPolys = NULL;
    672     psS32 maxChebyPoly = 0;
    673 
    674     // Determine how many Chebyshev polynomials
    675     // are needed, then create them.
    676     maxChebyPoly = myPoly->nX;
    677     if (myPoly->nY > maxChebyPoly) {
    678         maxChebyPoly = myPoly->nY;
    679     }
    680     if (myPoly->nZ > maxChebyPoly) {
    681         maxChebyPoly = myPoly->nZ;
    682     }
    683     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    684 
    685     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    686         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    687             for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    688                 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
    689                     polySum += myPoly->coeff[loop_x][loop_y][loop_z] *
    690                                psPolynomial1DEval(x, chebPolys[loop_x]) *
    691                                psPolynomial1DEval(y, chebPolys[loop_y]) *
    692                                psPolynomial1DEval(z, chebPolys[loop_z]);
    693                 }
    694             }
    695         }
    696     }
    697 
    698     for (i=0;i<maxChebyPoly;i++) {
    699         psFree(chebPolys[i]);
    700     }
    701     psFree(chebPolys);
    702     return(polySum);
    703 }
    704 
    7051247float psPolynomial3DEval(float x, float y, float z, const psPolynomial3D* myPoly)
    7061248{
    … …  
    7081250
    7091251    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    710         return(p_psOrdPolynomial3DEval(x, y, z, myPoly));
     1252        return(ordPolynomial3DEval(x, y, z, myPoly));
    7111253    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    712         return(p_psChebPolynomial3DEval(x, y, z, myPoly));
     1254        return(chebPolynomial3DEval(x, y, z, myPoly));
    7131255    } else {
    714         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1256        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1257                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1258                myPoly->type);
    7151259    }
    7161260    return(0.0);
    … …  
    7651309}
    7661310
    767 
    768 
    769 
    770 
    771 
    772 float p_psOrdPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)
    773 {
    774     psS32 loop_w = 0;
    775     psS32 loop_x = 0;
    776     psS32 loop_y = 0;
    777     psS32 loop_z = 0;
    778     float polySum = 0.0;
    779     float wSum = 1.0;
    780     float xSum = 1.0;
    781     float ySum = 1.0;
    782     float zSum = 1.0;
    783 
    784     for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
    785         xSum = wSum;
    786         for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    787             ySum = xSum;
    788             for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    789                 zSum = ySum;
    790                 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    791                     if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
    792                         polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];
    793                         zSum *= z;
    794                     }
    795                 }
    796                 ySum *= y;
    797             }
    798             xSum *= x;
    799         }
    800         wSum *= w;
    801     }
    802 
    803     return(polySum);
    804 }
    805 
    806 float p_psChebPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)
    807 {
    808     psS32 loop_w = 0;
    809     psS32 loop_x = 0;
    810     psS32 loop_y = 0;
    811     psS32 loop_z = 0;
    812     psS32 i = 0;
    813     float polySum = 0.0;
    814     psPolynomial1D* *chebPolys = NULL;
    815     psS32 maxChebyPoly = 0;
    816 
    817     // Determine how many Chebyshev polynomials
    818     // are needed, then create them.
    819     maxChebyPoly = myPoly->nW;
    820     if (myPoly->nX > maxChebyPoly) {
    821         maxChebyPoly = myPoly->nX;
    822     }
    823     if (myPoly->nY > maxChebyPoly) {
    824         maxChebyPoly = myPoly->nY;
    825     }
    826     if (myPoly->nZ > maxChebyPoly) {
    827         maxChebyPoly = myPoly->nZ;
    828     }
    829     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    830 
    831     for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
    832         for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    833             for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    834                 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    835                     if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
    836                         polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *
    837                                    psPolynomial1DEval(w, chebPolys[loop_w]) *
    838                                    psPolynomial1DEval(x, chebPolys[loop_x]) *
    839                                    psPolynomial1DEval(y, chebPolys[loop_y]) *
    840                                    psPolynomial1DEval(z, chebPolys[loop_z]);
    841                     }
    842                 }
    843             }
    844         }
    845     }
    846 
    847     for (i=0;i<maxChebyPoly;i++) {
    848         psFree(chebPolys[i]);
    849     }
    850     psFree(chebPolys);
    851     return(polySum);
    852 }
    853 
    8541311float psPolynomial4DEval(float w, float x, float y, float z, const psPolynomial4D* myPoly)
    8551312{
    … …  
    8571314
    8581315    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    859         return(p_psOrdPolynomial4DEval(w,x,y,z, myPoly));
     1316        return(ordPolynomial4DEval(w,x,y,z, myPoly));
    8601317    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    861         return(p_psChebPolynomial4DEval(w,x,y,z, myPoly));
     1318        return(chebPolynomial4DEval(w,x,y,z, myPoly));
    8621319    } else {
    863         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1320        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1321                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1322                myPoly->type);
    8641323    }
    8651324    return(0.0);
    … …  
    9241383    return(tmp);
    9251384}
    926 
    927 
    928 
    9291385
    9301386
    … …  
    10921548}
    10931549
    1094 static void dPolynomial1DFree(psDPolynomial1D* myPoly)
    1095 {
    1096     psFree(myPoly->coeff);
    1097     psFree(myPoly->coeffErr);
    1098     psFree(myPoly->mask);
    1099 }
    1100 
    1101 static void dPolynomial2DFree(psDPolynomial2D* myPoly)
    1102 {
    1103     psS32 x = 0;
    1104 
    1105     for (x = 0; x < myPoly->nX; x++) {
    1106         psFree(myPoly->coeff[x]);
    1107         psFree(myPoly->coeffErr[x]);
    1108         psFree(myPoly->mask[x]);
    1109     }
    1110     psFree(myPoly->coeff);
    1111     psFree(myPoly->coeffErr);
    1112     psFree(myPoly->mask);
    1113 }
    1114 
    1115 static void dPolynomial3DFree(psDPolynomial3D* myPoly)
    1116 {
    1117     psS32 x = 0;
    1118     psS32 y = 0;
    1119 
    1120     for (x = 0; x < myPoly->nX; x++) {
    1121         for (y = 0; y < myPoly->nY; y++) {
    1122             psFree(myPoly->coeff[x][y]);
    1123             psFree(myPoly->coeffErr[x][y]);
    1124             psFree(myPoly->mask[x][y]);
    1125         }
    1126         psFree(myPoly->coeff[x]);
    1127         psFree(myPoly->coeffErr[x]);
    1128         psFree(myPoly->mask[x]);
    1129     }
    1130 
    1131     psFree(myPoly->coeff);
    1132     psFree(myPoly->coeffErr);
    1133     psFree(myPoly->mask);
    1134 }
    1135 
    1136 static void dPolynomial4DFree(psDPolynomial4D* myPoly)
    1137 {
    1138     psS32 w = 0;
    1139     psS32 x = 0;
    1140     psS32 y = 0;
    1141 
    1142     for (w = 0; w < myPoly->nW; w++) {
    1143         for (x = 0; x < myPoly->nX; x++) {
    1144             for (y = 0; y < myPoly->nY; y++) {
    1145                 psFree(myPoly->coeff[w][x][y]);
    1146                 psFree(myPoly->coeffErr[w][x][y]);
    1147                 psFree(myPoly->mask[w][x][y]);
    1148             }
    1149             psFree(myPoly->coeff[w][x]);
    1150             psFree(myPoly->coeffErr[w][x]);
    1151             psFree(myPoly->mask[w][x]);
    1152         }
    1153         psFree(myPoly->coeff[w]);
    1154         psFree(myPoly->coeffErr[w]);
    1155         psFree(myPoly->mask[w]);
    1156     }
    1157 
    1158     psFree(myPoly->coeff);
    1159     psFree(myPoly->coeffErr);
    1160     psFree(myPoly->mask);
    1161 }
    1162 
    1163 /*****************************************************************************
    1164     Polynomial coefficients will be accessed in [w][x][y][z] fashion.
    1165  *****************************************************************************/
    1166 double p_psDOrdPolynomial1DEval(double x, const psDPolynomial1D* myPoly)
    1167 {
    1168     psS32 loop_x = 0;
    1169     double polySum = 0.0;
    1170     double xSum = 1.0;
    1171 
    1172     for (loop_x = 0; loop_x < myPoly->n; loop_x++) {
    1173         if (myPoly->mask[loop_x] == 0) {
    1174             polySum += xSum * myPoly->coeff[loop_x];
    1175             xSum *= x;
    1176         }
    1177     }
    1178 
    1179     return(polySum);
    1180 }
    1181 
    1182 // XXX: You can do this without having to psAlloc() vector d.
    1183 // XXX: How does the mask vector effect Crenshaw's formula?
    1184 double p_psDChebPolynomial1DEval(double x, const psDPolynomial1D* myPoly)
    1185 {
    1186     psVector *d;
    1187     psS32 n;
    1188     psS32 i;
    1189     double tmp;
    1190 
    1191     n = myPoly->n;
    1192     d = psVectorAlloc(n, PS_TYPE_F64);
    1193     d->data.F64[n-1] = myPoly->coeff[n-1];
    1194     d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]) + myPoly->coeff[n-2];
    1195     for (i=n-3;i>=1;i--) {
    1196         d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -
    1197                          (d->data.F64[i+2]) +
    1198                          (myPoly->coeff[i]);
    1199     }
    1200 
    1201     tmp = (x * d->data.F64[1]) -
    1202           (d->data.F64[2]) +
    1203           (0.5 * myPoly->coeff[0]);
    1204 
    1205     psFree(d);
    1206     return(tmp);
    1207 }
    12081550
    12091551double psDPolynomial1DEval(double x, const psDPolynomial1D* myPoly)
    … …  
    12121554
    12131555    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    1214         return(p_psDOrdPolynomial1DEval(x, myPoly));
     1556        return(dOrdPolynomial1DEval(x, myPoly));
    12151557    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    1216         return(p_psDChebPolynomial1DEval(x, myPoly));
     1558        return(dChebPolynomial1DEval(x, myPoly));
    12171559    } else {
    1218         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1560        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1561                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1562                myPoly->type);
    12191563    }
    12201564    return(0.0);
    … …  
    12441588
    12451589
    1246 
    1247 double p_psDOrdPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)
    1248 {
    1249     psS32 loop_x = 0;
    1250     psS32 loop_y = 0;
    1251     double polySum = 0.0;
    1252     double xSum = 1.0;
    1253     double ySum = 1.0;
    1254 
    1255     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1256         ySum = xSum;
    1257         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1258             if (myPoly->mask[loop_x][loop_y] == 0) {
    1259                 polySum += ySum * myPoly->coeff[loop_x][loop_y];
    1260                 ySum *= y;
    1261             }
    1262         }
    1263         xSum *= x;
    1264     }
    1265 
    1266     return(polySum);
    1267 }
    1268 
    1269 double p_psDChebPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)
    1270 {
    1271     psS32 loop_x = 0;
    1272     psS32 loop_y = 0;
    1273     psS32 i = 0;
    1274     double polySum = 0.0;
    1275     psPolynomial1D* *chebPolys = NULL;
    1276     psS32 maxChebyPoly = 0;
    1277 
    1278     // Determine how many Chebyshev polynomials
    1279     // are needed, then create them.
    1280     maxChebyPoly = myPoly->nX;
    1281     if (myPoly->nY > maxChebyPoly) {
    1282         maxChebyPoly = myPoly->nY;
    1283     }
    1284     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    1285 
    1286     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1287         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1288             if (myPoly->mask[loop_x][loop_y] == 0) {
    1289                 polySum += myPoly->coeff[loop_x][loop_y] *
    1290                            psPolynomial1DEval(x, chebPolys[loop_x]) *
    1291                            psPolynomial1DEval(y, chebPolys[loop_y]);
    1292             }
    1293         }
    1294     }
    1295 
    1296     for (i=0;i<maxChebyPoly;i++) {
    1297         psFree(chebPolys[i]);
    1298     }
    1299     psFree(chebPolys);
    1300     return(polySum);
    1301 }
    1302 
    13031590double psDPolynomial2DEval(double x, double y, const psDPolynomial2D* myPoly)
    13041591{
    … …  
    13061593
    13071594    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    1308         return(p_psDOrdPolynomial2DEval(x, y, myPoly));
     1595        return(dOrdPolynomial2DEval(x, y, myPoly));
    13091596    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    1310         return(p_psDChebPolynomial2DEval(x, y, myPoly));
     1597        return(dChebPolynomial2DEval(x, y, myPoly));
    13111598    } else {
    1312         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1599        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1600                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1601                myPoly->type);
    13131602    }
    13141603    return(0.0);
    … …  
    13531642
    13541643
    1355 
    1356 double p_psDOrdPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)
    1357 {
    1358     psS32 loop_x = 0;
    1359     psS32 loop_y = 0;
    1360     psS32 loop_z = 0;
    1361     double polySum = 0.0;
    1362     double xSum = 1.0;
    1363     double ySum = 1.0;
    1364     double zSum = 1.0;
    1365 
    1366     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1367         ySum = xSum;
    1368         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1369             zSum = ySum;
    1370             for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    1371                 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
    1372                     polySum += zSum * myPoly->coeff[loop_x][loop_y][loop_z];
    1373                     zSum *= z;
    1374                 }
    1375             }
    1376             ySum *= y;
    1377         }
    1378         xSum *= x;
    1379     }
    1380 
    1381     return(polySum);
    1382 }
    1383 
    1384 double p_psDChebPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)
    1385 {
    1386     psS32 loop_x = 0;
    1387     psS32 loop_y = 0;
    1388     psS32 loop_z = 0;
    1389     psS32 i = 0;
    1390     double polySum = 0.0;
    1391     psPolynomial1D* *chebPolys = NULL;
    1392     psS32 maxChebyPoly = 0;
    1393 
    1394     // Determine how many Chebyshev polynomials
    1395     // are needed, then create them.
    1396     maxChebyPoly = myPoly->nX;
    1397     if (myPoly->nY > maxChebyPoly) {
    1398         maxChebyPoly = myPoly->nY;
    1399     }
    1400     if (myPoly->nZ > maxChebyPoly) {
    1401         maxChebyPoly = myPoly->nZ;
    1402     }
    1403     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    1404 
    1405     for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1406         for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1407             for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    1408                 if (myPoly->mask[loop_x][loop_y][loop_z] == 0) {
    1409                     polySum += myPoly->coeff[loop_x][loop_y][loop_z] *
    1410                                psPolynomial1DEval(x, chebPolys[loop_x]) *
    1411                                psPolynomial1DEval(y, chebPolys[loop_y]) *
    1412                                psPolynomial1DEval(z, chebPolys[loop_z]);
    1413                 }
    1414             }
    1415         }
    1416     }
    1417 
    1418     for (i=0;i<maxChebyPoly;i++) {
    1419         psFree(chebPolys[i]);
    1420     }
    1421     psFree(chebPolys);
    1422     return(polySum);
    1423 }
    1424 
    14251644double psDPolynomial3DEval(double x, double y, double z, const psDPolynomial3D* myPoly)
    14261645{
    … …  
    14281647
    14291648    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    1430         return(p_psDOrdPolynomial3DEval(x, y, z, myPoly));
     1649        return(dOrdPolynomial3DEval(x, y, z, myPoly));
    14311650    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    1432         return(p_psDChebPolynomial3DEval(x, y, z, myPoly));
     1651        return(dChebPolynomial3DEval(x, y, z, myPoly));
    14331652    } else {
    1434         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1653        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1654                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1655                myPoly->type);
    14351656    }
    14361657    return(0.0);
    … …  
    14851706}
    14861707
    1487 
    1488 
    1489 
    1490 
    1491 
    1492 
    1493 
    1494 double p_psDOrdPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)
    1495 {
    1496     psS32 loop_w = 0;
    1497     psS32 loop_x = 0;
    1498     psS32 loop_y = 0;
    1499     psS32 loop_z = 0;
    1500     double polySum = 0.0;
    1501     double wSum = 1.0;
    1502     double xSum = 1.0;
    1503     double ySum = 1.0;
    1504     double zSum = 1.0;
    1505 
    1506     for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
    1507         xSum = wSum;
    1508         for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1509             ySum = xSum;
    1510             for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1511                 zSum = ySum;
    1512                 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    1513                     if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
    1514                         polySum += zSum * myPoly->coeff[loop_w][loop_x][loop_y][loop_z];
    1515                         zSum *= z;
    1516                     }
    1517                 }
    1518                 ySum *= y;
    1519             }
    1520             xSum *= x;
    1521         }
    1522         wSum *= w;
    1523     }
    1524 
    1525     return(polySum);
    1526 }
    1527 
    1528 double p_psDChebPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)
    1529 {
    1530     psS32 loop_w = 0;
    1531     psS32 loop_x = 0;
    1532     psS32 loop_y = 0;
    1533     psS32 loop_z = 0;
    1534     psS32 i = 0;
    1535     double polySum = 0.0;
    1536     psPolynomial1D* *chebPolys = NULL;
    1537     psS32 maxChebyPoly = 0;
    1538 
    1539     // Determine how many Chebyshev polynomials
    1540     // are needed, then create them.
    1541     maxChebyPoly = myPoly->nW;
    1542     if (myPoly->nX > maxChebyPoly) {
    1543         maxChebyPoly = myPoly->nX;
    1544     }
    1545     if (myPoly->nY > maxChebyPoly) {
    1546         maxChebyPoly = myPoly->nY;
    1547     }
    1548     if (myPoly->nZ > maxChebyPoly) {
    1549         maxChebyPoly = myPoly->nZ;
    1550     }
    1551     chebPolys = CreateChebyshevPolys(maxChebyPoly);
    1552 
    1553     for (loop_w = 0; loop_w < myPoly->nW; loop_w++) {
    1554         for (loop_x = 0; loop_x < myPoly->nX; loop_x++) {
    1555             for (loop_y = 0; loop_y < myPoly->nY; loop_y++) {
    1556                 for (loop_z = 0; loop_z < myPoly->nZ; loop_z++) {
    1557                     if (myPoly->mask[loop_w][loop_x][loop_y][loop_z] == 0) {
    1558                         polySum += myPoly->coeff[loop_w][loop_x][loop_y][loop_z] *
    1559                                    psPolynomial1DEval(w, chebPolys[loop_w]) *
    1560                                    psPolynomial1DEval(x, chebPolys[loop_x]) *
    1561                                    psPolynomial1DEval(y, chebPolys[loop_y]) *
    1562                                    psPolynomial1DEval(z, chebPolys[loop_z]);
    1563                     }
    1564                 }
    1565             }
    1566         }
    1567     }
    1568 
    1569     for (i=0;i<maxChebyPoly;i++) {
    1570         psFree(chebPolys[i]);
    1571     }
    1572     psFree(chebPolys);
    1573     return(polySum);
    1574 }
    1575 
    15761708double psDPolynomial4DEval(double w, double x, double y, double z, const psDPolynomial4D* myPoly)
    15771709{
    … …  
    15791711
    15801712    if (myPoly->type == PS_POLYNOMIAL_ORD) {
    1581         return(p_psDOrdPolynomial4DEval(w,x,y,z, myPoly));
     1713        return(dOrdPolynomial4DEval(w,x,y,z, myPoly));
    15821714    } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    1583         return(p_psDChebPolynomial4DEval(w,x,y,z, myPoly));
     1715        return(dChebPolynomial4DEval(w,x,y,z, myPoly));
    15841716    } else {
    1585         psError(__func__, "Unknown polynomial type 0x%x\n", myPoly->type);
     1717        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1718                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
     1719                myPoly->type);
    15861720    }
    15871721    return(0.0);
    … …  
    16991833    (tmp->domains)[numSplines] = max;
    17001834
     1835    p_psMemSetDeallocator(tmp,(psFreeFcn)spline1DFree);
    17011836    return(tmp);
    17021837}
    17031838
    1704 // XXX: Have Robert put the dealocator in the memory file.
    1705 psS32 p_psSpline1DFree(psSpline1D *tmpSpline)
    1706 {
    1707     psS32 i;
    1708 
    1709     if (tmpSpline == NULL) {
    1710         return(0);
    1711     }
    1712 
    1713     if (tmpSpline->spline != NULL) {
    1714         for (i=0;i<tmpSpline->n;i++) {
    1715             psFree((tmpSpline->spline)[i]);
    1716         }
    1717         psFree(tmpSpline->spline);
    1718     }
    1719 
    1720     if (tmpSpline->p_psDeriv2 != NULL) {
    1721         psFree(tmpSpline->p_psDeriv2);
    1722     }
    1723     psFree(tmpSpline->domains);
    1724     psFree(tmpSpline);
    1725 
    1726     return(0);
    1727 }
    17281839
    17291840/*****************************************************************************
    … …  
    17651876
    17661877/*****************************************************************************
    1767 p_psVectorBinDisectF32(): This is a private function which takes as input a
     1878vectorBinDisectF32(): This is a private function which takes as input a
    17681879vector of floating point data as well as a single floating point values.
    17691880The input vector values are assumed to be non-decreasing (v[i-1] <= v[j] for
    … …  
    17761887XXX: name since we don't take psVectors as input.
    17771888 *****************************************************************************/
    1778 psS32 p_psVectorBinDisectF32(float *bins,
    1779                              psS32 numBins,
    1780                              float x)
     1889static psS32 vectorBinDisectF32(float *bins,
     1890                                psS32 numBins,
     1891                                float x)
    17811892{
    17821893    psS32 min;
    … …  
    17841895    psS32 mid;
    17851896
    1786     psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectF32", 4,
    1787             "---- Calling p_psVectorBinDisectF32(%f)\n", x);
     1897    psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
     1898            "---- Calling vectorBinDisectF32(%f)\n", x);
    17881899
    17891900    if (x < bins[0]) {
    17901901        psLogMsg(__func__, PS_LOG_WARN,
    1791                  "p_psVectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
     1902                 "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
    17921903                 x, bins[0], bins[numBins-1]);
    17931904        return(-2);
    … …  
    17961907    if (x > bins[numBins-1]) {
    17971908        psLogMsg(__func__, PS_LOG_WARN,
    1798                  "p_psVectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
     1909                 "vectorBinDisectF32(): ordinate %f is outside vector range (%f - %f).",
    17991910                 x, bins[0], bins[numBins-1]);
    18001911        return(-1);
    … …  
    18061917
    18071918    while (min != max) {
    1808         psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectF32", 4,
     1919        psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
    18091920                "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n",
    18101921                min, mid, max, x, bins[mid]);
    18111922
    18121923        if (x == bins[mid]) {
    1813             psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectF32", 4,
    1814                     "---- Exiting p_psVectorBinDisectF32(): bin %d\n", mid);
     1924            psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
     1925                    "---- Exiting vectorBinDisectF32(): bin %d\n", mid);
    18151926            return(mid);
    18161927        } else if (x < bins[mid]) {
    … …  
    18221933    }
    18231934
    1824     psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectF32", 4,
    1825             "---- Exiting p_psVectorBinDisectF32(): bin %d\n", min);
     1935    psTrace(".psLib.dataManip.psFunctions.vectorBinDisectF32", 4,
     1936            "---- Exiting vectorBinDisectF32(): bin %d\n", min);
    18261937    return(min);
    18271938}
    18281939
    18291940/*****************************************************************************
    1830 p_psVectorBinDisectS32(): integer version of above.
     1941vectorBinDisectS32(): integer version of above.
    18311942 *****************************************************************************/
    1832 psS32 p_psVectorBinDisectS32(psS32 *bins,
    1833                              psS32 numBins,
    1834                              psS32 x)
     1943static psS32 vectorBinDisectS32(psS32 *bins,
     1944                                psS32 numBins,
     1945                                psS32 x)
    18351946{
    18361947    psS32 min;
    … …  
    18381949    psS32 mid;
    18391950
    1840     psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectS32", 4,
    1841             "---- Calling p_psVectorBinDisectS32(%f)\n", x);
     1951    psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
     1952            "---- Calling vectorBinDisectS32(%f)\n", x);
    18421953
    18431954    if ((x < bins[0]) ||
    18441955            (x > bins[numBins-1])) {
    18451956        psLogMsg(__func__, PS_LOG_WARN,
    1846                  "p_psVectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).",
     1957                 "vectorBinDisectS32(): ordinate %f is outside vector range (%f - %f).",
    18471958                 x, bins[0], bins[numBins-1]);
    18481959        return(-1);
    … …  
    18541965
    18551966    while (min != max) {
    1856         psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectS32", 4,
     1967        psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
    18571968                "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n",
    18581969                min, mid, max, x, bins[mid]);
    18591970
    18601971        if (x == bins[mid]) {
    1861             psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectS32", 4,
    1862                     "---- Exiting p_psVectorBinDisectS32(): bin %d\n", min);
     1972            psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
     1973                    "---- Exiting vectorBinDisectS32(): bin %d\n", min);
    18631974            return(min);
    18641975        } else if (x < bins[mid]) {
    … …  
    18701981    }
    18711982
    1872     psTrace(".psLib.dataManip.psFunctions.p_psVectorBinDisectS32", 4,
    1873             "---- Exiting p_psVectorBinDisectS32(): bin %d\n", min);
     1983    psTrace(".psLib.dataManip.psFunctions.vectorBinDisectS32", 4,
     1984            "---- Exiting vectorBinDisectS32(): bin %d\n", min);
    18741985    return(min);
    18751986}
    … …  
    18841995
    18851996    if (x->type.type == PS_TYPE_S32) {
    1886         return(p_psVectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
     1997        return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
    18871998    } else if (x->type.type == PS_TYPE_F32) {
    1888         return(p_psVectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
     1999        return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
    18892000    } else {
    1890         psError(__func__, "Unallowable data type.");
     2001        char* strType;
     2002        PS_TYPE_NAME(strType,x->type.type);
     2003        psError(PS_ERR_BAD_PARAMETER_TYPE,
     2004                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
     2005                strType);
    18912006        return(-2);
    18922007    }
    18932008    return(-1);
    1894 }
    1895 
    1896 /*****************************************************************************
    1897 p_psInterpolate1D(): This routine will take as input n-element floating
    1898 point arrays domain and range, and the x value, assumed to lie with the
    1899 domain vector.  It produces as output the (n-1)-order LaGrange interpolated
    1900 value of x.
    1901  
    1902 XXX: do we error check for non-distinct domain values?
    1903  *****************************************************************************/
    1904 float p_ps1DFullInterpolateF32(float *domain,
    1905                                float *range,
    1906                                psS32 n,
    1907                                float x)
    1908 {
    1909     PS_INT_CHECK_NON_NEGATIVE(n, NAN);
    1910     PS_PTR_CHECK_NULL(domain, NAN);
    1911     PS_PTR_CHECK_NULL(range, NAN);
    1912 
    1913     psS32 i;
    1914     psS32 m;
    1915     static psVector *p = NULL;
    1916     p = psVectorRecycle(p, n, PS_TYPE_F32);
    1917     p_psMemSetPersistent(p, true);
    1918     p_psMemSetPersistent(p->data.F32, true);
    1919     /*
    1920         psVector *p = psVectorAlloc(n, PS_TYPE_F32);
    1921         float tmp;
    1922     */
    1923 
    1924     psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 4,
    1925             "---- p_ps1DFullInterpolateF32() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n);
    1926 
    1927     for (i=0;i<n;i++) {
    1928         psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,
    1929                 "domain/range is (%f %f)\n", domain[i], range[i]);
    1930     }
    1931 
    1932     for (i=0;i<n;i++) {
    1933         p->data.F32[i] = range[i];
    1934         psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,
    1935                 "p->data.F32[%d] is %f\n", i, p->data.F32[i]);
    1936 
    1937     }
    1938 
    1939     // From NR, during each iteration of the m loop, we are computing the
    1940     // p_{i ... i+m} terms.
    1941     for (m=1;m<n;m++) {
    1942         for (i=0;i<n-m;i++) {
    1943             // From NR: we are computing P_{i ... i+m}
    1944             p->data.F32[i] = (((x-domain[i+m]) * p->data.F32[i]) +
    1945                               ((domain[i]-x) * p->data.F32[i+1])) /
    1946                              (domain[i] - domain[i+m]);
    1947             //printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.F32[i], domain[i], x, p->data.F32[i+1], domain[i], domain[i+m]);
    1948             psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 6,
    1949                     "p->data.F32[%d] is %f\n", i, p->data.F32[i]);
    1950         }
    1951     }
    1952     psTrace(".psLib.dataManip.psFunctions.p_ps1DFullInterpolateF32", 4,
    1953             "---- p_ps1DFullInterpolateF32() end ----\n");
    1954 
    1955     /*
    1956         tmp = p->data.F32[0];
    1957         psFree(p);
    1958         return(tmp);
    1959     */
    1960     return(p->data.F32[0]);
    1961 }
    1962 
    1963 
    1964 /*****************************************************************************
    1965 p_ps1DInterpolateF32(): this is the base 1-D flat memory routine to perform
    1966 LaGrange interpolation.
    1967  *****************************************************************************/
    1968 float p_ps1DInterpolateF32(float *domain,
    1969                            float *range,
    1970                            psS32 n,
    1971                            psS32 order,
    1972                            float x)
    1973 {
    1974     psS32 binNum;
    1975     psS32 numIntPoints = order+1;
    1976     psS32 origin;
    1977 
    1978     psTrace(".psLib.dataManip.psFunctions.p_ps1DInterpolateF32", 4,
    1979             "---- p_ps1DInterpolateF32() begin ----\n");
    1980 
    1981     binNum = p_psVectorBinDisectF32(domain, n, x);
    1982 
    1983     if (0 == numIntPoints%2) {
    1984         origin = binNum - ((numIntPoints/2) - 1);
    1985     } else {
    1986         origin = binNum - (numIntPoints/2);
    1987         if ((x-domain[binNum]) > (domain[binNum+1]-x)) {
    1988             // x is closer to binNum+1.
    1989             origin = 1 + (binNum - (numIntPoints/2));
    1990         }
    1991     }
    1992     if (origin < 0) {
    1993         origin = 0;
    1994     }
    1995     if ((origin + numIntPoints) > n) {
    1996         origin = n - numIntPoints;
    1997     }
    1998 
    1999     psTrace(".psLib.dataManip.psFunctions.p_ps1DInterpolateF32", 4,
    2000             "---- p_ps1DInterpolateF32() end ----\n");
    2001     return(p_ps1DFullInterpolateF32(&domain[origin], &range[origin], order+1, x));
    20022009}
    20032010
    … …  
    20352042
    20362043    if (order > (domain->n - 1)) {
    2037         psError(__func__, "not enough data points for %d-order interpolation.\n", order);
     2044        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     2045                PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS,
     2046                order);
    20382047        return(NULL);
    20392048    }
    … …  
    20422051        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
    20432052                "---- p_psVectorInterpolate() end ----\n");
    2044         return(psScalarAlloc(p_ps1DInterpolateF32(domain->data.F32,
    2045                              range->data.F32,
    2046                              domain->n,
    2047                              order,
    2048                              x->data.F32), PS_TYPE_F32));
     2053        return(psScalarAlloc(interpolate1DF32(domain->data.F32,
     2054                                              range->data.F32,
     2055                                              domain->n,
     2056                                              order,
     2057                                              x->data.F32), PS_TYPE_F32));
    20492058    } else if (x->type.type == PS_TYPE_F64) {
    20502059        // XXX: use recycled vectors here.
    … …  
    20532062
    20542063        psScalar *tmpScalar = psScalarAlloc((double)
    2055                                             p_ps1DInterpolateF32(domain32->data.F32,
    2056                                                                  range32->data.F32,
    2057                                                                  domain32->n,
    2058                                                                  order,
    2059                                                                  (float) x->data.F64), PS_TYPE_F64);
     2064                                            interpolate1DF32(domain32->data.F32,
     2065                                                             range32->data.F32,
     2066                                                             domain32->n,
     2067                                                             order,
     2068                                                             (float) x->data.F64), PS_TYPE_F64);
    20602069        psFree(range32);
    20612070        psFree(domain32);
    … …  
    20672076
    20682077    } else {
    2069         // XXX psError: type not supported
    2070         psError(__func__, "type %d not supported\n", x->type.type);
     2078        char* strType;
     2079        PS_TYPE_NAME(strType,x->type.type);
     2080        psError(PS_ERR_BAD_PARAMETER_TYPE,
     2081                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
     2082                strType);
    20712083    }
    20722084
    … …  
    20842096and an independent x value.  Each determines which spline that x corresponds
    20852097to by doing a bracket disection on the domains of the spline data structure
    2086 (p_psVectorBinDisectF32()).  Then it evaluates the spline at that x location
     2098(vectorBinDisectF32()).  Then it evaluates the spline at that x location
    20872099by a call to the 1D polynomial functions.
    20882100 
    … …  
    21002112
    21012113    n = spline->n;
    2102     binNum = p_psVectorBinDisectF32(spline->domains, (spline->n)+1, x);
     2114    binNum = vectorBinDisectF32(spline->domains, (spline->n)+1, x);
    21032115    if (binNum < 0) {
    21042116        psLogMsg(__func__, PS_LOG_WARN,
    … …  
    21392151        }
    21402152    } else {
    2141         psError(__func__, "Unknown data type.\n");
     2153        char* strType;
     2154        PS_TYPE_NAME(strType,x->type.type);
     2155        psError(PS_ERR_BAD_PARAMETER_TYPE,
     2156                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
     2157                strType);
    21422158        return(NULL);
    21432159    }
  • trunk/psLib/src/dataManip/psFunctions.h

    r2269 r2273  
    1212*  @author George Gusciora, MHPCC
    1313*
    14 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2004-11-03 03:30:30 $
     14*  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2004-11-04 01:04:59 $
    1616*
    1717*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    398398                            float max);
    399399
    400 psS32 p_psSpline1DFree(psSpline1D *tmpSpline);
    401 
    402400psSpline1D *psSpline1DAllocGeneric(const psVector *bounds,
    403401                                   psS32 order);
  • trunk/psLib/src/dataManip/psMatrix.c

    r2214 r2273  
    2020 *  @author Ross Harman, MHPCC
    2121 *   
    22  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    23  *  @date $Date: 2004-10-27 20:20:11 $
     22 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     23 *  @date $Date: 2004-11-04 01:04:59 $
    2424 *
    2525 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    4040#include "psVector.h"
    4141#include "psMatrix.h"
    42 
    43 /** Preprocessor macro to generate error a NULL image */
    44 #define PS_VECTOR_CHECK_NULL(NAME, RETURN)                                                          \
    45 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    46     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    47     return RETURN;                                                                                  \
    48 }
    49 
    50 /** Preprocessor macro to create vector based on another */
    51 #define PS_CHECK_ALLOC_VECTOR(NAME, SIZE, PS_TYPE)                                                  \
    52 if(NAME == NULL) {                                                                                  \
    53     NAME = psVectorAlloc(SIZE, PS_TYPE);                                                            \
    54 }
    55 
    56 /** Preprocessor macro to generate error for zero length vector */
    57 #define PS_CHECK_SIZE_VECTOR(NAME, RETURN)                                                          \
    58 if (NAME->n < 1) {                                                                                  \
    59     psError(__func__,"Invalid operation: %s has zero n value.", #NAME);                             \
    60     return RETURN;                                                                                  \
    61 }
    62 
    63 /** Preprocessor macro to generate error a NULL image */
    64 #define PS_IMAGE_CHECK_NULL(NAME, RETURN)                                                           \
    65 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    66     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    67     return RETURN;                                                                                  \
    68 }
    69 
    70 /** Preprocessor macro to create image based on another */
    71 #define PS_CHECK_ALLOC_IMAGE(NAME, NCOLS, NROWS, PS_TYPE)                                           \
    72 if(NAME == NULL) {                                                                                  \
    73     NAME = psImageAlloc(NCOLS, NROWS, PS_TYPE);                                                     \
    74 }
    75 
    76 /** Preprocessor macro to generate error for zero length rows or columns */
    77 #define PS_CHECK_SIZE_IMAGE(NAME, RETURN)                                                           \
    78 if (NAME->numCols < 1 || NAME->numRows < 1) {                                                       \
    79     psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME,              \
    80             NAME->numCols, NAME->numRows);                                                          \
    81     return RETURN;                                                                                  \
    82 }
     42#include "psConstants.h"
     43
     44
    8345
    8446/** Preprocessor macro to generate error for image dimensionality not set to PS_DIMEN_IMAGE */
    8547#define PS_CHECK_DIMEN_AND_TYPE(NAME, PS_DIMEN, RETURN)                                             \
    8648if (NAME->type.dimen != PS_DIMEN) {                                                                 \
    87     psError(__func__,"Invalid operation: %s incorrect dimensionality %d.", #NAME, PS_DIMEN);        \
     49    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                        \
     50            "Invalid operation. %s has incorrect dimensionality %d.", #NAME, PS_DIMEN);             \
    8851    return RETURN;                                                                                  \
    8952} else if(NAME->type.type != PS_TYPE_F64) {                                                         \
    90     psError(__func__, "Invalid operation: %s not PS_TYPE_F64.", #NAME);                             \
     53    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                        \
     54            "Invalid operation. %s not PS_TYPE_F64.", #NAME);                                       \
    9155    return RETURN;                                                                                  \
    9256}
    … …  
    9559#define PS_CHECK_POINTERS(NAME1, NAME2, RETURN)                                                     \
    9660if (NAME1 == NAME2) {                                                                               \
    97     psError(__func__,"Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2);            \
     61    psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                       \
     62            "Invalid operation: Pointer to %s is same as %s.", #NAME1, #NAME2);                     \
    9863    return RETURN;                                                                                  \
    9964}
    … …  
    10267#define PS_CHECK_SQUARE(NAME, RETURN)                                                               \
    10368if (NAME->numCols != NAME->numRows) {                                                               \
    104     psError(__func__,"Invalid operation: %s not square array.", #NAME);                             \
     69    psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                       \
     70            "Invalid operation: %s not square array.", #NAME);                             \
    10571    return RETURN;                                                                                  \
    10672}
    … …  
    12692    gsl_permutation perm;
    12793
     94    #define psMatrixLUD_EXIT { \
     95                               psFree(outImage); \
     96                               return NULL; \
     97                             }
     98
    12899    // Error checks
    129100    PS_CHECK_POINTERS(inImage, outImage, outImage);
    130     PS_IMAGE_CHECK_NULL(inImage, outImage);
    131101    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    132     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    133     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    134     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    135     PS_CHECK_SIZE_IMAGE(outImage, outImage);
    136     PS_CHECK_ALLOC_VECTOR(outPerm, inImage->numRows, inImage->type.type);
    137     PS_VECTOR_CHECK_NULL(outPerm, outImage);
     102
     103    PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixLUD_EXIT);
     104    PS_VECTOR_CHECK_NULL_GENERAL(outPerm, psMatrixLUD_EXIT);
     105
    138106    PS_CHECK_DIMEN_AND_TYPE(outPerm, PS_DIMEN_VECTOR, outImage);
     107
     108    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
     109    psVectorRecycle(outPerm, inImage->numRows, inImage->type.type);
    139110
    140111    // Initialize data
    … …  
    179150    PS_IMAGE_CHECK_NULL(inImage, outVector);
    180151    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    181     PS_CHECK_SIZE_IMAGE(inImage, outVector);
    182     PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     152    PS_IMAGE_CHECK_EMPTY(inImage, outVector);
    183153    PS_VECTOR_CHECK_NULL(outVector, outVector);
    184154    PS_CHECK_DIMEN_AND_TYPE(outVector, PS_DIMEN_VECTOR, outVector);
    … …  
    188158    PS_CHECK_DIMEN_AND_TYPE(inPerm, PS_DIMEN_VECTOR, outVector);
    189159
     160    psVectorRecycle(outVector, inImage->numRows, inImage->type.type);
     161
     162
    190163    // Initialize data
    191164    numRows = inImage->numRows;
    … …  
    226199
    227200    // Error checks
    228     if (det == NULL) {
    229         psError(__func__, "Invalid operation: determinant argument is NULL.");
    230         return outImage;
    231     }
     201    PS_PTR_CHECK_NULL(det, outImage);
    232202    PS_CHECK_POINTERS(inImage, outImage, outImage);
    233203    PS_IMAGE_CHECK_NULL(inImage, outImage);
    234204    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    235     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    236     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    237     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    238     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     205    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     206
     207    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    239208
    240209    // Initialize data
    … …  
    282251    PS_IMAGE_CHECK_NULL(inImage, NULL);
    283252    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, NULL);
    284     PS_CHECK_SIZE_IMAGE(inImage, NULL);
     253    PS_IMAGE_CHECK_EMPTY(inImage, NULL);
    285254
    286255    // Initialize data
    … …  
    325294    PS_IMAGE_CHECK_NULL(inImage1, outImage);
    326295    PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage);
    327     PS_CHECK_SIZE_IMAGE(inImage1, outImage);
     296    PS_IMAGE_CHECK_EMPTY(inImage1, outImage);
    328297    PS_IMAGE_CHECK_NULL(inImage2, outImage);
    329298    PS_CHECK_DIMEN_AND_TYPE(inImage2, PS_DIMEN_IMAGE, outImage);
    330     PS_CHECK_SIZE_IMAGE(inImage2, outImage);
    331     PS_CHECK_ALLOC_IMAGE(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type);
     299    PS_IMAGE_CHECK_EMPTY(inImage2, outImage);
    332300    PS_CHECK_DIMEN_AND_TYPE(inImage1, PS_DIMEN_IMAGE, outImage);
    333     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     301
     302    psImageRecycle(outImage, inImage2->numCols, inImage2->numRows, inImage2->type.type);
    334303
    335304    // Initialize data
    … …  
    364333    PS_IMAGE_CHECK_NULL(inImage, outImage);
    365334    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    366     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    367     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    368     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    369     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     335    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     336
     337    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    370338
    371339    // Initialize data
    … …  
    403371    PS_IMAGE_CHECK_NULL(inImage, outImage);
    404372    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outImage);
    405     PS_CHECK_SIZE_IMAGE(inImage, outImage);
    406     PS_CHECK_ALLOC_IMAGE(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    407     PS_CHECK_DIMEN_AND_TYPE(outImage, PS_DIMEN_IMAGE, outImage);
    408     PS_CHECK_SIZE_IMAGE(outImage, outImage);
     373    PS_IMAGE_CHECK_EMPTY(inImage, outImage);
     374
     375    psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
    409376
    410377    // Initialize data
    … …  
    438405    psS32 size = 0;
    439406
    440     // Error checks
    441     PS_IMAGE_CHECK_NULL(inImage, outVector);
     407    #define psMatrixToVector_EXIT { \
     408                                    psFree(outVector); \
     409                                    return NULL; \
     410                                  }
     411
     412    // Error checks
     413    PS_IMAGE_CHECK_NULL_GENERAL(inImage, psMatrixToVector_EXIT);
    442414    PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, outVector);
    443     PS_CHECK_SIZE_IMAGE(inImage, outVector);
     415    PS_IMAGE_CHECK_EMPTY_GENERAL(inImage, psMatrixToVector_EXIT);
    444416
    445417    if (inImage->numRows == 1) {
    446418        // Create transposed row vector
    447         PS_CHECK_ALLOC_VECTOR(outVector, inImage->numCols, inImage->type.type);
     419        psVectorRecycle(outVector, inImage->numCols, inImage->type.type);
    448420        outVector->type.dimen = PS_DIMEN_TRANSV;
    449421    } else if (inImage->numCols == 1) {
    450422        // Create non-transposed column vector
    451         PS_CHECK_ALLOC_VECTOR(outVector, inImage->numRows, inImage->type.type);
     423        psVectorRecycle(outVector, inImage->numRows, inImage->type.type);
    452424    } else {
    453         psError(__func__, "Image does not have dim with 1 col or 1 row: (%d x %d).", inImage->numRows,
    454                 inImage->numCols);
     425        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     426                "Image does not have dim with 1 col or 1 row: (%d x %d).",
     427                inImage->numRows, inImage->numCols);
    455428        return outVector;
    456429    }
    … …  
    467440
    468441        if (outVector->n != inImage->numRows) {
    469             psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numRows, outVector->n);
     442            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     443                    "Image and vector sizes differ: (%d vs %d).",
     444                    inImage->numRows, outVector->n);
    470445            return outVector;
    471446        }
    … …  
    481456
    482457        if (outVector->n != inImage->numCols) {
    483             psError(__func__, "Image and vector sizes differ: (%d vs %d).", inImage->numCols, outVector->n);
     458            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     459                    "Image and vector sizes differ: (%d vs %d).",
     460                    inImage->numCols, outVector->n);
    484461            return outVector;
    485462        }
    … …  
    502479    if (inVector->type.dimen == PS_DIMEN_VECTOR) {
    503480        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_VECTOR, outImage);
    504         PS_CHECK_SIZE_VECTOR(inVector, outImage);
    505         PS_CHECK_ALLOC_IMAGE(outImage, 1, inVector->n, PS_TYPE_F64)
     481        PS_VECTOR_CHECK_EMPTY(inVector, outImage);
     482        psImageRecycle(outImage, 1, inVector->n, PS_TYPE_F64);
    506483        // More checks for PS_DIMEN_VECTOR
    507484        if (outImage->numCols > 1) {
    508             psError(__func__, "Image has more than 1 column: numCols = %d.", outImage->numCols);
     485            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     486                    "Image has more than 1 column: numCols = %d.",
     487                    outImage->numCols);
    509488            return outImage;
    510489        } else if (outImage->numRows != inVector->n) {
    511             psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numRows, inVector->n);
     490            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     491                    "Image and vector sizes differ: (%d vs %d).",
     492                    outImage->numRows, inVector->n);
    512493            return outImage;
    513494        }
    … …  
    517498    } else if (inVector->type.dimen == PS_DIMEN_TRANSV) {
    518499        PS_CHECK_DIMEN_AND_TYPE(inVector, PS_DIMEN_TRANSV, outImage);
    519         PS_CHECK_SIZE_VECTOR(inVector, outImage);
    520         PS_CHECK_ALLOC_IMAGE(outImage, inVector->n, 1, PS_TYPE_F64)
     500        PS_VECTOR_CHECK_EMPTY(inVector, outImage);
     501        psImageRecycle(outImage, inVector->n, 1, PS_TYPE_F64);
    521502        // More checks for PS_DIMEN_TRANSV
    522503        if (outImage->numRows > 1) {
    523             psError(__func__, "Image has more than 1 row: numRows = %d.", outImage->numRows);
     504            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     505                    "Image has more than 1 row: numRows = %d.",
     506                    outImage->numRows);
    524507            return outImage;
    525508        } else if (outImage->numCols != inVector->n) {
    526             psError(__func__, "Image and vector sizes differ: (%d vs %d).", outImage->numCols, inVector->n);
     509            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     510                    "Image and vector sizes differ: (%d vs %d).",
     511                    outImage->numCols, inVector->n);
    527512            return outImage;
    528513        }
  • trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c

    r2204 r2273  
    2929 *  @author Ross Harman, MHPCC
    3030 *
    31  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    32  *  @date $Date: 2004-10-27 00:57:31 $
     31 *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
     32 *  @date $Date: 2004-11-04 01:04:59 $
    3333 *
    3434 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    4848#include "psScalar.h"
    4949#include "psLogMsg.h"
     50#include "psConstants.h"
     51#include "psDataManipErrors.h"
    5052
    5153/*****************************************************************************
    … …  
    5860// Conversion for radians to degrees
    5961#define R2D 57.29577950924861   /* 180.0/PI */
    60 
    61 /* IEEE Standards on floating-point makes this function pointless, really.
    62 // Division with NAN checking
    63 static complex double psNanDiv(complex double a, complex double b)
    64 {
    65     complex double out = 0 + 0i;
    66  
    67     out = a / b;
    68     if (isnan(creal(out)) || isnan(cimag(out))) {
    69         psError(__func__, ": Divide by zero");
    70     }
    71  
    72     return out;
    73 }
    74 */
    7562
    7663// Binary SCALAR_XXXX operations
    … …  
    142129#define VECTOR_VECTOR(OUT,IN1,OP,IN2,TYPE)                                                                   \
    143130{                                                                                                            \
    144     psS32 i = 0;                                                                                               \
    145     psS32 n1 = 0;                                                                                              \
    146     psS32 n2 = 0;                                                                                              \
     131    psS32 i = 0;                                                                                             \
     132    psS32 n1 = 0;                                                                                            \
     133    psS32 n2 = 0;                                                                                            \
    147134    ps##TYPE *o = NULL;                                                                                      \
    148135    ps##TYPE *i1 = NULL;                                                                                     \
    … …  
    151138    n2  = ((psVector* )IN2)->n;                                                                              \
    152139    if(n1 != n2) {                                                                                           \
    153         psError(__func__, ": Inconsistent element count: %d vs %d", n1, n2);                                 \
     140        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
     141                PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                         \
     142                n1, n2);                                                                                     \
    154143        if (OUT != IN1 && OUT != IN2) {                                                                      \
    155144            psFree(OUT);                                                                                     \
    … …  
    167156#define VECTOR_IMAGE(OUT,IN1,OP,IN2,TYPE)                                                                    \
    168157{                                                                                                            \
    169     psS32 i = 0;                                                                                               \
    170     psS32 j = 0;                                                                                               \
    171     psS32 n1 = 0;                                                                                              \
    172     psS32 numRows2 = 0;                                                                                        \
    173     psS32 numCols2 = 0;                                                                                        \
     158    psS32 i = 0;                                                                                             \
     159    psS32 j = 0;                                                                                             \
     160    psS32 n1 = 0;                                                                                            \
     161    psS32 numRows2 = 0;                                                                                      \
     162    psS32 numCols2 = 0;                                                                                      \
    174163    psDimen dim1 = 0;                                                                                        \
    175164    ps##TYPE *o = NULL;                                                                                      \
    … …  
    181170    numCols2 = ((psImage* )IN2)->numCols;                                                                    \
    182171    \
    183     if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */                                                      \
     172    if(dim1 == PS_DIMEN_VECTOR) { /* Regular vectors */                                             \
    184173        if(n1!=numRows2) {                                                                                   \
    185             psError(__func__, ": Inconsistent element count: %d vs %d", n1, numRows2);                       \
     174            psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                         \
     175                    PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                           \
     176                    n1, numRows2);                                                                           \
    186177            if (OUT != IN1 && OUT != IN2) {                                                                  \
    187178                psFree(OUT);                                                                                 \
    … …  
    200191    } else {  /* Transposed vectors */                                                                       \
    201192        if(n1!=numCols2) {                                                                                   \
    202             psError(__func__, ": Inconsistent element count: %d vs %d", n1, numCols2);                       \
     193            psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                 \
     194                    PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                     \
     195                    n1, numCols2);                       \
    203196            if (OUT != IN1 && OUT != IN2) {                                                                  \
    204197                psFree(OUT);                                                                                 \
    … …  
    256249    numCols1 = ((psImage* )IN1)->numCols;                                                                    \
    257250    \
    258     if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */                                                      \
     251    if(dim2 == PS_DIMEN_VECTOR) { /* Regular vectors */                                             \
    259252        if(n2!=numRows1) {                                                                                   \
    260             psError(__func__, ": Inconsistent element count: %d vs %d", n2, numRows1);                       \
     253            psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                         \
     254                    PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                     \
     255                    n2, numRows1);                                                                           \
    261256            if (OUT != IN1 && OUT != IN2) {                                                                  \
    262257                psFree(OUT);                                                                                 \
    … …  
    275270    } else {  /* Transposed vectors */                                                                       \
    276271        if(n2!=numCols1) {                                                                                   \
    277             psError(__func__, ": Inconsistent element count: %d vs %d", n2, numCols1);                       \
     272            psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                         \
     273                    PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                     \
     274                    n2, numCols1);                                                                           \
    278275            if (OUT != IN1) {                                                                                \
    279276                psFree(OUT);                                                                                 \
    … …  
    309306    numCols2 = ((psImage* )IN2)->numCols;                                                                    \
    310307    if(numRows1!=numRows2 || numCols1!=numCols2) {                                                           \
    311         psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRows1,     \
    312                 numRows2, numCols1, numCols2);                                                               \
     308        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
     309                PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS,                                                     \
     310                numCols1, numRows1, numCols2, numRows2);                                                     \
    313311        if (OUT != IN1 && OUT != IN2) {                                                                      \
    314312            psFree(OUT);                                                                                     \
    … …  
    366364    break;                                                                                                   \
    367365default:                                                                                                     \
    368     psError(__func__, ": Invalid PS_TYPE: %d", IN1->type);                                                   \
     366    /* char* strType; \
     367    PS_TYPE_NAME(strType,IN1->type);                                                                         \
     368    psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                                 \
     369            PS_ERRORTEXT_psMatrix_TYPE_MISMATCH,                                                             \
     370            strType);  */                                                                                      \
    369371    if (OUT != IN1 && OUT != IN2) {                                                                          \
    370372        psFree(OUT);                                                                                         \
    … …  
    391393} else if(!strncmp(OP, "min", 3)) {                                                                          \
    392394    if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) {                                                                \
    393         psError(__func__, ": Minimum operation not supported for complex numbers");                          \
     395        psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                            \
     396                PS_ERRORTEXT_psMatrix_MIN_COMPLEX_SUPPORT);                                                  \
    394397        if (OUT != IN1 && OUT != IN2) {                                                                      \
    395398            psFree(OUT);                                                                                     \
    … …  
    401404} else if(!strncmp(OP, "max", 3)) {                                                                          \
    402405    if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) {                                                                \
    403         psError(__func__, ": Maximum operation not supported for complex numbers");                          \
     406        psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                            \
     407                PS_ERRORTEXT_psMatrix_MAX_COMPLEX_SUPPORT);                                                  \
    404408        if (OUT != IN1 && OUT != IN2) {                                                                      \
    405409            psFree(OUT);                                                                                     \
    … …  
    410414    }                                                                                                        \
    411415} else {                                                                                                     \
    412     psError(__func__, ": Invalid operation: %s", OP);                                                        \
     416    psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                                \
     417            PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED,                                                     \
     418            OP);                                                                                             \
    413419    if (OUT != IN1 && OUT != IN2) {                                                                          \
    414420        psFree(OUT);                                                                                         \
    … …  
    419425psPtr psBinaryOp(psPtr out, psPtr in1, char *op, psPtr in2)
    420426{
    421     psDimen dim1 = 0;
    422     psDimen dim2 = 0;
    423     psElemType elType1 = 0;
    424     psElemType elType2 = 0;
    425     psType* psType1 = NULL;
    426     psType* psType2 = NULL;
    427 
    428     psType1 = (psType* ) in1;
    429     if (psType1 == NULL) {
    430         psError(__func__, ": Line %d - Null in1 argument", __LINE__);
    431         if (out != in1 && out != in2) {
    432             psFree(out);
    433         }
    434         return NULL;
    435     }
    436 
    437     psType2 = (psType* ) in2;
    438     if (psType2 == NULL) {
    439         psError(__func__, ": Line %d - Null in2 argument", __LINE__);
    440         if (out != in1 && out != in2) {
    441             psFree(out);
    442         }
    443         return NULL;
    444     }
    445 
    446     if (op == NULL) {
    447         psError(__func__, ": Line %d - Null op argument", __LINE__);
    448         if (out != in1 && out != in2) {
    449             psFree(out);
    450         }
    451         return NULL;
    452     }
    453 
    454     dim1 = psType1->dimen;
    455     dim2 = psType2->dimen;
    456     elType1 = psType1->type;
    457     elType2 = psType2->type;
    458 
    459     if (elType1 != elType2) {
    460         psError(__func__, ": Line %d - Element types for arguments inconsistent: (%d, %d)", __LINE__,
    461                 elType1, elType2);
    462         if (out != in1 && out != in2) {
    463             psFree(out);
    464         }
    465         return NULL;
    466     }
    467 
    468     if (dim1 == PS_DIMEN_OTHER || dim2 == PS_DIMEN_OTHER) {
    469         psError(__func__, ": Line %d - PS_DIMEN_OTHER not allowed for arguments: (%d, %d)", __LINE__,
    470                 dim1, dim2);
    471         if (out != in1 && out != in2) {
    472             psFree(out);
    473         }
    474         return NULL;
    475     }
     427
     428    psVector* input1 = (psVector* ) in1;
     429    psVector* input2 = (psVector* ) in2;
     430
     431    #define psBinaryOp_EXIT { \
     432                              if (out != in1 && out != in2) { \
     433                              psFree(out); \
     434                              } \
     435                              return NULL; \
     436                            }
     437
     438    PS_PTR_CHECK_NULL_GENERAL(input1, psBinaryOp_EXIT);
     439    PS_PTR_CHECK_NULL_GENERAL(input2, psBinaryOp_EXIT);
     440    PS_PTR_CHECK_NULL_GENERAL(op, psBinaryOp_EXIT);
     441
     442    PS_PTR_CHECK_TYPE_EQUAL_GENERAL(input1,input2, psBinaryOp_EXIT);
     443
     444    PS_PTR_CHECK_DIMEN_GENERAL(input1, PS_DIMEN_OTHER, psBinaryOp_EXIT);
     445    PS_PTR_CHECK_DIMEN_GENERAL(input2, PS_DIMEN_OTHER, psBinaryOp_EXIT);
     446
     447    psType* psType1 = (psType*)in1;
     448    psType* psType2 = (psType*)in2;
     449    psDimen dim1 = psType1->dimen;
     450    psDimen dim2 = psType2->dimen;
     451    psElemType elType1 = psType1->type;
     452    psElemType elType2 = psType2->type;
    476453
    477454    if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) {
    478455        if (((psVector* ) in1)->n == 0) {
    479             psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Vector contains zero elements");
     456            psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements");
    480457        }
    481458    } else if (dim1 == PS_DIMEN_IMAGE) {
    482459        if (((psImage* ) in1)->numCols == 0 || ((psImage* ) in1)->numRows == 0) {
    483             psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Image contains zero length row or cols");
     460            psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols");
    484461        }
    485462    }
    … …  
    487464    if (dim2 == PS_DIMEN_VECTOR || dim2 == PS_DIMEN_TRANSV) {
    488465        if (((psVector* ) in2)->n == 0) {
    489             psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Vector contains zero elements");
     466            psLogMsg(__func__, PS_LOG_WARN, "Vector contains zero elements");
    490467        }
    491468    } else if (dim2 == PS_DIMEN_IMAGE) {
    492469        if (((psImage* ) in2)->numCols == 0 || ((psImage* ) in2)->numRows == 0) {
    493             psLogMsg(__func__, PS_LOG_WARN, ": Line %d - Image contains zero length row or cols");
     470            psLogMsg(__func__, PS_LOG_WARN, "Image contains zero length row or cols");
    494471        }
    495472    }
    … …  
    513490            out = psVectorRecycle(out,((psVector*)in2)->n,elType1);
    514491            if (out == NULL) {
    515                 psError(__func__, "Couldn't create a proper output psVector.");
     492                psError(PS_ERR_UNKNOWN, false,
     493                        PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
    516494                return NULL;
    517495            }
    … …  
    520498            out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows,elType1);
    521499            if (out == NULL) {
    522                 psError(__func__, "Couldn't create a proper output psImage.");
     500                psError(PS_ERR_UNKNOWN, false,
     501                        PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
    523502                return NULL;
    524503            }
    525504            BINARY_OP(SCALAR, IMAGE, out, psType1, op, psType2);        // scalar op image
    526505        } else {
    527             psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
     506            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     507                    PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
     508                    "in2",dim2);
     509            psBinaryOp_EXIT;
    528510        }
    529511    } else if (dim1 == PS_DIMEN_VECTOR || dim1 == PS_DIMEN_TRANSV) {
    … …  
    531513            out = psVectorRecycle(out,((psVector*)in1)->n,elType1);
    532514            if (out == NULL) {
    533                 psError(__func__, "Couldn't create a proper output psVector.");
     515                psError(PS_ERR_UNKNOWN, false,
     516                        PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
    534517                return NULL;
    535518            }
    … …  
    538521            out = psVectorRecycle(out,((psVector*)in2)->n,elType2);
    539522            if (out == NULL) {
    540                 psError(__func__, "Couldn't create a proper output psVector.");
     523                psError(PS_ERR_UNKNOWN, false,
     524                        PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
    541525                return NULL;
    542526            }
    … …  
    545529            out = psImageRecycle(out, ((psImage* ) in2)->numCols, ((psImage* ) in2)->numRows, elType2);
    546530            if (out == NULL) {
    547                 psError(__func__, "Couldn't create a proper output psImage.");
     531                psError(PS_ERR_UNKNOWN, false,
     532                        PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
    548533                return NULL;
    549534            }
    550535            BINARY_OP(VECTOR, IMAGE, out, psType1, op, psType2);        // vector op image
    551536        } else {
    552             psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
     537            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     538                    PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
     539                    "in2",dim2);
     540            psBinaryOp_EXIT;
    553541        }
    554542    } else if (dim1 == PS_DIMEN_IMAGE) {
    555543        out = psImageRecycle(out, ((psImage*)in1)->numCols, ((psImage*)in1)->numRows, elType1);
    556544        if (out == NULL) {
    557             psError(__func__, "Couldn't create a proper output psImage.");
     545            psError(PS_ERR_UNKNOWN, false,
     546                    PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
    558547            return NULL;
    559548        }
    … …  
    565554            BINARY_OP(IMAGE, IMAGE, out, psType1, op, psType2); // image op image
    566555        } else {
    567             if (out != in1 && out != in2) {
    568                 psFree(out);
    569             }
    570             psError(__func__, ": Line %d - Invalid dimensionality for in2 arg: %d", __LINE__, dim2);
    571             return NULL;
     556            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     557                    PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
     558                    "in2",dim2);
     559            psBinaryOp_EXIT;
    572560        }
    573561    } else {
    574         if (out != in1 && out != in2) {
    575             psFree(out);
    576         }
    577         psError(__func__, ": Line %d - Invalid dimensionality for in1 arg: %d", __LINE__, dim1);
    578         return NULL;
     562        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     563                PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
     564                "in1",dim1);
     565        psBinaryOp_EXIT;
    579566    }
    580567
    … …  
    605592#define VECTOR(OUT,IN,OP,TYPE)                                                                               \
    606593{                                                                                                            \
    607     psS32 i = 0;                                                                                               \
    608     psS32 nIn = 0;                                                                                             \
    609     psS32 nOut = 0;                                                                                            \
     594    psS32 i = 0;                                                                                             \
     595    psS32 nIn = 0;                                                                                           \
     596    psS32 nOut = 0;                                                                                          \
    610597    ps##TYPE *o = NULL;                                                                                      \
    611598    ps##TYPE *i1 = NULL;                                                                                     \
    … …  
    613600    nOut = ((psVector* )OUT)->n;                                                                             \
    614601    if(nIn != nOut) {                                                                                        \
    615         psError(__func__, ": Inconsistent element count: %d vs %d", nIn, nOut);                              \
     602        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
     603                PS_ERRORTEXT_psMatrix_COUNT_DIFFERS,                                                         \
     604                nIn, nOut);                                                                                  \
    616605        if (OUT != IN) {                                                                                     \
    617606            psFree(OUT);                                                                                     \
    … …  
    629618#define IMAGE(OUT,IN,OP,TYPE)                                                                                \
    630619{                                                                                                            \
    631     psS32 i = 0;                                                                                               \
    632     psS32 j = 0;                                                                                               \
    633     psS32 numRowsIn = 0;                                                                                       \
    634     psS32 numColsIn = 0;                                                                                       \
    635     psS32 numRowsOut = 0;                                                                                      \
    636     psS32 numColsOut = 0;                                                                                      \
     620    psS32 i = 0;                                                                                             \
     621    psS32 j = 0;                                                                                             \
     622    psS32 numRowsIn = 0;                                                                                     \
     623    psS32 numColsIn = 0;                                                                                     \
     624    psS32 numRowsOut = 0;                                                                                    \
     625    psS32 numColsOut = 0;                                                                                    \
    637626    ps##TYPE *o = NULL;                                                                                      \
    638627    ps##TYPE *i1 = NULL;                                                                                     \
    … …  
    642631    numColsOut = ((psImage* )OUT)->numCols;                                                                  \
    643632    if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) {                                                     \
    644         psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRowsIn,    \
    645                 numRowsOut, numColsIn, numColsOut);                                                          \
     633        psError(PS_ERR_BAD_PARAMETER_SIZE, true,                                                             \
     634                PS_ERRORTEXT_psMatrix_IMAGE_SIZE_DIFFERS,                                                    \
     635                numColsIn, numRowsIn, numColsOut, numRowsOut);                                               \
    646636        if (OUT != IN) {                                                                                     \
    647637            psFree(OUT);                                                                                     \
    … …  
    697687    DIM(OUT,IN,OP,C32);                                                                                      \
    698688    break;                                                                                                   \
    699 default:                                                                                                     \
    700     psError(__func__, ": Invalid PS_TYPE: %d", IN->type);                                                    \
    701     if (OUT != IN) {                                                                                         \
    702         psFree(OUT);                                                                                         \
    703     }                                                                                                        \
    704     return NULL;                                                                                             \
     689default: {                                                                                                     \
     690        char* strType;                                                                                           \
     691        PS_TYPE_NAME(strType, IN->type);                                                                         \
     692        psError(PS_ERR_BAD_PARAMETER_TYPE, true,                                                                 \
     693                PS_ERRORTEXT_psMatrix_TYPE_MISMATCH,                                                             \
     694                strType);                                                                                        \
     695        if (OUT != IN) {                                                                                         \
     696            psFree(OUT);                                                                                         \
     697        }                                                                                                        \
     698        return NULL;                                                                                             \
     699    } \
    705700}
    706701
    … …  
    815810    }                                                                                                        \
    816811} else {                                                                                                     \
    817     psError(__func__, ": Invalid operation: %s", OP);                                                        \
     812    psError(PS_ERR_BAD_PARAMETER_VALUE, true,                                                                \
     813            PS_ERRORTEXT_psMatrix_OPERATION_UNSUPPORTED,                                                     \
     814            OP);                                                                                             \
    818815}
    819816
    820817psPtr psUnaryOp(psPtr out, psPtr in, char *op)
    821818{
    822     psDimen dimIn = 0;
    823     psElemType elTypeIn = 0;
    824     psType* psTypeIn = NULL;
    825 
    826     psTypeIn = (psType* ) in;
    827     if (psTypeIn == NULL) {
    828         psError(__func__, ": Line %d - Null in argument", __LINE__);
    829         if (out != in) {
    830             psFree(out);
    831         }
    832         return NULL;
    833     }
    834 
    835     if (op == NULL) {
    836         psError(__func__, ": Line %d - Null op argument", __LINE__);
    837         if (out != in) {
    838             psFree(out);
    839         }
    840         return NULL;
    841     }
    842 
    843     dimIn = psTypeIn->dimen;
    844     elTypeIn = psTypeIn->type;
     819    #define psUnaryOp_EXIT { \
     820                             if (out != in) { \
     821                             psFree(out); \
     822                             } \
     823                             if(psTypeIn->dimen==PS_DIMEN_SCALAR && in!=out) { \
     824                             psFree(in); \
     825                             } \
     826                             return NULL; \
     827                           }
     828
     829    psType* psTypeIn = (psType* ) in;
     830
     831    PS_PTR_CHECK_NULL_GENERAL(in, psUnaryOp_EXIT);
     832    PS_PTR_CHECK_NULL_GENERAL(op, psUnaryOp_EXIT);
     833
     834    psDimen dimIn = psTypeIn->dimen;
     835    psElemType elTypeIn = psTypeIn->type;
    845836
    846837    switch (dimIn) {
    … …  
    857848    case PS_DIMEN_TRANSV:
    858849        if (((psVector*)in)->n == 0) {
    859             if (out != in) {
    860                 psFree(out);
    861             }
    862             psError(__func__, ": Line %d - Vector contains zero elements");
    863             return NULL;
     850            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     851                    PS_ERRORTEXT_psMatrix_VECTOR_EMPTY);
     852            psUnaryOp_EXIT;
    864853        }
    865854
    … …  
    868857                              elTypeIn);
    869858        if (out == NULL) {
    870             psError(__func__, "Couldn't create a proper output psVector.");
    871             return NULL;
     859            psError(PS_ERR_UNKNOWN, false,
     860                    PS_ERRORTEXT_psMatrix_OUTPUT_VECTOR_NOT_CREATED);
     861            psUnaryOp_EXIT;
    872862        }
    873863
    … …  
    876866    case PS_DIMEN_IMAGE:
    877867        if (((psImage* ) in)->numCols == 0 || ((psImage* ) in)->numRows == 0) {
    878             if (out != in) {
    879                 psFree(out);
    880             }
    881             psError(__func__, ": Line %d - Image contains zero length row or cols");
    882             return NULL;
     868            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     869                    PS_ERRORTEXT_psMatrix_IMAGE_EMPTY);
     870            psUnaryOp_EXIT;
    883871        }
    884872
    … …  
    888876                             elTypeIn);
    889877        if (out == NULL) {
    890             psError(__func__, "Couldn't create a proper output psImage.");
    891             return NULL;
     878            psError(PS_ERR_UNKNOWN, false,
     879                    PS_ERRORTEXT_psMatrix_OUTPUT_IMAGE_NOT_CREATED);
     880            psUnaryOp_EXIT;
    892881        }
    893882
    … …  
    898887            psFree(out);
    899888        }
    900         psError(__func__, ": Line %d - Invalid dimensionality for in arg: %d", __LINE__, dimIn);
    901         return NULL;
     889        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     890                PS_ERRORTEXT_psMatrix_DIMEN_INVALID,
     891                "in", dimIn);
     892        psUnaryOp_EXIT;
    902893    }
    903894
  • trunk/psLib/src/dataManip/psMinimize.c

    r2269 r2273  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-11-03 03:30:30 $
     11 *  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-11-04 01:04:59 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    291291
    292292    if (y32->n != (1 + mySpline->n)) {
    293         psError(__func__, "data size / spline size mismatch (%d %d)\n",
     293        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     294                "data size / spline size mismatch (%d %d)\n",
    294295                y32->n, mySpline->n);
    295296        return(NULL);
    … …  
    318319    // Check if these are cubic splines (n==4).  If not, psError.
    319320    if (4 != (mySpline->spline[0])->n) {
    320         psError(__func__, "Don't know how to generate %d-order splines.",
     321        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
     322                "Don't know how to generate %d-order splines.",
    321323                (mySpline->spline[0])->n-1);
    322324        return(NULL);
    … …  
    952954        PS_VECTOR_GEN_X_INDEX_STATIC_F64(x64Static, y->n);
    953955        if (myPoly->type == PS_POLYNOMIAL_CHEB) {
    954             p_psNormalizeVectorRange(x64Static, -1.0, 1.0);
     956            psNormalizeVectorRange(x64Static, -1.0, 1.0);
    955957        }
    956958        x64 = x64Static;
    … …  
    968970        tmpPoly = VectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
    969971    } else {
    970         psError(__func__, "unknown polynomial type.\n");
     972        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     973                "unknown polynomial type.\n");
    971974        return(NULL);
    972975    }
    … …  
    13651368    bracket = p_psDetermineBracket2(params, line, paramMask, coords, func);
    13661369    if (bracket == NULL) {
    1367         psError(__func__, "(1) Could not bracket minimum.");
     1370        psError(PS_ERR_UNKNOWN, false,
     1371                "Could not bracket minimum.");
    13681372        return(NAN);
    13691373    }
    … …  
    15521556                                  func);
    15531557                if (isnan(mul)) {
    1554                     psError(__func__, "Could not perform line minimization (1).\n");
     1558                    psError(PS_ERR_UNKNOWN, false,
     1559                            "Could not perform line minimization");
    15551560                    psFree(v);
    15561561                    return(false);
    … …  
    15921597        mul = p_psLineMin(&dummyMin, params, u, myParamMask, coords, func);
    15931598        if (isnan(mul)) {
    1594             psError(__func__, "Could not perform line minimization. (2)\n");
     1599            psError(PS_ERR_UNKNOWN, false,
     1600                    "Could not perform line minimization.");
    15951601            psFree(v);
    15961602            return(false);
  • trunk/psLib/src/dataManip/psStats.c

    r2269 r2273  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-11-03 03:30:30 $
     11 *  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-11-04 01:04:59 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    3434#include "psFunctions.h"
    3535#include "psConstants.h"
     36
     37#include "psDataManipErrors.h"
    3638
    3739/*****************************************************************************/
    … …  
    735737
    736738    // Ensure that stats->clipIter is within the proper range.
    737     if (!((PS_CLIPPED_NUM_ITER_LB <= stats->clipIter) && (stats->clipIter <= PS_CLIPPED_NUM_ITER_UB))) {
    738         psError(__func__, "Unallowed value for clipIter (%d).\n", stats->clipIter);
    739         return(-1);
    740     }
     739    PS_INT_CHECK_RANGE(stats->clipIter,PS_CLIPPED_NUM_ITER_LB,PS_CLIPPED_NUM_ITER_UB,-1);
     740
    741741    // Ensure that stats->clipSigma is within the proper range.
    742     if (!((PS_CLIPPED_SIGMA_LB <= stats->clipSigma) && (stats->clipSigma <= PS_CLIPPED_SIGMA_UB))) {
    743         psError(__func__, "Unallowed value for clipSigma (%f).\n", stats->clipSigma);
    744         return(-1);
    745     }
     742    PS_INT_CHECK_RANGE(stats->clipSigma,PS_CLIPPED_SIGMA_LB,PS_CLIPPED_SIGMA_UB,-1);
     743
    746744    // We allocate a temporary mask vector since during the iterative
    747745    // steps that follow, we will be masking off additional data points.
    … …  
    869867        p_psNormalizeVectorRangeF64(myData, low, high);
    870868    } else {
    871         psError(__func__, "Unalowable data type.\n");
     869        char* strType;
     870        PS_TYPE_NAME(strType,myData->type.type);
     871        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     872                PS_ERRORTEXT_psStats_NOT_F32_F64,
     873                strType);
    872874    }
    873875}
    … …  
    954956        // Ensure that yVal is within the range of the bins we are using.
    955957        if (!((y->data.F64[0] <= yVal) && (yVal <= y->data.F64[2]))) {
    956             printf("((%f), %f, %f)\n", yVal, y->data.F64[0], y->data.F64[2]);
    957             psError(__func__, "yVal not within y-range\n");
     958            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     959                    PS_ERRORTEXT_psStats_YVAL_OUT_OF_RANGE,
     960                    (double)yVal,y->data.F64[2],y->data.F64[0]);
    958961        }
    959962        yErr->data.F64[0] = 1.0;
    … …  
    11131116
    11141117    if ((LQBinNum < 0) || (UQBinNum < 0)) {
    1115         psError(__func__, "Could not determine the robust lower/upper quartile bin numbers.");
     1118        psError(PS_ERR_UNKNOWN, true,
     1119                PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED);
    11161120        return(1);
    11171121    }
    11181122    if (medianBinNum < 0) {
    1119         psError(__func__, "Could not determine the robust lower/upper quartile bin numbers.");
     1123        psError(PS_ERR_UNKNOWN, true,
     1124                PS_ERRORTEXT_psStats_ROBUST_QUARTILE_BINS_FAILED);
    11201125        return(1);
    11211126    }
    … …  
    11741179    psVector *y = psVectorAlloc(robustHistogramVector->n, PS_TYPE_F32);
    11751180
    1176     p_psNormalizeVectorRange(robustHistogramVector, 0.0, 1.0);
     1181    psNormalizeVectorRange(robustHistogramVector, 0.0, 1.0);
    11771182    for (i=0;i<robustHistogramVector->n;i++) {
    11781183        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
    … …  
    15361541        // do nothing
    15371542    } else {
    1538         psError(__func__, "unsupported vector type 0x%x\n", in->type.type);
     1543        char* strType;
     1544        PS_TYPE_NAME(strType,in->type.type);
     1545        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     1546                PS_ERRORTEXT_psStats_VECTOR_TYPE_UNSUPPORTED,
     1547                strType);
    15391548    }
    15401549    return (tmp);
    … …  
    16031612            (stats->options & PS_STAT_ROBUST_STDEV) || (stats->options & PS_STAT_ROBUST_QUARTILE)) {
    16041613        if (0 != p_psVectorRobustStats(inF32, mask, maskVal, stats)) {
    1605             psError(__func__, "p_psVectorRobustStats() failed.\n");
     1614            psError(PS_ERR_UNKNOWN, false,
     1615                    PS_ERRORTEXT_psStats_STATS_FAILED);
    16061616        }
    16071617    }
    … …  
    16091619    if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) {
    16101620        if (0 != p_psVectorClippedStats(inF32, mask, maskVal, stats)) {
    1611             psError(__func__, "p_psVectorClippedStats() failed.\n");
     1621            psError(PS_ERR_UNKNOWN, false,
     1622                    "Failed to calculate statistics for input psVector.");
    16121623        }
    16131624    }
  • trunk/psLib/src/dataManip/psVectorFFT.c

    r2204 r2273  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-10-27 00:57:31 $
     7 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-11-04 01:04:59 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    … …  
    6363                                 (fftwf_complex *) out->data.C32, FFTW_BACKWARD, P_FFTW_PLAN_RIGOR);
    6464    } else {
    65         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorFFT",
    66                    PS_ERR_BAD_PARAMETER_VALUE, true,
    67                    PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET);
     65        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     66                PS_ERRORTEXT_psVectorFFT_DIRECTION_NOTSET);
    6867        psFree(out);
    6968        return NULL;
    … …  
    7271    /* check if a plan exists now */
    7372    if (plan == NULL) {
    74         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorFFT",
    75                    PS_ERR_BAD_PARAMETER_TYPE, true,
    76                    PS_ERRORTEXT_psVectorFFT_FFTW_PLAN_NULL);
     73        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     74                PS_ERRORTEXT_psVectorFFT_FFTW_PLAN_NULL);
    7775        psFree(out);
    7876        return NULL;
    … …  
    144142        char* typeStr;
    145143        PS_TYPE_NAME(typeStr,type);
    146         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorReal",
    147                    PS_ERR_BAD_PARAMETER_TYPE, true,
    148                    PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED,
    149                    typeStr);
     144        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     145                PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED,
     146                typeStr);
    150147        psFree(out);
    151148        return NULL;
    … …  
    204201        char* typeStr;
    205202        PS_TYPE_NAME(typeStr,type);
    206         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorImaginary",
    207                    PS_ERR_BAD_PARAMETER_TYPE, true,
    208                    PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED,
    209                    typeStr);
     203        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     204                PS_ERRORTEXT_psVectorFFT_TYPE_UNSUPPORTED,
     205                typeStr);
    210206        psFree(out);
    211207        return NULL;
    … …  
    237233        PS_TYPE_NAME(typeStrReal,type);
    238234        PS_TYPE_NAME(typeStrImag,imag->type.type);
    239         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorComplex",
    240                    PS_ERR_BAD_PARAMETER_TYPE, true,
    241                    PS_ERRORTEXT_psVectorFFT_REAL_IMAG_TYPE_MISMATCH,
    242                    typeStrReal,typeStrImag);
     235        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     236                PS_ERRORTEXT_psVectorFFT_REAL_IMAG_TYPE_MISMATCH,
     237                typeStrReal,typeStrImag);
    243238        psFree(out);
    244239        return NULL;
    … …  
    272267        char* typeStr;
    273268        PS_TYPE_NAME(typeStr,type);
    274         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorComplex",
    275                    PS_ERR_BAD_PARAMETER_TYPE, true,
    276                    PS_ERRORTEXT_psVectorFFT_NONREAL_NOTSUPPORTED,
    277                    typeStr);
     269        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     270                PS_ERRORTEXT_psVectorFFT_NONREAL_NOTSUPPORTED,
     271                typeStr);
    278272        psFree(out);
    279273        return NULL;
    … …  
    333327        char* typeStr;
    334328        PS_TYPE_NAME(typeStr,type);
    335         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorConjugate",
    336                    PS_ERR_BAD_PARAMETER_TYPE, true,
    337                    PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED,
    338                    typeStr);
     329        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     330                PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED,
     331                typeStr);
    339332        psFree(out);
    340333        return NULL;
    … …  
    414407        char* typeStr;
    415408        PS_TYPE_NAME(typeStr,type);
    416         psErrorMsg(PS_ERRORNAME_DOMAIN "psVectorPowerSpectrum",
    417                    PS_ERR_BAD_PARAMETER_TYPE, true,
    418                    PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED,
    419                    typeStr);
    420         psFree(out);
    421         return NULL;
    422     }
    423 
    424     return out;
    425 
    426 }
     409        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     410                PS_ERRORTEXT_psVectorFFT_NONCOMPLEX_NOTSUPPORTED,
     411                typeStr);
     412        psFree(out);
     413        return NULL;
     414    }
     415
     416    return out;
     417
     418}
Note: See TracChangeset for help on using the changeset viewer.