Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mayo_analyze.c

Go to the documentation of this file.
00001 
00002 #include "mrilib.h"
00003 #include "mayo_analyze.h"
00004 
00005 void ShowHdr(char *, struct dsr *);
00006 void swap_long(void *);
00007 void swap_short(void *);
00008 
00009 static int swapped ;
00010 
00011 int main( int argc , char * argv[] )
00012 {
00013     struct dsr hdr;
00014     int size, nn ;
00015     double cmax, cmin;
00016     FILE *fp;
00017 
00018     if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00019       printf("Usage: mayo_analyze file.hdr ...\n"
00020              "Prints out info from the Mayo Analyze 7.5 header file(s)\n"
00021       ) ;
00022       exit(0) ;
00023     }
00024 
00025     for( nn=1 ; nn < argc ; nn++ ){
00026 
00027        if((fp=fopen(argv[nn],"r"))==NULL){
00028            fprintf(stderr,"Can't open:<%s>\n", argv[1]);
00029            continue ;
00030        }
00031        fread(&hdr,1,sizeof(struct dsr),fp);
00032 
00033        if(hdr.dime.dim[0] < 0 || hdr.dime.dim[0] > 15){
00034           printf("Byte swapping header %s\n",argv[nn]) ;
00035           swap_hdr(&hdr); swapped = 1 ;
00036        } else {
00037           swapped = 0 ;
00038        }
00039 
00040        ShowHdr(argv[nn], &hdr);
00041        fclose(fp) ;
00042        if( nn < argc-1 )
00043           printf("======================================================\n") ;
00044     }
00045     exit(0) ;
00046 }
00047 
00048 
00049 void ShowHdr(char *fileName, struct dsr *hdr)
00050 {
00051    int i;
00052    char string[128];
00053    printf("Analyze Header Dump of: <%s> \n", fileName);
00054 /* Header Key */
00055    printf("sizeof_hdr: <%d> \n", hdr->hk.sizeof_hdr);
00056    printf("data_type:  <%s> \n", hdr->hk.data_type);
00057    printf("db_name:    <%s> \n", hdr->hk.db_name);
00058    printf("extents:    <%d> \n", hdr->hk.extents);
00059    printf("session_error: <%d> \n", hdr->hk.session_error);
00060    printf("regular:  <%c> \n", hdr->hk.regular);
00061    printf("hkey_un0: <%c> \n", hdr->hk.hkey_un0);
00062 
00063 /* Image Dimension */
00064    for(i=0;i<8;i++)
00065        printf("dim[%d]: <%d> \n", i, hdr->dime.dim[i]);
00066 
00067 #if 0
00068    strncpy(string,hdr->dime.vox_units,4);
00069    printf("vox_units:  <%s> \n", string);
00070 #endif
00071 
00072 #if 0
00073    strncpy(string,hdr->dime.cal_units,8);
00074    printf("cal_units: <%s> \n", string);
00075    printf("unused1:   <%d> \n", hdr->dime.unused1);
00076 #endif
00077    printf("datatype:  <%d> \n", hdr->dime.datatype);
00078    printf("bitpix:    <%d> \n", hdr->dime.bitpix);
00079 
00080    for(i=0;i<8;i++)
00081        printf("pixdim[%d]: <%6.4f> \n",i, hdr->dime.pixdim[i]);
00082 
00083    printf("vox_offset: <%6.4f> \n",  hdr->dime.vox_offset);
00084    printf("funused1:   <%6.4f> \n", hdr->dime.funused1);
00085    printf("funused2:   <%6.4f> \n", hdr->dime.funused2);
00086    printf("funused3:   <%6.4f> \n", hdr->dime.funused3);
00087    printf("cal_max:    <%6.4f> \n", hdr->dime.cal_max);
00088    printf("cal_min:    <%6.4f> \n", hdr->dime.cal_min);
00089    printf("compressed: <%6.4f> \n", hdr->dime.compressed);
00090    printf("verified:   <%6.4f> \n", hdr->dime.verified);
00091    printf("glmax:      <%d>    \n", hdr->dime.glmax);
00092    printf("glmin:      <%d>    \n", hdr->dime.glmin);
00093 
00094 /* Data History */
00095    strncpy(string,hdr->hist.descrip,80);
00096    printf("descrip:  <%s> \n", string);
00097    strncpy(string,hdr->hist.aux_file,24);
00098    printf("aux_file: <%s> \n", string);
00099    printf("orient:   <%d> \n", (int) hdr->hist.orient);
00100 
00101    /* 28 Nov 2001: attempt to decode originator a la SPM */
00102 
00103    { short xyzuv[5] , xx,yy,zz ;
00104      memcpy( xyzuv , hdr->hist.originator , 10 ) ;
00105      if( xyzuv[3] == 0 && xyzuv[4] == 0 ){
00106         xx = xyzuv[0] ; yy = xyzuv[1] ; zz = xyzuv[2] ;
00107         if( swapped ){ swap_short(&xx); swap_short(&yy); swap_short(&zz); }
00108         if( xx > 0 && xx < hdr->dime.dim[1] &&
00109             yy > 0 && yy < hdr->dime.dim[2] &&
00110             zz > 0 && zz < hdr->dime.dim[3]   ){
00111 
00112            printf("SPM originator decodes to %d %d %d\n",xx,yy,zz) ;
00113         }
00114      }
00115    }
00116 
00117    strncpy(string,hdr->hist.originator,10);
00118    printf("originator: <%s> \n", string);
00119 
00120    strncpy(string,hdr->hist.generated,10);
00121    printf("generated: <%s> \n", string);
00122 
00123    strncpy(string,hdr->hist.scannum,10);
00124    printf("scannum: <%s> \n", string);
00125 
00126    strncpy(string,hdr->hist.patient_id,10);
00127    printf("patient_id: <%s> \n", string);
00128 
00129    strncpy(string,hdr->hist.exp_date,10);
00130    printf("exp_date: <%s> \n", string);
00131 
00132    strncpy(string,hdr->hist.exp_time,10);
00133    printf("exp_time: <%s> \n", string);
00134 
00135    strncpy(string,hdr->hist.hist_un0,10);
00136    printf("hist_un0: <%s> \n", string);
00137 
00138    printf("views:      <%d> \n", hdr->hist.views);
00139    printf("vols_added: <%d> \n", hdr->hist.vols_added);
00140    printf("start_field:<%d> \n", hdr->hist.start_field);
00141    printf("field_skip: <%d> \n", hdr->hist.field_skip);
00142    printf("omax: <%d> \n", hdr->hist.omax);
00143    printf("omin: <%d> \n", hdr->hist.omin);
00144    printf("smin: <%d> \n", hdr->hist.smax);
00145    printf("smin: <%d> \n", hdr->hist.smin);
00146 
00147 }
00148 
00149 swap_hdr(struct dsr *pntr)
00150 {
00151        swap_long(&pntr->hk.sizeof_hdr) ;
00152        swap_long(&pntr->hk.extents) ;
00153        swap_short(&pntr->hk.session_error) ;
00154        swap_short(&pntr->dime.dim[0]) ;
00155        swap_short(&pntr->dime.dim[1]) ;
00156        swap_short(&pntr->dime.dim[2]) ;
00157        swap_short(&pntr->dime.dim[3]) ;
00158        swap_short(&pntr->dime.dim[4]) ;
00159        swap_short(&pntr->dime.dim[5]) ;
00160        swap_short(&pntr->dime.dim[6]) ;
00161        swap_short(&pntr->dime.dim[7]) ;
00162 #if 0
00163        swap_short(&pntr->dime.unused1) ;
00164 #endif
00165        swap_short(&pntr->dime.datatype) ;
00166        swap_short(&pntr->dime.bitpix) ;
00167        swap_long(&pntr->dime.pixdim[0]) ;
00168        swap_long(&pntr->dime.pixdim[1]) ;
00169        swap_long(&pntr->dime.pixdim[2]) ;
00170        swap_long(&pntr->dime.pixdim[3]) ;
00171        swap_long(&pntr->dime.pixdim[4]) ;
00172        swap_long(&pntr->dime.pixdim[5]) ;
00173        swap_long(&pntr->dime.pixdim[6]) ;
00174        swap_long(&pntr->dime.pixdim[7]) ;
00175        swap_long(&pntr->dime.vox_offset) ;
00176        swap_long(&pntr->dime.funused1) ;
00177        swap_long(&pntr->dime.funused2) ;
00178        swap_long(&pntr->dime.cal_max) ;
00179        swap_long(&pntr->dime.cal_min) ;
00180        swap_long(&pntr->dime.compressed) ;
00181        swap_long(&pntr->dime.verified) ;
00182        swap_short(&pntr->dime.dim_un0) ;
00183        swap_long(&pntr->dime.glmax) ;
00184        swap_long(&pntr->dime.glmin) ;
00185 }
00186 
00187 void swap_long(void *ppp)
00188 {
00189    unsigned char *pntr = (unsigned char *) ppp ;
00190         unsigned char b0, b1, b2, b3;
00191 
00192         b0 = *pntr;
00193         b1 = *(pntr+1);
00194         b2 = *(pntr+2);
00195         b3 = *(pntr+3);
00196 
00197         *pntr = b3;
00198         *(pntr+1) = b2;
00199         *(pntr+2) = b1;
00200         *(pntr+3) = b0;
00201 }
00202 
00203 void swap_short(void *ppp)
00204 {
00205    unsigned char *pntr = (unsigned char *) ppp ;
00206         unsigned char b0, b1;
00207 
00208         b0 = *pntr;
00209         b1 = *(pntr+1);
00210 
00211         *pntr = b1;
00212         *(pntr+1) = b0;
00213 }
 

Powered by Plone

This site conforms to the following standards: