Doxygen Source Code Documentation
3dZcutup.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Function Documentation
|
---------- Adapted from 3dZeropad.c by RWCox - 08 Aug 2001 ----------* Definition at line 5 of file 3dZcutup.c. References AFNI_logger(), argc, THD_3dim_dataset::daxes, DSET_BRIKNAME, DSET_HEADNAME, DSET_NZ, DSET_write, machdep(), mainENTRY, nz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, PRINT_VERSION, STATUS, THD_filename_ok(), THD_is_file(), THD_open_dataset(), THD_zeropad(), tross_Copy_History(), tross_Make_History(), ZPAD_PURGE, and THD_dataxes::zzorient.
00006 { 00007 int iarg ; 00008 THD_3dim_dataset *inset , *outset ; 00009 int keep_bot=-1 , keep_top , nz ; 00010 int add_I=0 , add_S=0 , add_A=0 , add_P=0 , add_L=0 , add_R=0 ; 00011 char * prefix="zcutup" ; 00012 00013 /*-- help? --*/ 00014 00015 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){ 00016 printf("Usage: 3dZcutup [options] dataset\n" 00017 "Cuts slices off a dataset in its z-direction, and writes a new\n" 00018 "dataset. The z-direction and number of slices in a dataset\n" 00019 "can be determined using the 3dinfo program.\n" 00020 "Options:\n" 00021 " -keep b t = Keep slices numbered 'b' through 't', inclusive.\n" 00022 " This is a mandatory option. If you want to\n" 00023 " create a single-slice dataset, this is allowed,\n" 00024 " but AFNI may not display such datasets properly.\n" 00025 " A single slice dataset would have b=t. Slice\n" 00026 " numbers start at 0.\n" 00027 " -prefix ppp = Write result into dataset with prefix 'ppp'\n" 00028 " [default = 'zcutup']\n" 00029 "Notes:\n" 00030 " * You can use a sub-brick selector on the input dataset.\n" 00031 " * 3dZcutup won't overwrite an existing dataset (I hope).\n" 00032 " * This program is adapted from 3dZeropad, which does the\n" 00033 " same thing, but along all 3 axes.\n" 00034 " * You can glue datasets back together in the z-direction\n" 00035 " using program 3dZcat. A sample C shell script that\n" 00036 " uses these progams to carry out an analysis of a large\n" 00037 " dataset is:\n" 00038 "\n" 00039 " #!/bin/csh\n" 00040 " # Cut 3D+time dataset epi07+orig into individual slices\n" 00041 "\n" 00042 " foreach sl ( `count -dig 2 0 20` )\n" 00043 " 3dZcutup -prefix zcut${sl} -keep $sl $sl epi07+orig\n" 00044 "\n" 00045 " # Analyze this slice with 3dDeconvolve separately\n" 00046 "\n" 00047 " 3dDeconvolve -input zcut${sl}+orig.HEAD \\\n" 00048 " -num_stimts 3 \\\n" 00049 " -stim_file 1 ann_response_07.1D \\\n" 00050 " -stim_file 2 antiann_response_07.1D \\\n" 00051 " -stim_file 3 righthand_response_07.1D \\\n" 00052 " -stim_label 1 annulus \\\n" 00053 " -stim_label 2 antiann \\\n" 00054 " -stim_label 3 motor \\\n" 00055 " -stim_minlag 1 0 -stim_maxlag 1 0 \\\n" 00056 " -stim_minlag 2 0 -stim_maxlag 2 0 \\\n" 00057 " -stim_minlag 3 0 -stim_maxlag 3 0 \\\n" 00058 " -fitts zcut${sl}_fitts \\\n" 00059 " -fout -bucket zcut${sl}_stats\n" 00060 " end\n" 00061 "\n" 00062 " # Assemble slicewise outputs into final datasets\n" 00063 "\n" 00064 " time 3dZcat -verb -prefix zc07a_fitts zcut??_fitts+orig.HEAD\n" 00065 " time 3dZcat -verb -prefix zc07a_stats zcut??_stats+orig.HEAD\n" 00066 "\n" 00067 " # Remove individual slice datasets\n" 00068 "\n" 00069 " /bin/rm -f zcut*\n" 00070 ) ; 00071 exit(0) ; 00072 } 00073 00074 mainENTRY("3dZcutup main") ; machdep() ; AFNI_logger("3dZcutup",argc,argv) ; 00075 PRINT_VERSION("3dZcutup") ; 00076 00077 /*-- read command line options --*/ 00078 00079 iarg = 1 ; 00080 while( iarg < argc && argv[iarg][0] == '-' ){ 00081 00082 /*- -prefix -*/ 00083 00084 if( strcmp(argv[iarg],"-prefix") == 0 ){ 00085 prefix = argv[++iarg] ; 00086 if( !THD_filename_ok(prefix) ){ 00087 fprintf(stderr,"*** Illegal string after -prefix!\n"); exit(1) ; 00088 } 00089 iarg++ ; continue ; 00090 } 00091 00092 /*- -keep -*/ 00093 00094 if( strcmp(argv[iarg],"-keep") == 0 ){ 00095 if( iarg+2 >= argc ){ 00096 fprintf(stderr,"*** Need 2 arguments after -keep!\n"); exit(1); 00097 } 00098 keep_bot = strtol( argv[++iarg] , NULL , 10 ) ; 00099 keep_top = strtol( argv[++iarg] , NULL , 10 ) ; 00100 if( keep_bot < 0 || keep_top > keep_top ){ 00101 fprintf(stderr,"*** Nonsense values after -keep!\n"); exit(1); 00102 } 00103 iarg++ ; continue ; 00104 } 00105 00106 /*- what the hell? -*/ 00107 00108 fprintf(stderr,"*** Illegal option: %s\n",argv[iarg]) ; exit(1) ; 00109 } 00110 00111 /*- check to see if the user asked for something, anything -*/ 00112 00113 if( keep_bot < 0 ){ 00114 fprintf(stderr,"*** Don't you want to -keep SOMETHING!?\n"); exit(1); 00115 } 00116 00117 /*-- read the input dataset --*/ 00118 00119 if( iarg >= argc ){ 00120 fprintf(stderr,"*** No input dataset on command line!\n"); exit(1); 00121 } 00122 00123 inset = THD_open_dataset( argv[iarg] ) ; 00124 if( inset == NULL ){ 00125 fprintf(stderr,"*** Can't open dataset %s\n",argv[iarg]); exit(1); 00126 } 00127 00128 nz = DSET_NZ(inset) ; 00129 if( keep_top >= nz ){ 00130 fprintf(stderr,"*** -keep %d %d goes past last slice %d\n", 00131 keep_bot,keep_top,nz-1 ) ; 00132 exit(1) ; 00133 } 00134 00135 /*-- set orientation codes correctly --*/ 00136 00137 switch( inset->daxes->zzorient ){ 00138 case ORI_R2L_TYPE: 00139 add_R = -keep_bot ; add_L = keep_top - (nz-1) ; break ; 00140 case ORI_L2R_TYPE: 00141 add_L = -keep_bot ; add_R = keep_top - (nz-1) ; break ; 00142 case ORI_P2A_TYPE: 00143 add_P = -keep_bot ; add_A = keep_top - (nz-1) ; break ; 00144 case ORI_A2P_TYPE: 00145 add_A = -keep_bot ; add_P = keep_top - (nz-1) ; break ; 00146 case ORI_I2S_TYPE: 00147 add_I = -keep_bot ; add_S = keep_top - (nz-1) ; break ; 00148 case ORI_S2I_TYPE: 00149 add_S = -keep_bot ; add_I = keep_top - (nz-1) ; break ; 00150 default: 00151 fprintf(stderr,"*** Unknown orientation code in dataset!\n"); 00152 exit(1) ; 00153 } 00154 00155 outset = THD_zeropad( inset , 00156 add_I, add_S, add_A, add_P, add_L, add_R, 00157 prefix , ZPAD_PURGE ) ; 00158 00159 if( outset == NULL ){ 00160 fprintf(stderr,"*** 3dZcutup: Some error occurred in processing!\n") ; 00161 exit(1) ; 00162 } 00163 00164 STATUS("checking output filename") ; 00165 00166 if( THD_is_file(DSET_HEADNAME(outset)) ){ 00167 fprintf(stderr, 00168 "*** 3dZcutup: output file %s already exists - FATAL ERROR!\n", 00169 DSET_HEADNAME(outset) ) ; 00170 exit(1) ; 00171 } 00172 00173 STATUS("making history") ; 00174 00175 tross_Copy_History( inset , outset ) ; 00176 tross_Make_History( "3dZcutup" , argc,argv , outset ) ; 00177 00178 STATUS("writing output") ; 00179 00180 DSET_write(outset) ; 00181 fprintf(stderr,"++ output dataset: %s\n",DSET_BRIKNAME(outset)) ; 00182 exit(0) ; 00183 } |