1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
#ifndef MINC_BASIC_H
#define MINC_BASIC_H
/* ----------------------------- MNI Header -----------------------------------
@NAME : minc_basic.h
@INPUT :
@OUTPUT :
@RETURNS :
@DESCRIPTION: Constants and macros for private use by MINC routines.
@METHOD :
@GLOBALS :
@CALLS :
@CREATED : August 28, 1992 (Peter Neelin)
@MODIFIED :
* $Log: minc_basic.h,v $
* Revision 6.8 2010-03-27 15:09:28 rotor
* * back to 1000000
*
* Revision 6.7 2010-03-02 12:23:14 rotor
* * ported HDF calls to 1.8.x
* * Makefile.am: updated for minccmp
*
* Revision 6.6 2008/04/11 05:15:00 rotor
* * rewrote error code (Claude) to remove global defs that were
* causing build problems with DYLIB on OSX
*
* Revision 6.5 2008/01/12 01:05:37 rotor
* * initial commits from Steve to remove warnings
*
* Revision 6.4 2007/08/09 17:05:25 rotor
* * added some fixes of Claudes for chunking and internal compression
*
* Revision 6.3 2004/04/27 15:48:15 bert
* Minor changes
*
* Revision 6.2 2001/04/17 18:40:13 neelin
* Modifications to work with NetCDF 3.x
* In particular, changed NC_LONG to NC_INT (and corresponding longs to ints).
* Changed NC_UNSPECIFIED to NC_NAT.
* A few fixes to the configure script.
*
* Revision 6.1 1999/10/19 14:45:08 neelin
* Fixed Log substitutions for CVS
*
* Revision 6.0 1997/09/12 13:24:54 neelin
* Release of minc version 0.6
*
* Revision 5.0 1997/08/21 13:25:53 neelin
* Release of minc version 0.5
*
* Revision 4.0 1997/05/07 20:07:52 neelin
* Release of minc version 0.4
*
* Revision 3.0 1995/05/15 19:33:12 neelin
* Release of minc version 0.3
*
* Revision 2.0 1994/09/28 10:38:01 neelin
* Release of minc version 0.2
*
* Revision 1.8 94/09/28 10:37:26 neelin
* Pre-release
*
* Revision 1.7 93/10/28 10:18:23 neelin
* Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
*
* Revision 1.6 93/08/11 12:06:37 neelin
* Added RCS logging in source.
*
@COPYRIGHT :
Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre,
Montreal Neurological Institute, McGill University.
Permission to use, copy, modify, and distribute this
software and its documentation for any purpose and without
fee is hereby granted, provided that the above copyright
notice appear in all copies. The author and McGill University
make no representations about the suitability of this
software for any purpose. It is provided "as is" without
express or implied warranty.
@RCSID : $Header: /private-cvsroot/minc/libsrc/minc_basic.h,v 6.8 2010-03-27 15:09:28 rotor Exp $ MINC (MNI)
---------------------------------------------------------------------------- */
#include <minc.h>
/* --------- MINC specific constants ------------- */
/* Maximum buffer size for conversions. Should not be a power of 2 - this
can cause poor performance on some systems (e.g. SGI) due to caching-
related inefficiencies */
#define MI_MAX_VAR_BUFFER_SIZE 1000000
/* Possible values for sign of a value */
#define MI_PRIV_DEFSIGN 0
#define MI_PRIV_SIGNED 1
#define MI_PRIV_UNSIGNED 2
/* Operations for MI_varaccess */
#define MI_PRIV_GET 10
#define MI_PRIV_PUT 11
/* Suffix for dimension width variable names */
#define MI_WIDTH_SUFFIX "-width"
/* Epsilon for detecting fillvalues */
#define FILLVALUE_EPSILON (10.0 * FLT_EPSILON)
/* Macros for converting data types. These macros are compound statements,
so don't put a semi-colon after them. dvalue should be a double, type
is an int NetCDF type, sign is one of MI_PRIV_UNSIGNED and
MI_PRIV_SIGNED and ptr is a void pointer */
#define MI_TO_DOUBLE(dvalue, type, sign, ptr) \
switch (type) { \
case NC_BYTE : \
case NC_CHAR: \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = (double) *((unsigned char *) ptr); break; \
case MI_PRIV_SIGNED : \
dvalue = (double) *((signed char *) ptr); break; \
} \
break; \
case NC_SHORT : \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = (double) *((unsigned short *) ptr); break; \
case MI_PRIV_SIGNED : \
dvalue = (double) *((signed short *) ptr); break; \
} \
break; \
case NC_INT : \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = (double) *((unsigned int *) ptr); break; \
case MI_PRIV_SIGNED : \
dvalue = (double) *((signed int *) ptr); break; \
} \
break; \
case NC_FLOAT : \
dvalue = (double) *((float *) ptr); \
break; \
case NC_DOUBLE : \
dvalue = (double) *((double *) ptr); \
break; \
case NC_NAT : \
MI_LOG_PKG_ERROR2(MI_ERR_NONNUMERIC, \
"Attempt to convert NC_NAT value to double"); \
dvalue = 0; \
break; \
}
#define MI_FROM_DOUBLE(dvalue, type, sign, ptr) \
switch (type) { \
case NC_BYTE : \
case NC_CHAR : \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = MAX(0, dvalue); \
dvalue = MIN(UCHAR_MAX, dvalue); \
*((unsigned char *) ptr) = ROUND(dvalue); \
break; \
case MI_PRIV_SIGNED : \
dvalue = MAX(SCHAR_MIN, dvalue); \
dvalue = MIN(SCHAR_MAX, dvalue); \
*((signed char *) ptr) = ROUND(dvalue); \
break; \
} \
break; \
case NC_SHORT : \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = MAX(0, dvalue); \
dvalue = MIN(USHRT_MAX, dvalue); \
*((unsigned short *) ptr) = ROUND(dvalue); \
break; \
case MI_PRIV_SIGNED : \
dvalue = MAX(SHRT_MIN, dvalue); \
dvalue = MIN(SHRT_MAX, dvalue); \
*((signed short *) ptr) = ROUND(dvalue); \
break; \
} \
break; \
case NC_INT : \
switch (sign) { \
case MI_PRIV_UNSIGNED : \
dvalue = MAX(0, dvalue); \
dvalue = MIN(UINT_MAX, dvalue); \
*((unsigned int *) ptr) = ROUND(dvalue); \
break; \
case MI_PRIV_SIGNED : \
dvalue = MAX(INT_MIN, dvalue); \
dvalue = MIN(INT_MAX, dvalue); \
*((signed int *) ptr) = ROUND(dvalue); \
break; \
} \
break; \
case NC_FLOAT : \
dvalue = MAX(-FLT_MAX,dvalue); \
*((float *) ptr) = MIN(FLT_MAX,dvalue); \
break; \
case NC_DOUBLE : \
*((double *) ptr) = dvalue; \
break; \
case NC_NAT : \
MI_LOG_PKG_ERROR2(MI_ERR_NONNUMERIC, \
"Attempt to convert to NC_NAT from double"); \
dvalue = 0; \
break; \
}
/**/
#define _(x) x /* For future gettext */
#endif
|