38 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
39 if(verbose>0) {printf(
"%s(%s, ...)\n", __func__, filename); fflush(stdout);}
43 if(hdrfile!=NULL) hdrfile[0]=(char)0;
44 if(imgfile!=NULL) imgfile[0]=(char)0;
45 if(siffile!=NULL) siffile[0]=(char)0;
54 char basefile[FILENAME_MAX];
strlcpy(basefile, filename, FILENAME_MAX);
57 if(verbose>1) printf(
" basefile := %s\n", basefile);
61 char temp[FILENAME_MAX+10], localhdrfile[FILENAME_MAX];
62 localhdrfile[0]=(char)0;
63 strcpy(temp, basefile); strcat(temp,
".nii");
65 if(verbose>1) printf(
" %s exists.\n", temp);
67 strcpy(localhdrfile, temp);
68 if(hdrfile!=NULL)
strlcpy(hdrfile, temp, FILENAME_MAX);
69 if(imgfile!=NULL)
strlcpy(imgfile, temp, FILENAME_MAX);
72 if(verbose>1) printf(
" %s does not exist.\n", temp);
74 strcpy(temp, basefile); strcat(temp,
".hdr");
76 strcpy(temp, basefile); strcat(temp,
".img.hdr");
78 if(verbose>1) printf(
" hdr file not found.\n");
84 strlcpy(localhdrfile, temp, FILENAME_MAX);
85 if(hdrfile!=NULL)
strlcpy(hdrfile, temp, FILENAME_MAX);
86 if(verbose>1) printf(
" %s is found.\n", localhdrfile);
88 strcpy(temp, basefile); strcat(temp,
".img");
90 if(verbose>1) printf(
" %s not found.\n", temp);
95 if(imgfile!=NULL)
strlcpy(imgfile, temp, FILENAME_MAX);
96 if(verbose>1) printf(
" %s is found.\n", temp);
98 if(verbose>1) {printf(
" combined := %d\n", combined); fflush(stdout);}
102 ANALYZE_DSR *dsr, local_dsr;
if(header==NULL) dsr=&local_dsr;
else dsr=header;
106 printf(
" %s was not identified as Analyze header file.\n", localhdrfile); fflush(stdout);}
107 statusSet(status, __func__, __FILE__, __LINE__, ret);
110 if(verbose>1) {printf(
" %s is identified as Analyze.\n", localhdrfile); fflush(stdout);}
114 strcpy(temp, basefile); strcat(temp,
".sif");
115 if(verbose>3) printf(
" checking if %s exists\n", temp);
117 strcpy(temp, basefile); strcat(temp,
".img.sif");
118 if(verbose>3) printf(
" checking if %s exists\n", temp);
120 strcpy(temp, basefile); strcat(temp,
".nii.sif");
121 if(verbose>3) printf(
" checking if %s exists\n", temp);
123 if(verbose>0) printf(
" SIF not found or accessible.\n");
130 if(siffile!=NULL) strcpy(siffile, temp);
131 if(verbose>1) {printf(
" %s is found.\n", temp); fflush(stdout);}
146 const char *filename,
152 if(verbose>0) {printf(
"%s(%s, ...)\n", __func__, filename); fflush(stdout);}
161 if(little) printf(
"little endian platform\n");
else printf(
"big endian platform\n");
174 memcpy(&hdrSize, buf, 4);
176 swawbip(&hdrSize, 4); same_order=0;
178 if(verbose>1) {printf(
" sizeof_hdr := %d\n", hdrSize); fflush(stdout);}
180 if(verbose>1) {printf(
" NIfTI-2 header size.\n"); fflush(stdout);}
183 if(verbose>1) {printf(
" Analyze or NIfTI-1 header size.\n"); fflush(stdout);}
185 if(verbose>1) {printf(
" invalid Analyze sizeof_hdr\n"); fflush(stdout);}
192 if(verbose>1) {printf(
" reading header as binary data\n"); fflush(stdout);}
200 memcpy(magic, buf+344, 4); magic[3]=(char)0;
201 if(strcasecmp(magic,
"ni1")==0 || strcasecmp(magic,
"n+1")==0) {
202 if(verbose>1) {printf(
" Nifti magic number was found"); fflush(stdout);}
214 if(!same_order)
swawbip(buf+32, 4);
216 if(!same_order)
swabip(buf+36, 2);
222 if(!same_order)
swabip(buf+40, 16);
223 memcpy(dsr->
h.
dim, buf+40, 16);
224 if(!same_order)
swabip(buf+56, 2);
226 if(!same_order)
swabip(buf+58, 2);
228 if(!same_order)
swabip(buf+60, 2);
230 if(!same_order)
swabip(buf+62, 2);
232 if(!same_order)
swabip(buf+64, 2);
234 if(!same_order)
swabip(buf+66, 2);
236 if(!same_order)
swabip(buf+68, 2);
238 if(!same_order)
swabip(buf+70, 2);
240 if(!same_order)
swabip(buf+72, 2);
241 memcpy(&dsr->
h.
bitpix, buf+72, 2);
242 if(!same_order)
swabip(buf+74, 2);
244 if(!same_order)
swawbip(buf+76, 32);
245 memcpy(dsr->
h.
pixdim, buf+76, 32);
246 if(!same_order)
swawbip(buf+108, 4);
248 if(!same_order)
swawbip(buf+112, 4);
250 if(!same_order)
swawbip(buf+116, 4);
252 if(!same_order)
swawbip(buf+120, 4);
254 if(!same_order)
swawbip(buf+124, 4);
255 memcpy(&dsr->
h.
cal_max, buf+124, 4);
256 if(!same_order)
swawbip(buf+128, 4);
257 memcpy(&dsr->
h.
cal_min, buf+128, 4);
258 if(!same_order)
swawbip(buf+132, 4);
260 if(!same_order)
swawbip(buf+136, 4);
262 if(!same_order)
swawbip(buf+140, 4);
263 memcpy(&dsr->
h.
glmax, buf+140, 4);
264 if(!same_order)
swawbip(buf+144, 4);
265 memcpy(&dsr->
h.
glmin, buf+144, 4);
268 memcpy(dsr->
h.
descrip, buf+148, 80);
270 memcpy(&dsr->
h.
orient, buf+252, 1);
273 memcpy(dsr->
h.
scannum, buf+273, 10);
278 if(!same_order)
swawbip(buf+316, 4);
279 memcpy(&dsr->
h.
views, buf+316, 4);
280 if(!same_order)
swawbip(buf+320, 4);
282 if(!same_order)
swawbip(buf+324, 4);
284 if(!same_order)
swawbip(buf+328, 4);
286 if(!same_order)
swawbip(buf+332, 4);
287 memcpy(&dsr->
h.
omax, buf+332, 4);
288 if(!same_order)
swawbip(buf+336, 4);
289 memcpy(&dsr->
h.
omin, buf+336, 4);
290 if(!same_order)
swawbip(buf+340, 4);
291 memcpy(&dsr->
h.
smax, buf+340, 4);
292 if(!same_order)
swawbip(buf+344, 4);
293 memcpy(&dsr->
h.
smin, buf+344, 4);
297 if(verbose>0) printf(
"h.extents := %d\n", dsr->
h.
extents);
301 if(verbose>1) printf(
"h.regular := %c\n", dsr->
h.
regular);
305 if(verbose>1) {printf(
" complete Analyze header was read.\n"); fflush(stdout);}