IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 5, 2004, 12:47:21 PM (22 years ago)
Author:
gusciora
Message:

Added macros in psConstants.h to check for NULL and mis-typed vectors.

File:
1 edited

Legend:

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

    r1953 r1963  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-10-05 01:43:58 $
     8 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-10-05 22:47:21 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#define RIGHT_SPLINE_DERIV 0.0
    1919
     20#define CONVERT_VECTOR_F64_TO_F32(OLD, NEW_PTR32, NEW_STATIC32) \
     21if (OLD->type.type == PS_TYPE_F32) { \
     22    NEW_PTR32 = (psVector *) OLD; \
     23} else if (OLD->type.type == PS_TYPE_F64) { \
     24    NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \
     25    p_psMemSetPersistent(NEW_STATIC32, true); \
     26    p_psMemSetPersistent(NEW_STATIC32->data.V, true); \
     27    for (i=0; i < OLD->n ; i++) { \
     28        NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \
     29    } \
     30    NEW_PTR32 = NEW_STATIC32; \
     31} \
     32
     33#define CONVERT_VECTOR_F32_TO_F64(OLD, NEW_PTR64, NEW_STATIC64) \
     34if (OLD->type.type == PS_TYPE_F64) { \
     35    NEW_PTR64 = (psVector *) OLD; \
     36} else if (OLD->type.type == PS_TYPE_F32) { \
     37    NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \
     38    p_psMemSetPersistent(NEW_STATIC64, true); \
     39    p_psMemSetPersistent(NEW_STATIC64->data.V, true); \
     40    for (i=0; i < OLD->n ; i++) { \
     41        NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \
     42    } \
     43    NEW_PTR64 = NEW_STATIC64; \
     44} \
     45
     46#define VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(VEC) \
     47if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \
     48    psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \
     49    return(NULL); \
     50} \
     51
     52#define GEN_PERSIST_YERR_VEC_F32(VEC, N) \
     53VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
     54p_psMemSetPersistent(VEC, true); \
     55p_psMemSetPersistent(VEC->data.V, true); \
     56for (int i=0;i<N;i++) { \
     57    VEC->data.F32[i] = 1.0; \
     58} \
     59
     60#define GEN_PERSIST_YERR_VEC_F64(VEC, N) \
     61VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
     62p_psMemSetPersistent(VEC, true); \
     63p_psMemSetPersistent(VEC->data.V, true); \
     64for (int i=0;i<N;i++) { \
     65    VEC->data.F64[i] = 1.0; \
     66} \
     67
     68#define GEN_PERSIST_X_INDEX_VEC_F32(VEC, N) \
     69VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
     70p_psMemSetPersistent(VEC, true); \
     71p_psMemSetPersistent(VEC->data.V, true); \
     72for (int i=0;i<N;i++) { \
     73    VEC->data.F32[i] = (float) i; \
     74} \
     75
     76#define GEN_PERSIST_X_INDEX_VEC_F64(VEC, N) \
     77VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
     78p_psMemSetPersistent(VEC, true); \
     79p_psMemSetPersistent(VEC->data.V, true); \
     80for (int i=0;i<N;i++) { \
     81    VEC->data.F64[i] = (float) i; \
     82} \
     83
    2084#define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \
    2185static psVector *NAME = NULL; \
     
    2387p_psMemSetPersistent(NAME, true); \
    2488p_psMemSetPersistent(NAME->data.V, true); \
    25 
    26 
    27 
    2889
    2990/** Preprocessor macro to generate error on an incorrect type */
     
    51112}
    52113
     114/** Preprocessor macro to generate error on a NULL vector */
     115#define PS_CHECK_NULL_VECTOR_RETURN_NULL(NAME) \
     116if (NAME == NULL || NAME->data.V == NULL) { \
     117    psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \
     118    return(NULL); \
     119} \
     120
    53121/** Preprocessor macro to generate error on a NULL poniter */
    54122#define PS_CHECK_NULL_PTR(NAME) \
    55123if (NAME == NULL) { \
    56124    psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
     125}
     126
     127/** Preprocessor macro to generate error on a NULL poniter */
     128#define PS_CHECK_NULL_PTR_RETURN_NULL(NAME) \
     129if (NAME == NULL) { \
     130    psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
     131    return(NULL); \
    57132}
    58133
     
    75150}
    76151
     152/** Preprocessor macro to generate error for zero length vector */
     153#define PS_CHECK_EMPTY_VECTOR_RETURN_NULL(NAME) \
     154if (NAME->n < 1) { \
     155    psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \
     156    return(NULL); \
     157} \
     158
    77159/** Preprocessor macro to generate error on differing size vectors */
    78160#define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \
    79161if (VEC1->n != VEC2->n) { \
    80162    psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
     163}
     164
     165/** Preprocessor macro to generate error on differing size vectors */
     166#define PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(VEC1, VEC2) \
     167if (VEC1->n != VEC2->n) { \
     168    psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
     169    return(NULL); \
    81170}
    82171
     
    112201}
    113202
     203#define PS_CHECK_NULL_1DPOLY_RETURN_NULL(NAME)                                                          \
     204if (NAME == NULL || NAME->coeff == NULL) {                                                         \
     205    psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME);                          \
     206    return(NULL); \
     207} \
     208
    114209#define PS_PRINT_VECTOR(NAME) \
    115210for (int my_i=0;my_i<NAME->n;my_i++) { \
Note: See TracChangeset for help on using the changeset viewer.