1 #include "afni.h"
2 
3 #ifndef ALLOW_PLUGINS
4 #  error "Plugins not properly set up -- see machdep.h"
5 #endif
6 
7 /*****************************************************************************
8    Like 3ddup, but as a plugin.  RWCox - 06 Aug 2003.
9 ******************************************************************************/
10 
11 static char helpstring[] =
12   " Purpose: Make a 'warp-on-demand' duplicated of a dataset.\n"
13   "\n"
14   " Inputs:\n"
15   "  Dataset = A dataset in the current session (not warp-on-demand itself).\n"
16   "  Prefix  = Name for the new dataset.\n"
17   "\n"
18   " Note: output dataset will be in the AFNI .HEAD format.\n"
19   "\n"
20   " RWCox - 06 Aug 2003 - cf. 3ddup."
21 ;
22 
23 static char * DUP_main( PLUGIN_interface *plint ) ;
24 
25 /***********************************************************************
26    Set up the interface to the user
27 ************************************************************************/
28 
29 DEFINE_PLUGIN_PROTOTYPE
30 
PLUGIN_init(int ncall)31 PLUGIN_interface * PLUGIN_init( int ncall )
32 {
33    PLUGIN_interface * plint ;
34 
35    if( ncall > 0 ) return NULL ;  /* only one interface */
36 
37    CHECK_IF_ALLOWED("DATASETDUP","Dataset Dup") ;  /* 30 Sep 2016 */
38 
39    /*-- set titles and call point --*/
40 
41    plint = PLUTO_new_interface( "Dataset Dup" , "Warp-on-Demand duplicate" , helpstring ,
42                                  PLUGIN_CALL_VIA_MENU , DUP_main  ) ;
43 
44    PLUTO_add_hint( plint , "Warp-on-Demand duplicate" ) ;
45 
46    /*-- first line of input: Dataset --*/
47 
48    PLUTO_add_option( plint , "Input" , "Input" , TRUE ) ;
49    PLUTO_add_dataset(plint , "Dataset" ,
50                                     ANAT_ALL_MASK , FUNC_ALL_MASK ,
51                                     DIMEN_ALL_MASK | BRICK_ALLTYPE_MASK ) ;
52 
53    /*-- second line of input: Prefix for output dataset --*/
54 
55    PLUTO_add_option( plint , "Output" , "Output" , TRUE ) ;
56    PLUTO_add_string( plint , "Prefix" , 0,NULL , 19 ) ;
57 
58    return plint ;
59 }
60 
61 /*----------------------------------------------------------------------------*/
62 
DUP_main(PLUGIN_interface * plint)63 static char * DUP_main( PLUGIN_interface *plint )
64 {
65    THD_3dim_dataset *dset_in , *dset_out ;
66    THD_warp *warp , *twarp ;
67    MCW_idcode *idc ;
68    char *new_prefix ;
69 
70    if( plint == NULL ) return " \nDUP_main: NULL input!\n" ;
71 
72    PLUTO_next_option(plint) ;
73    idc     = PLUTO_get_idcode(plint) ;
74    dset_in = PLUTO_find_dset(idc) ;
75    if( dset_in == NULL )
76      return "****************************\n"
77             "DUP_main:  bad input dataset\n"
78             "****************************"  ;
79    if( !DSET_ONDISK(dset_in) )
80      return "********************************\n"
81             "DUP_main:  illegal input dataset\n"
82             "********************************"  ;
83 
84    PLUTO_next_option(plint) ;
85    new_prefix = PLUTO_get_string(plint) ;
86    if( ! PLUTO_prefix_ok(new_prefix) )
87      return "*********************\n"
88             "DUP_main:  bad prefix\n"
89             "*********************"  ;
90 
91    /*** copy header info ***/
92 
93    dset_out = EDIT_empty_copy( dset_in ) ;
94    if( !ISVALID_3DIM_DATASET(dset_out) )
95      return "****************************\n"
96             "DUP_main:  can't duplicate?!\n"
97             "****************************"  ;
98 
99    EDIT_dset_items( dset_out , ADN_prefix,new_prefix , ADN_none ) ;
100 
101    tross_Copy_History( dset_in , dset_out ) ;
102    tross_Append_History( dset_out , "Warp-on-Demand duplicate from plug_3ddup." ) ;
103 
104    warp = myXtNew(THD_warp) ; *warp = IDENTITY_WARP ;
105 
106    EDIT_dset_items( dset_out ,
107                       ADN_warp        , warp    ,
108                       ADN_warp_parent , dset_in ,
109                     ADN_none ) ;
110 
111    /*** done! ***/
112 
113    THD_write_3dim_dataset( NULL , NULL , dset_out , False ) ;
114    PLUTO_add_dset( plint , dset_out , DSET_ACTION_MAKE_CURRENT ) ;
115 
116    return NULL ;
117 }
118