Mercurial > hg > minc-tools
annotate libsrc/minc_basic.h @ 2278:380ee8551b73
Added script test.
author | baghdadi <baghdadi> |
---|---|
date | Fri, 28 Jul 2006 17:28:09 +0000 |
parents | 411f50377e67 |
children | 63bc51e187a0 |
rev | line source |
---|---|
0 | 1 |
2 #ifndef MINC_BASIC_HEADER_FILE | |
3 #define MINC_BASIC_HEADER_FILE | |
4 | |
5 /* ----------------------------- MNI Header ----------------------------------- | |
6 @NAME : minc_basic.h | |
7 @INPUT : | |
8 @OUTPUT : | |
9 @RETURNS : | |
10 @DESCRIPTION: Constants and macros for private use by MINC routines. | |
11 @METHOD : | |
12 @GLOBALS : | |
13 @CALLS : | |
14 @CREATED : August 28, 1992 (Peter Neelin) | |
1232 | 15 @MODIFIED : |
16 * $Log: minc_basic.h,v $ | |
1756 | 17 * Revision 6.3 2004-04-27 15:48:15 bert |
18 * Minor changes | |
19 * | |
20 * Revision 6.2 2001/04/17 18:40:13 neelin | |
1336 | 21 * Modifications to work with NetCDF 3.x |
22 * In particular, changed NC_LONG to NC_INT (and corresponding longs to ints). | |
23 * Changed NC_UNSPECIFIED to NC_NAT. | |
24 * A few fixes to the configure script. | |
25 * | |
26 * Revision 6.1 1999/10/19 14:45:08 neelin | |
1232 | 27 * Fixed Log subsitutions for CVS |
28 * | |
29 * Revision 6.0 1997/09/12 13:24:54 neelin | |
30 * Release of minc version 0.6 | |
31 * | |
1112 | 32 * Revision 5.0 1997/08/21 13:25:53 neelin |
33 * Release of minc version 0.5 | |
34 * | |
1094 | 35 * Revision 4.0 1997/05/07 20:07:52 neelin |
36 * Release of minc version 0.4 | |
37 * | |
1062 | 38 * Revision 3.0 1995/05/15 19:33:12 neelin |
39 * Release of minc version 0.3 | |
40 * | |
870 | 41 * Revision 2.0 1994/09/28 10:38:01 neelin |
42 * Release of minc version 0.2 | |
43 * | |
619 | 44 * Revision 1.8 94/09/28 10:37:26 neelin |
45 * Pre-release | |
46 * | |
618 | 47 * Revision 1.7 93/10/28 10:18:23 neelin |
48 * Added FILLVALUE_EPSILON for doing fillvalue checking in icv's. | |
49 * | |
416
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
50 * Revision 1.6 93/08/11 12:06:37 neelin |
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
51 * Added RCS logging in source. |
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
52 * |
247 | 53 @COPYRIGHT : |
54 Copyright 1993 Peter Neelin, McConnell Brain Imaging Centre, | |
55 Montreal Neurological Institute, McGill University. | |
56 Permission to use, copy, modify, and distribute this | |
57 software and its documentation for any purpose and without | |
58 fee is hereby granted, provided that the above copyright | |
59 notice appear in all copies. The author and McGill University | |
60 make no representations about the suitability of this | |
61 software for any purpose. It is provided "as is" without | |
62 express or implied warranty. | |
1756 | 63 @RCSID : $Header: /private-cvsroot/minc/libsrc/minc_basic.h,v 6.3 2004-04-27 15:48:15 bert Exp $ MINC (MNI) |
0 | 64 ---------------------------------------------------------------------------- */ |
65 | |
66 /* --------- MINC specific constants ------------- */ | |
67 | |
68 /* Maximum buffer size for conversions. Should not be a power of 2 - this | |
69 can cause poor performance on some systems (e.g. SGI) due to caching- | |
14 | 70 related inefficiencies */ |
0 | 71 #define MI_MAX_VAR_BUFFER_SIZE 10000 |
72 | |
73 /* Possible values for sign of a value */ | |
74 #define MI_PRIV_DEFSIGN 0 | |
75 #define MI_PRIV_SIGNED 1 | |
76 #define MI_PRIV_UNSIGNED 2 | |
77 | |
78 /* Operations for MI_varaccess */ | |
79 #define MI_PRIV_GET 10 | |
80 #define MI_PRIV_PUT 11 | |
81 | |
82 /* Suffix for dimension width variable names */ | |
83 #define MI_WIDTH_SUFFIX "-width" | |
84 | |
416
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
85 /* Epsilon for detecting fillvalues */ |
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
86 #define FILLVALUE_EPSILON (10.0 * FLT_EPSILON) |
bf610f6d6480
Added FILLVALUE_EPSILON for doing fillvalue checking in icv's.
neelin <neelin>
parents:
298
diff
changeset
|
87 |
0 | 88 /* NetCDF routine name variable (for error logging) */ |
89 extern char *cdf_routine_name ; /* defined in globdef.c */ | |
90 #define MI_NC_ROUTINE_VAR cdf_routine_name | |
91 | |
92 /* MINC routine name variable, call depth counter (for keeping track of | |
93 minc routines calling minc routines) and variable for keeping track | |
94 of callers ncopts. All of these are for error logging. They are | |
95 defined in minc_globdef.c */ | |
96 extern char *minc_routine_name; | |
97 extern int minc_call_depth; | |
98 extern int minc_trash_var; /* Just for getting rid of lint messages */ | |
99 #define MI_ROUTINE_VAR minc_routine_name | |
100 #define MI_CALL_DEPTH minc_call_depth | |
101 #define MI_TRASH_VAR minc_trash_var | |
102 | |
103 /* Macros for logging errors. All routines should start with MI_SAVE_ROUTINE | |
104 and exit with MI_RETURN (which includes MI_RETURN_ERROR and | |
105 MI_CHK_ERROR). All the macros except MI_CHK_ERROR are single line | |
106 commands. MI_CHK_ERROR is in a block and so should not be followed by | |
107 a ';' */ | |
108 #define MI_SAVE_ROUTINE_NAME(name) \ | |
109 (MI_TRASH_VAR = (((MI_CALL_DEPTH++)==0) ? \ | |
110 MI_save_routine_name(name) : MI_NOERROR)) | |
111 #define MI_RETURN(value) \ | |
112 return( (((--MI_CALL_DEPTH)!=0) || MI_return()) ? (value) : (value)) | |
113 #define MI_RETURN_ERROR(error) \ | |
114 return( (((--MI_CALL_DEPTH)!=0) || MI_return_error()) ? (error) : (error)) | |
115 #define MI_LOG_PKG_ERROR2(p1,p2) MI_log_pkg_error2(p1, p2) | |
116 #define MI_LOG_PKG_ERROR3(p1,p2,p3) MI_log_pkg_error3(p1, p2, p3) | |
117 #define MI_LOG_SYS_ERROR1(p1) MI_log_sys_error1(p1) | |
1756 | 118 #define MI_CHK_ERR(expr) {if ((expr)<0) MI_RETURN_ERROR(MI_ERROR);} |
119 | |
0 | 120 |
121 /* Macros for converting data types. These macros are compound statements, | |
122 so don't put a semi-colon after them. dvalue should be a double, type | |
123 is an int NetCDF type, sign is one of MI_PRIV_UNSIGNED and | |
124 MI_PRIV_SIGNED and ptr is a void pointer */ | |
125 | |
126 #define MI_TO_DOUBLE(dvalue, type, sign, ptr) \ | |
127 switch (type) { \ | |
128 case NC_BYTE : \ | |
129 switch (sign) { \ | |
130 case MI_PRIV_UNSIGNED : \ | |
131 dvalue = (double) *((unsigned char *) ptr); break; \ | |
132 case MI_PRIV_SIGNED : \ | |
133 dvalue = (double) *((signed char *) ptr); break; \ | |
134 } \ | |
135 break; \ | |
136 case NC_SHORT : \ | |
137 switch (sign) { \ | |
138 case MI_PRIV_UNSIGNED : \ | |
139 dvalue = (double) *((unsigned short *) ptr); break; \ | |
140 case MI_PRIV_SIGNED : \ | |
141 dvalue = (double) *((signed short *) ptr); break; \ | |
142 } \ | |
143 break; \ | |
1336 | 144 case NC_INT : \ |
0 | 145 switch (sign) { \ |
146 case MI_PRIV_UNSIGNED : \ | |
1336 | 147 dvalue = (double) *((unsigned int *) ptr); break; \ |
0 | 148 case MI_PRIV_SIGNED : \ |
1336 | 149 dvalue = (double) *((signed int *) ptr); break; \ |
0 | 150 } \ |
151 break; \ | |
152 case NC_FLOAT : \ | |
153 dvalue = (double) *((float *) ptr); \ | |
154 break; \ | |
155 case NC_DOUBLE : \ | |
156 dvalue = (double) *((double *) ptr); \ | |
157 break; \ | |
158 } | |
159 | |
160 #define MI_FROM_DOUBLE(dvalue, type, sign, ptr) \ | |
161 switch (type) { \ | |
162 case NC_BYTE : \ | |
163 switch (sign) { \ | |
164 case MI_PRIV_UNSIGNED : \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
165 dvalue = MAX(0, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
166 dvalue = MIN(UCHAR_MAX, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
167 *((unsigned char *) ptr) = ROUND(dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
168 break; \ |
0 | 169 case MI_PRIV_SIGNED : \ |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
170 dvalue = MAX(SCHAR_MIN, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
171 dvalue = MIN(SCHAR_MAX, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
172 *((signed char *) ptr) = ROUND(dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
173 break; \ |
0 | 174 } \ |
175 break; \ | |
176 case NC_SHORT : \ | |
177 switch (sign) { \ | |
178 case MI_PRIV_UNSIGNED : \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
179 dvalue = MAX(0, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
180 dvalue = MIN(USHRT_MAX, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
181 *((unsigned short *) ptr) = ROUND(dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
182 break; \ |
0 | 183 case MI_PRIV_SIGNED : \ |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
184 dvalue = MAX(SHRT_MIN, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
185 dvalue = MIN(SHRT_MAX, dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
186 *((signed short *) ptr) = ROUND(dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
187 break; \ |
0 | 188 } \ |
189 break; \ | |
1336 | 190 case NC_INT : \ |
0 | 191 switch (sign) { \ |
192 case MI_PRIV_UNSIGNED : \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
193 dvalue = MAX(0, dvalue); \ |
1336 | 194 dvalue = MIN(UINT_MAX, dvalue); \ |
195 *((unsigned int *) ptr) = ROUND(dvalue); \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
196 break; \ |
0 | 197 case MI_PRIV_SIGNED : \ |
1336 | 198 dvalue = MAX(INT_MIN, dvalue); \ |
199 dvalue = MIN(INT_MAX, dvalue); \ | |
200 *((signed int *) ptr) = ROUND(dvalue); \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
201 break; \ |
0 | 202 } \ |
203 break; \ | |
204 case NC_FLOAT : \ | |
16
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
205 dvalue = MAX(-FLT_MAX,dvalue); \ |
50217eb93c0a
Improved MI_FROM_DOUBLE to avoid problems with nested macros
neelin <neelin>
parents:
14
diff
changeset
|
206 *((float *) ptr) = MIN(FLT_MAX,dvalue); \ |
0 | 207 break; \ |
208 case NC_DOUBLE : \ | |
209 *((double *) ptr) = dvalue; \ | |
210 break; \ | |
211 } | |
212 | |
1756 | 213 /**/ |
214 #define _(x) x /* For future gettext */ | |
0 | 215 |
216 #endif |