00001
00002
00003
00004
00005
00006
00007 #include "afni.h"
00008
00009 #ifndef ALLOW_PLUGINS
00010 # error "Plugins not properly set up -- see machdep.h"
00011 #endif
00012
00013
00014
00015
00016
00017 char * ZPAD_main( PLUGIN_interface * ) ;
00018
00019 static char helpstring[] =
00020 " Purpose: Creating a zero-padded copy of a dataset [like 3dZeropad].\n"
00021 " Inputs:\n"
00022 " Dataset = A dataset in the current session that exists in memory\n"
00023 " (not warp-on-demand).\n"
00024 " Prefix = Filename prefix to be used for the output dataset.\n"
00025 " Type = Lets you change the 'type' of the output dataset, for\n"
00026 " example from anat to func.\n"
00027 " Padding = I, S, A, P, L, R = number of planes to add (or subtract)\n"
00028 " at the Inferior, Superior, Anterior, Posterior, Left,\n"
00029 " and Right edges, respectively.\n"
00030 "\n"
00031 "Author -- RWCox - Oct 2000"
00032 ;
00033
00034
00035
00036
00037
00038
00039 DEFINE_PLUGIN_PROTOTYPE
00040
00041 PLUGIN_interface * PLUGIN_init( int ncall )
00042 {
00043 PLUGIN_interface * plint ;
00044
00045 if( ncall > 0 ) return NULL ;
00046
00047
00048
00049 plint = PLUTO_new_interface( "Dset Zeropad" ,
00050 "Make a Zero-Padded Copy of a Dataset" ,
00051 helpstring ,
00052 PLUGIN_CALL_VIA_MENU , ZPAD_main ) ;
00053
00054 PLUTO_add_hint( plint , "Copy and Zero-Pad a Dataset" ) ;
00055
00056 PLUTO_set_sequence( plint , "A:newdset:copy" ) ;
00057
00058 PLUTO_set_runlabels( plint , "Copy+Keep" , "Copy+Close" ) ;
00059
00060
00061
00062 PLUTO_add_option( plint , "Input" , "Input" , TRUE ) ;
00063 PLUTO_add_dataset(plint , "Dataset" ,
00064 ANAT_ALL_MASK , FUNC_ALL_MASK ,
00065 DIMEN_ALL_MASK | BRICK_ALLTYPE_MASK ) ;
00066
00067
00068
00069 PLUTO_add_option( plint , "Output" , "Output" , TRUE ) ;
00070 PLUTO_add_string( plint , "Prefix" , 0,NULL , 19 ) ;
00071
00072
00073
00074 PLUTO_add_option( plint , "Padding" , "Padding" , TRUE ) ;
00075 PLUTO_add_number( plint , "I" , -19 , 19 , 0 , 0 , FALSE ) ;
00076 PLUTO_add_number( plint , "S" , -19 , 19 , 0 , 0 , FALSE ) ;
00077 PLUTO_add_number( plint , "A" , -19 , 19 , 0 , 0 , FALSE ) ;
00078 PLUTO_add_number( plint , "P" , -19 , 19 , 0 , 0 , FALSE ) ;
00079 PLUTO_add_number( plint , "L" , -19 , 19 , 0 , 0 , FALSE ) ;
00080 PLUTO_add_number( plint , "R" , -19 , 19 , 0 , 0 , FALSE ) ;
00081
00082
00083
00084 PLUTO_add_option( plint , "Dataset" , "Dataset" , FALSE ) ;
00085 PLUTO_add_string( plint , "Type" , NUM_DSET_TYPES,DSET_prefixstr , 0 ) ;
00086
00087 return plint ;
00088 }
00089
00090
00091
00092
00093
00094 char * ZPAD_main( PLUGIN_interface * plint )
00095 {
00096 char * tag , * new_prefix , * cpt ;
00097 MCW_idcode * idc ;
00098 THD_3dim_dataset * dset , * new_dset ;
00099 int ftyp=-1 , dtyp=-1 , ival ;
00100 int add_I, add_S, add_A, add_P, add_L, add_R;
00101
00102
00103
00104
00105 if( plint == NULL )
00106 return "**********************\n"
00107 "ZPAD_main: NULL input\n"
00108 "**********************" ;
00109
00110 PLUTO_next_option(plint) ;
00111 idc = PLUTO_get_idcode(plint) ;
00112 dset = PLUTO_find_dset(idc) ;
00113 if( dset == NULL )
00114 return "*****************************\n"
00115 "ZPAD_main: bad input dataset\n"
00116 "*****************************" ;
00117
00118 dtyp = dset->type ;
00119
00120 PLUTO_next_option(plint) ;
00121 new_prefix = PLUTO_get_string(plint) ;
00122 if( ! PLUTO_prefix_ok(new_prefix) )
00123 return "**********************\n"
00124 "ZPAD_main: bad prefix\n"
00125 "**********************" ;
00126
00127 PLUTO_next_option(plint) ;
00128 add_I = PLUTO_get_number(plint) ;
00129 add_S = PLUTO_get_number(plint) ;
00130 add_A = PLUTO_get_number(plint) ;
00131 add_P = PLUTO_get_number(plint) ;
00132 add_L = PLUTO_get_number(plint) ;
00133 add_R = PLUTO_get_number(plint) ;
00134 if( add_I==0 && add_S==0 && add_P==0 && add_A==0 && add_L==0 && add_R==0 )
00135 return "***********************\n"
00136 "ZPAD_main: no padding?!\n"
00137 "***********************" ;
00138
00139 tag = PLUTO_get_optiontag(plint) ;
00140 while( tag != NULL ){
00141
00142 if( strcmp(tag,"Dataset") == 0 ){
00143 cpt = PLUTO_get_string(plint) ;
00144 ftyp = PLUTO_string_index( cpt , NUM_DSET_TYPES,DSET_prefixstr ) ;
00145 if( ftyp >= 0 ){
00146 if( ftyp <= LAST_FUNC_TYPE ){
00147 dtyp = HEAD_FUNC_TYPE ;
00148 } else {
00149 ftyp -= (LAST_FUNC_TYPE+1) ;
00150 dtyp = HEAD_ANAT_TYPE ;
00151 }
00152 }
00153 }
00154
00155 tag = PLUTO_get_optiontag(plint) ;
00156 }
00157
00158
00159
00160
00161
00162
00163 new_dset = THD_zeropad( dset ,
00164 add_I, add_S, add_A, add_P, add_L, add_R,
00165 new_prefix , ZPAD_PURGE ) ;
00166
00167 if( new_dset == NULL )
00168 return "****************************************\n"
00169 "ZPAD_main: failed to create new dataset\n"
00170 "****************************************" ;
00171
00172 DSET_unload( dset ) ;
00173
00174
00175
00176 if( ftyp >= 0 ) EDIT_dset_items( new_dset ,
00177 ADN_type , dtyp ,
00178 ADN_func_type , ftyp ,
00179 ADN_none ) ;
00180
00181 ival = PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ;
00182
00183 if( ival ){
00184 DSET_delete(new_dset) ;
00185 return "**********************************************\n"
00186 "ZPAD_main: failure to add new dataset to AFNI\n"
00187 "**********************************************" ;
00188 }
00189
00190
00191
00192 return NULL ;
00193 }