Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
3dLRflip.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002
00003 int main( int argc , char * argv[] )
00004 {
00005 THD_3dim_dataset *dset ;
00006 int iarg=1 ;
00007 char *prefix = "flip" ;
00008 void *row ;
00009 int nx,ny,nz , ii,jj,kk , dcode , ival ;
00010
00011 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00012 printf("Usage: 3dLRflip [-prefix ppp] dataset\n"
00013 "Flips the Left-to-Right rows of a dataset.\n"
00014 ) ;
00015 exit(0) ;
00016 }
00017
00018 mainENTRY("3dLRflip main"); machdep(); AFNI_logger("3dLRflip",argc,argv);
00019
00020 while( argv[iarg][0] == '-' ){
00021
00022 if( strcmp(argv[iarg],"-prefix") == 0 ){
00023 prefix = argv[++iarg] ;
00024 if( !THD_filename_ok(prefix) ){
00025 fprintf(stderr,"** Illegal prefix: %s\n",prefix); exit(1);
00026 }
00027 iarg++ ; continue ;
00028 }
00029 }
00030
00031
00032
00033 dset = THD_open_dataset(argv[iarg]) ;
00034 if( !ISVALID_DSET(dset) ){ fprintf(stderr,"** CAN'T open dataset\n");exit(1); }
00035 DSET_mallocize(dset) ; DSET_load(dset) ;
00036 if( !DSET_LOADED(dset) ){ fprintf(stderr,"** CAN'T load dataset\n");exit(1); }
00037
00038 nx=DSET_NX(dset); ny=DSET_NY(dset); nz=DSET_NZ(dset);
00039
00040 if( dset->daxes->xxorient == ORI_R2L_TYPE ||
00041 dset->daxes->xxorient == ORI_L2R_TYPE ) dcode = 1 ;
00042 else
00043 if( dset->daxes->yyorient == ORI_R2L_TYPE ||
00044 dset->daxes->yyorient == ORI_L2R_TYPE ) dcode = 2 ;
00045 else
00046 if( dset->daxes->zzorient == ORI_R2L_TYPE ||
00047 dset->daxes->zzorient == ORI_L2R_TYPE ) dcode = 3 ;
00048 else
00049 { fprintf(stderr,"** Dataset has no L-R axis!\n"); exit(1); }
00050
00051
00052
00053 dset->dblk->diskptr->storage_mode = STORAGE_BY_BRICK ;
00054 dset->idcode = MCW_new_idcode() ;
00055 EDIT_dset_items( dset , ADN_prefix , prefix , ADN_none ) ;
00056 tross_Make_History( "3dLRflip", argc,argv, dset ) ;
00057
00058
00059
00060 for( ival=0 ; ival < DSET_NVALS(dset) ; ival++ ){
00061
00062 switch( dcode ){
00063
00064 case 1:
00065 for( kk=0 ; kk < nz ; kk++ )
00066 for( jj=0 ; jj < ny ; jj++ ){
00067 row = THD_get_dset_row( dset , ival , -dcode , 0,jj,kk ) ;
00068 THD_put_dset_row( dset , ival , dcode , 0,jj,kk , row ) ;
00069 free(row) ;
00070 }
00071 break ;
00072
00073 case 2:
00074 for( kk=0 ; kk < nz ; kk++ )
00075 for( ii=0 ; ii < nx ; ii++ ){
00076 row = THD_get_dset_row( dset , ival , -dcode , ii,0,kk ) ;
00077 THD_put_dset_row( dset , ival , dcode , ii,0,kk , row ) ;
00078 free(row) ;
00079 }
00080 break ;
00081
00082 case 3:
00083 for( jj=0 ; jj < ny ; jj++ )
00084 for( ii=0 ; ii < nx ; ii++ ){
00085 row = THD_get_dset_row( dset , ival , -dcode , ii,jj,0 ) ;
00086 THD_put_dset_row( dset , ival , dcode , ii,jj,0 , row ) ;
00087 free(row) ;
00088 }
00089 break ;
00090
00091 }
00092 }
00093
00094
00095
00096 DSET_write(dset) ; exit(0) ;
00097 }