1 /*****************************************************************************
2 Major portions of this software are copyrighted by the Medical College
3 of Wisconsin, 1994-2000, and are released under the Gnu General Public
4 License, Version 2. See the file README.Copyright for details.
5 ******************************************************************************/
6
7 #include "mrilib.h"
8
9 /*---------------------------------------------------------------------
10 Routine to make a copy of a dataset, with data attached.
11 -----------------------------------------------------------------------*/
12
EDIT_full_copy(THD_3dim_dataset * dset,char * new_prefix)13 THD_3dim_dataset * EDIT_full_copy( THD_3dim_dataset *dset , char *new_prefix )
14 {
15 THD_3dim_dataset *new_dset ;
16 int ival , ityp , nbytes , nvals ;
17 void *new_brick , *old_brick ;
18
19 ENTRY("EDIT_full_copy") ;
20
21 /*-- sanity check --*/
22
23 if( ! ISVALID_3DIM_DATASET(dset) ){
24 ERROR_message("EDIT_full_copy: invalid dataset input ptr=%p",(void *)dset) ;
25 RETURN(NULL) ;
26 }
27
28 /*-- make the empty copy --*/
29
30 new_dset = EDIT_empty_copy( dset ) ; /* copy is set to MALLOC memory */
31
32 /*-- change its name? --*/
33
34 if( new_prefix != NULL )
35 EDIT_dset_items( new_dset ,
36 ADN_prefix , new_prefix ,
37 ADN_label1 , new_prefix ,
38 ADN_none ) ;
39
40 /*-- make brick(s) for this dataset --*/
41
42 if( !DSET_LOADED(dset) )
43 DSET_load(dset) ; /* make sure is in memory */
44
45 nvals = DSET_NVALS(dset) ;
46
47 for( ival=0 ; ival < nvals ; ival++ ){
48 ityp = DSET_BRICK_TYPE(new_dset,ival) ; /* type of data */
49 nbytes = DSET_BRICK_BYTES(new_dset,ival) ; /* how much data */
50 new_brick = malloc( nbytes ) ; /* make room */
51
52 if( new_brick == NULL ){
53 THD_delete_3dim_dataset( new_dset , False ) ;
54 ERROR_message("EDIT_full_copy: can't malloc %d bytes for new sub-brick %d",nbytes,ival) ;
55 ININFO_message(" Dataset %s",DSET_HEADNAME(dset)) ;
56 RETURN(NULL) ;
57 }
58
59 EDIT_substitute_brick( new_dset , ival , ityp , new_brick ) ;
60
61 /*-- copy data from old brick to new brick --*/
62
63 old_brick = DSET_BRICK_ARRAY(dset,ival) ;
64
65 if( old_brick == NULL ){
66 THD_delete_3dim_dataset( new_dset , False ) ;
67 ERROR_message("EDIT_full_copy: input sub-brick %d is NULL",ival) ;
68 ININFO_message(" Dataset %s",DSET_HEADNAME(dset)) ;
69 RETURN(NULL) ;
70 }
71
72 memcpy( new_brick , old_brick , nbytes ) ;
73 }
74
75 if (0) { /* For DG to activate */
76 THD_copy_labeltable_atr( new_dset->dblk, dset->dblk);
77 }
78
79 RETURN( new_dset );
80 }
81