Doxygen Source Code Documentation
thd_niftiwrite.h File Reference
#include "nifti1_io.h"Go to the source code of this file.
| Data Structures | |
| struct | niftiwr_opts_t | 
| Defines | |
| #define | VARIOUS_CONSTANTS 2 | 
| Functions | |
| nifti_image * | populate_nifti_image (THD_3dim_dataset *dset, niftiwr_opts_t options) | 
| int | THD_write_nifti (THD_3dim_dataset *dset, niftiwr_opts_t options) | 
Define Documentation
| 
 | 
| 
 Definition at line 6 of file thd_niftiwrite.h. | 
Function Documentation
| 
 | ||||||||||||
| 
 Referenced by THD_write_nifti(). | 
| 
 | ||||||||||||
| Write an AFNI dataset as a NIFTI file. 
 Definition at line 19 of file thd_niftiwrite.c. References niftiwr_opts_t::debug_level, DSET_ARRAY, DSET_BRICK_BYTES, DSET_load, DSET_LOADED, DSET_NVALS, ENTRY, niftiwr_opts_t::infile_name, ISVALID_DSET, malloc, nifti_set_afni_extension(), populate_nifti_image(), RETURN, and THD_filename_ok(). Referenced by main(), and THD_write_3dim_dataset(). 
 00020 {
00021   nifti_image * nim ;
00022   nifti_brick_list nbl ;
00023   int ii ;
00024   char * fname ;
00025 
00026 ENTRY("THD_write_nifti") ;
00027 
00028   nifti_set_debug_level(options.debug_level) ;
00029 
00030    /*-- check inputs for goodness --*/
00031 
00032   fname = nifti_strdup(options.infile_name );
00033 
00034   if( !THD_filename_ok(fname) || fname[0] == '-' ){
00035     fprintf(stderr,"** ERROR: Illegal filename for NIFTI output: %s\n",
00036       (fname != NULL) ? fname : "(null)" ) ;
00037     RETURN(0) ;
00038   }
00039 
00040   if( !ISVALID_DSET(dset) ){
00041     fprintf(stderr,
00042          "** ERROR: Illegal input dataset for NIFTI output: %s\n",
00043          fname ) ;
00044     RETURN(0) ;
00045   }
00046 
00047   /*-- load dataset from disk, if need be --*/
00048 
00049   DSET_load(dset) ;
00050   if( !DSET_LOADED(dset) ){
00051     fprintf(stderr,
00052             "** ERROR: Can't write NIFTI file since dataset isn't loaded: %s\n", fname) ;
00053     RETURN(0) ;
00054   }
00055 
00056   nim = populate_nifti_image(dset,options) ;
00057 
00058   /*-- construct filename --*/
00059 
00060    nim->fname = malloc( strlen(fname)+16 ) ;
00061    nim->iname = malloc( strlen(fname)+16 ) ;
00062    strcpy(nim->fname,fname) ;
00063    strcpy(nim->iname,fname) ;
00064 
00065   /*-- construct nifti_brick_list of pointers to data briks */
00066 
00067   if( options.debug_level > 2 ) nifti_image_infodump(nim) ;
00068   nbl.bricks = (void **) malloc ( DSET_NVALS(dset) * sizeof(void*) ) ;
00069   nbl.nbricks = DSET_NVALS(dset) ;
00070   nbl.bsize = DSET_BRICK_BYTES(dset,0) ;
00071   for (ii = 0 ; ii < DSET_NVALS(dset) ; ii++ ) {
00072     nbl.bricks[ii] = DSET_ARRAY(dset,ii) ;
00073   }
00074 
00075   /*-- use handy-dandy library function to write out data */
00076 
00077   nifti_set_afni_extension( dset , nim ) ;  /* 09 May 2005 - RWCox */
00078 
00079   nifti_image_write_bricks (nim, &nbl ) ;
00080   RETURN(1) ;
00081 }
 | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  