TPCCLIB
Loading...
Searching...
No Matches
imgfile.c
Go to the documentation of this file.
1
12/*****************************************************************************/
13#include "libtpcimgio.h"
14/*****************************************************************************/
15
16/*****************************************************************************/
28 const char *fname,
32 IMG *img
33) {
34 FILE *fp;
35 int ret;
36 ECAT7_mainheader ecat7_main_header;
37 ECAT63_mainheader ecat63_main_header;
38 char temp[FILENAME_MAX];
39
40 if(IMG_TEST) {printf("imgRead(%s, *img)\n", fname); fflush(stdout);}
41 /* Check the arguments */
42 if(fname==NULL) {img->statmsg=imgStatus(STATUS_FAULT); return(1);}
43 if(img==NULL || img->status!=IMG_STATUS_INITIALIZED) {
44 img->statmsg=imgStatus(STATUS_FAULT); return(2);}
45
46 /* Check if we have NIfTI file, which may be in single file format,
47 or dual file format which has similar names as microPET and Analyze */
48 if(niftiExists(fname, NULL, NULL, NULL, NULL, IMG_TEST-3, NULL)>0) {
49 /* Read NIfTI image */
50 ret=imgReadNifti(fname, img, IMG_TEST);
51 if(IMG_TEST) {printf("imgReadNifti() := %d\n", ret); fflush(stdout);}
52 if(ret==STATUS_OK) {
53 if(IMG_TEST) printf("%s identified as supported NIfTI.\n", fname);
54 img->statmsg=imgStatus(STATUS_OK);
55 return(STATUS_OK);
56 }
57 img->statmsg=imgStatus(ret); return(4);
58 }
59
60 /* Check if we have microPET or Analyze file, which consist of separate header
61 and data files, and have similar names */
62 if(upetExists(fname, NULL, NULL, IMG_TEST-3)==2) {
63 /* Read microPET image */
64 ret=imgReadMicropet(fname, img); if(ret!=STATUS_OK) return(3);
65 if(IMG_TEST) printf("%s identified as microPET format.\n", fname);
66 return(0);
67 }
68 if(anaExistsNew(fname, temp, NULL, NULL)!=0) {
70 /* Read Analyze image */
71 ret=imgReadAnalyze(temp, img);
72 if(IMG_TEST) {printf("imgReadAnalyze() := %d\n", ret); fflush(stdout);}
73 if(ret==STATUS_OK) {
74 if(IMG_TEST) printf("%s identified as supported Analyze 7.5 format.\n", fname);
75 img->statmsg=imgStatus(STATUS_OK);
76 return(0);
77 }
78 if(ret==STATUS_NOSIFDATA || ret==STATUS_WRONGSIFDATA) {
79 img->statmsg=imgStatus(ret); return(0);}
80 img->statmsg=imgStatus(ret); return(4);
81 }
82
83 /* Check if we have an ECAT file */
84 /* Open file for read */
85 if((fp=fopen(fname, "rb")) == NULL) {
86 img->statmsg=imgStatus(STATUS_NOFILE); return(4);
87 }
88 /* Try to read ECAT 7.x main header */
89 ret=ecat7ReadMainheader(fp, &ecat7_main_header);
90 if(ret) {fclose(fp); img->statmsg=imgStatus(STATUS_UNKNOWNFORMAT); return(4);}
91 /* If header could be read, check for magic number */
92 if(strncmp(ecat7_main_header.magic_number, ECAT7V_MAGICNR, 7)==0) {
93 /* This is ECAT 7.x file */
94 /* Check if file type is supported */
95 if(imgEcat7Supported(&ecat7_main_header)==0) {
96 fclose(fp); img->statmsg=imgStatus(STATUS_UNSUPPORTED); return(5);
97 }
98 fclose(fp);
99 /* Read file */
100 if(IMG_TEST) printf("%s identified as supported ECAT 7.x %s format\n",
101 fname, ecat7filetype(ecat7_main_header.file_type));
102 ret=imgReadEcat7(fname, img);
103 if(ret) {if(IMG_TEST) printf("imgReadEcat7()=%d\n", ret); return(6);}
104 } else {
105 /* Check if file is in ECAT 6.3 format */
106 ret=ecat63ReadMainheader(fp, &ecat63_main_header);
107 fclose(fp);
108 if(ret==0) {
109 /* It seems to be ECAT 6.3, so read it */
110 if(IMG_TEST) printf("%s identified as supported ECAT 6.3 %s format\n",
111 fname, ecat7filetype(ecat63_main_header.file_type));
112 ret=ecat63ReadAllToImg(fname, img);
113 if(ret) {
114 if(IMG_TEST) fprintf(stderr, "ecat63ReaddAllToImg: %s\n", ecat63errmsg);
115 if(ret==6) img->statmsg=imgStatus(STATUS_MISSINGMATRIX);
116 else img->statmsg=imgStatus(STATUS_UNSUPPORTED);
117 return(6);
118 }
119 } else {img->statmsg=imgStatus(STATUS_UNKNOWNFORMAT); return(4);}
120 }
121
122 img->statmsg=imgStatus(STATUS_OK);
123 return(0);
124}
125/*****************************************************************************/
126
127/*****************************************************************************/
139 const char *fname,
141 IMG *img
142) {
143 int ret;
144
145 if(IMG_TEST) printf("imgWrite(%s, *img)\n", fname);
146 /* Check the arguments */
147 if(fname==NULL) return(1);
148 if(img==NULL || img->status!=IMG_STATUS_OCCUPIED) {
149 imgSetStatus(img, STATUS_FAULT); return(2);}
150 if(img->type!=IMG_TYPE_RAW &&
151 img->type!=IMG_TYPE_IMAGE &&
152 img->type!=IMG_TYPE_POLARMAP) {
153 imgSetStatus(img, STATUS_FAULT); return(2);}
154
155 /* If _fileFormat is not defined, then determine it from the file name */
156 if(img->_fileFormat==IMG_UNKNOWN) {
157 if(IMG_TEST>1) printf(" file format determined based on file name\n");
158 imgFormatFromFName(img, fname);
159 if(IMG_TEST>1) printf(" _fileFormat := %d\n", img->_fileFormat);
160 }
161
162 /* Write */
163 if(img->_fileFormat==IMG_E63) {
164 ret=ecat63WriteAllImg(fname, img);
165 switch(ret) {
166 case 0: break;
167 case 4: imgSetStatus(img, STATUS_NOMEMORY); break;
168 case 3: imgSetStatus(img, STATUS_NOWRITEPERM); break;
169 case 9: imgSetStatus(img, STATUS_DISKFULL); break;
170 default: imgSetStatus(img, STATUS_FAULT);
171 }
172 if(ret) return(7);
173 } else if(img->_fileFormat==IMG_ANA || img->_fileFormat==IMG_ANA_L) {
174 ret=imgWriteAnalyze(fname, img); if(ret) return(5);
175 } else if(img->_fileFormat==IMG_NIFTI_1S || img->_fileFormat==IMG_NIFTI_1D) {
176 ret=imgWriteNifti(fname, img, 1, IMG_TEST-1); if(ret) return(5);
177 } else if(img->_fileFormat==IMG_E7_2D) {
178 ret=imgWrite2DEcat7(fname, img); if(ret) return(5);
179 } else if(img->_fileFormat==IMG_POLARMAP) {
180 ret=imgWritePolarmap(fname, img); if(ret) return(5);
181 } else {
182 ret=imgWriteEcat7(fname, img); if(ret) return(5);
183 }
184 imgSetStatus(img, STATUS_OK);
185 return(0);
186}
187/*****************************************************************************/
188
189/*****************************************************************************/
202 const char *fname,
204 IMG *img,
207 int format
208) {
209 int ret;
210
211 if(IMG_TEST) {
212 printf("\nimgReadHeader(%s, *img, %d)\n", fname, format);
213 fflush(stdout);
214 }
215
216 /* Check the arguments */
217 if(fname==NULL) return STATUS_FAULT;
218 if(img==NULL) return STATUS_FAULT;
219 if(img->status!=IMG_STATUS_INITIALIZED) return STATUS_FAULT;
220
221 /* If user did not know the file format, then try to decide it */
222 if(format==IMG_UNKNOWN) {
223 int scanner, imgtype, modality;
224 ret=imgFormatDetermine(fname, NULL, NULL, NULL, NULL,
225 &format, &scanner, &imgtype, &modality, IMG_TEST-3);
226 if(ret!=0) {
227 imgSetStatus(img, ret);
228 return(ret);
229 }
230 if(format==IMG_UNKNOWN) {
231 imgSetStatus(img, STATUS_UNSUPPORTED);
232 return(STATUS_UNSUPPORTED);
233 }
234 }
235
236 /* Read the header for the file format */
237 ret=STATUS_UNSUPPORTED;
238 if(format==IMG_ANA || format==IMG_ANA_L) {
239 /* Read Analyze header information */
240 ret=imgReadAnalyzeHeader(fname, img);
241 } else if(format==IMG_NIFTI_1S || format==IMG_NIFTI_1D) {
242 /* Read NIfTI image header information */
243 ret=imgReadNiftiHeader(fname, img, IMG_TEST-2);
244 } else if(format==IMG_MICROPET) {
245 /* Read microPET header information */
246 ret=imgReadMicropetHeader(fname, img);
247 } else if(format==IMG_E7 || format==IMG_E7_2D) {
248 ret=imgReadEcat7Header(fname, img);
249 } else if(format==IMG_E63 || format==IMG_POLARMAP) {
250 ret=imgReadEcat63Header(fname, img);
251 }
252 imgSetStatus(img, ret);
253 return(ret);
254}
255/*****************************************************************************/
256
257/*****************************************************************************/
275 const char *fname,
277 int frame_to_read,
282 IMG *img,
285 int frame_index
286) {
287 IMG test_img;
288 int ret=0;
289
290 if(IMG_TEST) {
291 printf("\nimgReadFrame(%s, %d, *img, %d)\n", fname, frame_to_read, frame_index);
292 fflush(stdout);
293 }
294 /*
295 * Check the input
296 */
297 if(fname==NULL) return STATUS_FAULT;
298 if(img==NULL) return STATUS_FAULT;
299 if(img->status!=IMG_STATUS_INITIALIZED && img->status!=IMG_STATUS_OCCUPIED) return STATUS_FAULT;
300 if(frame_to_read<1) return STATUS_FAULT;
301 if(frame_index<0) return STATUS_FAULT;
302 /* if frame_index>0, then there must be sufficient memory allocated for it */
303 if(frame_index>0) {
304 if(img->status!=IMG_STATUS_OCCUPIED) return STATUS_FAULT;
305 if(frame_index>img->dimt-1) return STATUS_FAULT;
306 }
307
308 /*
309 * If IMG is preallocated, check that fundamental header information
310 * is compatible with old and new contents.
311 * If not allocated, then read the header contents, and allocate it
312 */
313 imgInit(&test_img);
314 if(img->status==IMG_STATUS_OCCUPIED) {
315 ret=imgReadHeader(fname, &test_img, img->_fileFormat);
316 imgSetStatus(&test_img, ret);
317 if(IMG_TEST>1) printf("imgReadHeader() return message := %s\n", test_img.statmsg);
318 if(ret) return(ret);
319 if(IMG_TEST>3) imgInfo(&test_img);
320 /* Test that file format and type are the same */
321 ret=0;
322 if(img->type!=test_img.type) ret++;
323 if(img->_fileFormat!=test_img._fileFormat) ret++;
324 /* Test that x, y, and z dimensions are the same */
325 if(img->dimx!=test_img.dimx) ret++;
326 if(img->dimy!=test_img.dimy) ret++;
327 if(img->dimz!=test_img.dimz) ret++;
328 imgEmpty(&test_img); if(ret>0) return STATUS_INVALIDHEADER;
329 } else {
330 ret=imgReadHeader(fname, img, IMG_UNKNOWN);
331 imgSetStatus(img, ret);
332 if(IMG_TEST>1) printf("imgReadHeader() return message := %s\n", img->statmsg);
333 if(ret) return(ret);
334 if(IMG_TEST>3) imgInfo(img);
335 /* Allocate memory for one frame */
336 img->dimt=1;
337 ret=imgAllocate(img, img->dimz, img->dimy, img->dimx, img->dimt);
338 if(ret) return STATUS_NOMEMORY;
339 }
340
341 /*
342 * Read the frame data and corresponding information like frame time
343 * if available
344 */
345 switch(img->_fileFormat) {
346 case IMG_E7:
347 case IMG_E7_2D:
348 case IMG_POLARMAP:
349 ret=imgReadEcat7Frame(fname, frame_to_read, img, frame_index);
350 if(IMG_TEST>1) printf("imgReadEcat7Frame() return value := %d\n", ret);
351 break;
352 case IMG_E63:
353 ret=imgReadEcat63Frame(fname, frame_to_read, img, frame_index);
354 if(IMG_TEST>1) printf("imgReadEcat63Frame() return value := %d\n", ret);
355 break;
356 case IMG_ANA:
357 case IMG_ANA_L:
358 ret=imgReadAnalyzeFrame(fname, frame_to_read, img, frame_index);
359 if(IMG_TEST>1) printf("imgReadAnalyzeFrame() return value := %d\n", ret);
360 break;
361 case IMG_NIFTI_1S:
362 case IMG_NIFTI_1D:
363 ret=imgReadNiftiFrame(fname, frame_to_read, img, frame_index, IMG_TEST-2);
364 if(IMG_TEST>1) printf("imgReadNiftiFrame() return value := %d\n", ret);
365 break;
366 case IMG_MICROPET:
367 ret=imgReadMicropetFrame(fname, frame_to_read, img, frame_index);
368 if(IMG_TEST>1) printf("imgReadAnalyzeFrame() return value := %d\n", ret);
369 break;
370 default:
371 ret=STATUS_UNSUPPORTED;
372 }
373 imgSetStatus(img, ret);
374 return ret;
375}
376/*****************************************************************************/
377
378/*****************************************************************************/
398 const char *fname,
404 int frame_to_write,
406 IMG *img,
408 int frame_index
409) {
410 int ret=0;
411
412 if(IMG_TEST>0) {
413 printf("\nimgWriteFrame(%s, %d, *img, %d)\n", fname, frame_to_write, frame_index);
414 fflush(stdout);
415 }
416 if(IMG_TEST>3) {
417 char buf[32];
418 if(!ctime_r_int(&img->scanStart, buf)) strcpy(buf, "1900-01-01 00:00:00");
419 fprintf(stdout, " scan_start_time := %s\n", buf);
420 }
421
422 /*
423 * Check the input
424 */
425 if(fname==NULL) return STATUS_FAULT;
426 if(img==NULL) return STATUS_FAULT;
427 if(img->status!=IMG_STATUS_OCCUPIED) return STATUS_FAULT;
428 if(frame_to_write<0) return STATUS_FAULT;
429 if(frame_index<0 || frame_index>=img->dimt) return STATUS_FAULT;
430
431
432 /*
433 * Call separate function for each supported file format
434 */
435 imgFormatFromFName(img, fname);
436 switch(img->_fileFormat) {
437 case IMG_E7:
438 case IMG_E7_2D:
439 case IMG_POLARMAP:
440 ret=imgWriteEcat7Frame(fname, frame_to_write, img, frame_index);
441 break;
442 case IMG_E63:
443 ret=imgWriteEcat63Frame(fname, frame_to_write, img, frame_index);
444 break;
445 case IMG_ANA:
446 case IMG_ANA_L:
447 ret=STATUS_UNSUPPORTED;
448 /* Not supported because would require global min&max values
449 * if saved in short ints which is now the only possibility
450 * ret=imgWriteAnaFrame(fname, frame_to_write, img, frame_index);
451 */
452 break;
453 case IMG_NIFTI_1D:
454 case IMG_NIFTI_1S:
455#if(0)
456 /* Not supported because would require global min&max values
457 * if saved in short ints which is now the only possibility
458 */
459 ret=STATUS_UNSUPPORTED;
460#endif
461 /* Nifti is currently always written as floats, therefore
462 global min and max pixel values are not yet needed */
463 ret=imgWriteNiftiFrame(fname, frame_to_write, img, frame_index, 0, 0, IMG_TEST-2);
464 break;
465 default:
466 ret=STATUS_UNSUPPORTED;
467 }
468 imgSetStatus(img, ret);
469 return ret;
470}
471/*****************************************************************************/
472
473/*****************************************************************************/
486 IMG *img,
488 const char *fname
489) {
490 char *cptr=NULL, *cptr2=NULL, temp[FILENAME_MAX];
491
492 if(IMG_TEST>2) printf("imgFormatFromFName(img, %s)\n", fname);
493 if(img->_fileFormat!=IMG_UNKNOWN && img->_fileFormat>0) {
494 if(IMG_TEST>3) printf(" _fileFormat := %d, not changed\n", img->_fileFormat);
495 return;
496 }
497 img->_fileFormat=IMG_E7; /* default */
498 /* get extensions */
499 strcpy(temp, fname); cptr=strrchr(temp, '.');
500 if(cptr!=NULL) {
501 *cptr=(char)0; cptr++;
502 cptr2=strrchr(temp, '.'); if(cptr2!=NULL) {*cptr2=(char)0; cptr2++;}
503 }
504 if(cptr2!=NULL) {
505 if(strcasecmp(cptr2, "i.hdr")==0) { img->_fileFormat=IMG_INTERFILE; return;}
506 if(strcasecmp(cptr2, "i.img")==0) { img->_fileFormat=IMG_INTERFILE; return;}
507 }
508 if(cptr!=NULL) {
509 if(strcasecmp(cptr, "hdr")==0) { img->_fileFormat=IMG_ANA; return;}
510 if(strcasecmp(cptr, "polmap")==0) { img->_fileFormat=IMG_POLARMAP; return;}
511 if(strcasecmp(cptr, "img")==0 ||
512 strcasecmp(cptr, "scn")==0 ||
513 strcasecmp(cptr, "nrm")==0 ||
514 strcasecmp(cptr, "atn")==0) {
515 img->_fileFormat=IMG_E63; return;
516 }
517 if(strcasecmp(cptr, "dcm")==0) { img->_fileFormat=IMG_DICOM; return;}
518 if(strcasecmp(cptr, "i")==0) { img->_fileFormat=IMG_INTERFILE; return;}
519 if(strcasecmp(cptr, "nii")==0) { img->_fileFormat=IMG_NIFTI_1S; return;}
520 } else { /* no extension at all */
521 img->_fileFormat=IMG_ANA;
522 }
523}
524/*****************************************************************************/
525
526/*****************************************************************************/
540 const char *fname,
543 char *basename,
546 char *hdrfile,
549 char *imgfile,
552 char *siffile,
555 int *file_format,
558 int *scanner,
561 int *type,
564 int *modality,
566 int verbose
567) {
568 char *cptr, temp[FILENAME_MAX];
569 int ret, fformat=IMG_UNKNOWN;
570 NIFTI_DSR nifti_dsr;
571 IMG img;
572
573 if(verbose>0) {printf("imgFormatDetermine(\"%s\", ...)\n", fname); fflush(stdout);}
574 /* Initiate results */
575 if(basename!=NULL) strcpy(basename, "");
576 if(hdrfile!=NULL) strcpy(hdrfile, "");
577 if(imgfile!=NULL) strcpy(imgfile, "");
578 if(siffile!=NULL) strcpy(siffile, "");
579 if(file_format!=NULL) *file_format=IMG_UNKNOWN;
580 if(scanner!=NULL) *scanner=SCANNER_UNKNOWN;
581 if(type!=NULL) *type=IMG_TYPE_UNKNOWN;
582 if(modality!=NULL) *modality=IMG_MODALITY_UNKNOWN;
583 if(fname==NULL) return STATUS_FAULT;
584 if(strlen(fname)<1) return STATUS_NOFILE;
585
586 /* Check the image data exists and is accessible */
587 strcpy(temp, fname);
588 if(access(temp, 0) == -1) {
589 if(verbose>1) printf(" file is not directly accessible.\n");
590 /* Try to add .nii to the name */
591 sprintf(temp, "%s.nii", fname);
592 if(access(temp, 0) == -1) {
593 if(verbose>1) printf(" file is not accessible with .nii extension.\n");
594 /* Try to add .img to the name */
595 sprintf(temp, "%s.img", fname);
596 if(access(temp, 0) == -1) {
597 if(verbose>1) printf(" file is not accessible with .img extension.\n");
598 /* Try to add .hdr to the name */
599 sprintf(temp, "%s.hdr", fname);
600 if(access(temp, 0) == -1) sprintf(temp, "%s.i.hdr", fname);
601 if(access(temp, 0) == -1) sprintf(temp, "%s.img.hdr", fname);
602 if(access(temp, 0) == -1) {
603 if(verbose>1) printf(" file is not accessible with .hdr extension.\n");
604 /* Try to add .dcm to the name */
605 sprintf(temp, "%s.dcm", fname);
606 if(access(temp, 0) == -1) {
607 if(verbose>1) printf(" file is not accessible with .dcm extension.\n");
608 return STATUS_NOFILE;
609 }
610 }
611 }
612 }
613 }
614 if(verbose>1) {printf("'%s' is accessible.\n", temp); fflush(stdout);}
615
616 /* DICOM is identified from the file name extension, and not processed any further */
617 cptr=strrchr(temp, '.');
618 if(cptr!=NULL && strcasecmp(cptr, ".DCM")==0) {
619 fformat=IMG_DICOM; if(file_format!=NULL) *file_format=fformat;
620 if(verbose>1) printf("file was identified to be in DICOM format.\n");
621 return STATUS_OK;
622 }
623
624 /* Try to read it as ECAT file first, because images which consist of
625 more than one file may reside in the same folder with
626 other formats */
627 imgInit(&img);
628 /* Is this an ECAT7 file */
629 ret=imgReadEcat7Header(fname, &img);
630 if(ret==STATUS_OK) {
631 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
632 if(verbose>1) printf("file was identified to be in ECAT7 format.\n");
633 } else if(ret==STATUS_VARMATSIZE) {
634 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
635 if(verbose>1) printf("file is ECAT7 but matrix sizes are different\n.");
636 } else if(ret==STATUS_UNKNOWNFORMAT || ret==STATUS_NOFILE) {
637 /* If main header was read but format was not identified as Ecat7,
638 it might be in Ecat6 format */
639 ret=imgReadEcat63Header(fname, &img);
640 /* if necessary, try also with .img added */
641 if(ret!=STATUS_OK && ret!=STATUS_VARMATSIZE && ret!=STATUS_MISSINGMATRIX) {
642 sprintf(temp, "%s.img", fname); ret=imgReadEcat63Header(temp, &img);}
643 if(ret==STATUS_OK) {
644 /* Is this an ECAT6 file; however this is rather uncertain step, because
645 ECAT6 files don't contain any magic number */
646 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
647 if(verbose>1) printf("file was identified to be in ECAT6 format.\n");
648 } else if(ret==STATUS_VARMATSIZE || ret==STATUS_MISSINGMATRIX) {
649 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
650 if(verbose>1) printf("file is ECAT63 but matrix sizes are different\n.");
651 }
652 }
653
654 /* If format was not yet identified, then try to read it as NIfTI;
655 this must be done before trying Analyze, because dual format NIfTI
656 is compatible with Analyze format */
657 if(fformat==IMG_UNKNOWN &&
658 niftiExists(fname, hdrfile, imgfile, siffile, &nifti_dsr, verbose-2, NULL)>0)
659 {
660 if(verbose>1) printf("file was identified to be in NIfTI format.\n");
661 /* Read NIfTI header information into IMG struct */
662 ret=imgGetNiftiHeader(&img, &nifti_dsr, verbose-2);
663 if(ret==STATUS_OK) {
664 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
665 }
666 }
667
668 /* If format was not yet identified, then try to read it as microPET */
669 if(fformat==IMG_UNKNOWN && upetExists(fname, hdrfile, imgfile, verbose-1)==2) {
670 fformat=IMG_MICROPET; if(file_format!=NULL) *file_format=fformat;
671 if(verbose>1) printf("file was identified to be in microPET format\n.");
672 /* Read header information from file */
673 ret=imgReadMicropetHeader(fname, &img);
674 if(ret==STATUS_OK) {
675 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
676 }
677 }
678
679 /* If format was not yet identified, then try to read it as Analyze */
680 if(fformat==IMG_UNKNOWN && anaDatabaseExists(fname, hdrfile, imgfile, siffile)>0) {
681 if(verbose>1) printf("file was identified to be in Analyze format.\n");
682 fformat=IMG_ANA; if(file_format!=NULL) *file_format=fformat;
683 /* Read Analyze header information */
684 ret=imgReadAnalyzeHeader(hdrfile, &img);
685 if(ret==STATUS_OK) {
686 fformat=img._fileFormat; if(file_format!=NULL) *file_format=fformat;
687 }
688 }
689
690 /* If format was not yet identified, check if it is DICOM (without .dcm extension
691 that was checked previously) */
692 if(dcmVerifyMagic(fname, NULL)) {
693 fformat=IMG_DICOM; if(file_format!=NULL) *file_format=fformat;
694 if(verbose>1) printf("file was identified to be in DICOM format.\n");
695 return STATUS_OK;
696 }
697
698 /* If format was not yet identified, check if it is Interfile */
699 if(fformat==IMG_UNKNOWN && interfileExists(fname, hdrfile, imgfile, verbose-1)!=0) {
700 fformat=IMG_INTERFILE; if(file_format!=NULL) *file_format=fformat;
701 if(verbose>1) printf("file was identified to be in Interfile format\n.");
702 }
703
704 /* Fill other information */
705 if(scanner!=NULL) *scanner=img.scanner;
706 if(type!=NULL) *type=img.type;
707 if(modality!=NULL) *modality=img.modality;
708
709 /* Quit */
710 imgEmpty(&img);
711 if(verbose>1) printf("fformat := %d\n", fformat);
712 return STATUS_OK;
713}
714/*****************************************************************************/
715
716/*****************************************************************************/
int anaExistsNew(const char *filename, char *hdrfile, char *imgfile, char *siffile)
Definition analyze.c:43
int anaDatabaseExists(const char *dbname, char *hdrfile, char *imgfile, char *siffile)
Definition analyze.c:704
void anaRemoveFNameExtension(char *fname)
Definition analyze.c:687
char * ctime_r_int(const time_t *t, char *buf)
Convert calendard time t into a null-terminated string of the form YYYY-MM-DD hh:mm:ss,...
Definition datetime.c:110
int dcmVerifyMagic(const char *filename, FILE *fp)
Definition dcm.c:157
char ecat63errmsg[128]
Definition ecat63h.c:7
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
Definition ecat63r.c:25
char * ecat7filetype(short int file_type)
Definition ecat7p.c:447
int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h)
Definition ecat7r.c:15
int IMG_TEST
Definition img.c:6
void imgInfo(IMG *image)
Definition img.c:359
char * imgStatus(int status_index)
Definition img.c:330
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
Definition img.c:194
void imgSetStatus(IMG *img, int status_index)
Definition img.c:345
void imgEmpty(IMG *image)
Definition img.c:121
void imgInit(IMG *image)
Definition img.c:60
int imgWriteAnalyze(const char *dbname, IMG *img)
Definition img_ana.c:162
int imgReadAnalyzeFrame(const char *fname, int frame_to_read, IMG *img, int frame_index)
Definition img_ana.c:639
int imgReadAnalyzeHeader(const char *dbname, IMG *img)
Definition img_ana.c:360
int imgReadAnalyze(const char *dbname, IMG *img)
Definition img_ana.c:24
int ecat63WriteAllImg(const char *fname, IMG *img)
Definition img_e63.c:335
int imgWriteEcat63Frame(const char *fname, int frame_to_write, IMG *img, int frame_index)
Definition img_e63.c:1711
int imgReadEcat63Header(const char *fname, IMG *img)
Definition img_e63.c:1318
int imgReadEcat63Frame(const char *fname, int frame_to_read, IMG *img, int frame_index)
Definition img_e63.c:1503
int ecat63ReadAllToImg(const char *fname, IMG *img)
Definition img_e63.c:22
int imgWrite2DEcat7(const char *fname, IMG *img)
Definition img_e7.c:526
int imgWriteEcat7(const char *fname, IMG *img)
Definition img_e7.c:382
int imgReadEcat7Frame(const char *fname, int frame_to_read, IMG *img, int frame_index)
Definition img_e7.c:1103
int imgEcat7Supported(ECAT7_mainheader *h)
Definition img_e7.c:1036
int imgReadEcat7(const char *fname, IMG *img)
Definition img_e7.c:19
int imgReadEcat7Header(const char *fname, IMG *img)
Definition img_e7.c:860
int imgWriteEcat7Frame(const char *fname, int frame_to_write, IMG *img, int frame_index)
Definition img_e7.c:1295
int imgWritePolarmap(const char *fname, IMG *img)
Definition img_e7.c:661
int imgReadNiftiHeader(const char *filename, IMG *img, int verbose)
Definition img_nii.c:134
int imgReadNifti(const char *filename, IMG *img, int verbose)
Definition img_nii.c:23
int imgReadNiftiFrame(const char *filename, int frame_to_read, IMG *img, int frame_index, int verbose)
Definition img_nii.c:311
int imgWriteNiftiFrame(const char *dbname, int frame_to_write, IMG *img, int frame_index, float fmin, float fmax, int verbose)
Definition img_nii.c:594
int imgWriteNifti(const char *dbname, IMG *img, int save_sif, int verbose)
Definition img_nii.c:811
int imgGetNiftiHeader(IMG *img, NIFTI_DSR *dsr, int verbose)
Definition img_nii.c:218
int imgReadMicropetFrame(const char *fname, int frame_to_read, IMG *img, int frame_index)
Definition img_upet.c:819
int imgReadMicropetHeader(const char *dbname, IMG *img)
Definition img_upet.c:767
int imgReadMicropet(const char *fname, IMG *img)
Definition img_upet.c:971
int imgFormatDetermine(const char *fname, char *basename, char *hdrfile, char *imgfile, char *siffile, int *file_format, int *scanner, int *type, int *modality, int verbose)
Definition imgfile.c:537
int imgRead(const char *fname, IMG *img)
Definition imgfile.c:26
int imgWriteFrame(const char *fname, int frame_to_write, IMG *img, int frame_index)
Definition imgfile.c:393
int imgReadFrame(const char *fname, int frame_to_read, IMG *img, int frame_index)
Definition imgfile.c:270
void imgFormatFromFName(IMG *img, const char *fname)
Definition imgfile.c:484
int imgWrite(const char *fname, IMG *img)
Definition imgfile.c:137
int imgReadHeader(const char *fname, IMG *img, int format)
Definition imgfile.c:200
int interfileExists(const char *fname, char *hdrfile, char *imgfile, int verbose)
Definition interfile.c:193
Header file for libtpcimgio.
#define IMG_TYPE_RAW
#define IMG_E7
#define IMG_INTERFILE
#define IMG_STATUS_OCCUPIED
#define IMG_TYPE_UNKNOWN
#define IMG_NIFTI_1S
#define IMG_ANA_L
#define IMG_UNKNOWN
#define IMG_E7_2D
#define IMG_TYPE_POLARMAP
#define IMG_DICOM
#define IMG_STATUS_INITIALIZED
#define IMG_E63
int niftiExists(const char *dbname, char *hdrfile, char *imgile, char *siffile, NIFTI_DSR *header, int verbose, char *status)
Definition nifti.c:160
#define IMG_ANA
#define IMG_MICROPET
#define IMG_POLARMAP
int upetExists(const char *upetname, char *hdrfile, char *imgfile, int verbose)
Definition micropet.c:86
#define IMG_NIFTI_1D
#define SCANNER_UNKNOWN
#define IMG_MODALITY_UNKNOWN
#define IMG_TYPE_IMAGE
short int file_type
char magic_number[14]
unsigned short int dimx
char type
char status
time_t scanStart
int _fileFormat
unsigned short int dimt
int scanner
unsigned short int dimz
int modality
unsigned short int dimy
const char * statmsg