Doxygen Source Code Documentation
thd_delete.c
Go to the documentation of this file.00001 /***************************************************************************** 00002 Major portions of this software are copyrighted by the Medical College 00003 of Wisconsin, 1994-2000, and are released under the Gnu General Public 00004 License, Version 2. See the file README.Copyright for details. 00005 ******************************************************************************/ 00006 00007 #include "mrilib.h" 00008 #include "thd.h" 00009 00010 /*--------------------------------------------------------------- 00011 erase the insides of a diskptr from the earth 00012 -----------------------------------------------------------------*/ 00013 00014 void THD_delete_diskptr( THD_diskptr *dkptr ) 00015 { 00016 if( ! ISVALID_DISKPTR(dkptr) ) return ; 00017 } 00018 00019 /*--------------------------------------------------------------- 00020 erase the insides of a datablock from the earth 00021 -----------------------------------------------------------------*/ 00022 00023 void THD_delete_datablock( THD_datablock *dblk ) 00024 { 00025 int ibr ; 00026 00027 ENTRY("THD_delete_datablock") ; 00028 00029 if( ! ISVALID_DATABLOCK(dblk) ) EXRETURN ; 00030 00031 /** free the actual brick data (method depends on how it is stored) **/ 00032 00033 if( dblk->brick != NULL ){ 00034 dblk->locked = 0 ; 00035 00036 switch( dblk->malloc_type ){ 00037 00038 default: 00039 STATUS("count bricks") ; 00040 ibr = THD_count_databricks( dblk ) ; 00041 if( ibr > 0 ) 00042 fprintf(stderr, 00043 "** attempt to delete non-NULL unknown type of datablock **\n"); 00044 00045 if( dblk->brick != NULL ) FREE_IMARR( dblk->brick ) ; 00046 break ; 00047 00048 case DATABLOCK_MEM_MALLOC: 00049 case DATABLOCK_MEM_MMAP: 00050 THD_purge_datablock( dblk , dblk->malloc_type ) ; 00051 DESTROY_IMARR( dblk->brick ) ; 00052 break ; 00053 00054 case DATABLOCK_MEM_SHARED: /* 02 May 2003 */ 00055 /* ??? */ 00056 break ; 00057 } 00058 } 00059 00060 /** free the other information **/ 00061 00062 STATUS("free brick_ stuff") ; 00063 00064 myXtFree( dblk->brick_fac ) ; 00065 myXtFree( dblk->brick_bytes ) ; 00066 00067 /** 30 Nov 1997 **/ 00068 00069 if( dblk->brick_lab != NULL ){ 00070 for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_lab[ibr] ) ; 00071 myXtFree( dblk->brick_lab ) ; 00072 } 00073 00074 if( dblk->brick_keywords != NULL ){ 00075 for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_keywords[ibr] ) ; 00076 myXtFree( dblk->brick_keywords ) ; 00077 } 00078 00079 if( dblk->brick_statcode != NULL ) myXtFree( dblk->brick_statcode ) ; 00080 if( dblk->brick_stataux != NULL ){ 00081 for( ibr=0 ; ibr < dblk->nvals ; ibr++ ) myXtFree( dblk->brick_stataux[ibr] ) ; 00082 myXtFree( dblk->brick_stataux ) ; 00083 } 00084 00085 if( DBLK_IS_MASTERED(dblk) ){ /* 11 Jan 1999 */ 00086 myXtFree( dblk->master_ival ) ; 00087 myXtFree( dblk->master_bytes ) ; 00088 } 00089 00090 THD_delete_diskptr( dblk->diskptr ) ; 00091 00092 STATUS("KILL_KILL") ; 00093 KILL_KILL( dblk->kl ) ; 00094 00095 STATUS("free attributes") ; 00096 myXtFree( dblk->atr ) ; /* not on the kill list */ 00097 00098 EXRETURN ; 00099 } 00100 00101 /*------------------------------------------------------------------- 00102 destroy a 3D dataset (possibly including files) 00103 ---------------------------------------------------------------------*/ 00104 00105 void THD_delete_3dim_dataset( THD_3dim_dataset *dset, Boolean kill_files ) 00106 { 00107 ENTRY("THD_delete_3dim_dataset") ; 00108 00109 if( ! ISVALID_3DIM_DATASET(dset) ) EXRETURN ; 00110 00111 if( DSET_IS_MINC(dset) ) kill_files = False ; /* 29 Oct 2001 */ 00112 if( DSET_IS_VOLUMES(dset) ) kill_files = False ; /* 20 Jun 2002 */ 00113 if( DSET_IS_ANALYZE(dset) ) kill_files = False ; /* 27 Aug 2002 */ 00114 if( DSET_IS_1D(dset) ) kill_files = False ; 00115 if( DSET_IS_3D(dset) ) kill_files = False ; 00116 if( DSET_IS_CTFMRI(dset) ) kill_files = False ; 00117 if( DSET_IS_CTFSAM(dset) ) kill_files = False ; 00118 if( DSET_IS_NIFTI(dset) ) kill_files = False ; /* 28 Aug 2003 */ 00119 00120 if( kill_files ){ 00121 THD_diskptr *dkptr = dset->dblk->diskptr ; 00122 00123 STATUS("killing files") ; 00124 unlink( dkptr->header_name ) ; 00125 COMPRESS_unlink(dkptr->brick_name) ; 00126 } 00127 00128 #ifdef ALLOW_DATASET_VLIST 00129 STATUS("destroy vlist") ; 00130 DESTROY_VLIST(dset->pts) ; 00131 #endif 00132 00133 if( ISVALID_TIMEAXIS(dset->taxis) ){ 00134 STATUS("destroy taxis") ; 00135 myXtFree( dset->taxis->toff_sl ) ; 00136 myXtFree( dset->taxis ) ; 00137 } 00138 00139 THD_delete_datablock( dset->dblk ) ; 00140 00141 STATUS("KILL_KILL") ; 00142 KILL_KILL( dset->kl ) ; 00143 00144 EXRETURN ; 00145 }