57 if(fp==NULL || h==NULL)
return(1);
58 little=little_endian();
60 fseek(fp, 0, SEEK_SET);
if(ftell(fp)!=0)
return(1);
95 memcpy(h->
fill2, buf+472, 40);
120 if(strncmp(h->
ecat_format,
"ECAT63", 6)!=0)
return(3);
124 if(
ECAT63_TEST) printf(
"Invalid data types; probable conversion error.\n");
128 if(
ECAT63_TEST) printf(
"Invalid calibration factor; possible conversion error.\n");
133 if(
ECAT63_TEST) printf(
"Invalid file types; probable conversion error.\n");
158 if(
ECAT63_TEST) printf(
"ecat63ReadImageheader(fp, %d ih)\n", blk);
159 if(fp==NULL || blk<2 || h==NULL)
return(1);
160 little=little_endian();
164 if(fread(buf,
MatBLKSIZE, 1, fp)<1)
return(3);
182 memcpy(h->
fill2, buf+460, 52);
212 if(
ECAT63_TEST) printf(
"Invalid data types; probable conversion error.\n");
216 if(
ECAT63_TEST) printf(
"Invalid calibration factor; probable conversion error.\n");
220 if(
ECAT63_TEST) printf(
"Invalid frame duration; probable conversion error.\n");
243 if(
ECAT63_TEST) printf(
"ecat63ReadAttnheader(fp, %d, ah)\n", blk);
244 if(fp==NULL || blk<2 || h==NULL)
return(1);
245 little=little_endian();
249 if(fread(buf,
MatBLKSIZE, 1, fp)<1)
return(3);
273 if(
ECAT63_TEST) printf(
"Invalid data types; probable conversion error.\n");
277 if(
ECAT63_TEST) printf(
"Invalid scale factor; probable conversion error.\n");
302 if(
ECAT63_TEST) printf(
"ecat63ReadScanheader(fp, %d, sh)\n", blk);
303 if(fp==NULL || blk<2 || h==NULL)
return(1);
304 little=little_endian();
308 if(fread(buf,
MatBLKSIZE, 1, fp)<1)
return(3);
311 memcpy(h->
fill1, buf+0, 126);
322 memcpy(h->
fill2, buf+468, 44);
349 if(
ECAT63_TEST) printf(
"Invalid data types; probable conversion error.\n");
353 if(
ECAT63_TEST) printf(
"Invalid scale factor; probable conversion error.\n");
357 if(
ECAT63_TEST) printf(
"Invalid frame duration; probable conversion error.\n");
380 if(
ECAT63_TEST) printf(
"ecat63ReadNormheader(fp, %d, nh)\n", blk);
381 if(fp==NULL || blk<2 || h==NULL)
return(1);
382 little=little_endian();
386 if(fread(buf,
MatBLKSIZE, 1, fp)<1)
return(3);
406 if(
ECAT63_TEST) printf(
"Invalid data types; probable conversion error.\n");
410 if(
ECAT63_TEST) printf(
"Invalid scale factor; probable conversion error.\n");
433 int i, n, little, err=0;
438 if(
ECAT63_TEST) printf(
"ecat63ReadMatdata(fp, %d, %d, data, %d)\n", strtblk, blkNr, dtype);
440 if(blkNr<=0 || strtblk<1 || data==NULL)
return(1);
443 if(ftell(fp)!=(strtblk-1)*
MatBLKSIZE)
return(9);
445 if(fread(data,
MatBLKSIZE, blkNr, fp) < blkNr)
return(2);
447 little=little_endian();
452 if(!little) {cptr=data; swabip(cptr, blkNr*
MatBLKSIZE);}
455 for(i=0, cptr=data; i<blkNr*
MatBLKSIZE; i+=4, cptr+=4) {
456 n=
ecat63rInt(cptr, 1, little); memcpy(cptr, &n, 4);
460 for(i=0, cptr=data; i<blkNr*
MatBLKSIZE; i+=4, cptr+=4) {
495 int i, ret, blockNr, pxlNr;
497 float *_fdata, *fptr;
502 if(
ECAT63_TEST) printf(
"ecat63ReadImageMatrix(fp, %d, %d, hdr, fdata)\n",
503 first_block, last_block);
513 sprintf(
ecat63errmsg,
"cannot read subheader (%d).\n", ret);
524 blockNr=last_block-first_block;
if(blockNr<1)
return(0);
532 if(ret || mdata==NULL) {
533 sprintf(
ecat63errmsg,
"cannot read matrix data (%d).\n", ret);
534 free(mdata);
return(9);
538 _fdata=(
float*)malloc(pxlNr*
sizeof(
float));
541 free(mdata);
return(11);
546 fptr=_fdata; mptr=mdata;
548 for(i=0; i<pxlNr; i++, mptr++, fptr++)
551 for(i=0; i<pxlNr; i++, mptr+=2, fptr++) {
552 sptr=(
short int*)mptr;
556 for(i=0; i<pxlNr; i++, mptr+=4, fptr++) {
561 memcpy(fptr, mptr, pxlNr*4);
562 for(i=0; i<pxlNr; i++, fptr++) *fptr *= h->
quant_scale;
587 int i, ret, blockNr, pxlNr;
589 float *_fdata, *fptr;
594 if(
ECAT63_TEST) printf(
"ecat63ReadScanMatrix(fp, %d, %d, hdr, fdata)\n",
595 first_block, last_block);
605 sprintf(
ecat63errmsg,
"cannot read subheader (%d).\n", ret);
616 blockNr=last_block-first_block;
if(blockNr<1)
return(0);
624 if(ret || mdata==NULL) {
625 sprintf(
ecat63errmsg,
"cannot read matrix data (%d).\n", ret);
626 free(mdata);
return(9);
630 _fdata=(
float*)malloc(pxlNr*
sizeof(
float));
633 free(mdata);
return(11);
637 fptr=_fdata; mptr=mdata;
639 for(i=0; i<pxlNr; i++, mptr++, fptr++)
642 for(i=0; i<pxlNr; i++, mptr+=2, fptr++) {
643 sptr=(
short int*)mptr;
647 for(i=0; i<pxlNr; i++, mptr+=4, fptr++) {
652 memcpy(fptr, mptr, pxlNr*4);
653 for(i=0; i<pxlNr; i++, fptr++) *fptr *= h->
scale_factor;
672 union {
unsigned int ul;
float f;} t;
674 memcpy(&t.ul, bufi, 4);
if(t.ul==0) {
return(0.0);}
677 if(islittle) swawip(&t.ul, 4);
else swabip(&t.ul, 4);
680 if(!islittle) swawbip(&t.ul, 4);
698 memcpy(&i, bufi, 4);
if(!islittle) swawbip(&i, 4);
716 case SUN_I2: byteNr=2;
break;
720 case SUN_I4: byteNr=4;
break;
void ecat63PrintImageheader(ECAT63_imageheader *h, FILE *fp)
void ecat63PrintScanheader(ECAT63_scanheader *h, FILE *fp)
float ecat63rFloat(void *bufi, int isvax, int islittle)
int ecat63rInt(void *bufi, int isvax, int islittle)
int ecat63ReadImageMatrix(FILE *fp, int first_block, int last_block, ECAT63_imageheader *h, float **fdata)
int ecat63ReadNormheader(FILE *fp, int blk, ECAT63_normheader *h)
int ecat63ReadMatdata(FILE *fp, int strtblk, int blkNr, char *data, int dtype)
int ecat63ReadScanMatrix(FILE *fp, int first_block, int last_block, ECAT63_scanheader *h, float **fdata)
int ecat63ReadScanheader(FILE *fp, int blk, ECAT63_scanheader *h)
int ecat63ReadAttnheader(FILE *fp, int blk, ECAT63_attnheader *h)
int ecat63ReadImageheader(FILE *fp, int blk, ECAT63_imageheader *h)
int ecat63pxlbytes(short int data_type)
int ecat63ReadMainheader(FILE *fp, ECAT63_mainheader *h)
short int scan_start_minute
short int acquisition_type
short int scan_start_hour
char radiopharmaceutical[32]
short int axial_samp_mode
char study_description[32]
char original_file_name[20]
short int transm_source_type
short int compression_code
short int rot_source_speed
short int scan_start_year
short int scan_start_month
short int calibration_units
short int scan_start_second
char user_process_code[10]
short int transaxial_samp_mode