Doxygen Source Code Documentation
plug_rename.c File Reference
#include "afni.h"Go to the source code of this file.
Functions | |
| char * | RENAME_main (PLUGIN_interface *) |
| DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface * | PLUGIN_init (int ncall) |
Variables | |
| char | helpstring [] |
Function Documentation
|
|
Definition at line 38 of file plug_rename.c. References ANAT_ALL_MASK, FUNC_ALL_MASK, helpstring, PLUTO_add_hint(), PLUTO_set_runlabels(), PLUTO_set_sequence(), and RENAME_main().
00039 {
00040 PLUGIN_interface * plint ;
00041
00042 if( ncall > 0 ) return NULL ; /* only one interface */
00043
00044 /*-- set titles and call point --*/
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" ) ; /* 04 Nov 2003 */
00054
00055 /*-- first line of input: Dataset --*/
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 /*-- second line of input: Prefix for output dataset --*/
00064
00065 PLUTO_add_option( plint , "Output" , "Output" , TRUE ) ;
00066 PLUTO_add_string( plint , "Prefix" , 0,NULL , 19 ) ;
00067
00068 return plint ;
00069 }
|
|
|
Definition at line 75 of file plug_rename.c. References ADN_none, ADN_prefix, THD_diskptr::brick_name, COMPRESS_add_suffix(), COMPRESS_filecode(), COMPRESS_NOFILE, THD_3dim_dataset::dblk, THD_datablock::diskptr, THD_slist_find::dset_index, THD_session::dsset, EDIT_dset_items(), FIND_IDCODE, FIRST_VIEW_TYPE, free, GLOBAL_library, THD_diskptr::header_name, ISVALID_3DIM_DATASET, LAST_VIEW_TYPE, PLUTO_find_dset(), PLUTO_fixup_names(), PLUTO_prefix_ok(), THD_slist_find::sess_index, THD_sessionlist::ssar, AFNI_library_type::sslist, THD_dset_in_sessionlist(), THD_is_file(), and XtFree. Referenced by PLUGIN_init().
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 /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/
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 /*---------- At this point, the inputs are OK ----------*/
00111
00112 /*-- find this dataset in the AFNI library --*/
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 /*-- set up session_row to point to all the associated datasets --*/
00119
00120 id = find.dset_index ;
00121 session_row = ss->dsset[id] ;
00122
00123 /*-- for each element of this row,
00124 change its internal names and, if needed, filenames on disk --*/
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 ; /* skip this one */
00132
00133 /*-- copy the old filenames --*/
00134
00135 old_header_name = XtNewString( dset->dblk->diskptr->header_name ) ;
00136 old_brick_name = XtNewString( dset->dblk->diskptr->brick_name ) ;
00137
00138 /*-- initialize the new filenames inside the dataset --*/
00139
00140 EDIT_dset_items( dset , ADN_prefix , new_prefix , ADN_none ) ;
00141
00142 /*-- rename the old files to the new files, if they exist on disk --*/
00143
00144 if( THD_is_file(old_header_name) )
00145 ierr += rename( old_header_name , dset->dblk->diskptr->header_name ) ;
00146
00147 /* May 1998: fix .BRIK rename to allow for compression */
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 /*-- clean up AFNI --*/
00165
00166 PLUTO_fixup_names() ;
00167
00168 /*-- done --*/
00169
00170 if( ierr ) return "***********************************************\n"
00171 "RENAME_main: some file rename operations failed\n"
00172 "***********************************************" ;
00173
00174 return NULL ;
00175 }
|
Variable Documentation
|
|
Initial value: " Purpose: Renaming a dataset from within AFNI\n" " Inputs:\n" " Dataset = A dataset in the current session.\n" " Prefix = New filename prefix.\n" " N.B.: All views containing this dataset's\n" " children and/or parents will be affected\n" " affected by this operation." Definition at line 21 of file plug_rename.c. Referenced by PLUGIN_init(). |