Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
plug_rename.c
Go to the documentation of this file.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
00018
00019 char * RENAME_main( PLUGIN_interface * ) ;
00020
00021 static char helpstring[] =
00022 " Purpose: Renaming a dataset from within AFNI\n"
00023 " Inputs:\n"
00024 " Dataset = A dataset in the current session.\n"
00025 " Prefix = New filename prefix.\n"
00026 " N.B.: All views containing this dataset's\n"
00027 " children and/or parents will be affected\n"
00028 " affected by this operation."
00029 ;
00030
00031
00032
00033
00034
00035
00036 DEFINE_PLUGIN_PROTOTYPE
00037
00038 PLUGIN_interface * PLUGIN_init( int ncall )
00039 {
00040 PLUGIN_interface * plint ;
00041
00042 if( ncall > 0 ) return NULL ;
00043
00044
00045
00046 plint = PLUTO_new_interface( "Dataset Rename" , "Dataset Renaming" , helpstring ,
00047 PLUGIN_CALL_VIA_MENU , RENAME_main ) ;
00048
00049 PLUTO_add_hint( plint , "Rename a Dataset" ) ;
00050
00051 PLUTO_set_sequence( plint , "A:afnicontrol:dset" ) ;
00052
00053 PLUTO_set_runlabels( plint , "Rename+Keep" , "Rename+Close" ) ;
00054
00055
00056
00057 PLUTO_add_option( plint , "Input" , "Input" , TRUE ) ;
00058 PLUTO_add_dataset(plint , "Dataset" ,
00059 ANAT_ALL_MASK , FUNC_ALL_MASK ,
00060 WARP_ON_DEMAND_MASK | DIMEN_ALL_MASK |
00061 SESSION_ALL_MASK | BRICK_ALLTYPE_MASK ) ;
00062
00063
00064
00065 PLUTO_add_option( plint , "Output" , "Output" , TRUE ) ;
00066 PLUTO_add_string( plint , "Prefix" , 0,NULL , 19 ) ;
00067
00068 return plint ;
00069 }
00070
00071
00072
00073
00074
00075 char * RENAME_main( PLUGIN_interface * plint )
00076 {
00077 char * new_prefix ;
00078 MCW_idcode * idc ;
00079 THD_3dim_dataset * dset ;
00080 THD_3dim_dataset ** session_row ;
00081 char * old_header_name , * old_brick_name ;
00082 THD_slist_find find ;
00083 THD_session * ss ;
00084 int iss , id , ivv , ierr , mm ;
00085
00086
00087
00088
00089 if( plint == NULL )
00090 return "***********************\n"
00091 "RENAME_main: NULL input\n"
00092 "***********************" ;
00093
00094 PLUTO_next_option(plint) ;
00095 idc = PLUTO_get_idcode(plint) ;
00096 dset = PLUTO_find_dset(idc) ;
00097 if( dset == NULL )
00098 return "******************************\n"
00099 "RENAME_main:bad input dataset\n"
00100 "******************************" ;
00101
00102 PLUTO_next_option(plint) ;
00103 new_prefix = PLUTO_get_string(plint) ;
00104 if( ! PLUTO_prefix_ok(new_prefix) )
00105 return "***********************\n"
00106 "RENAME_main:bad prefix\n"
00107 "***********************" ;
00108
00109
00110
00111
00112
00113
00114 find = THD_dset_in_sessionlist( FIND_IDCODE, idc, GLOBAL_library.sslist, -1 ) ;
00115 iss = find.sess_index ;
00116 ss = GLOBAL_library.sslist->ssar[iss] ;
00117
00118
00119
00120 id = find.dset_index ;
00121 session_row = ss->dsset[id] ;
00122
00123
00124
00125
00126 ierr = 0 ;
00127
00128 for( ivv=FIRST_VIEW_TYPE ; ivv <= LAST_VIEW_TYPE ; ivv++ ){
00129
00130 dset = session_row[ivv] ;
00131 if( ! ISVALID_3DIM_DATASET(dset) ) continue ;
00132
00133
00134
00135 old_header_name = XtNewString( dset->dblk->diskptr->header_name ) ;
00136 old_brick_name = XtNewString( dset->dblk->diskptr->brick_name ) ;
00137
00138
00139
00140 EDIT_dset_items( dset , ADN_prefix , new_prefix , ADN_none ) ;
00141
00142
00143
00144 if( THD_is_file(old_header_name) )
00145 ierr += rename( old_header_name , dset->dblk->diskptr->header_name ) ;
00146
00147
00148 #if 0
00149 if( THD_is_file(old_brick_name) )
00150 ierr += rename( old_brick_name , dset->dblk->diskptr->brick_name ) ;
00151 #else
00152 mm = COMPRESS_filecode(old_brick_name) ;
00153 if( mm != COMPRESS_NOFILE ){
00154 char * old_name = COMPRESS_add_suffix(old_brick_name,mm) ;
00155 char * new_name = COMPRESS_add_suffix(dset->dblk->diskptr->brick_name,mm) ;
00156 ierr += rename( old_name , new_name ) ;
00157 free(old_name) ; free(new_name) ;
00158 }
00159 #endif
00160
00161 XtFree(old_header_name) ; XtFree(old_brick_name) ;
00162 }
00163
00164
00165
00166 PLUTO_fixup_names() ;
00167
00168
00169
00170 if( ierr ) return "***********************************************\n"
00171 "RENAME_main: some file rename operations failed\n"
00172 "***********************************************" ;
00173
00174 return NULL ;
00175 }