Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

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    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 #include "thd_niftiwrite.h"
00010 
00011 static int use_3D_format    = 0 ;  /* 21 Mar 2003 */
00012 static int use_NIFTI_format = 0 ;  /* 06 Apr 2005 */
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 /*! This routine writes all the header data in the struct to
00019     the datablock attributes, then writes the dataset to disk.
00020 
00021    29 Apr 1998: erase attributes that are unused, so that
00022                   they won't be left over from a previous life
00023 
00024    09 Mar 2005: attributes are now set in function
00025                 THD_set_dataset_attributes() rather than here
00026 
00027    06 Apr 2005: might go all NIFTI on you
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 ;  /* 06 Apr 2005 */
00036 
00037 ENTRY("THD_write_3dim_dataset") ;
00038 
00039    /*-- sanity checks --*/
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 ;  /* 05 Jul 2005 */
00047 
00048    /* Can only write AFNI formatted datasets */
00049 
00050    if( DSET_IS_MINC(dset)     ) RETURN(False) ;  /* 29 Oct 2001 */
00051    if( DSET_IS_MASTERED(dset) ) RETURN(False) ;  /* 11 Jan 1999 */
00052    if( DSET_IS_ANALYZE(dset)  ) RETURN(False) ;  /* 27 Aug 2002 */
00053    if( DSET_IS_CTFMRI(dset)   ) RETURN(False) ;  /* 05 Dec 2002 */
00054    if( DSET_IS_CTFSAM(dset)   ) RETURN(False) ;  /* 05 Dec 2002 */
00055    if( DSET_IS_TCAT(dset)     ) RETURN(False) ;  /* 05 Aug 2004 */
00056 
00057    if( DSET_IS_VOLUMES(dset) && write_brick ) RETURN(False) ;  /* 20 Jun 2002 */
00058 
00059    if( DSET_IS_1D(dset) ||
00060        ( DSET_NY(dset)==1 && DSET_NZ(dset)==1 ) ){            /* 04 Mar 2003 */
00061 
00062      THD_write_1D( new_sessname , new_prefixname , dset ) ;
00063      RETURN(True) ;
00064    }
00065 
00066    /*------------------------------*/
00067    /*-----  change filenames? -----*/
00068 
00069    THD_init_diskptr_names( blk->diskptr ,
00070                            new_sessname , NULL , new_prefixname ,
00071                            dset->view_type , True ) ;
00072 
00073    /*----- 09 Mar 2005: set attribute structs in the datablock -----*/
00074 
00075    THD_set_dataset_attributes( dset ) ;
00076 
00077    /*------ 06 Apr 2005: write a NIFTI-1 dataset??? -----*/
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      {  /* set the nifti_io debug level       8 Apr 2005 [rickr] */
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    /*------ 21 Mar 2003: use the .3D format? -----*/
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    /*----- write datablock to disk in AFNI .HEAD/.BRIK format -----*/
00127 
00128    RETURN( THD_write_datablock(blk,write_brick) ) ;
00129 }
 

Powered by Plone

This site conforms to the following standards: