1 /** \file nifti1_io.h
2     \brief Data structures for using nifti1_io API.
3            - Written by Bob Cox, SSCC NIMH
4            - Revisions by Rick Reynolds, SSCC NIMH
5  */
6 #ifndef _NIFTI_IO_HEADER_
7 #define _NIFTI_IO_HEADER_
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <math.h>
13 #include <ctype.h>
14 
15 #ifndef DONT_INCLUDE_ANALYZE_STRUCT
16 #define DONT_INCLUDE_ANALYZE_STRUCT  /*** not needed herein ***/
17 #endif
18 #include "nifti1.h"                  /*** NIFTI-1 header specification ***/
19 
20 #include <znzlib.h>
21 
22 /*=================*/
23 #ifdef  __cplusplus
24 extern "C" {
25 #endif
26 /*=================*/
27 
28 /*****===================================================================*****/
29 /*****         File nifti1_io.h == Declarations for nifti1_io.c          *****/
30 /*****...................................................................*****/
31 /*****            This code is released to the public domain.            *****/
32 /*****...................................................................*****/
33 /*****  Author: Robert W Cox, SSCC/DIRP/NIMH/NIH/DHHS/USA/EARTH          *****/
34 /*****  Date:   August 2003                                              *****/
35 /*****...................................................................*****/
36 /*****  Neither the National Institutes of Health (NIH), nor any of its  *****/
37 /*****  employees imply any warranty of usefulness of this software for  *****/
38 /*****  any purpose, and do not assume any liability for damages,        *****/
39 /*****  incidental or otherwise, caused by any use of this document.     *****/
40 /*****===================================================================*****/
41 
42 /*
43    Modified by: Mark Jenkinson (FMRIB Centre, University of Oxford, UK)
44    Date: July/August 2004
45 
46       Mainly adding low-level IO and changing things to allow gzipped files
47       to be read and written
48       Full backwards compatability should have been maintained
49 
50    Modified by: Rick Reynolds (SSCC/DIRP/NIMH, National Institutes of Health)
51    Date: December 2004
52 
53       Modified and added many routines for I/O.
54 */
55 
56 /********************** Some sample data structures **************************/
57 
58 typedef struct {                   /** 4x4 matrix struct **/
59   float m[4][4] ;
60 } mat44 ;
61 
62 typedef struct {                   /** 3x3 matrix struct **/
63   float m[3][3] ;
64 } mat33 ;
65 
66 /*...........................................................................*/
67 
68 /*! \enum analyze_75_orient_code
69  *  \brief Old-style analyze75 orientation
70  *         codes.
71  */
72 typedef enum _analyze75_orient_code {
73   a75_transverse_unflipped = 0,
74   a75_coronal_unflipped = 1,
75   a75_sagittal_unflipped = 2,
76   a75_transverse_flipped = 3,
77   a75_coronal_flipped = 4,
78   a75_sagittal_flipped = 5,
79   a75_orient_unknown = 6
80 } analyze_75_orient_code;
81 
82 /*! \struct nifti_image
83     \brief High level data structure for open nifti datasets in the
84            nifti1_io API.  Note that this structure is not part of the
85            nifti1 format definition; it is used to implement one API
86            for reading/writing formats in the nifti1 format.
87  */
88 typedef struct {                /*!< Image storage struct **/
89 
90   int ndim ;                    /*!< last dimension greater than 1 (1..7) */
91   int nx ;                      /*!< dimensions of grid array             */
92   int ny ;                      /*!< dimensions of grid array             */
93   int nz ;                      /*!< dimensions of grid array             */
94   int nt ;                      /*!< dimensions of grid array             */
95   int nu ;                      /*!< dimensions of grid array             */
96   int nv ;                      /*!< dimensions of grid array             */
97   int nw ;                      /*!< dimensions of grid array             */
98   int dim[8] ;                  /*!< dim[0]=ndim, dim[1]=nx, etc.         */
99   size_t nvox ;                    /*!< number of voxels = nx*ny*nz*...*nw   */
100   int nbyper ;                  /*!< bytes per voxel, matches datatype    */
101   int datatype ;                /*!< type of data in voxels: DT_* code    */
102 
103   float dx ;                    /*!< grid spacings      */
104   float dy ;                    /*!< grid spacings      */
105   float dz ;                    /*!< grid spacings      */
106   float dt ;                    /*!< grid spacings      */
107   float du ;                    /*!< grid spacings      */
108   float dv ;                    /*!< grid spacings      */
109   float dw ;                    /*!< grid spacings      */
110   float pixdim[8] ;             /*!< pixdim[1]=dx, etc. */
111 
112   float scl_slope ;             /*!< scaling parameter - slope        */
113   float scl_inter ;             /*!< scaling parameter - intercept    */
114 
115   float cal_min ;               /*!< calibration parameter, minimum   */
116   float cal_max ;               /*!< calibration parameter, maximum   */
117 
118   int qform_code ;              /*!< codes for (x,y,z) space meaning  */
119   int sform_code ;              /*!< codes for (x,y,z) space meaning  */
120 
121   int freq_dim  ;               /*!< indexes (1,2,3, or 0) for MRI    */
122   int phase_dim ;               /*!< directions in dim[]/pixdim[]     */
123   int slice_dim ;               /*!< directions in dim[]/pixdim[]     */
124 
125   int   slice_code  ;           /*!< code for slice timing pattern    */
126   int   slice_start ;           /*!< index for start of slices        */
127   int   slice_end   ;           /*!< index for end of slices          */
128   float slice_duration ;        /*!< time between individual slices   */
129 
130   /*! quaternion transform parameters
131     [when writing a dataset, these are used for qform, NOT qto_xyz]   */
132   float quatern_b , quatern_c , quatern_d ,
133         qoffset_x , qoffset_y , qoffset_z ,
134         qfac      ;
135 
136   mat44 qto_xyz ;               /*!< qform: transform (i,j,k) to (x,y,z) */
137   mat44 qto_ijk ;               /*!< qform: transform (x,y,z) to (i,j,k) */
138 
139   mat44 sto_xyz ;               /*!< sform: transform (i,j,k) to (x,y,z) */
140   mat44 sto_ijk ;               /*!< sform: transform (x,y,z) to (i,j,k) */
141 
142   float toffset ;               /*!< time coordinate offset */
143 
144   int xyz_units  ;              /*!< dx,dy,dz units: NIFTI_UNITS_* code  */
145   int time_units ;              /*!< dt       units: NIFTI_UNITS_* code  */
146 
147   int nifti_type ;              /*!< 0==ANALYZE, 1==NIFTI-1 (1 file),
148                                                  2==NIFTI-1 (2 files),
149                                                  3==NIFTI-ASCII (1 file) */
150   int   intent_code ;           /*!< statistic type (or something)       */
151   float intent_p1 ;             /*!< intent parameters                   */
152   float intent_p2 ;             /*!< intent parameters                   */
153   float intent_p3 ;             /*!< intent parameters                   */
154   char  intent_name[16] ;       /*!< optional description of intent data */
155 
156   char descrip[80]  ;           /*!< optional text to describe dataset   */
157   char aux_file[24] ;           /*!< auxiliary filename                  */
158 
159   char *fname ;                 /*!< header filename (.hdr or .nii)         */
160   char *iname ;                 /*!< image filename  (.img or .nii)         */
161   int   iname_offset ;          /*!< offset into iname where data starts    */
162   int   swapsize ;              /*!< swap unit in image data (might be 0)   */
163   int   byteorder ;             /*!< byte order on disk (MSB_ or LSB_FIRST) */
164   void *data ;                  /*!< pointer to data: nbyper*nvox bytes     */
165 
166   int                num_ext ;  /*!< number of extensions in ext_list       */
167   nifti1_extension * ext_list ; /*!< array of extension structs (with data) */
168   analyze_75_orient_code analyze75_orient; /*!< for old analyze files, orient */
169 
170 } nifti_image ;
171 
172 
173 
174 /* struct for return from nifti_image_read_bricks() */
175 typedef struct {
176   int       nbricks;    /* the number of allocated pointers in 'bricks' */
177   size_t    bsize;      /* the length of each data block, in bytes      */
178   void   ** bricks;     /* array of pointers to data blocks             */
179 } nifti_brick_list;
180 
181 
182 /*****************************************************************************/
183 /*------------------ NIfTI version of ANALYZE 7.5 structure -----------------*/
184 
185 /* (based on fsliolib/dbh.h, but updated for version 7.5) */
186 
187 typedef struct {
188        /* header info fields - describes the header    overlap with NIfTI */
189        /*                                              ------------------ */
190        int sizeof_hdr;                  /* 0 + 4        same              */
191        char data_type[10];              /* 4 + 10       same              */
192        char db_name[18];                /* 14 + 18      same              */
193        int extents;                     /* 32 + 4       same              */
194        short int session_error;         /* 36 + 2       same              */
195        char regular;                    /* 38 + 1       same              */
196        char hkey_un0;                   /* 39 + 1                40 bytes */
197 
198        /* image dimension fields - describes image sizes */
199        short int dim[8];                /* 0 + 16       same              */
200        short int unused8;               /* 16 + 2       intent_p1...      */
201        short int unused9;               /* 18 + 2         ...             */
202        short int unused10;              /* 20 + 2       intent_p2...      */
203        short int unused11;              /* 22 + 2         ...             */
204        short int unused12;              /* 24 + 2       intent_p3...      */
205        short int unused13;              /* 26 + 2         ...             */
206        short int unused14;              /* 28 + 2       intent_code       */
207        short int datatype;              /* 30 + 2       same              */
208        short int bitpix;                /* 32 + 2       same              */
209        short int dim_un0;               /* 34 + 2       slice_start       */
210        float pixdim[8];                 /* 36 + 32      same              */
211 
212        float vox_offset;                /* 68 + 4       same              */
213        float funused1;                  /* 72 + 4       scl_slope         */
214        float funused2;                  /* 76 + 4       scl_inter         */
215        float funused3;                  /* 80 + 4       slice_end,        */
216                                                      /* slice_code,       */
217                                                      /* xyzt_units        */
218        float cal_max;                   /* 84 + 4       same              */
219        float cal_min;                   /* 88 + 4       same              */
220        float compressed;                /* 92 + 4       slice_duration    */
221        float verified;                  /* 96 + 4       toffset           */
222        int glmax,glmin;                 /* 100 + 8              108 bytes */
223 
224        /* data history fields - optional */
225        char descrip[80];                /* 0 + 80       same              */
226        char aux_file[24];               /* 80 + 24      same              */
227        char orient;                     /* 104 + 1      NO GOOD OVERLAP   */
228        char originator[10];             /* 105 + 10     FROM HERE DOWN... */
229        char generated[10];              /* 115 + 10                       */
230        char scannum[10];                /* 125 + 10                       */
231        char patient_id[10];             /* 135 + 10                       */
232        char exp_date[10];               /* 145 + 10                       */
233        char exp_time[10];               /* 155 + 10                       */
234        char hist_un0[3];                /* 165 + 3                        */
235        int views;                       /* 168 + 4                        */
236        int vols_added;                  /* 172 + 4                        */
237        int start_field;                 /* 176 + 4                        */
238        int field_skip;                  /* 180 + 4                        */
239        int omax, omin;                  /* 184 + 8                        */
240        int smax, smin;                  /* 192 + 8              200 bytes */
241 } nifti_analyze75;                                   /* total:  348 bytes */
242 
243 
244 /*****************************************************************************/
245 /*--------------- Prototypes of functions defined in this file --------------*/
246 
247 char *nifti_datatype_string   ( int dt ) ;
248 char *nifti_units_string      ( int uu ) ;
249 char *nifti_intent_string     ( int ii ) ;
250 char *nifti_xform_string      ( int xx ) ;
251 char *nifti_slice_string      ( int ss ) ;
252 char *nifti_orientation_string( int ii ) ;
253 
254 int   nifti_is_inttype( int dt ) ;
255 
256 mat44 nifti_mat44_inverse( mat44 R ) ;
257 
258 mat33 nifti_mat33_inverse( mat33 R ) ;
259 mat33 nifti_mat33_polar  ( mat33 A ) ;
260 float nifti_mat33_rownorm( mat33 A ) ;
261 float nifti_mat33_colnorm( mat33 A ) ;
262 float nifti_mat33_determ ( mat33 R ) ;
263 mat33 nifti_mat33_mul    ( mat33 A , mat33 B ) ;
264 
265 void  nifti_swap_2bytes ( size_t n , void *ar ) ;
266 void  nifti_swap_4bytes ( size_t n , void *ar ) ;
267 void  nifti_swap_8bytes ( size_t n , void *ar ) ;
268 void  nifti_swap_16bytes( size_t n , void *ar ) ;
269 void  nifti_swap_Nbytes ( size_t n , int siz , void *ar ) ;
270 
271 int    nifti_datatype_is_valid   (int dtype, int for_nifti);
272 int    nifti_datatype_from_string(const char * name);
273 char * nifti_datatype_to_string  (int dtype);
274 
275 int   nifti_get_filesize( const char *pathname ) ;
276 void  swap_nifti_header ( struct nifti_1_header *h , int is_nifti ) ;
277 void  old_swap_nifti_header( struct nifti_1_header *h , int is_nifti );
278 int   nifti_swap_as_analyze( nifti_analyze75 *h );
279 
280 
281 /* main read/write routines */
282 
283 nifti_image *nifti_image_read_bricks(const char *hname , int nbricks,
284                                      const int *blist, nifti_brick_list * NBL);
285 int          nifti_image_load_bricks(nifti_image *nim , int nbricks,
286                                      const int *blist, nifti_brick_list * NBL);
287 void         nifti_free_NBL( nifti_brick_list * NBL );
288 
289 nifti_image *nifti_image_read    ( const char *hname , int read_data ) ;
290 int          nifti_image_load    ( nifti_image *nim ) ;
291 void         nifti_image_unload  ( nifti_image *nim ) ;
292 void         nifti_image_free    ( nifti_image *nim ) ;
293 
294 int          nifti_read_collapsed_image( nifti_image * nim, const int dims [8],
295                                          void ** data );
296 
297 int          nifti_read_subregion_image( nifti_image * nim,
298                                          int *start_index, int *region_size,
299                                          void ** data );
300 
301 void         nifti_image_write   ( nifti_image * nim ) ;
302 void         nifti_image_write_bricks(nifti_image * nim,
303                                       const nifti_brick_list * NBL);
304 void         nifti_image_infodump( const nifti_image * nim ) ;
305 
306 void         nifti_disp_lib_hist( void ) ;     /* to display library history */
307 void         nifti_disp_lib_version( void ) ;  /* to display library version */
308 int          nifti_disp_matrix_orient( const char * mesg, mat44 mat );
309 int          nifti_disp_type_list( int which );
310 
311 
312 char *       nifti_image_to_ascii  ( const nifti_image * nim ) ;
313 nifti_image *nifti_image_from_ascii( const char * str, int * bytes_read ) ;
314 
315 size_t       nifti_get_volsize(const nifti_image *nim) ;
316 
317 /* basic file operations */
318 int    nifti_set_filenames(nifti_image * nim, const char * prefix, int check,
319                            int set_byte_order);
320 char * nifti_makehdrname  (const char * prefix, int nifti_type, int check,
321                            int comp);
322 char * nifti_makeimgname  (const char * prefix, int nifti_type, int check,
323                            int comp);
324 int    is_nifti_file      (const char *hname);
325 char * nifti_find_file_extension(const char * name);
326 int    nifti_is_complete_filename(const char* fname);
327 int    nifti_validfilename(const char* fname);
328 
329 int    disp_nifti_1_header(const char * info, const nifti_1_header * hp ) ;
330 void   nifti_set_debug_level( int level ) ;
331 void   nifti_set_skip_blank_ext( int skip ) ;
332 void   nifti_set_allow_upper_fext( int allow ) ;
333 
334 int    valid_nifti_brick_list(nifti_image * nim , int nbricks,
335                               const int * blist, int disp_error);
336 
337 /* znzFile operations */
338 znzFile nifti_image_open(const char * hname, char * opts, nifti_image ** nim);
339 znzFile nifti_image_write_hdr_img(nifti_image *nim, int write_data,
340                                   const char* opts);
341 znzFile nifti_image_write_hdr_img2( nifti_image *nim , int write_opts ,
342                const char* opts, znzFile imgfile, const nifti_brick_list * NBL);
343 size_t  nifti_read_buffer(znzFile fp, void* datatptr, size_t ntot,
344                          nifti_image *nim);
345 int     nifti_write_all_data(znzFile fp, nifti_image * nim,
346                              const nifti_brick_list * NBL);
347 size_t  nifti_write_buffer(znzFile fp, const void * buffer, size_t numbytes);
348 nifti_image *nifti_read_ascii_image(znzFile fp, char *fname, int flen,
349                          int read_data);
350 znzFile nifti_write_ascii_image(nifti_image *nim, const nifti_brick_list * NBL,
351                          const char * opts, int write_data, int leave_open);
352 
353 
354 void nifti_datatype_sizes( int datatype , int *nbyper, int *swapsize ) ;
355 
356 void nifti_mat44_to_quatern( mat44 R ,
357                              float *qb, float *qc, float *qd,
358                              float *qx, float *qy, float *qz,
359                              float *dx, float *dy, float *dz, float *qfac ) ;
360 
361 mat44 nifti_quatern_to_mat44( float qb, float qc, float qd,
362                               float qx, float qy, float qz,
363                               float dx, float dy, float dz, float qfac );
364 
365 mat44 nifti_make_orthog_mat44( float r11, float r12, float r13 ,
366                                float r21, float r22, float r23 ,
367                                float r31, float r32, float r33  ) ;
368 
369 int nifti_short_order(void) ;              /* CPU byte order */
370 
371 
372 /* Orientation codes that might be returned from nifti_mat44_to_orientation().*/
373 
374 #define NIFTI_L2R  1    /* Left to Right         */
375 #define NIFTI_R2L  2    /* Right to Left         */
376 #define NIFTI_P2A  3    /* Posterior to Anterior */
377 #define NIFTI_A2P  4    /* Anterior to Posterior */
378 #define NIFTI_I2S  5    /* Inferior to Superior  */
379 #define NIFTI_S2I  6    /* Superior to Inferior  */
380 
381 void nifti_mat44_to_orientation( mat44 R , int *icod, int *jcod, int *kcod ) ;
382 
383 /*--------------------- Low level IO routines ------------------------------*/
384 
385 char * nifti_findhdrname (const char* fname);
386 char * nifti_findimgname (const char* fname , int nifti_type);
387 int    nifti_is_gzfile   (const char* fname);
388 
389 char * nifti_makebasename(const char* fname);
390 
391 
392 /* other routines */
393 struct nifti_1_header   nifti_convert_nim2nhdr(const nifti_image* nim);
394 nifti_1_header * nifti_make_new_header(const int arg_dims[], int arg_dtype);
395 nifti_1_header * nifti_read_header(const char *hname, int *swapped, int check);
396 nifti_image    * nifti_copy_nim_info(const nifti_image * src);
397 nifti_image    * nifti_make_new_nim(const int dims[], int datatype,
398                                                       int data_fill);
399 nifti_image    * nifti_simple_init_nim(void);
400 nifti_image    * nifti_convert_nhdr2nim(struct nifti_1_header nhdr,
401                                         const char * fname);
402 
403 int    nifti_hdr_looks_good        (const nifti_1_header * hdr);
404 int    nifti_is_valid_datatype     (int dtype);
405 int    nifti_is_valid_ecode        (int ecode);
406 int    nifti_nim_is_valid          (nifti_image * nim, int complain);
407 int    nifti_nim_has_valid_dims    (nifti_image * nim, int complain);
408 int    is_valid_nifti_type         (int nifti_type);
409 int    nifti_test_datatype_sizes   (int verb);
410 int    nifti_type_and_names_match  (nifti_image * nim, int show_warn);
411 int    nifti_update_dims_from_array(nifti_image * nim);
412 void   nifti_set_iname_offset      (nifti_image *nim);
413 int    nifti_set_type_from_names   (nifti_image * nim);
414 int    nifti_add_extension(nifti_image * nim, const char * data, int len,
415                            int ecode );
416 int    nifti_compiled_with_zlib    (void);
417 int    nifti_copy_extensions (nifti_image *nim_dest,const nifti_image *nim_src);
418 int    nifti_free_extensions (nifti_image *nim);
419 int  * nifti_get_intlist     (int nvals , const char *str);
420 char * nifti_strdup          (const char *str);
421 int    valid_nifti_extensions(const nifti_image *nim);
422 
423 
424 /*-------------------- Some C convenience macros ----------------------------*/
425 
426 /* NIfTI-1.1 extension codes:
427    see http://nifti.nimh.nih.gov/nifti-1/documentation/faq#Q21 */
428 
429 #define NIFTI_ECODE_IGNORE           0  /* changed from UNKNOWN, 29 June 2005 */
430 
431 #define NIFTI_ECODE_DICOM            2  /* intended for raw DICOM attributes  */
432 
433 #define NIFTI_ECODE_AFNI             4  /* Robert W Cox: rwcox@nih.gov
434                                            http://afni.nimh.nih.gov/afni      */
435 
436 #define NIFTI_ECODE_COMMENT          6  /* plain ASCII text only              */
437 
438 #define NIFTI_ECODE_XCEDE            8  /* David B Keator: dbkeator@uci.edu
439                                            http://www.nbirn.net/Resources
440                                                 /Users/Applications/
441                                                 /xcede/index.htm              */
442 
443 #define NIFTI_ECODE_JIMDIMINFO      10  /* Mark A Horsfield:
444                                            mah5@leicester.ac.uk
445                                            http://someplace/something         */
446 
447 #define NIFTI_ECODE_WORKFLOW_FWDS   12  /* Kate Fissell: fissell@pitt.edu
448                                            http://kraepelin.wpic.pitt.edu
449                                             /~fissell/NIFTI_ECODE_WORKFLOW_FWDS
450                                             /NIFTI_ECODE_WORKFLOW_FWDS.html   */
451 
452 #define NIFTI_ECODE_FREESURFER      14  /* http://surfer.nmr.mgh.harvard.edu  */
453 
454 #define NIFTI_ECODE_PYPICKLE        16  /* embedded Python objects
455                                            http://niftilib.sourceforge.net
456                                                  /pynifti                     */
457 
458         /* LONI MiND codes: http://www.loni.ucla.edu/twiki/bin/view/Main/MiND */
459 #define NIFTI_ECODE_MIND_IDENT      18  /* Vishal Patel: vishal.patel@ucla.edu*/
460 #define NIFTI_ECODE_B_VALUE         20
461 #define NIFTI_ECODE_SPHERICAL_DIRECTION 22
462 #define NIFTI_ECODE_DT_COMPONENT    24
463 #define NIFTI_ECODE_SHC_DEGREEORDER 26  /* end LONI MiND codes                */
464 
465 #define NIFTI_ECODE_VOXBO           28  /* Dan Kimberg: www.voxbo.org         */
466 
467 #define NIFTI_ECODE_CARET           30  /* John Harwell: john@brainvis.wustl.edu
468                                            http://brainvis.wustl.edu/wiki
469                                              /index.php/Caret:Documentation
470                                              :CaretNiftiExtension             */
471 
472 #define NIFTI_MAX_ECODE             30  /******* maximum extension code *******/
473 
474 /* nifti_type file codes */
475 #define NIFTI_FTYPE_ANALYZE   0
476 #define NIFTI_FTYPE_NIFTI1_1  1
477 #define NIFTI_FTYPE_NIFTI1_2  2
478 #define NIFTI_FTYPE_ASCII     3
479 #define NIFTI_MAX_FTYPE       3    /* this should match the maximum code */
480 
481 /*------------------------------------------------------------------------*/
482 /*-- the rest of these apply only to nifti1_io.c, check for _NIFTI1_IO_C_ */
483 /*                                                    Feb 9, 2005 [rickr] */
484 #ifdef _NIFTI1_IO_C_
485 
486 typedef struct {
487     int debug;               /*!< debug level for status reports  */
488     int skip_blank_ext;      /*!< skip extender if no extensions  */
489     int allow_upper_fext;    /*!< allow uppercase file extensions */
490 } nifti_global_options;
491 
492 typedef struct {
493     int    type;           /* should match the NIFTI_TYPE_ #define */
494     int    nbyper;         /* bytes per value, matches nifti_image */
495     int    swapsize;       /* bytes per swap piece, matches nifti_image */
496     char * name;           /* text string to match #define */
497 } nifti_type_ele;
498 
499 #undef  LNI_FERR /* local nifti file error, to be compact and repetative */
500 #define LNI_FERR(func,msg,file)                                      \
501             fprintf(stderr,"** ERROR (%s): %s '%s'\n",func,msg,file)
502 
503 #undef  swap_2
504 #undef  swap_4
505 #define swap_2(s) nifti_swap_2bytes(1,&(s)) /* s: 2-byte short; swap in place */
506 #define swap_4(v) nifti_swap_4bytes(1,&(v)) /* v: 4-byte value; swap in place */
507 
508                         /***** isfinite() is a C99 macro, which is
509                                present in many C implementations already *****/
510 
511 #undef IS_GOOD_FLOAT
512 #undef FIXED_FLOAT
513 
514 #ifdef isfinite       /* use isfinite() to check floats/doubles for goodness */
515 #  define IS_GOOD_FLOAT(x) isfinite(x)       /* check if x is a "good" float */
516 #  define FIXED_FLOAT(x)   (isfinite(x) ? (x) : 0)           /* fixed if bad */
517 #else
518 #  define IS_GOOD_FLOAT(x) 1                               /* don't check it */
519 #  define FIXED_FLOAT(x)   (x)                               /* don't fix it */
520 #endif
521 
522 #undef  ASSIF                                 /* assign v to *p, if possible */
523 #define ASSIF(p,v) if( (p)!=NULL ) *(p) = (v)
524 
525 #undef  MSB_FIRST
526 #undef  LSB_FIRST
527 #undef  REVERSE_ORDER
528 #define LSB_FIRST 1
529 #define MSB_FIRST 2
530 #define REVERSE_ORDER(x) (3-(x))    /* convert MSB_FIRST <--> LSB_FIRST */
531 
532 #define LNI_MAX_NIA_EXT_LEN 100000  /* consider a longer extension invalid */
533 
534 #endif  /* _NIFTI1_IO_C_ section */
535 /*------------------------------------------------------------------------*/
536 
537 /*=================*/
538 #ifdef  __cplusplus
539 }
540 #endif
541 /*=================*/
542 
543 #endif /* _NIFTI_IO_HEADER_ */
544