| 1 |
/* http://www.mayo.edu/bir/analyze/AnalyzeFileInfo.html */ |
| 2 |
/* if this blows up remember to check byte-alignment for originator */ |
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include "analyze_db.h" |
| 7 |
|
| 8 |
void ShowHdr(char *fileName, struct dsr *hdr); |
| 9 |
void swap_hdr(struct dsr *pntr); |
| 10 |
void swap_long(unsigned char *); |
| 11 |
void swap_short(unsigned char *); |
| 12 |
|
| 13 |
main(int argc, char **argv){ |
| 14 |
struct dsr hdr; |
| 15 |
FILE *fp; |
| 16 |
|
| 17 |
if((fp=fopen(argv[1],"r"))==NULL) |
| 18 |
{ |
| 19 |
fprintf(stderr,"Can't open:<%s>\n", argv[1]); |
| 20 |
exit(0); |
| 21 |
} |
| 22 |
fread(&hdr,1,sizeof(struct dsr),fp); |
| 23 |
|
| 24 |
if(hdr.dime.dim[0] < 0 || hdr.dime.dim[0] > 15) |
| 25 |
swap_hdr(&hdr); |
| 26 |
|
| 27 |
ShowHdr(argv[1], &hdr); |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void ShowHdr(char *fileName, struct dsr *hdr){ |
| 34 |
int i; |
| 35 |
char string[128]; |
| 36 |
printf("Analyze Header Dump of: <%s> \n", fileName); |
| 37 |
/* Header Key */ |
| 38 |
printf("sizeof_hdr: <%d> \n", hdr->hk.sizeof_hdr); |
| 39 |
printf("data_type: <%s> \n", hdr->hk.data_type); |
| 40 |
printf("db_name: <%s> \n", hdr->hk.db_name); |
| 41 |
printf("extents: <%d> \n", hdr->hk.extents); |
| 42 |
printf("session_error: <%d> \n", hdr->hk.session_error); |
| 43 |
printf("regular: <%c> \n", hdr->hk.regular); |
| 44 |
printf("hkey_un0: <%c> \n", hdr->hk.hkey_un0); |
| 45 |
|
| 46 |
/* Image Dimension */ |
| 47 |
for(i=0;i<8;i++) |
| 48 |
printf("dim[%d]: <%d> \n", i, hdr->dime.dim[i]); |
| 49 |
|
| 50 |
strncpy(string,hdr->dime.vox_units,4); |
| 51 |
printf("vox_units: <%s> \n", string); |
| 52 |
|
| 53 |
strncpy(string,hdr->dime.cal_units,8); |
| 54 |
printf("cal_units: <%s> \n", string); |
| 55 |
printf("unused1: <%d> \n", hdr->dime.unused1); |
| 56 |
printf("datatype: <%d> \n", hdr->dime.datatype); |
| 57 |
printf("bitpix: <%d> \n", hdr->dime.bitpix); |
| 58 |
|
| 59 |
for(i=0;i<8;i++) |
| 60 |
printf("pixdim[%d]: <%6.4f> \n",i, hdr->dime.pixdim[i]); |
| 61 |
|
| 62 |
printf("vox_offset: <%6.4> \n", hdr->dime.vox_offset); |
| 63 |
printf("funused1: <%6.4f> \n", hdr->dime.funused1); |
| 64 |
printf("funused2: <%6.4f> \n", hdr->dime.funused2); |
| 65 |
printf("cal_max: <%6.4f> \n", hdr->dime.cal_max); |
| 66 |
printf("cal_min: <%6.4f> \n", hdr->dime.cal_min); |
| 67 |
printf("compressed: <%d> \n", hdr->dime.compressed); |
| 68 |
printf("verified: <%d> \n", hdr->dime.verified); |
| 69 |
printf("glmax: <%d> \n", hdr->dime.glmax); |
| 70 |
printf("glmin: <%d> \n", hdr->dime.glmin); |
| 71 |
|
| 72 |
/* Data History */ |
| 73 |
strncpy(string,hdr->hist.descrip,80); |
| 74 |
printf("descrip: <%s> \n", string); |
| 75 |
strncpy(string,hdr->hist.aux_file,24); |
| 76 |
printf("aux_file: <%s> \n", string); |
| 77 |
printf("orient: <%d> \n", hdr->hist.orient); |
| 78 |
|
| 79 |
for(i=0;i<5;i++){ |
| 80 |
swap_short(&hdr->hist.originator[i]); |
| 81 |
printf("originator[%d]: <%u> \n", i, hdr->hist.originator[i]); |
| 82 |
} |
| 83 |
|
| 84 |
strncpy(string,hdr->hist.generated,10); |
| 85 |
printf("generated: <%s> \n", string); |
| 86 |
|
| 87 |
|
| 88 |
strncpy(string,hdr->hist.scannum,10); |
| 89 |
printf("scannum: <%s> \n", string); |
| 90 |
|
| 91 |
strncpy(string,hdr->hist.patient_id,10); |
| 92 |
printf("patient_id: <%s> \n", string); |
| 93 |
|
| 94 |
strncpy(string,hdr->hist.exp_date,10); |
| 95 |
printf("exp_date: <%s> \n", string); |
| 96 |
|
| 97 |
strncpy(string,hdr->hist.exp_time,10); |
| 98 |
printf("exp_time: <%s> \n", string); |
| 99 |
|
| 100 |
strncpy(string,hdr->hist.hist_un0,3); |
| 101 |
printf("hist_un0: <%s> \n", string); |
| 102 |
|
| 103 |
printf("views: <%d> \n", hdr->hist.views); |
| 104 |
printf("vols_added: <%d> \n", hdr->hist.vols_added); |
| 105 |
printf("start_field:<%d> \n", hdr->hist.start_field); |
| 106 |
printf("field_skip: <%d> \n", hdr->hist.field_skip); |
| 107 |
printf("omax: <%d> \n", hdr->hist.omax); |
| 108 |
printf("omin: <%d> \n", hdr->hist.omin); |
| 109 |
printf("smin: <%d> \n", hdr->hist.smax); |
| 110 |
printf("smin: <%d> \n", hdr->hist.smin); |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
void swap_hdr(struct dsr *pntr){ |
| 116 |
swap_long(&pntr->hk.sizeof_hdr) ; |
| 117 |
swap_long(&pntr->hk.extents) ; |
| 118 |
swap_short(&pntr->hk.session_error) ; |
| 119 |
swap_short(&pntr->dime.dim[0]) ; |
| 120 |
swap_short(&pntr->dime.dim[1]) ; |
| 121 |
swap_short(&pntr->dime.dim[2]) ; |
| 122 |
swap_short(&pntr->dime.dim[3]) ; |
| 123 |
swap_short(&pntr->dime.dim[4]) ; |
| 124 |
swap_short(&pntr->dime.dim[5]) ; |
| 125 |
swap_short(&pntr->dime.dim[6]) ; |
| 126 |
swap_short(&pntr->dime.dim[7]) ; |
| 127 |
swap_short(&pntr->dime.unused1) ; |
| 128 |
swap_short(&pntr->dime.datatype) ; |
| 129 |
swap_short(&pntr->dime.bitpix) ; |
| 130 |
swap_long(&pntr->dime.pixdim[0]) ; |
| 131 |
swap_long(&pntr->dime.pixdim[1]) ; |
| 132 |
swap_long(&pntr->dime.pixdim[2]) ; |
| 133 |
swap_long(&pntr->dime.pixdim[3]) ; |
| 134 |
swap_long(&pntr->dime.pixdim[4]) ; |
| 135 |
swap_long(&pntr->dime.pixdim[5]) ; |
| 136 |
swap_long(&pntr->dime.pixdim[6]) ; |
| 137 |
swap_long(&pntr->dime.pixdim[7]) ; |
| 138 |
swap_long(&pntr->dime.vox_offset) ; |
| 139 |
swap_long(&pntr->dime.funused1) ; |
| 140 |
swap_long(&pntr->dime.funused2) ; |
| 141 |
swap_long(&pntr->dime.cal_max) ; |
| 142 |
swap_long(&pntr->dime.cal_min) ; |
| 143 |
swap_long(&pntr->dime.compressed) ; |
| 144 |
swap_long(&pntr->dime.verified) ; |
| 145 |
swap_short(&pntr->dime.dim_un0) ; |
| 146 |
swap_long(&pntr->dime.glmax) ; |
| 147 |
swap_long(&pntr->dime.glmin) ; |
| 148 |
} |
| 149 |
|
| 150 |
void swap_long(unsigned char *pntr){ |
| 151 |
unsigned char b0, b1, b2, b3; |
| 152 |
|
| 153 |
b0 = *pntr; |
| 154 |
b1 = *(pntr+1); |
| 155 |
b2 = *(pntr+2); |
| 156 |
b3 = *(pntr+3); |
| 157 |
|
| 158 |
*pntr = b3; |
| 159 |
*(pntr+1) = b2; |
| 160 |
*(pntr+2) = b1; |
| 161 |
*(pntr+3) = b0; |
| 162 |
} |
| 163 |
|
| 164 |
void swap_short(unsigned char *pntr){ |
| 165 |
unsigned char b0, b1; |
| 166 |
|
| 167 |
b0 = *pntr; |
| 168 |
b1 = *(pntr+1); |
| 169 |
|
| 170 |
*pntr = b1; |
| 171 |
*(pntr+1) = b0; |
| 172 |
} |