35 if(
ECAT63_TEST>0) {printf(
"ecat63ReadMainheader()\n"); fflush(stdout);}
36 if(fp==NULL || h==NULL)
return(1);
39 fseek(fp, 0, SEEK_SET);
if(ftell(fp)!=0)
return(1);
45 memcpy(h->
fill1, buf+14, 14);
67 if(!little)
swabip(buf+50, 2);
71 if(
ECAT63_TEST>1) {printf(
"invalid data_type; assuming VAX_I2\n"); fflush(stdout);}
76 if(!little)
swabip(buf+48, 2);
78 if(!little)
swabip(buf+52, 2);
80 if(!little)
swabip(buf+54, 2);
83 if(!little)
swabip(buf+66, 2);
85 if(!little)
swabip(buf+68, 2);
87 if(!little)
swabip(buf+70, 2);
89 if(!little)
swabip(buf+72, 2);
91 if(!little)
swabip(buf+74, 2);
93 if(!little)
swabip(buf+76, 2);
95 if(!little)
swabip(buf+134, 2);
97 if(!little)
swabip(buf+136, 2);
99 if(!little)
swabip(buf+138, 2);
101 if(!little)
swabip(buf+148, 2);
103 if(!little)
swabip(buf+150, 2);
105 if(!little)
swabip(buf+152, 2);
107 if(!little)
swabip(buf+158, 2);
109 if(!little)
swabip(buf+160, 2);
111 if(!little)
swabip(buf+350, 2);
113 if(!little)
swabip(buf+352, 2);
115 if(!little)
swabip(buf+354, 2);
117 if(!little)
swabip(buf+376, 2);
119 if(!little)
swabip(buf+378, 2);
121 if(!little)
swabip(buf+380, 2);
123 if(!little)
swabip(buf+382, 2);
125 if(!little)
swabip(buf+452, 2);
127 if(!little)
swabip(buf+454, 2);
129 if(!little)
swabip(buf+456, 2);
131 if(!little)
swabip(buf+472, 40);
132 memcpy(h->
fill2, buf+472, 40);
155 if(strncmp(h->
ecat_format,
"ECAT63", 6)!=0)
return(3);
163 if(
ECAT63_TEST>1) {printf(
"Invalid data types; probable conversion error.\n"); fflush(stdout);}
168 printf(
"Invalid calibration factor; possible conversion error.\n"); fflush(stdout);}
173 if(
ECAT63_TEST>1) {printf(
"Invalid file types; probable conversion error.\n"); fflush(stdout);}
203 if(verbose>0) {printf(
"ecat63ReadImageheader(fp, %d ih)\n", blk); fflush(stdout);}
204 if(fp==NULL || blk<2 || h==NULL) {
205 if(errmsg!=NULL) strcpy(errmsg,
"invalid input");
206 if(verbose>0) {fprintf(stderr,
"Invalid input.\n"); fflush(stderr);}
213 if(errmsg!=NULL) sprintf(errmsg,
"failed to find block %d", blk);
214 if(verbose>0) {fprintf(stderr,
"Failed to find block %d.\n", blk); fflush(stderr);}
219 if(errmsg!=NULL) sprintf(errmsg,
"failed to read block %d", blk);
220 if(verbose>0) {fprintf(stderr,
"Failed to read block %d.\n", blk); fflush(stderr);}
231 if(verbose>10) printf(
"data_type=%d\n", h->
data_type);
240 memcpy(h->
fill2, buf+460, 52);
270 if(errmsg!=NULL) strcpy(errmsg,
"invalid data types; probable conversion error");
271 if(verbose>0) {fprintf(stderr,
"Invalid data types; probable conversion error.\n"); fflush(stderr);}
272 if(verbose>1) {printf(
"data_type := %d\n", h->
data_type); fflush(stdout);}
276 if(errmsg!=NULL) strcpy(errmsg,
"invalid calibration factor; probable conversion error");
277 if(verbose>0) {fprintf(stderr,
"Invalid calibration factor; probable conversion error.\n"); fflush(stderr);}
281 if(errmsg!=NULL) strcpy(errmsg,
"invalid frame duration; probable conversion error");
282 if(verbose>0) {fprintf(stderr,
"Invalid frame duration; probable conversion error.\n"); fflush(stderr);}
285 if(errmsg!=NULL) strcpy(errmsg,
"ok");
312 if(
ECAT63_TEST) printf(
"ecat63ReadAttnheader(fp, %d, ah)\n", blk);
313 if(fp==NULL || blk<2 || h==NULL) {
314 if(errmsg!=NULL) strcpy(errmsg,
"invalid input");
315 if(verbose>0) fprintf(stderr,
"Invalid input.\n");
322 if(errmsg!=NULL) sprintf(errmsg,
"failed to find block %d", blk);
323 if(verbose>0) fprintf(stderr,
"Failed to find block %d.\n", blk);
328 if(errmsg!=NULL) sprintf(errmsg,
"failed to read block %d", blk);
329 if(verbose>0) fprintf(stderr,
"Failed to read block %d.\n", blk);
355 if(errmsg!=NULL) strcpy(errmsg,
"invalid data types; probable conversion error");
356 if(verbose>0) fprintf(stderr,
"Invalid data types; probable conversion error.\n");
357 if(verbose>1) printf(
"data_type := %d\n", h->
data_type);
361 if(errmsg!=NULL) strcpy(errmsg,
"invalid scale factor; probable conversion error");
362 if(verbose>0) fprintf(stderr,
"Invalid scale factor; probable conversion error.\n");
365 if(errmsg!=NULL) strcpy(errmsg,
"ok");
393 if(
ECAT63_TEST) printf(
"ecat63ReadScanheader(fp, %d, sh)\n", blk);
394 if(fp==NULL || blk<2 || h==NULL) {
395 if(errmsg!=NULL) strcpy(errmsg,
"invalid input");
396 if(verbose>0) fprintf(stderr,
"Invalid input.\n");
403 if(errmsg!=NULL) sprintf(errmsg,
"failed to find block %d", blk);
404 if(verbose>0) fprintf(stderr,
"Failed to find block %d.\n", blk);
409 if(errmsg!=NULL) sprintf(errmsg,
"failed to read block %d", blk);
410 if(verbose>0) fprintf(stderr,
"Failed to read block %d.\n", blk);
415 memcpy(h->
fill1, buf+0, 126);
426 memcpy(h->
fill2, buf+468, 44);
453 if(errmsg!=NULL) strcpy(errmsg,
"invalid data types; probable conversion error");
454 if(verbose>0) fprintf(stderr,
"Invalid data types; probable conversion error.\n");
455 if(verbose>1) printf(
"data_type := %d\n", h->
data_type);
459 if(errmsg!=NULL) strcpy(errmsg,
"invalid calibration factor; probable conversion error");
460 if(verbose>0) fprintf(stderr,
"Invalid calibration factor; probable conversion error.\n");
464 if(errmsg!=NULL) strcpy(errmsg,
"invalid frame duration; probable conversion error");
465 if(verbose>0) fprintf(stderr,
"Invalid frame duration; probable conversion error.\n");
468 if(errmsg!=NULL) strcpy(errmsg,
"ok");
499 if(
ECAT63_TEST) printf(
"ecat63ReadNormheader(fp, %d, nh)\n", blk);
500 if(fp==NULL || blk<2 || h==NULL) {
501 if(errmsg!=NULL) strcpy(errmsg,
"invalid input");
502 if(verbose>0) fprintf(stderr,
"Invalid input.\n");
509 if(errmsg!=NULL) sprintf(errmsg,
"failed to find block %d", blk);
510 if(verbose>0) fprintf(stderr,
"Failed to find block %d.\n", blk);
515 if(errmsg!=NULL) sprintf(errmsg,
"failed to read block %d", blk);
516 if(verbose>0) fprintf(stderr,
"Failed to read block %d.\n", blk);
524 if(verbose>10) printf(
"data_type=%d\n", h->
data_type);
538 if(errmsg!=NULL) strcpy(errmsg,
"invalid data types; probable conversion error");
539 if(verbose>0) fprintf(stderr,
"Invalid data types; probable conversion error.\n");
540 if(verbose>1) printf(
"data_type := %d\n", h->
data_type);
544 if(errmsg!=NULL) strcpy(errmsg,
"invalid scale factor; probable conversion error");
545 if(verbose>0) fprintf(stderr,
"Invalid scale factor; probable conversion error.\n");
548 if(errmsg!=NULL) strcpy(errmsg,
"ok");
569 int n, little, err=0;
574 if(
ECAT63_TEST) printf(
"ecat63ReadMatdata(fp, %d, %d, data, %d)\n", strtblk, blkNr, dtype);
576 if(blkNr<=0 || strtblk<1 || data==NULL)
return(1);
579 if(ftello(fp)!=(strtblk-1)*
MatBLKSIZE)
return(9);
581 if(fread(data,
MatBLKSIZE, blkNr, fp) < (
unsigned int)blkNr)
return(2);
592 for(
long long int i=0; i<blkNr*
MatBLKSIZE; i+=4, cptr+=4) {
593 n=
ecat63rInt(cptr, 1, little); memcpy(cptr, &n, 4);
598 for(
long long i=0; i<blkNr*
MatBLKSIZE; i+=4, cptr+=4) {
641 char *mdata, *mptr, errmsg[128];
642 float *_fdata, *fptr;
647 if(
ECAT63_TEST) printf(
"ecat63ReadImageMatrix(fp, %d, %d, hdr, fdata)\n",
648 first_block, last_block);
669 blockNr=last_block-first_block;
if(blockNr<1)
return(0);
670 mdata=(
char*)malloc((
size_t)blockNr*
MatBLKSIZE);
677 if(ret || mdata==NULL) {
678 sprintf(
ecat63errmsg,
"cannot read matrix data (%d).\n", ret);
679 free(mdata);
return(9);
683 _fdata=(
float*)malloc((
size_t)pxlNr*
sizeof(
float));
686 free(mdata);
return(11);
691 fptr=_fdata; mptr=mdata;
693 for(
long long i=0; i<pxlNr; i++, mptr++, fptr++)
696 for(
long long i=0; i<pxlNr; i++, mptr+=2, fptr++) {
697 sptr=(
short int*)mptr;
699 if(!(*fptr>-1.0E+22 && *fptr<1.0E+22)) *fptr=0.0;
702 for(
long long i=0; i<pxlNr; i++, mptr+=4, fptr++) {
705 if(!(*fptr>-1.0E+22 && *fptr<1.0E+22)) *fptr=0.0;
708 memcpy(fptr, mptr, pxlNr*4);
709 for(
long long i=0; i<pxlNr; i++, fptr++) {
711 if(!(*fptr>-1.0E+22 && *fptr<1.0E+22)) *fptr=0.0;
746 char *mdata, *mptr, errmsg[128];
747 float *_fdata, *fptr;
752 if(
ECAT63_TEST) printf(
"ecat63ReadScanMatrix(fp, %d, %d, hdr, fdata)\n",
753 first_block, last_block);
774 blockNr=last_block-first_block;
if(blockNr<1)
return(0);
775 mdata=(
char*)malloc((
size_t)blockNr*
MatBLKSIZE);
782 if(ret || mdata==NULL) {
783 sprintf(
ecat63errmsg,
"cannot read matrix data (%d).\n", ret);
784 free(mdata);
return(9);
788 _fdata=(
float*)malloc((
size_t)pxlNr*
sizeof(
float));
791 free(mdata);
return(11);
795 fptr=_fdata; mptr=mdata;
797 for(
long long i=0; i<pxlNr; i++, mptr++, fptr++)
800 for(
long long i=0; i<pxlNr; i++, mptr+=2, fptr++) {
801 sptr=(
short int*)mptr;
805 for(
long long i=0; i<pxlNr; i++, mptr+=4, fptr++) {
810 memcpy(fptr, mptr, pxlNr*4);
811 for(
long long i=0; i<pxlNr; i++, fptr++) *fptr *= h->
scale_factor;
845 char *mdata, *mptr, errmsg[128];
846 float *_fdata, *fptr;
851 if(
ECAT63_TEST) printf(
"ecat63ReadAttnMatrix(fp, %d, %d, hdr, fdata)\n",
852 first_block, last_block);
873 blockNr=last_block-first_block;
if(blockNr<1)
return(0);
874 mdata=(
char*)malloc((
size_t)blockNr*
MatBLKSIZE);
881 if(ret || mdata==NULL) {
882 sprintf(
ecat63errmsg,
"cannot read matrix data (%d).\n", ret);
883 free(mdata);
return(9);
887 _fdata=(
float*)malloc((
size_t)pxlNr*
sizeof(
float));
890 free(mdata);
return(11);
894 fptr=_fdata; mptr=mdata;
896 for(
long long i=0; i<pxlNr; i++, mptr++, fptr++)
899 for(
long long i=0; i<pxlNr; i++, mptr+=2, fptr++) {
900 sptr=(
short int*)mptr;
904 for(
long long i=0; i<pxlNr; i++, mptr+=4, fptr++) {
909 memcpy(fptr, mptr, pxlNr*4);
910 for(
long long i=0; i<pxlNr; i++, fptr++) *fptr *= h->
scale_factor;
short int transaxial_samp_mode
short int transm_source_type