c_nifti 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/COPYING +621 -0
- data/COPYING.lesser +166 -0
- data/Gemfile +4 -0
- data/README.md +117 -0
- data/Rakefile +6 -0
- data/c_nifti.gemspec +31 -0
- data/ext/nifticlib/extconf.rb +30 -0
- data/ext/nifticlib/include/nifti_image.h +2 -0
- data/ext/nifticlib/include/nifti_image_converters.h +3 -0
- data/ext/nifticlib/include/nifti_image_dimensions.h +1 -0
- data/ext/nifticlib/include/nifti_image_intents.h +1 -0
- data/ext/nifticlib/include/nifti_image_metadata.h +1 -0
- data/ext/nifticlib/include/nifti_image_quaternions.h +1 -0
- data/ext/nifticlib/include/nifti_image_spacings.h +1 -0
- data/ext/nifticlib/include/nifti_image_timings.h +1 -0
- data/ext/nifticlib/include/nifti_image_transforms.h +1 -0
- data/ext/nifticlib/nifti_image.c +169 -0
- data/ext/nifticlib/nifti_image_converters.c +65 -0
- data/ext/nifticlib/nifti_image_dimensions.c +113 -0
- data/ext/nifticlib/nifti_image_intents.c +45 -0
- data/ext/nifticlib/nifti_image_metadata.c +133 -0
- data/ext/nifticlib/nifti_image_quaternions.c +59 -0
- data/ext/nifticlib/nifti_image_spacings.c +87 -0
- data/ext/nifticlib/nifti_image_timings.c +66 -0
- data/ext/nifticlib/nifti_image_transforms.c +38 -0
- data/ext/nifticlib/nifticlib-2.0.0/CMakeLists.txt +140 -0
- data/ext/nifticlib/nifticlib-2.0.0/CTestConfig.cmake +13 -0
- data/ext/nifticlib/nifticlib-2.0.0/LICENSE +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Makefile +265 -0
- data/ext/nifticlib/nifticlib-2.0.0/Makefile.cross_mingw32 +94 -0
- data/ext/nifticlib/nifticlib-2.0.0/README +79 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/CMakeLists.txt +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/Data/ATestReferenceImageForReadingAndWriting.nii.gz +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/Makefile +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/README_regress +50 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@show.diffs +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@test +80 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/CMakeLists.txt +47 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/bricks_test.sh +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/comment_test.sh +65 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dci_test.sh +46 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dsets_test.sh +61 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dts_test.sh +75 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/fetch_data_test.sh +45 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/mod_header_test.sh +60 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/newfiles_test.sh +36 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c01.versions +10 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c02.nt.help +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c03.hist +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c04.disp.anat0.info +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c05.mod.hdr +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c06.add.ext +22 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c07.cbl.4bricks +8 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c08.dts.19.36.11 +4 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c09.dts4.compare +9 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10.dci.ts4 +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10a.dci.run.210 +16 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c11.add.comment +8 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c12.check.comments +7 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c13.check.hdrs +5 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c14.make.dsets +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c15.new.files +21 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c16.rand.swap +35 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c17.file.case +34 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/CMakeLists.txt +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test.c +690 -0
- data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test2.c +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/Updates.txt +110 -0
- data/ext/nifticlib/nifticlib-2.0.0/bin/.gitkeep +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/docs/Doxy_nifti.txt +123 -0
- data/ext/nifticlib/nifticlib-2.0.0/docs/Doxyfile.ORIG +746 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/CMakeLists.txt +15 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/Makefile +48 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/clib_01_read_write.c +94 -0
- data/ext/nifticlib/nifticlib-2.0.0/examples/fsl_api_driver.c +142 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/CMakeLists.txt +32 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/Makefile +29 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.c +2426 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.tcl +83 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imcp +65 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imglob +59 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imln +37 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/immv +64 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imrm +29 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imtest +53 -0
- data/ext/nifticlib/nifticlib-2.0.0/fsliolib/remove_ext +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/include/.gitkeep +0 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/CMakeLists.txt +28 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/Makefile +28 -0
- data/ext/nifticlib/nifticlib-2.0.0/nifticdf/nifticdf.c +11107 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/CMakeLists.txt +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/Makefile +31 -0
- data/ext/nifticlib/nifticlib-2.0.0/niftilib/nifti1_io.c +7509 -0
- data/ext/nifticlib/nifticlib-2.0.0/packaging/DevPackage.template +18 -0
- data/ext/nifticlib/nifticlib-2.0.0/packaging/nifticlib.spec +62 -0
- data/ext/nifticlib/nifticlib-2.0.0/real_easy/nifti1_read_write.c +361 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/CMakeLists.txt +73 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/Makefile +55 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti1_test.c +95 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_stats.c +95 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.c +4193 -0
- data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.h +163 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/CMakeLists.txt +31 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/Makefile +33 -0
- data/ext/nifticlib/nifticlib-2.0.0/znzlib/znzlib.c +322 -0
- data/ext/nifticlib/nifticlib.c +107 -0
- data/ext/nifticlib/patches/nifticlib_fpic.patch +13 -0
- data/features/read_modify_write.feature +11 -0
- data/features/step_definitions/nifti_image_steps.rb +16 -0
- data/features/support/env.rb +14 -0
- data/features/support/fixtures/sample.nii.gz +0 -0
- data/lib/c_nifti.rb +9 -0
- data/lib/c_nifti/data.rb +70 -0
- data/lib/c_nifti/header.rb +16 -0
- data/lib/c_nifti/header_element.rb +13 -0
- data/lib/c_nifti/header_element/datatype.rb +49 -0
- data/lib/c_nifti/header_element/datatype/base.rb +9 -0
- data/lib/c_nifti/header_element/datatype/binary.rb +11 -0
- data/lib/c_nifti/header_element/datatype/double.rb +11 -0
- data/lib/c_nifti/header_element/datatype/float.rb +11 -0
- data/lib/c_nifti/header_element/datatype/long_double.rb +11 -0
- data/lib/c_nifti/header_element/datatype/long_long.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_char.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_int.rb +11 -0
- data/lib/c_nifti/header_element/datatype/signed_short.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_char.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_int.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_long_long.rb +11 -0
- data/lib/c_nifti/header_element/datatype/unsigned_short.rb +11 -0
- data/lib/c_nifti/header_element/dimensions.rb +53 -0
- data/lib/c_nifti/header_element/intents.rb +25 -0
- data/lib/c_nifti/header_element/metadata.rb +49 -0
- data/lib/c_nifti/header_element/miscellaneous.rb +25 -0
- data/lib/c_nifti/header_element/quaternions.rb +33 -0
- data/lib/c_nifti/header_element/spacings.rb +45 -0
- data/lib/c_nifti/header_element/timings.rb +37 -0
- data/lib/c_nifti/header_element/transforms.rb +21 -0
- data/lib/c_nifti/image.rb +31 -0
- data/lib/c_nifti/version.rb +3 -0
- data/lib/nifticlib.rb +1 -0
- data/spec/data_spec.rb +112 -0
- data/spec/factories/nifti_images.rb +9 -0
- data/spec/header_element/datatype/base_spec.rb +9 -0
- data/spec/header_element/datatype/binary_spec.rb +9 -0
- data/spec/header_element/datatype/double_spec.rb +9 -0
- data/spec/header_element/datatype/float_spec.rb +9 -0
- data/spec/header_element/datatype/long_double_spec.rb +9 -0
- data/spec/header_element/datatype/long_long_spec.rb +9 -0
- data/spec/header_element/datatype/signed_char_spec.rb +9 -0
- data/spec/header_element/datatype/signed_int_spec.rb +9 -0
- data/spec/header_element/datatype/signed_short_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_char_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_int_spec.rb +9 -0
- data/spec/header_element/datatype/unsigned_long_long.rb +9 -0
- data/spec/header_element/datatype/unsigned_short_spec.rb +9 -0
- data/spec/header_element/datatype_spec.rb +109 -0
- data/spec/header_element/dimensions_spec.rb +105 -0
- data/spec/header_element/intents_spec.rb +48 -0
- data/spec/header_element/metadata_spec.rb +96 -0
- data/spec/header_element/miscellaneous_spec.rb +48 -0
- data/spec/header_element/quaternions_spec.rb +64 -0
- data/spec/header_element/spacings_spec.rb +88 -0
- data/spec/header_element/timings_spec.rb +72 -0
- data/spec/header_element/transforms_spec.rb +64 -0
- data/spec/image_spec.rb +39 -0
- data/spec/spec_helper.rb +85 -0
- metadata +363 -0
@@ -0,0 +1,163 @@
|
|
1
|
+
#ifndef _NIFTI_TOOL_H_
|
2
|
+
#define _NIFTI_TOOL_H_
|
3
|
+
|
4
|
+
#define NT_CMD_LEN 2048
|
5
|
+
|
6
|
+
typedef struct{
|
7
|
+
int len;
|
8
|
+
char ** list;
|
9
|
+
} str_list;
|
10
|
+
|
11
|
+
typedef struct{
|
12
|
+
int len;
|
13
|
+
int * list;
|
14
|
+
} int_list;
|
15
|
+
|
16
|
+
typedef struct{
|
17
|
+
/* action options (flags) */
|
18
|
+
int check_hdr, check_nim;
|
19
|
+
int diff_hdr, diff_nim;
|
20
|
+
int disp_hdr, disp_nim, disp_ana;
|
21
|
+
int disp_exts, add_exts, rm_exts;
|
22
|
+
int mod_hdr, mod_nim;
|
23
|
+
int swap_hdr, swap_ana, swap_old;
|
24
|
+
|
25
|
+
int strip; /* strip extras from dataset(s) */
|
26
|
+
int cbl, cci; /* -copy_XXX option flags */
|
27
|
+
int dts, dci, dci_lines; /* display collapsed img flags */
|
28
|
+
int make_im; /* create a new image on the fly */
|
29
|
+
int ci_dims[8]; /* user dims list (last 7 valid) */
|
30
|
+
int new_dim[8]; /* user dim list for new image */
|
31
|
+
int new_datatype; /* datatype for new image */
|
32
|
+
int debug, keep_hist; /* debug level and history flag */
|
33
|
+
int overwrite; /* overwrite flag */
|
34
|
+
char * prefix; /* for output file */
|
35
|
+
str_list elist; /* extension strings */
|
36
|
+
int_list etypes; /* extension type list */
|
37
|
+
str_list flist; /* fields (to display or modify) */
|
38
|
+
str_list vlist; /* values (to set fields to) */
|
39
|
+
str_list infiles; /* input files */
|
40
|
+
char command[NT_CMD_LEN]; /* for inserting the command */
|
41
|
+
} nt_opts;
|
42
|
+
|
43
|
+
#define USE_SHORT 1
|
44
|
+
#define USE_FULL 2
|
45
|
+
#define USE_HIST 3
|
46
|
+
#define USE_FIELD_HDR 4
|
47
|
+
#define USE_FIELD_NIM 5
|
48
|
+
#define USE_FIELD_ANA 6
|
49
|
+
#define USE_DTYPES 7
|
50
|
+
#define USE_VERSION 8
|
51
|
+
|
52
|
+
#define CHECK_NEXT_OPT(n,m,str) \
|
53
|
+
do { if ( (n) >= (m) ) { \
|
54
|
+
fprintf(stderr,"** option '%s': missing parameter\n",str); \
|
55
|
+
fprintf(stderr," consider: 'nifti_tool -help'\n"); \
|
56
|
+
return 1; } \
|
57
|
+
} while(0)
|
58
|
+
|
59
|
+
#define CHECK_NEXT_OPT_MSG(n,m,str,msg) \
|
60
|
+
do { if ( (n) >= (m) ) { \
|
61
|
+
fprintf(stderr,"** option '%s': %s\n",str,msg); \
|
62
|
+
fprintf(stderr," consider: 'nifti_tool -help'\n"); \
|
63
|
+
return 1; } \
|
64
|
+
} while(0)
|
65
|
+
|
66
|
+
/*----------------------------------------------------------------------
|
67
|
+
* this structure and definitions will be used to process the nifti_1_header
|
68
|
+
* and nifti_image structure fields (actions disp, diff, mod)
|
69
|
+
*----------------------------------------------------------------------*/
|
70
|
+
|
71
|
+
#define NT_FIELD_NAME_LEN 20 /* more than length of longest name */
|
72
|
+
#define NT_HDR_NUM_FIELDS 43 /* in the nifti_1_header struct */
|
73
|
+
#define NT_ANA_NUM_FIELDS 47 /* in the nifti_analyze75 struct */
|
74
|
+
#define NT_NIM_NUM_FIELDS 63 /* in the nifti_image struct */
|
75
|
+
#define NT_DT_STRING -0xfff /* some strange number to abuse... */
|
76
|
+
#define NT_DT_POINTER -0xfef /* some strange number to abuse... */
|
77
|
+
#define NT_DT_CHAR_PTR -0xfee /* another... */
|
78
|
+
#define NT_DT_EXT_PTR -0xfed /* and another... */
|
79
|
+
|
80
|
+
typedef struct {
|
81
|
+
int type; /* one of the DT_* types from nifti1.h */
|
82
|
+
int offset; /* bytes from the start of the struct */
|
83
|
+
int size; /* size of one element type */
|
84
|
+
int len; /* number of elements */
|
85
|
+
char name[NT_FIELD_NAME_LEN]; /* actual structure name used */
|
86
|
+
} field_s;
|
87
|
+
|
88
|
+
/* for computing the offset from the start of the struct */
|
89
|
+
#define NT_OFF(str,field) ((int)( ((char *)&str.field) - ((char *)&str) ))
|
90
|
+
|
91
|
+
/* call fill_field() for a single type, name and number of elements */
|
92
|
+
/* nstr is the base struct, and fldp is a field pointer */
|
93
|
+
#define NT_SFILL(nstr,fldp,type,name,num,rv) do{ \
|
94
|
+
rv=fill_field(fldp,type,NT_OFF(nstr,name),num,#name); \
|
95
|
+
fldp++; } while (0)
|
96
|
+
|
97
|
+
#define NT_MAKE_IM_NAME "MAKE_IM"
|
98
|
+
|
99
|
+
/*----------------------------------------------------------------------*/
|
100
|
+
/*----- prototypes ---------------------------------------------------*/
|
101
|
+
/*----------------------------------------------------------------------*/
|
102
|
+
int act_add_exts ( nt_opts * opts );
|
103
|
+
int act_cbl ( nt_opts * opts ); /* copy brick list */
|
104
|
+
int act_cci ( nt_opts * opts ); /* copy collapsed dimensions */
|
105
|
+
int act_check_hdrs ( nt_opts * opts ); /* check for valid hdr or nim */
|
106
|
+
int act_diff_hdrs ( nt_opts * opts );
|
107
|
+
int act_diff_nims ( nt_opts * opts );
|
108
|
+
int act_disp_ci ( nt_opts * opts ); /* display general collapsed data */
|
109
|
+
int act_disp_exts ( nt_opts * opts );
|
110
|
+
int act_disp_hdrs ( nt_opts * opts );
|
111
|
+
int act_disp_nims ( nt_opts * opts );
|
112
|
+
int act_disp_anas ( nt_opts * opts );
|
113
|
+
int act_disp_ts ( nt_opts * opts ); /* display time series */
|
114
|
+
int act_mod_hdrs ( nt_opts * opts );
|
115
|
+
int act_mod_nims ( nt_opts * opts );
|
116
|
+
int act_swap_hdrs ( nt_opts * opts );
|
117
|
+
int act_rm_ext ( nt_opts * opts );
|
118
|
+
int act_strip ( nt_opts * opts ); /* strip extras from datasets */
|
119
|
+
|
120
|
+
|
121
|
+
field_s * get_hdr_field( char * fname, int show_fail );
|
122
|
+
field_s * get_nim_field( char * fname, int show_fail );
|
123
|
+
char * field_type_str (int type);
|
124
|
+
|
125
|
+
int diff_hdrs (nifti_1_header *s0, nifti_1_header *s1, int display);
|
126
|
+
int diff_hdrs_list(nifti_1_header *s0, nifti_1_header *s1, str_list *slist,
|
127
|
+
int display);
|
128
|
+
int diff_nims (nifti_image *s0,nifti_image *s1, int display);
|
129
|
+
int diff_nims_list(nifti_image *s0,nifti_image *s1,str_list *slist,int display);
|
130
|
+
|
131
|
+
int add_int (int_list * ilist, int val);
|
132
|
+
int add_string (str_list * slist, char * str);
|
133
|
+
int check_total_size (char *mesg, field_s *fields, int nfields, int tot_size);
|
134
|
+
int clear_float_zeros( char * str );
|
135
|
+
int diff_field (field_s *fieldp, void * str0, void * str1, int nfields);
|
136
|
+
int disp_nifti1_extension(char *mesg, nifti1_extension * ext, int maxlen);
|
137
|
+
int disp_field (char *mesg,field_s *fp,void *str,int nfields,int header);
|
138
|
+
int disp_field_s_list(char * mesg, field_s *, int nfields);
|
139
|
+
int disp_nt_opts (char * mesg, nt_opts * opts);
|
140
|
+
int disp_raw_data (void * data, int type, int nvals, char space,int newline);
|
141
|
+
int fill_cmd_string (nt_opts * opts, int argc, char * argv[]);
|
142
|
+
int fill_field (field_s *fp, int type, int offset, int num, char *name);
|
143
|
+
int fill_hdr_field_array(field_s * nh_fields);
|
144
|
+
int fill_nim_field_array(field_s * nim_fields);
|
145
|
+
int fill_ana_field_array(field_s * ah_fields);
|
146
|
+
int modify_all_fields(void *basep, nt_opts *opts, field_s *fields, int flen);
|
147
|
+
int modify_field (void * basep, field_s * field, char * data);
|
148
|
+
int process_opts (int argc, char * argv[], nt_opts * opts);
|
149
|
+
int remove_ext_list (nifti_image * nim, char ** elist, int len);
|
150
|
+
int usage (char * prog, int level);
|
151
|
+
int use_full (char * prog);
|
152
|
+
int verify_opts (nt_opts * opts, char * prog);
|
153
|
+
int write_hdr_to_file(nifti_1_header * nhdr, char * fname);
|
154
|
+
|
155
|
+
/* wrappers for nifti reading functions (allow MAKE_IM) */
|
156
|
+
nifti_image * nt_image_read (nt_opts * opts, char * fname, int doread);
|
157
|
+
nifti_image * nt_read_bricks(nt_opts * opts, char * fname, int len,
|
158
|
+
int * list, nifti_brick_list * NBL);
|
159
|
+
nifti_1_header * nt_read_header(nt_opts * opts, char * fname, int * swapped,
|
160
|
+
int check);
|
161
|
+
|
162
|
+
|
163
|
+
#endif /* _NIFTI_TOOL_H_ */
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#File Generated by Hans J. Johnson
|
2
|
+
#Please contact hans-johnson@uiowa.edu for making enhancments/corrections
|
3
|
+
PROJECT(ZNZLIB)
|
4
|
+
SET(ZNZLIB_SRC znzlib.c)
|
5
|
+
INCLUDE_REGULAR_EXPRESSION("^.*$")
|
6
|
+
|
7
|
+
SET(NIFTI_ZNZLIB_NAME ${PACKAGE_PREFIX}znz)
|
8
|
+
|
9
|
+
ADD_LIBRARY(${NIFTI_ZNZLIB_NAME} ${ZNZLIB_SRC} )
|
10
|
+
TARGET_LINK_LIBRARIES( ${NIFTI_ZNZLIB_NAME} ${NIFTI_ZLIB_LIBRARIES} )
|
11
|
+
|
12
|
+
# Set library version if building shared libs.
|
13
|
+
IF (BUILD_SHARED_LIBS)
|
14
|
+
SET_TARGET_PROPERTIES(${NIFTI_ZNZLIB_NAME} PROPERTIES ${NIFTI_LIBRARY_PROPERTIES})
|
15
|
+
ENDIF (BUILD_SHARED_LIBS)
|
16
|
+
|
17
|
+
|
18
|
+
IF(NOT NIFTI_INSTALL_NO_LIBRARIES)
|
19
|
+
INSTALL(TARGETS ${NIFTI_ZNZLIB_NAME}
|
20
|
+
RUNTIME DESTINATION ${NIFTI_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
|
21
|
+
LIBRARY DESTINATION ${NIFTI_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
|
22
|
+
ARCHIVE DESTINATION ${NIFTI_INSTALL_LIB_DIR} COMPONENT Development)
|
23
|
+
ENDIF(NOT NIFTI_INSTALL_NO_LIBRARIES)
|
24
|
+
|
25
|
+
IF(NOT NIFTI_INSTALL_NO_DEVELOPMENT)
|
26
|
+
FILE(GLOB __files "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
|
27
|
+
INSTALL(FILES ${__files}
|
28
|
+
DESTINATION ${NIFTI_INSTALL_INCLUDE_DIR}
|
29
|
+
COMPONENT Development)
|
30
|
+
ENDIF(NOT NIFTI_INSTALL_NO_DEVELOPMENT)
|
31
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
include ../Makefile
|
2
|
+
|
3
|
+
PROJNAME = znzlib
|
4
|
+
|
5
|
+
INCFLAGS = $(ZLIB_INC)
|
6
|
+
|
7
|
+
SRCS=znzlib.c
|
8
|
+
OBJS=znzlib.o
|
9
|
+
|
10
|
+
TESTXFILES = testprog
|
11
|
+
|
12
|
+
depend:
|
13
|
+
$(RM) -f depend.mk
|
14
|
+
$(MAKE) depend.mk
|
15
|
+
|
16
|
+
depend.mk:
|
17
|
+
$(CC) $(DEPENDFLAGS) $(INCFLAGS) $(SRCS) >> depend.mk
|
18
|
+
|
19
|
+
lib: libznz.a
|
20
|
+
|
21
|
+
test: $(TESTXFILES)
|
22
|
+
|
23
|
+
znzlib.o: znzlib.c znzlib.h
|
24
|
+
$(CC) -c $(CFLAGS) $(USEZLIB) $(INCFLAGS) $<
|
25
|
+
|
26
|
+
libznz.a: $(OBJS)
|
27
|
+
$(AR) -r libznz.a $(OBJS)
|
28
|
+
$(RANLIB) $@
|
29
|
+
|
30
|
+
testprog: libznz.a testprog.c
|
31
|
+
$(CC) $(CFLAGS) $(LDFLAGS) -o testprog testprog.c $(ZLIB_LIBS)
|
32
|
+
|
33
|
+
include depend.mk
|
@@ -0,0 +1,322 @@
|
|
1
|
+
/** \file znzlib.c
|
2
|
+
\brief Low level i/o interface to compressed and noncompressed files.
|
3
|
+
Written by Mark Jenkinson, FMRIB
|
4
|
+
|
5
|
+
This library provides an interface to both compressed (gzip/zlib) and
|
6
|
+
uncompressed (normal) file IO. The functions are written to have the
|
7
|
+
same interface as the standard file IO functions.
|
8
|
+
|
9
|
+
To use this library instead of normal file IO, the following changes
|
10
|
+
are required:
|
11
|
+
- replace all instances of FILE* with znzFile
|
12
|
+
- change the name of all function calls, replacing the initial character
|
13
|
+
f with the znz (e.g. fseek becomes znzseek)
|
14
|
+
one exception is rewind() -> znzrewind()
|
15
|
+
- add a third parameter to all calls to znzopen (previously fopen)
|
16
|
+
that specifies whether to use compression (1) or not (0)
|
17
|
+
- use znz_isnull rather than any (pointer == NULL) comparisons in the code
|
18
|
+
for znzfile types (normally done after a return from znzopen)
|
19
|
+
|
20
|
+
NB: seeks for writable files with compression are quite restricted
|
21
|
+
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include "znzlib.h"
|
25
|
+
|
26
|
+
/*
|
27
|
+
znzlib.c (zipped or non-zipped library)
|
28
|
+
|
29
|
+
***** This code is released to the public domain. *****
|
30
|
+
|
31
|
+
***** Author: Mark Jenkinson, FMRIB Centre, University of Oxford *****
|
32
|
+
***** Date: September 2004 *****
|
33
|
+
|
34
|
+
***** Neither the FMRIB Centre, the University of Oxford, nor any of *****
|
35
|
+
***** its employees imply any warranty of usefulness of this software *****
|
36
|
+
***** for any purpose, and do not assume any liability for damages, *****
|
37
|
+
***** incidental or otherwise, caused by any use of this document. *****
|
38
|
+
|
39
|
+
*/
|
40
|
+
|
41
|
+
|
42
|
+
/* Note extra argument (use_compression) where
|
43
|
+
use_compression==0 is no compression
|
44
|
+
use_compression!=0 uses zlib (gzip) compression
|
45
|
+
*/
|
46
|
+
|
47
|
+
znzFile znzopen(const char *path, const char *mode, int use_compression)
|
48
|
+
{
|
49
|
+
znzFile file;
|
50
|
+
file = (znzFile) calloc(1,sizeof(struct znzptr));
|
51
|
+
if( file == NULL ){
|
52
|
+
fprintf(stderr,"** ERROR: znzopen failed to alloc znzptr\n");
|
53
|
+
return NULL;
|
54
|
+
}
|
55
|
+
|
56
|
+
file->nzfptr = NULL;
|
57
|
+
|
58
|
+
#ifdef HAVE_ZLIB
|
59
|
+
file->zfptr = NULL;
|
60
|
+
|
61
|
+
if (use_compression) {
|
62
|
+
file->withz = 1;
|
63
|
+
if((file->zfptr = gzopen(path,mode)) == NULL) {
|
64
|
+
free(file);
|
65
|
+
file = NULL;
|
66
|
+
}
|
67
|
+
} else {
|
68
|
+
#endif
|
69
|
+
|
70
|
+
file->withz = 0;
|
71
|
+
if((file->nzfptr = fopen(path,mode)) == NULL) {
|
72
|
+
free(file);
|
73
|
+
file = NULL;
|
74
|
+
}
|
75
|
+
|
76
|
+
#ifdef HAVE_ZLIB
|
77
|
+
}
|
78
|
+
#endif
|
79
|
+
|
80
|
+
return file;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
znzFile znzdopen(int fd, const char *mode, int use_compression)
|
85
|
+
{
|
86
|
+
znzFile file;
|
87
|
+
file = (znzFile) calloc(1,sizeof(struct znzptr));
|
88
|
+
if( file == NULL ){
|
89
|
+
fprintf(stderr,"** ERROR: znzdopen failed to alloc znzptr\n");
|
90
|
+
return NULL;
|
91
|
+
}
|
92
|
+
#ifdef HAVE_ZLIB
|
93
|
+
if (use_compression) {
|
94
|
+
file->withz = 1;
|
95
|
+
file->zfptr = gzdopen(fd,mode);
|
96
|
+
file->nzfptr = NULL;
|
97
|
+
} else {
|
98
|
+
#endif
|
99
|
+
file->withz = 0;
|
100
|
+
#ifdef HAVE_FDOPEN
|
101
|
+
file->nzfptr = fdopen(fd,mode);
|
102
|
+
#endif
|
103
|
+
#ifdef HAVE_ZLIB
|
104
|
+
file->zfptr = NULL;
|
105
|
+
};
|
106
|
+
#endif
|
107
|
+
return file;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
int Xznzclose(znzFile * file)
|
112
|
+
{
|
113
|
+
int retval = 0;
|
114
|
+
if (*file!=NULL) {
|
115
|
+
#ifdef HAVE_ZLIB
|
116
|
+
if ((*file)->zfptr!=NULL) { retval = gzclose((*file)->zfptr); }
|
117
|
+
#endif
|
118
|
+
if ((*file)->nzfptr!=NULL) { retval = fclose((*file)->nzfptr); }
|
119
|
+
|
120
|
+
free(*file);
|
121
|
+
*file = NULL;
|
122
|
+
}
|
123
|
+
return retval;
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
/* we already assume ints are 4 bytes */
|
128
|
+
#undef ZNZ_MAX_BLOCK_SIZE
|
129
|
+
#define ZNZ_MAX_BLOCK_SIZE (1<<30)
|
130
|
+
|
131
|
+
size_t znzread(void* buf, size_t size, size_t nmemb, znzFile file)
|
132
|
+
{
|
133
|
+
size_t remain = size*nmemb;
|
134
|
+
char * cbuf = (char *)buf;
|
135
|
+
unsigned n2read;
|
136
|
+
int nread;
|
137
|
+
|
138
|
+
if (file==NULL) { return 0; }
|
139
|
+
#ifdef HAVE_ZLIB
|
140
|
+
if (file->zfptr!=NULL) {
|
141
|
+
/* gzread/write take unsigned int length, so maybe read in int pieces
|
142
|
+
(noted by M Hanke, example given by M Adler) 6 July 2010 [rickr] */
|
143
|
+
while( remain > 0 ) {
|
144
|
+
n2read = (remain < ZNZ_MAX_BLOCK_SIZE) ? remain : ZNZ_MAX_BLOCK_SIZE;
|
145
|
+
nread = gzread(file->zfptr, (void *)cbuf, n2read);
|
146
|
+
if( nread < 0 ) return nread; /* returns -1 on error */
|
147
|
+
|
148
|
+
remain -= nread;
|
149
|
+
cbuf += nread;
|
150
|
+
|
151
|
+
/* require reading n2read bytes, so we don't get stuck */
|
152
|
+
if( nread < (int)n2read ) break; /* return will be short */
|
153
|
+
}
|
154
|
+
|
155
|
+
/* warn of a short read that will seem complete */
|
156
|
+
if( remain > 0 && remain < size )
|
157
|
+
fprintf(stderr,"** znzread: read short by %u bytes\n",(unsigned)remain);
|
158
|
+
|
159
|
+
return nmemb - remain/size; /* return number of members processed */
|
160
|
+
}
|
161
|
+
#endif
|
162
|
+
return fread(buf,size,nmemb,file->nzfptr);
|
163
|
+
}
|
164
|
+
|
165
|
+
size_t znzwrite(const void* buf, size_t size, size_t nmemb, znzFile file)
|
166
|
+
{
|
167
|
+
size_t remain = size*nmemb;
|
168
|
+
char * cbuf = (char *)buf;
|
169
|
+
unsigned n2write;
|
170
|
+
int nwritten;
|
171
|
+
|
172
|
+
if (file==NULL) { return 0; }
|
173
|
+
#ifdef HAVE_ZLIB
|
174
|
+
if (file->zfptr!=NULL) {
|
175
|
+
while( remain > 0 ) {
|
176
|
+
n2write = (remain < ZNZ_MAX_BLOCK_SIZE) ? remain : ZNZ_MAX_BLOCK_SIZE;
|
177
|
+
nwritten = gzwrite(file->zfptr, (void *)cbuf, n2write);
|
178
|
+
|
179
|
+
/* gzread returns 0 on error, but in case that ever changes... */
|
180
|
+
if( nwritten < 0 ) return nwritten;
|
181
|
+
|
182
|
+
remain -= nwritten;
|
183
|
+
cbuf += nwritten;
|
184
|
+
|
185
|
+
/* require writing n2write bytes, so we don't get stuck */
|
186
|
+
if( nwritten < (int)n2write ) break;
|
187
|
+
}
|
188
|
+
|
189
|
+
/* warn of a short write that will seem complete */
|
190
|
+
if( remain > 0 && remain < size )
|
191
|
+
fprintf(stderr,"** znzwrite: write short by %u bytes\n",(unsigned)remain);
|
192
|
+
|
193
|
+
return nmemb - remain/size; /* return number of members processed */
|
194
|
+
}
|
195
|
+
#endif
|
196
|
+
return fwrite(buf,size,nmemb,file->nzfptr);
|
197
|
+
}
|
198
|
+
|
199
|
+
long znzseek(znzFile file, long offset, int whence)
|
200
|
+
{
|
201
|
+
if (file==NULL) { return 0; }
|
202
|
+
#ifdef HAVE_ZLIB
|
203
|
+
if (file->zfptr!=NULL) return (long) gzseek(file->zfptr,offset,whence);
|
204
|
+
#endif
|
205
|
+
return fseek(file->nzfptr,offset,whence);
|
206
|
+
}
|
207
|
+
|
208
|
+
int znzrewind(znzFile stream)
|
209
|
+
{
|
210
|
+
if (stream==NULL) { return 0; }
|
211
|
+
#ifdef HAVE_ZLIB
|
212
|
+
/* On some systems, gzrewind() fails for uncompressed files.
|
213
|
+
Use gzseek(), instead. 10, May 2005 [rickr]
|
214
|
+
|
215
|
+
if (stream->zfptr!=NULL) return gzrewind(stream->zfptr);
|
216
|
+
*/
|
217
|
+
|
218
|
+
if (stream->zfptr!=NULL) return (int)gzseek(stream->zfptr, 0L, SEEK_SET);
|
219
|
+
#endif
|
220
|
+
rewind(stream->nzfptr);
|
221
|
+
return 0;
|
222
|
+
}
|
223
|
+
|
224
|
+
long znztell(znzFile file)
|
225
|
+
{
|
226
|
+
if (file==NULL) { return 0; }
|
227
|
+
#ifdef HAVE_ZLIB
|
228
|
+
if (file->zfptr!=NULL) return (long) gztell(file->zfptr);
|
229
|
+
#endif
|
230
|
+
return ftell(file->nzfptr);
|
231
|
+
}
|
232
|
+
|
233
|
+
int znzputs(const char * str, znzFile file)
|
234
|
+
{
|
235
|
+
if (file==NULL) { return 0; }
|
236
|
+
#ifdef HAVE_ZLIB
|
237
|
+
if (file->zfptr!=NULL) return gzputs(file->zfptr,str);
|
238
|
+
#endif
|
239
|
+
return fputs(str,file->nzfptr);
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
char * znzgets(char* str, int size, znzFile file)
|
244
|
+
{
|
245
|
+
if (file==NULL) { return NULL; }
|
246
|
+
#ifdef HAVE_ZLIB
|
247
|
+
if (file->zfptr!=NULL) return gzgets(file->zfptr,str,size);
|
248
|
+
#endif
|
249
|
+
return fgets(str,size,file->nzfptr);
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
int znzflush(znzFile file)
|
254
|
+
{
|
255
|
+
if (file==NULL) { return 0; }
|
256
|
+
#ifdef HAVE_ZLIB
|
257
|
+
if (file->zfptr!=NULL) return gzflush(file->zfptr,Z_SYNC_FLUSH);
|
258
|
+
#endif
|
259
|
+
return fflush(file->nzfptr);
|
260
|
+
}
|
261
|
+
|
262
|
+
|
263
|
+
int znzeof(znzFile file)
|
264
|
+
{
|
265
|
+
if (file==NULL) { return 0; }
|
266
|
+
#ifdef HAVE_ZLIB
|
267
|
+
if (file->zfptr!=NULL) return gzeof(file->zfptr);
|
268
|
+
#endif
|
269
|
+
return feof(file->nzfptr);
|
270
|
+
}
|
271
|
+
|
272
|
+
|
273
|
+
int znzputc(int c, znzFile file)
|
274
|
+
{
|
275
|
+
if (file==NULL) { return 0; }
|
276
|
+
#ifdef HAVE_ZLIB
|
277
|
+
if (file->zfptr!=NULL) return gzputc(file->zfptr,c);
|
278
|
+
#endif
|
279
|
+
return fputc(c,file->nzfptr);
|
280
|
+
}
|
281
|
+
|
282
|
+
|
283
|
+
int znzgetc(znzFile file)
|
284
|
+
{
|
285
|
+
if (file==NULL) { return 0; }
|
286
|
+
#ifdef HAVE_ZLIB
|
287
|
+
if (file->zfptr!=NULL) return gzgetc(file->zfptr);
|
288
|
+
#endif
|
289
|
+
return fgetc(file->nzfptr);
|
290
|
+
}
|
291
|
+
|
292
|
+
#if !defined (WIN32)
|
293
|
+
int znzprintf(znzFile stream, const char *format, ...)
|
294
|
+
{
|
295
|
+
int retval=0;
|
296
|
+
char *tmpstr;
|
297
|
+
va_list va;
|
298
|
+
if (stream==NULL) { return 0; }
|
299
|
+
va_start(va, format);
|
300
|
+
#ifdef HAVE_ZLIB
|
301
|
+
if (stream->zfptr!=NULL) {
|
302
|
+
int size; /* local to HAVE_ZLIB block */
|
303
|
+
size = strlen(format) + 1000000; /* overkill I hope */
|
304
|
+
tmpstr = (char *)calloc(1, size);
|
305
|
+
if( tmpstr == NULL ){
|
306
|
+
fprintf(stderr,"** ERROR: znzprintf failed to alloc %d bytes\n", size);
|
307
|
+
return retval;
|
308
|
+
}
|
309
|
+
vsprintf(tmpstr,format,va);
|
310
|
+
retval=gzprintf(stream->zfptr,"%s",tmpstr);
|
311
|
+
free(tmpstr);
|
312
|
+
} else
|
313
|
+
#endif
|
314
|
+
{
|
315
|
+
retval=vfprintf(stream->nzfptr,format,va);
|
316
|
+
}
|
317
|
+
va_end(va);
|
318
|
+
return retval;
|
319
|
+
}
|
320
|
+
|
321
|
+
#endif
|
322
|
+
|