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  

exx.c

Go to the documentation of this file.
00001 #include "mrilib.h"
00002 
00003 #define ASSIGN_DIRECTIONS                                       \
00004  do{ switch( fixdir ){                                          \
00005       default:                                                  \
00006       case 1:            /* x-direction: (a,b,c) = (y,z,x) */   \
00007          astep = nx ; bstep = nxy ; cstep = 1  ;                \
00008          na    = ny ; nb    = nz  ; nc    = nx ;                \
00009       break ;                                                   \
00010                                                                 \
00011       case 2:            /* y-direction: (a,b,c) = (z,x,y) */   \
00012          astep = nxy ; bstep = 1  ; cstep = nx ;                \
00013          na    = nz  ; nb    = nx ; nc    = ny ;                \
00014       break ;                                                   \
00015                                                                 \
00016       case 3:            /* z-direction: (a,b,c) = (x,y,z) */   \
00017          astep = 1  ; bstep = nx ; cstep = nxy ;                \
00018          na    = nx ; nb    = ny ; nc    = nz  ;                \
00019       break ;                                                   \
00020     } } while(0)
00021 
00022 /*-----------------------------------------------------------------------
00023    Simple get/put of a fixed plane (no shifting, zero padding).
00024 -------------------------------------------------------------------------*/
00025 
00026 void getplane_byte( int nx , int ny , int nz , byte * vol ,
00027                     int fixdir , int fixijk , byte * im )
00028 {
00029    int bb , nxy=nx*ny ;
00030    register int aa , ijkoff , aoff,boff ;
00031    int astep,bstep,cstep , na,nb,nc ;
00032 
00033    if( fixijk < 0 ) return ;
00034 
00035    ASSIGN_DIRECTIONS ;
00036 
00037    if( fixijk >= nc ) return ;
00038 
00039    ijkoff = fixijk*cstep ;
00040 
00041    for( bb=0,boff=0 ; bb < nb ; bb++,boff+=na,ijkoff+=bstep )
00042       for( aa=0,aoff=0 ; aa < na ; aa++,aoff+=astep )
00043          im[aa+boff] = vol[aoff+ijkoff] ;
00044 
00045    return ;
00046 }
00047 
00048 void putplane_byte( int nx , int ny , int nz , byte * vol ,
00049                     int fixdir , int fixijk , byte * im )
00050 {
00051    int bb , nxy=nx*ny ;
00052    register int aa , ijkoff , aoff,boff ;
00053    int astep,bstep,cstep , na,nb,nc ;
00054 
00055    if( fixijk < 0 ) return ;
00056 
00057    ASSIGN_DIRECTIONS ;
00058 
00059    if( fixijk >= nc ) return ;
00060 
00061    ijkoff = fixijk*cstep ;
00062 
00063    for( bb=0,boff=0 ; bb < nb ; bb++,boff+=na,ijkoff+=bstep )
00064       for( aa=0,aoff=0 ; aa < na ; aa++,aoff+=astep )
00065          vol[aoff+ijkoff] = im[aa+boff] ;
00066 
00067    return ;
00068 }
00069 
00070 void swaptest( int nrep , int fixdir )
00071 {
00072    double cputim ;
00073    int pp , nx=100,ny=100,nz=100,nxy=nx*ny , kk ;
00074    byte * vin , * vout  ;
00075    int astep,bstep,cstep , na,nb,nc ;
00076 
00077    if( nrep <= 0 ) nrep = 1 ;
00078 
00079    ASSIGN_DIRECTIONS ;
00080 
00081    /* setup bricks */
00082 
00083    vin = (byte *) malloc( sizeof(byte) * (nx*ny*nz) ) ;
00084    if( vin == NULL ) return ;
00085 
00086    vout = (byte *) malloc( sizeof(byte) * (na*nb*nc) ) ;
00087    if( vout == NULL ){ free(vin) ; return ; }
00088 
00089    for( kk=0 ; kk < nx*ny*nz ; kk++ ) vin[kk] = (byte) kk ;
00090 
00091    cputim = COX_cpu_time() ;
00092 
00093    for( pp=0 ; pp < nrep ; pp++ ){
00094 #if 0
00095       for( kk=0 ; kk < nc ; kk++ ){
00096          getplane_byte( nx,ny,nz , vin , fixdir , kk , vout + kk*na*nb ) ;
00097       }
00098 #else
00099       for( kk=0 ; kk < nz ; kk++ ){
00100          putplane_byte( nx,ny,nz , vout , fixdir , kk , vin + kk*nx*ny ) ;
00101       }
00102 #endif
00103    }
00104    cputim = COX_cpu_time() - cputim ;
00105    printf("fixdir = %d CPU time = %g (%g/rep)\n",fixdir,cputim,cputim/nrep) ;
00106    return ;
00107 }
00108 
00109 int main( int argc , char * argv[] )
00110 {
00111    int nrep ;
00112 
00113    if( argc < 2 ){printf("Usage: exx nrep\n");exit(0);}
00114 
00115    nrep = strtol(argv[1],NULL,10) ;
00116    swaptest( nrep , 1 ) ;
00117    swaptest( nrep , 2 ) ;
00118    swaptest( nrep , 3 ) ;
00119    exit(0) ;
00120 }
 

Powered by Plone

This site conforms to the following standards: