Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psConstants.h

Go to the documentation of this file.
00001 /** @file  psConstants.h
00002  *
00003  *  This file will hold definitions of various constants as well as common
00004  *  macros used throughout psLib.
00005  *
00006  *  @author GLG, MHPCC
00007  *
00008  *  @version $Revision: 1.1.1.1 $ $Name:  $
00009  *  @date $Date: 2005/09/14 20:42:48 $
00010  *
00011  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00012  *
00013  *  XXX: Add parenthesis around all arguments so that these macros can be
00014  *       called with complex expressions.
00015  *
00016  *  XXX: All functions which use the PS_CHECK macros must be scrutinized so
00017  *  that we ensure that an argument which is expected to be output is
00018  *  psFree'ed before reurning NULL.
00019  *
00020  *  XXX: The macros have a name similar to PS_CHECK_CONDITION() and generally
00021  *  throw a psError if the CONDITION is true.  However, some throw the error
00022  *  if the CONDITION is false.  This should be consistant.
00023  *
00024  *  XXX: rename all these with form PS_ASSERT_CONDITION().
00025  *
00026  */
00027 
00028 #include<math.h> // for M_PI
00029 
00030 /*****************************************************************************
00031 These constants are used by various functions in the psLib.
00032  *****************************************************************************/
00033 #define PS_DETERMINE_BRACKET_STEP_SIZE 0.10
00034 #define PS_MAX_LMM_ITERATIONS 100
00035 #define PS_MAX_MINIMIZE_ITERATIONS 100
00036 #define PS_LEFT_SPLINE_DERIV 0.0
00037 #define PS_RIGHT_SPLINE_DERIV 0.0
00038 /*****************************************************************************
00039 These are common mathimatical constants used by various functions in the psLib.
00040  *****************************************************************************/
00041 #ifndef M_PI
00042 #define M_PI   3.1415926535897932384626433832795029  /* pi */
00043 #define M_PI_2 1.5707963267948966192313216916397514  /* pi/2 */
00044 #define M_PI_4 0.7853981633974483096156608458198757  /* pi/4 */
00045 #define M_1_PI 0.3183098861837906715377675267450287  /* 1/pi */
00046 #define M_2_PI 0.6366197723675813430755350534900574  /* 2/pi */
00047 #endif // #ifndef M_PI
00048 
00049 #define DEG_TO_RAD(DEGREES) ((DEGREES) * M_PI / 180.0)
00050 #define MIN_TO_RAD(MINUTES) ((MINUTES) * M_PI / (180.0 * 60.0))
00051 #define SEC_TO_RAD(SECONDS) ((SECONDS) * M_PI / (180.0 * 60.0 * 60.0))
00052 #define RAD_TO_DEG(RADIANS) ((RADIANS) * 180.0 / M_PI)
00053 #define RAD_TO_MIN(RADIANS) ((RADIANS) * 180.0 * 60.0 / M_PI)
00054 #define RAD_TO_SEC(RADIANS) ((RADIANS) * 180.0 * 60.0 * 60.0 / M_PI)
00055 
00056 /*****************************************************************************
00057  
00058 *****************************************************************************/
00059 
00060 #define PS_ASSERT_INT_UNEQUAL(NAME1, NAME2, RVAL) \
00061 if ((NAME1) == (NAME2)) { \
00062     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00063             "Error: %s and %s are equal.", \
00064             #NAME1, #NAME2); \
00065     return(RVAL); \
00066 }
00067 
00068 #define PS_ASSERT_INT_EQUAL(NAME1, NAME2, RVAL) \
00069 if ((NAME1) != (NAME2)) { \
00070     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00071             "Error: %s and %s are not equal.", \
00072             #NAME1, #NAME2); \
00073     return(RVAL); \
00074 }
00075 
00076 #define PS_ASSERT_INT_NONNEGATIVE(NAME, RVAL) \
00077 if ((NAME) < 0) { \
00078     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00079             "Error: %s is less than 0.", #NAME); \
00080     return(RVAL); \
00081 }
00082 
00083 #define PS_ASSERT_INT_POSITIVE(NAME, RVAL) \
00084 if ((NAME) < 1) { \
00085     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00086             "Error: %s is 0 or less.", #NAME); \
00087     return(RVAL); \
00088 }
00089 
00090 #define PS_ASSERT_INT_ZERO(NAME, RVAL) \
00091 if ((NAME) != 0) { \
00092     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00093             "Error: %s is 0.", #NAME); \
00094     return(RVAL); \
00095 }
00096 
00097 #define PS_ASSERT_INT_NONZERO(NAME, RVAL) \
00098 if ((NAME) == 0) { \
00099     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00100             "Error: %s is 0.", #NAME); \
00101     return(RVAL); \
00102 }
00103 
00104 // XXX: Where did these int casts come from?
00105 #define PS_ASSERT_INT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00106 if ((int)(NAME) < LOWER || (int)(NAME) > UPPER) { \
00107     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00108             "Error: %s, %d, is out of range.  Must be between %d and %d.", \
00109             #NAME,(int)NAME,LOWER,UPPER); \
00110     return RVAL; \
00111 }
00112 
00113 #define PS_ASSERT_INT_LESS_THAN(VAR1, VAR2, RVAL) \
00114 if (!(VAR1 < VAR2)) { \
00115     psError(PS_ERR_UNKNOWN, true, \
00116             "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
00117     return(RVAL); \
00118 }
00119 
00120 #define PS_ASSERT_INT_LESS_THAN_OR_EQUAL(VAR1, VAR2, RVAL) \
00121 if (!(VAR1 <= VAR2)) { \
00122     psError(PS_ERR_UNKNOWN, true, \
00123             "Error: %s is not less than %s (%d, %d)", #VAR1, #VAR2, VAR1, VAR2); \
00124     return(RVAL); \
00125 }
00126 
00127 #define PS_ASSERT_INT_LARGER_THAN(NAME1, NAME2, RVAL) \
00128 if (!((NAME1) > (NAME2))) { \
00129     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00130             "Error: !(%s > %s) (%d %d).", \
00131             #NAME1, #NAME2, NAME1, NAME2); \
00132     return(RVAL); \
00133 }
00134 
00135 #define PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
00136 if (!((NAME1) >= (NAME2))) { \
00137     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00138             "Error: !(%s >= %s) (%d %d).", \
00139             #NAME1, #NAME2, NAME1, NAME2); \
00140     return(RVAL); \
00141 }
00142 #define PS_ASSERT_FLOAT_LARGER_THAN(NAME1, NAME2, RVAL) \
00143 if (!((NAME1) > (NAME2))) { \
00144     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00145             "Error: !(%s > %s) (%f %f).", \
00146             #NAME1, #NAME2, NAME1, NAME2); \
00147     return(RVAL); \
00148 }
00149 
00150 #define PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(NAME1, NAME2, RVAL) \
00151 if (!((NAME1) >= (NAME2))) { \
00152     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00153             "Error: !(%s >= %s) (%f %f).", \
00154             #NAME1, #NAME2, NAME1, NAME2); \
00155     return(RVAL); \
00156 }
00157 
00158 // Produce an error if (NAME1 > NAME2)
00159 // XXX: Get rid of this, use above macros.
00160 #define PS_INT_COMPARE(NAME1, NAME2, RVAL) \
00161 if ((NAME1) > (NAME2)) { \
00162     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00163             "Error: (%s > %s) (%d %d).", \
00164             #NAME1, #NAME2, NAME1, NAME2); \
00165     return(RVAL); \
00166 }
00167 
00168 // Produce an error if ((NAME1 > NAME2)
00169 // XXX: Get rid of this, use above macros.
00170 #define PS_FLOAT_COMPARE(NAME1, NAME2, RVAL) \
00171 if ((NAME1) > (NAME2)) { \
00172     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00173             "Error: (%s > %s) (%f %f)", \
00174             #NAME1, #NAME2, NAME1, NAME2); \
00175     return(RVAL); \
00176 }
00177 
00178 #define PS_ASSERT_FLOAT_NON_EQUAL(NAME1, NAME2, RVAL) \
00179 if (fabs((NAME2) - (NAME1)) < FLT_EPSILON) { \
00180     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00181             "Error: %s and %s are equal.", \
00182             #NAME1, #NAME2); \
00183     return(RVAL); \
00184 }
00185 
00186 #define PS_ASSERT_FLOAT_EQUAL(NAME1, NAME2, RVAL) \
00187 if (fabs((NAME2) - (NAME1)) > FLT_EPSILON) { \
00188     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00189             "Error: %s and %s are not equal.", \
00190             #NAME1, #NAME2); \
00191     return(RVAL); \
00192 }
00193 
00194 // Return an error if the arg is lies outside the supplied range.
00195 #define PS_ASSERT_FLOAT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00196 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00197     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00198             "Error: %s, %f, is out of range.  Must be between %f and %f.", \
00199             #NAME, NAME, LOWER, UPPER); \
00200     return RVAL; \
00201 }
00202 
00203 #define PS_ASSERT_DOUBLE_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00204 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00205     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00206             "Error: %s, %lf, is out of range.  Must be between %lf and %lf.", \
00207             #NAME, NAME, LOWER, UPPER); \
00208     return RVAL; \
00209 }
00210 
00211 // Return an error if the arg lies outside the supplied range
00212 #define PS_ASSERT_LONG_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \
00213 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \
00214     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
00215             "Error: %s, %lld, is out of range.", \
00216             #NAME, NAME, LOWER, UPPER); \
00217     return RVAL; \
00218 }
00219 
00220 /*****************************************************************************
00221 Macros which take a generic psLib type and determine if it is NULL, or has
00222 the wrong type.
00223 *****************************************************************************/
00224 #define PS_ASSERT_PTR_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, return RVAL)
00225 #define PS_ASSERT_GENERAL_PTR_NON_NULL(NAME, CLEANUP) \
00226 if ((NAME) == NULL) { \
00227     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00228             "Unallowable operation: %s is NULL.", \
00229             #NAME); \
00230     CLEANUP; \
00231 }
00232 
00233 #define PS_ASSERT_PTR_TYPE(NAME, TYPE, RVAL) \
00234 if ((NAME)->type.type != TYPE) { \
00235     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00236             "Unallowable operation: %s has incorrect type.", \
00237             #NAME); \
00238     return(RVAL); \
00239 }
00240 
00241 #define PS_ASSERT_PTR_DIMEN(NAME, DIMEN, RVAL) PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, return RVAL)
00242 #define PS_ASSERT_GENERAL_PTR_DIMEN(NAME, DIMEN, CLEANUP) \
00243 if ((NAME)->type.dimen != DIMEN) { \
00244     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00245             "Unallowable operation: %s has incorrect dimensionality.", \
00246             #NAME); \
00247     CLEANUP; \
00248 }
00249 
00250 #define PS_ASSERT_PTR_DIMEN_GENERAL_NOT(NAME, DIMEN, CLEANUP) \
00251 if ((NAME)->type.dimen == DIMEN) { \
00252     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00253             "Unallowable operation: %s has incorrect dimensionality.", \
00254             #NAME); \
00255     CLEANUP; \
00256 }
00257 
00258 
00259 #define PS_ASSERT_PTRS_SIZE_EQUAL(PTR1, PTR2, RVAL) \
00260 if (PTR1->n != PTR2->n) { \
00261     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00262             "ptr %s has size %d, ptr %s has size %d.", \
00263             #PTR1, PTR1->n, #PTR2, PTR2->n); \
00264     return(RVAL); \
00265 }
00266 
00267 #define PS_ASSERT_PTR_TYPE_EQUAL(PTR1, PTR2, RVAL) PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, return RVAL)
00268 #define PS_ASSERT_PTRS_TYPE_EQUAL_GENERAL(PTR1, PTR2, CLEANUP) \
00269 if (PTR1->type.type != PTR2->type.type) { \
00270     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00271             "ptr %s has type %d, ptr %s has type %d.", \
00272             #PTR1, PTR1->type.type, #PTR2, PTR2->type.type); \
00273     CLEANUP; \
00274 }
00275 
00276 
00277 /*****************************************************************************
00278     PS_VECTOR macros:
00279  *****************************************************************************/
00280 #define PS_ASSERT_VECTOR_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, return RVAL)
00281 #define PS_ASSERT_GENERAL_VECTOR_NON_NULL(NAME, CLEANUP) \
00282 if ((NAME) == NULL || (NAME)->data.U8 == NULL) { \
00283     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00284             "Unallowable operation: psVector %s or its data is NULL.", \
00285             #NAME); \
00286     CLEANUP; \
00287 } \
00288 
00289 #define PS_ASSERT_VECTOR_NON_EMPTY(NAME, RVAL) PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, return RVAL)
00290 #define PS_ASSERT_GENERAL_VECTOR_NON_EMPTY(NAME, CLEANUP) \
00291 if ((NAME)->n < 1) { \
00292     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00293             "Unallowable operation: psVector %s has no elements.", \
00294             #NAME); \
00295     CLEANUP; \
00296 } \
00297 
00298 #define PS_ASSERT_VECTOR_TYPE_F32_OR_F64(NAME, RVAL) \
00299 if (((NAME)->type.type != PS_TYPE_F32) && ((NAME)->type.type != PS_TYPE_F64)) { \
00300     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00301             "psVector %s: bad type(%d)", \
00302             #NAME, NAME->type.type); \
00303     return(RVAL); \
00304 } \
00305 
00306 #define PS_ASSERT_VECTOR_TYPE_S16_S32_F32(NAME, RVAL) \
00307 if (((NAME)->type.type != PS_TYPE_S16) && ((NAME)->type.type != PS_TYPE_S32) && ((NAME)->type.type != PS_TYPE_F32)) { \
00308     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00309             "psVector %s: bad type(%d)", \
00310             #NAME, NAME->type.type); \
00311     return(RVAL); \
00312 } \
00313 
00314 #define PS_ASSERT_VECTOR_TYPE(NAME, TYPE, RVAL) \
00315 if ((NAME)->type.type != TYPE) { \
00316     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00317             "Unallowable operation: psVector %s has incorrect type.", \
00318             #NAME); \
00319     return(RVAL); \
00320 }
00321 
00322 #define PS_ASSERT_VECTORS_SIZE_EQUAL(VEC1, VEC2, RVAL) \
00323 if (VEC1->n != VEC2->n) { \
00324     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00325             "psVector %s has size %d, psVector %s has size %d.", \
00326             #VEC1, VEC1->n, #VEC2, VEC2->n); \
00327     return(RVAL); \
00328 }
00329 
00330 #define PS_ASSERT_VECTOR_SIZE(VEC, SIZE, RVAL) \
00331 if (VEC->n != SIZE) { \
00332     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00333             "psVector %s has size %d, should be %d." \
00334             #VEC, VEC->n, SIZE); \
00335     return(RVAL); \
00336 }
00337 
00338 #define PS_ASSERT_VECTOR_TYPE_EQUAL(VEC1, VEC2, RVAL) \
00339 if (VEC1->type.type != VEC2->type.type) { \
00340     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00341             "psVector %s has size %d, psVector %s has size %d.", \
00342             #VEC1, VEC1->type.type, #VEC2, VEC2->type.type); \
00343     return(RVAL); \
00344 }
00345 
00346 #define PS_VECTOR_F64_TO_F32(X64, X32) \
00347 psVector *X32 = psVectorAlloc(X64->n, PS_TYPE_F32); \
00348 for (int i=0;i<X64->n;i++) { \
00349     X32->data.F32[i] = (float) X64->data.F64[i]; \
00350 } \
00351 
00352 #define PS_VECTOR_F32_TO_F64(X32, X64) \
00353 psVector *X64 = psVectorAlloc(X32->n, PS_TYPE_F64); \
00354 for (int i=0;i<X32->n;i++) { \
00355     X64->data.F64[i] = (float) X32->data.F32[i]; \
00356 } \
00357 
00358 #define PS_VECTOR_PRINT_F32(NAME) \
00359 if (NAME != NULL) { \
00360     for (int my_i=0;my_i<(NAME)->n;my_i++) { \
00361         printf("%s->data.F32[%d] is %f\n", #NAME, my_i, (NAME)->data.F32[my_i]); \
00362     } \
00363     printf("\n"); \
00364 } else {\
00365     printf("MACRO WARNING: vector %s is NULL.\n", #NAME); \
00366 }\
00367 
00368 #define PS_VECTOR_PRINT_F64(NAME) \
00369 if (NAME != NULL) { \
00370     for (int my_i=0;my_i<(NAME)->n;my_i++) { \
00371         printf("%s->data.F64[%d] is %f\n", #NAME, my_i, (NAME)->data.F64[my_i]); \
00372     } \
00373     printf("\n"); \
00374 } else {\
00375     printf("MACRO WARNING: vector %s is NULL.\n", #NAME); \
00376 }\
00377 
00378 #define PS_VECTOR_CONVERT_F64_TO_F32_STATIC(OLD, NEW_PTR32, NEW_STATIC32) \
00379 if (OLD->type.type == PS_TYPE_F32) { \
00380     NEW_PTR32 = (psVector *) OLD; \
00381 } else if (OLD->type.type == PS_TYPE_F64) { \
00382     NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \
00383     p_psMemSetPersistent(NEW_STATIC32, true); \
00384     p_psMemSetPersistent(NEW_STATIC32->data.U8, true); \
00385     for (i=0; i < OLD->n ; i++) { \
00386         NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \
00387     } \
00388     NEW_PTR32 = NEW_STATIC32; \
00389 } \
00390 
00391 #define PS_VECTOR_CONVERT_F32_TO_F64_STATIC(OLD, NEW_PTR64, NEW_STATIC64) \
00392 if (OLD->type.type == PS_TYPE_F64) { \
00393     NEW_PTR64 = (psVector *) OLD; \
00394 } else if (OLD->type.type == PS_TYPE_F32) { \
00395     NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \
00396     p_psMemSetPersistent(NEW_STATIC64, true); \
00397     p_psMemSetPersistent(NEW_STATIC64->data.U8, true); \
00398     for (i=0; i < OLD->n ; i++) { \
00399         NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \
00400     } \
00401     NEW_PTR64 = NEW_STATIC64; \
00402 } \
00403 
00404 #define PS_VECTOR_GEN_YERR_STATIC_F32(VEC, N) \
00405 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
00406 p_psMemSetPersistent(VEC, true); \
00407 p_psMemSetPersistent(VEC->data.U8, true); \
00408 for (int i=0;i<N;i++) { \
00409     VEC->data.F32[i] = 1.0; \
00410 } \
00411 
00412 #define PS_VECTOR_GEN_YERR_STATIC_F64(VEC, N) \
00413 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
00414 p_psMemSetPersistent(VEC, true); \
00415 p_psMemSetPersistent(VEC->data.U8, true); \
00416 for (int i=0;i<N;i++) { \
00417     VEC->data.F64[i] = 1.0; \
00418 } \
00419 
00420 #define PS_VECTOR_GEN_X_INDEX_STATIC_F32(VEC, N) \
00421 VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
00422 p_psMemSetPersistent(VEC, true); \
00423 p_psMemSetPersistent(VEC->data.U8, true); \
00424 for (int i=0;i<N;i++) { \
00425     VEC->data.F32[i] = (float) i; \
00426 } \
00427 
00428 #define PS_VECTOR_GEN_X_INDEX_STATIC_F64(VEC, N) \
00429 VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
00430 p_psMemSetPersistent(VEC, true); \
00431 p_psMemSetPersistent(VEC->data.U8, true); \
00432 for (int i=0;i<N;i++) { \
00433     VEC->data.F64[i] = (float) i; \
00434 } \
00435 
00436 #define PS_VECTOR_GEN_STATIC_RECYCLED(NAME, SIZE, TYPE) \
00437 static psVector *NAME = NULL; \
00438 (NAME) = psVectorRecycle((NAME), SIZE, TYPE); \
00439 p_psMemSetPersistent((NAME), true); \
00440 p_psMemSetPersistent((NAME)->data.U8, true); \
00441 
00442 #define PS_VECTOR_DECLARE_ALLOC_STATIC(NAME, SIZE, TYPE) \
00443 static psVector *(NAME) = NULL; \
00444 if ((NAME) == NULL) { \
00445     (NAME) = psVectorAlloc(SIZE, TYPE); \
00446     p_psMemSetPersistent((NAME), true); \
00447 } \
00448 
00449 #define PS_VECTOR_SET_U8(NAME, VALUE) \
00450 for (int i = 0 ; i < (NAME)->n ; i++) { \
00451     (NAME)->data.U8[i] = VALUE; \
00452 }\
00453 
00454 #define PS_VECTOR_SET_U16(NAME, VALUE) \
00455 for (int i = 0 ; i < (NAME)->n ; i++) { \
00456     (NAME)->data.U16[i] = VALUE; \
00457 }\
00458 
00459 #define PS_VECTOR_SET_U32(NAME, VALUE) \
00460 for (int i = 0 ; i < (NAME)->n ; i++) { \
00461     (NAME)->data.U32[i] = VALUE; \
00462 }\
00463 
00464 #define PS_VECTOR_SET_U64(NAME, VALUE) \
00465 for (int i = 0 ; i < (NAME)->n ; i++) { \
00466     (NAME)->data.U64[i] = VALUE; \
00467 }\
00468 
00469 #define PS_VECTOR_SET_S8(NAME, VALUE) \
00470 for (int i = 0 ; i < (NAME)->n ; i++) { \
00471     (NAME)->data.S8[i] = VALUE; \
00472 }\
00473 
00474 #define PS_VECTOR_SET_S16(NAME, VALUE) \
00475 for (int i = 0 ; i < (NAME)->n ; i++) { \
00476     (NAME)->data.S16[i] = VALUE; \
00477 }\
00478 
00479 #define PS_VECTOR_SET_S32(NAME, VALUE) \
00480 for (int i = 0 ; i < (NAME)->n ; i++) { \
00481     (NAME)->data.S32[i] = VALUE; \
00482 }\
00483 
00484 #define PS_VECTOR_SET_S64(NAME, VALUE) \
00485 for (int i = 0 ; i < (NAME)->n ; i++) { \
00486     (NAME)->data.S64[i] = VALUE; \
00487 }\
00488 
00489 #define PS_VECTOR_SET_F64(NAME, VALUE) \
00490 for (int i = 0 ; i < (NAME)->n ; i++) { \
00491     (NAME)->data.F64[i] = VALUE; \
00492 }\
00493 
00494 #define PS_VECTOR_SET_F32(NAME, VALUE) \
00495 for (int i = 0 ; i < (NAME)->n ; i++) { \
00496     (NAME)->data.F32[i] = VALUE; \
00497 }\
00498 
00499 
00500 /*****************************************************************************
00501     PS_POLY macros:
00502 *****************************************************************************/
00503 #define PS_ASSERT_POLY_NON_NULL(NAME, RVAL) \
00504 if ((NAME) == NULL || (NAME)->coeff == NULL) { \
00505     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00506             "Unallowable operation: polynomial %s or its coeffs is NULL.", \
00507             #NAME); \
00508     return(RVAL); \
00509 } \
00510 
00511 #define PS_ASSERT_POLY_TYPE(NAME, TYPE, RVAL) \
00512 if ((NAME)->type != TYPE) { \
00513     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00514             "Unallowable operation: polynomial %s has wrong type.", #NAME); \
00515     return(RVAL); \
00516 } \
00517 
00518 // The following macros declare and allocate a static polynomial of the
00519 // specified order and type.
00520 
00521 #define PS_POLY_1D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00522 static psPolynomial1D *(NAME) = NULL; \
00523 if ((NAME) == NULL) { \
00524     (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
00525     p_psMemSetPersistent((NAME), true); \
00526     p_psMemSetPersistent((NAME)->coeff, true); \
00527     p_psMemSetPersistent((NAME)->coeffErr, true); \
00528     p_psMemSetPersistent((NAME)->mask, true); \
00529 } \
00530 
00531 #define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00532 static psPolynomial2D *(NAME) = NULL; \
00533 if ((NAME) == NULL) { \
00534     (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
00535     p_psMemSetPersistent((NAME), true); \
00536 } \
00537 
00538 #define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00539 static psPolynomial3D *(NAME) = NULL; \
00540 if ((NAME) == NULL) { \
00541     (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
00542     p_psMemSetPersistent((NAME), true); \
00543 } \
00544 
00545 #define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00546 static psPolynomial4D *(NAME) = NULL; \
00547 if ((NAME) == NULL) { \
00548     (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
00549     p_psMemSetPersistent((NAME), true); \
00550 } \
00551 
00552 #define PS_POLY_1D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00553 static psPolynomial1D *(NAME) = NULL; \
00554 if ((NAME) == NULL) { \
00555     (NAME) = psPolynomial1DAlloc(ORDER, TYPE); \
00556     p_psMemSetPersistent((NAME), true); \
00557 } \
00558 
00559 #define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00560 static psPolynomial2D *(NAME) = NULL; \
00561 if ((NAME) == NULL) { \
00562     (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \
00563     p_psMemSetPersistent((NAME), true); \
00564 } \
00565 
00566 #define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00567 static psPolynomial3D *(NAME) = NULL; \
00568 if ((NAME) == NULL) { \
00569     (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \
00570     p_psMemSetPersistent((NAME), true); \
00571 } \
00572 
00573 #define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \
00574 static psPolynomial4D *(NAME) = NULL; \
00575 if ((NAME) == NULL) { \
00576     (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \
00577     p_psMemSetPersistent((NAME), true); \
00578 } \
00579 
00580 /*****************************************************************************
00581     PS_IMAGE macros:
00582 *****************************************************************************/
00583 #define PS_ASSERT_IMAGE_NON_NULL(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, return RVAL)
00584 #define PS_ASSERT_GENERAL_IMAGE_NON_NULL(NAME, CLEANUP) \
00585 if ((NAME) == NULL || (NAME)->data.V == NULL) { \
00586     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00587             "Unallowable operation: psImage %s or its data is NULL.", \
00588             #NAME); \
00589     CLEANUP; \
00590 }
00591 
00592 #define PS_ASSERT_IMAGE_NON_EMPTY(NAME, RVAL) PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, return RVAL)
00593 #define PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(NAME, CLEANUP) \
00594 if ((NAME)->numCols < 1 || (NAME)->numRows < 1) { \
00595     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00596             "Unallowable operation: psImage %s has zero rows or columns (%dx%d).", \
00597             #NAME, (NAME)->numCols, (NAME)->numRows); \
00598     CLEANUP; \
00599 }
00600 
00601 #define PS_ASSERT_IMAGE_TYPE(NAME, TYPE, RVAL) \
00602 if ((NAME)->type.type != TYPE) { \
00603     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00604             "Unallowable operation: psImage %s has incorrect type.", \
00605             #NAME); \
00606     return(RVAL); \
00607 }
00608 
00609 #define PS_ASSERT_IMAGES_SIZE_EQUAL(NAME1, NAME2, RVAL) \
00610 if (((NAME1)->numCols != (NAME2)->numCols) || \
00611         ((NAME1)->numRows != (NAME2)->numRows)) { \
00612     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00613             "Unallowable operation: psImages %s and %s are not the same size.", \
00614             #NAME1, #NAME2); \
00615     return(RVAL); \
00616 }
00617 
00618 #define PS_ASSERT_IMAGE_SIZE(NAME1, NUM_COLS, NUM_ROWS, RVAL) \
00619 if (((NAME1)->numCols != NUM_COLS) || \
00620         ((NAME1)->numRows != NUM_ROWS)) { \
00621     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00622             "Unallowable operation: psImages %s is not the correct size.", \
00623             #NAME1); \
00624     return(RVAL); \
00625 }
00626 
00627 #define PS_IMAGE_PRINT_F32(NAME) \
00628 printf("======== printing %s ========\n", #NAME); \
00629 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00630     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00631         printf("%.2f ", (NAME)->data.F32[i][j]); \
00632     } \
00633     printf("\n"); \
00634 }\
00635 
00636 #define PS_IMAGE_PRINT_F64(NAME) \
00637 printf("======== printing %s ========\n", #NAME); \
00638 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00639     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00640         printf("%.2f ", (NAME)->data.F64[i][j]); \
00641     } \
00642     printf("\n"); \
00643 }\
00644 
00645 #define PS_IMAGE_SET_U8(NAME, VALUE) \
00646 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00647     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00648         (NAME)->data.U8[i][j] = (VALUE); \
00649     } \
00650 }\
00651 
00652 #define PS_IMAGE_SET_U16(NAME, VALUE) \
00653 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00654     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00655         (NAME)->data.U16[i][j] = (VALUE); \
00656     } \
00657 }\
00658 
00659 #define PS_IMAGE_SET_U32(NAME, VALUE) \
00660 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00661     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00662         (NAME)->data.U32[i][j] = (VALUE); \
00663     } \
00664 }\
00665 
00666 #define PS_IMAGE_SET_U64(NAME, VALUE) \
00667 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00668     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00669         (NAME)->data.U64[i][j] = (VALUE); \
00670     } \
00671 }\
00672 
00673 #define PS_IMAGE_SET_S8(NAME, VALUE) \
00674 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00675     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00676         (NAME)->data.S8[i][j] = (VALUE); \
00677     } \
00678 }\
00679 
00680 #define PS_IMAGE_SET_S16(NAME, VALUE) \
00681 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00682     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00683         (NAME)->data.S16[i][j] = (VALUE); \
00684     } \
00685 }\
00686 
00687 #define PS_IMAGE_SET_S32(NAME, VALUE) \
00688 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00689     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00690         (NAME)->data.S32[i][j] = (VALUE); \
00691     } \
00692 }\
00693 
00694 #define PS_IMAGE_SET_S64(NAME, VALUE) \
00695 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00696     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00697         (NAME)->data.S64[i][j] = (VALUE); \
00698     } \
00699 }\
00700 
00701 #define PS_IMAGE_SET_F32(NAME, VALUE) \
00702 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00703     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00704         (NAME)->data.F32[i][j] = (VALUE); \
00705     } \
00706 }\
00707 
00708 #define PS_IMAGE_SET_F64(NAME, VALUE) \
00709 for (int i = 0 ; i < (NAME)->numRows ; i++) { \
00710     for (int j = 0 ; j < (NAME)->numCols ; j++) { \
00711         (NAME)->data.F64[i][j] = (VALUE); \
00712     } \
00713 }\
00714 
00715 /*****************************************************************************
00716     PS_READOUT macros:
00717 *****************************************************************************/
00718 #define PS_ASSERT_READOUT_NON_NULL(NAME, RVAL) \
00719 if ((NAME) == NULL || (NAME)->image == NULL) { \
00720     psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00721             "Unallowable operation: psReadout %s or its data is NULL.", \
00722             #NAME); \
00723     return(RVAL); \
00724 }
00725 
00726 #define PS_ASSERT_READOUT_NON_EMPTY(NAME, RVAL) \
00727 if ((NAME)->image->numCols < 1 || (NAME)->image->numRows < 1) { \
00728     psError(PS_ERR_BAD_PARAMETER_SIZE, true, \
00729             "Unallowable operation: psReadout %s or its data is NULL.", #NAME); \
00730     return(RVAL); \
00731 }
00732 
00733 #define PS_ASSERT_READOUT_TYPE(NAME, TYPE, RVAL) \
00734 if ((NAME)->image->type.type != TYPE) { \
00735     psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00736             "Unallowable operation: psImage %s has incorrect type.", #NAME); \
00737     return(RVAL); \
00738 }
00739 
00740 /*****************************************************************************
00741     Misc. macros:
00742  *****************************************************************************/
00743 #define PS_MAX(A, B) \
00744 (((A) > (B)) ? (A) : (B))
00745 
00746 #define PS_MIN(A, B) \
00747 (((A) < (B)) ? (A) : (B))
00748 
00749 #define PS_SQR(A) \
00750 ((A) * (A))
00751 
00752 # define PS_SWAP(X,Y) {double tmp=(X); (X) = (Y); (Y) = tmp;}

Generated on Wed Sep 14 10:42:48 2005 for Pan-STARRS Foundation Library by  doxygen 1.4.2