Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
thd_writedset.c
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 #include "mrilib.h"
00008 #include "thd.h"
00009 #include "thd_niftiwrite.h"
00010 
00011 static int use_3D_format    = 0 ;  
00012 static int use_NIFTI_format = 0 ;  
00013 
00014 void THD_use_3D_format   ( int uu ){ use_3D_format    = uu; }
00015 void THD_use_NIFTI_format( int uu ){ use_NIFTI_format = uu; }
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 Boolean THD_write_3dim_dataset( char *new_sessname , char *new_prefixname ,
00031                                 THD_3dim_dataset *dset , Boolean write_brick )
00032 {
00033    THD_datablock *blk ;
00034    int ii ;
00035    char *ppp ;  
00036 
00037 ENTRY("THD_write_3dim_dataset") ;
00038 
00039    
00040 
00041    if( ! ISVALID_3DIM_DATASET(dset)    ||
00042        ! ISVALID_DATABLOCK(dset->dblk) ||
00043        ! ISVALID_DISKPTR(dset->dblk->diskptr) ) RETURN(False) ;
00044 
00045    blk = dset->dblk ;
00046    blk->parent = (XtPointer)dset ;  
00047 
00048    
00049 
00050    if( DSET_IS_MINC(dset)     ) RETURN(False) ;  
00051    if( DSET_IS_MASTERED(dset) ) RETURN(False) ;  
00052    if( DSET_IS_ANALYZE(dset)  ) RETURN(False) ;  
00053    if( DSET_IS_CTFMRI(dset)   ) RETURN(False) ;  
00054    if( DSET_IS_CTFSAM(dset)   ) RETURN(False) ;  
00055    if( DSET_IS_TCAT(dset)     ) RETURN(False) ;  
00056 
00057    if( DSET_IS_VOLUMES(dset) && write_brick ) RETURN(False) ;  
00058 
00059    if( DSET_IS_1D(dset) ||
00060        ( DSET_NY(dset)==1 && DSET_NZ(dset)==1 ) ){            
00061 
00062      THD_write_1D( new_sessname , new_prefixname , dset ) ;
00063      RETURN(True) ;
00064    }
00065 
00066    
00067    
00068 
00069    THD_init_diskptr_names( blk->diskptr ,
00070                            new_sessname , NULL , new_prefixname ,
00071                            dset->view_type , True ) ;
00072 
00073    
00074 
00075    THD_set_dataset_attributes( dset ) ;
00076 
00077    
00078 
00079    ppp = DSET_PREFIX(dset) ;
00080    if( STRING_HAS_SUFFIX(ppp,".nii")    ||
00081        STRING_HAS_SUFFIX(ppp,".nii.gz") || use_NIFTI_format ){
00082 
00083      niftiwr_opts_t options ;
00084 
00085      ii = strlen(DSET_DIRNAME(dset)) + strlen(ppp) + 16 ;
00086      options.infile_name = calloc(1,ii) ;
00087      strcpy(options.infile_name,DSET_DIRNAME(dset)) ;
00088      strcat(options.infile_name,ppp) ;
00089 
00090      if( !STRING_HAS_SUFFIX(options.infile_name,".nii")    &&
00091          !STRING_HAS_SUFFIX(options.infile_name,".nii.gz")   )
00092        strcat(options.infile_name,".nii") ;
00093 
00094      {  
00095         char * ept = my_getenv("AFNI_NIFTI_DEBUG");
00096         if( ept != NULL ) options.debug_level = atoi(ept);
00097         else              options.debug_level = 0 ;
00098      }
00099 
00100      if( !write_brick ){
00101        fprintf(stderr,
00102                "** ERROR: can't write HEADER only for NIfTI-1 file: %s\n",
00103                options.infile_name ) ;
00104        ii = 0 ;
00105      } else {
00106        ii = THD_write_nifti(dset,options) ;
00107        strcpy( dset->dblk->diskptr->brick_name , options.infile_name ) ;
00108      }
00109 
00110      free((void *)options.infile_name) ;
00111      RETURN( (Boolean)ii ) ;
00112    }
00113 
00114    
00115 
00116    if( STRING_HAS_SUFFIX(ppp,".3D") || DSET_IS_3D(dset) || use_3D_format ){
00117      if( !write_brick ){
00118        fprintf(stderr,
00119                "** ERROR: can't write HEADER only for .3D file: %s\n",
00120                DSET_PREFIX(dset) ) ;
00121        RETURN(False) ;
00122      }
00123      THD_write_3D( NULL, NULL, dset ) ; RETURN(True) ;
00124    }
00125 
00126    
00127 
00128    RETURN( THD_write_datablock(blk,write_brick) ) ;
00129 }