Doxygen Source Code Documentation
3ddup.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | DUPERR(str) do{ fprintf(stderr,"ERROR: %s\n",(str)) ; exit(1) ; } while(0) |
Functions | |
THD_3dim_dataset * | duplicate_dataset (THD_3dim_dataset *parent) |
int | main (int argc, char *argv[]) |
Variables | |
char | DUP_session [THD_MAX_NAME] = "./" |
char | DUP_prefix [THD_MAX_PREFIX] = "dup" |
int | anatomy_type = ILLEGAL_TYPE |
int | function_type = ILLEGAL_TYPE |
int | dataset_type = ILLEGAL_TYPE |
Define Documentation
|
|
Function Documentation
|
scan command line options * Definition at line 201 of file dsetdup.c.
00202 { 00203 THD_3dim_dataset * new_dset ; 00204 int ii ; 00205 00206 /* sanity checks */ 00207 00208 if( ! ISVALID_3DIM_DATASET(parent) ) return NULL ; 00209 00210 /* make new dataset, copying appropriate fields from its various parents */ 00211 00212 new_dset = myXtNew( THD_3dim_dataset ) ; INIT_KILL( new_dset->kl ) ; 00213 00214 new_dset->type = parent->type ; 00215 new_dset->func_type = parent->func_type ; 00216 new_dset->view_type = parent->view_type ; 00217 00218 new_dset->anat_parent = NULL ; /* no anat parent */ 00219 new_dset->anat_parent_name[0] = '\0' ; 00220 00221 new_dset->warp_parent = parent ; /* yes warp parent */ 00222 MCW_strncpy( new_dset->warp_parent_name , parent->self_name , THD_MAX_NAME ) ; 00223 00224 /* make the actual warp from the warp_parent to this dataset */ 00225 00226 new_dset->vox_warp = myXtNew( THD_warp ) ; 00227 new_dset->vox_warp->type = ILLEGAL_TYPE ; /* created when needed */ 00228 new_dset->warp = myXtNew( THD_warp ) ; 00229 *(new_dset->warp) = IDENTITY_WARP ; 00230 00231 /* make up some names for this new dataset */ 00232 00233 MCW_strncpy( new_dset->self_name , parent->self_name , THD_MAX_NAME-5 ) ; 00234 ii = strlen( new_dset->self_name ) ; 00235 MCW_strncpy( &(new_dset->self_name[ii]) , "%duplicate" , THD_MAX_NAME-ii ) ; 00236 00237 MCW_strncpy( new_dset->label1 , parent->label1 , THD_MAX_LABEL ) ; 00238 MCW_strncpy( new_dset->label2 , parent->label2 , THD_MAX_LABEL ) ; 00239 00240 /* set the axes for this new dataset 00241 (same as parent, since that's the meaning of this routine) */ 00242 00243 new_dset->daxes = myXtNew( THD_dataxes ) ; /* copy data axes of */ 00244 *(new_dset->daxes) = *(parent->daxes) ; /* parent */ 00245 new_dset->daxes->parent = (XtPointer) new_dset ; /* reset parent */ 00246 00247 new_dset->wod_daxes = myXtNew( THD_dataxes ) ; /* warp-on-demand */ 00248 *(new_dset->wod_daxes) = *(new_dset->daxes) ; 00249 new_dset->wod_flag = True ; 00250 00251 /* create a datablock and diskptr, in case the data is ever 00252 filled into memory (instead of wod) and written to disk */ 00253 00254 new_dset->dblk = myXtNew( THD_datablock ) ; INIT_KILL( new_dset->dblk->kl ) ; 00255 00256 new_dset->dblk->type = DATABLOCK_TYPE ; 00257 new_dset->dblk->nvals = parent->dblk->nvals ; 00258 new_dset->dblk->brick = NULL ; 00259 new_dset->dblk->malloc_type = DATABLOCK_MEM_UNDEFINED ; 00260 new_dset->dblk->total_bytes = 0 ; 00261 new_dset->dblk->brick_bytes = 0 ; 00262 new_dset->dblk->natr = new_dset->dblk->natr_alloc = 0 ; 00263 new_dset->dblk->atr = NULL ; 00264 new_dset->dblk->parent = (XtPointer) new_dset ; 00265 00266 DBLK_unlock(new_dset->dblk) ; 00267 00268 new_dset->dblk->diskptr = myXtNew( THD_diskptr ) ; 00269 new_dset->dblk->diskptr->type = DISKPTR_TYPE ; 00270 new_dset->dblk->diskptr->nvals = parent->dblk->nvals ; 00271 new_dset->dblk->diskptr->rank = 3 ; 00272 new_dset->dblk->diskptr->storage_mode = STORAGE_UNDEFINED ; 00273 new_dset->dblk->diskptr->byte_order = THD_get_write_order() ; /* 25 April 1998 */ 00274 new_dset->dblk->diskptr->dimsizes[0] = new_dset->daxes->nxx ; 00275 new_dset->dblk->diskptr->dimsizes[1] = new_dset->daxes->nyy ; 00276 new_dset->dblk->diskptr->dimsizes[2] = new_dset->daxes->nzz ; 00277 00278 /* create the names for storage on disk (if ever) 00279 -- note we put it in the same directory as the parent */ 00280 00281 THD_init_diskptr_names( new_dset->dblk->diskptr , 00282 parent->dblk->diskptr->directory_name , NULL , 00283 parent->dblk->diskptr->prefix , 00284 new_dset->view_type , True ) ; 00285 00286 ADDTO_KILL( new_dset->dblk->kl , new_dset->dblk->diskptr ) ; 00287 00288 /* oh yeah, set the new_dset kill list, 00289 copy statistics if available, and NULL out any unused stuff */ 00290 00291 ADDTO_KILL( new_dset->kl , new_dset->warp ) ; 00292 ADDTO_KILL( new_dset->kl , new_dset->vox_warp ) ; 00293 ADDTO_KILL( new_dset->kl , new_dset->daxes ) ; 00294 ADDTO_KILL( new_dset->kl , new_dset->wod_daxes ) ; 00295 ADDTO_KILL( new_dset->kl , new_dset->dblk ) ; 00296 00297 new_dset->self_warp = NULL ; /* 26 Aug 2002 */ 00298 00299 if( parent->stats != NULL ){ 00300 new_dset->stats = myXtNew( THD_statistics ) ; /* copy statistics */ 00301 *(new_dset->stats) = *(parent->stats) ; /* of parent */ 00302 new_dset->stats->parent = (XtPointer) new_dset ; 00303 ADDTO_KILL( new_dset->kl , new_dset->stats ) ; 00304 } else { 00305 new_dset->stats = NULL ; 00306 } 00307 00308 new_dset->markers = NULL ; /* no markers */ 00309 new_dset->death_mark = 0 ; /* don't kill me! */ 00310 new_dset->tcat_list = 0 ; 00311 new_dset->tcat_num = 0 ; 00312 new_dset->tcat_len = NULL ; 00313 00314 return(new_dset) ; 00315 } |
|
compute the overall minimum and maximum voxel values for a dataset Definition at line 28 of file 3ddup.c. References ADN_directory_name, ADN_func_type, ADN_label1, ADN_none, ADN_prefix, ADN_self_name, ADN_type, ADN_warp, ADN_warp_parent, ANAT_BUCK_TYPE, anatomy_type, argc, dataset_type, THD_3dim_dataset::dblk, DSET_NUM_TIMES, DSET_NVALS_PER_TIME, DUP_prefix, DUP_session, EDIT_dset_items(), EDIT_empty_copy(), FIRST_3DIM_TYPE, FIRST_ANAT_TYPE, FIRST_FUNC_TYPE, FUNC_BUCK_TYPE, function_type, HEAD_ANAT_TYPE, HEAD_FUNC_TYPE, IDENTITY_WARP, ISANATTYPE, ISFUNCTYPE, ISVALID_3DIM_DATASET, LAST_3DIM_TYPE, LAST_ANAT_TYPE, LAST_FUNC_TYPE, MCW_strncpy, myXtNew, THD_datablock::nvals, THD_MAX_NAME, THD_MAX_PREFIX, THD_open_one_dataset(), THD_write_3dim_dataset(), tross_Copy_History(), and tross_Make_History().
00029 { 00030 int nopt , ii ; 00031 THD_3dim_dataset * dset_in , * dset_out ; 00032 THD_warp * warp , * twarp ; 00033 00034 /** check for help **/ 00035 00036 if( argc < 2 || strncmp(argv[1],"-help",3) == 0 ){ 00037 printf( 00038 "Usage: 3ddup [options] dataset\n" 00039 " 'Duplicates' a 3D dataset by making a warp-on-demand copy.\n" 00040 " Applications:\n" 00041 " - allows AFNI to resample a dataset to a new grid without\n" 00042 " destroying an existing data .BRIK\n" 00043 " - change a functional dataset to anatomical, or vice-versa\n" 00044 "\n" 00045 "OPTIONS:\n" 00046 " -'type' = Convert to the given 'type', which must be\n" 00047 " chosen from the same list as in to3d\n" 00048 " -session dirname = Write output into given directory (default=./)\n" 00049 " -prefix pname = Use 'pname' for the output directory prefix\n" 00050 " (default=dup)\n" 00051 "N.B.: Even if the new dataset is anatomical, it will not contain\n" 00052 " any markers, duplicated from the original, or otherwise.\n" 00053 ) ; 00054 exit(0) ; 00055 } 00056 00057 /** scan command line options **/ 00058 00059 #define DUPERR(str) \ 00060 do{ fprintf(stderr,"ERROR: %s\n",(str)) ; exit(1) ; } while(0) 00061 00062 nopt = 1 ; 00063 while( nopt < argc && argv[nopt][0] == '-' ){ 00064 00065 /*** the following code is stolen from to3d ***/ 00066 00067 /* -type from the anatomy prefixes */ 00068 00069 for( ii=FIRST_ANAT_TYPE ; ii <= LAST_ANAT_TYPE ; ii++ ) 00070 if( strncmp( &(argv[nopt][1]) , 00071 ANAT_prefixstr[ii] , THD_MAX_PREFIX ) == 0 ) break ; 00072 00073 if( ii <= LAST_ANAT_TYPE ){ 00074 anatomy_type = ii ; 00075 dataset_type = HEAD_ANAT_TYPE ; 00076 nopt++ ; continue ; 00077 } 00078 00079 /* -type from the function prefixes */ 00080 00081 for( ii=FIRST_FUNC_TYPE ; ii <= LAST_FUNC_TYPE ; ii++ ) 00082 if( strncmp( &(argv[nopt][1]) , 00083 FUNC_prefixstr[ii] , THD_MAX_PREFIX ) == 0 ) break ; 00084 00085 if( ii <= LAST_FUNC_TYPE ){ 00086 function_type = ii ; 00087 dataset_type = HEAD_FUNC_TYPE ; 00088 nopt++ ; continue ; 00089 } 00090 00091 /**** -session dirname ****/ 00092 00093 if( strncmp(argv[nopt],"-session",6) == 0 ){ 00094 nopt++ ; 00095 if( nopt >= argc ) DUPERR("need argument after -session!") ; 00096 MCW_strncpy( DUP_session , argv[nopt++] , THD_MAX_NAME ) ; 00097 continue ; 00098 } 00099 00100 /**** -prefix prefix ****/ 00101 00102 if( strncmp(argv[nopt],"-prefix",6) == 0 ){ 00103 nopt++ ; 00104 if( nopt >= argc ) DUPERR("need argument after -prefix!") ; 00105 MCW_strncpy( DUP_prefix , argv[nopt++] , THD_MAX_PREFIX ) ; 00106 continue ; 00107 } 00108 00109 /**** unknown switch ****/ 00110 00111 fprintf(stderr,"*** unrecognized option %s\n",argv[nopt]) ; 00112 exit(1) ; 00113 } /* end of loop over options */ 00114 00115 if( nopt >= argc ) DUPERR("no input dataset name given!") ; 00116 00117 /*** read input dataset ***/ 00118 00119 dset_in = THD_open_one_dataset( argv[nopt] ) ; 00120 if( ! ISVALID_3DIM_DATASET(dset_in) ) DUPERR("cannot read dataset!\n") ; 00121 00122 /*** copy header info ***/ 00123 00124 dset_out = EDIT_empty_copy( dset_in ) ; 00125 if( !ISVALID_3DIM_DATASET(dset_out) ) DUPERR("duplication fails!\n"); 00126 00127 EDIT_dset_items( dset_out , 00128 ADN_prefix , DUP_prefix , 00129 ADN_label1 , DUP_prefix , /* label = prefix */ 00130 ADN_directory_name , DUP_session , 00131 ADN_self_name , DUP_prefix , 00132 ADN_none ) ; 00133 00134 tross_Copy_History( dset_in , dset_out ) ; 00135 tross_Make_History( "3ddup" , argc , argv , dset_out ) ; 00136 00137 /*** change of type? ***/ 00138 00139 if( dataset_type>=FIRST_3DIM_TYPE && dataset_type<=LAST_3DIM_TYPE ){ 00140 00141 int isfunc , new_nvals , old_ntimes ; 00142 00143 old_ntimes = DSET_NUM_TIMES(dset_in) ; 00144 00145 isfunc = ISFUNCTYPE(dataset_type) ; 00146 new_nvals = (isfunc) ? FUNC_nvals[function_type] 00147 : ANAT_nvals[anatomy_type] ; 00148 00149 if( ( isfunc && function_type == FUNC_BUCK_TYPE) || 00150 (!isfunc && anatomy_type == ANAT_BUCK_TYPE) ) /* 30 Nov 1997 */ 00151 new_nvals = dset_in->dblk->nvals ; 00152 00153 00154 if( new_nvals > dset_in->dblk->nvals ){ 00155 fprintf(stderr, 00156 "ERROR: new dataset type has %d values per voxel," 00157 " but old has %d!\n" 00158 " ==> cannot make duplicate!\n" , 00159 new_nvals , dset_in->dblk->nvals ) ; 00160 exit(1) ; 00161 00162 } else if( new_nvals < dset_in->dblk->nvals ){ 00163 if( old_ntimes == 1 ) 00164 fprintf(stderr, 00165 "WARNING: new dataset type has %d values per voxel," 00166 " but old has %d!\n" 00167 " ==> new dataset will not access all data in old!\n", 00168 new_nvals , dset_in->dblk->nvals ) ; 00169 else if( new_nvals > 1){ 00170 fprintf(stderr, 00171 "ERROR: new dataset type has %d values per voxel per time," 00172 " but old has %d!\n" 00173 " *** this conversion is not legal for time-dependent data!\n", 00174 new_nvals , DSET_NVALS_PER_TIME(dset_in) ) ; 00175 exit(1) ; 00176 } 00177 } 00178 00179 EDIT_dset_items( dset_out , 00180 ADN_type , dataset_type , 00181 ADN_func_type , 00182 ISANATTYPE(dataset_type) ? (anatomy_type) 00183 : (function_type) , 00184 ADN_none ) ; 00185 } 00186 00187 warp = myXtNew( THD_warp ) ; *warp = IDENTITY_WARP ; 00188 00189 EDIT_dset_items( dset_out , 00190 ADN_warp , warp , 00191 ADN_warp_parent , dset_in , 00192 ADN_none ) ; 00193 00194 /*** done! ***/ 00195 00196 THD_write_3dim_dataset( NULL , NULL , dset_out , False ) ; 00197 00198 exit(0) ; 00199 } |
Variable Documentation
|
Definition at line 22 of file 3ddup.c. Referenced by main(). |
|
Definition at line 24 of file 3ddup.c. Referenced by main(). |
|
Definition at line 20 of file 3ddup.c. Referenced by main(). |
|
Definition at line 19 of file 3ddup.c. Referenced by main(). |
|
Definition at line 23 of file 3ddup.c. Referenced by main(). |