Doxygen Source Code Documentation
3dAFNItoNIFTI.c File Reference
#include "mrilib.h"
#include "thd_niftiwrite.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Function Documentation
|
convert three sub-briks to a raw dataset with consecutive triplets Definition at line 4 of file 3dAFNItoNIFTI.c. References argc, calloc, niftiwr_opts_t::debug_level, DSET_BRICK_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_NVOX, DSET_PREFIX, EDIT_BRICK_FACTOR, EDIT_coerce_scale_type(), EDIT_substitute_brick(), ERROR_exit(), far, flags, THD_3dim_dataset::idcode, niftiwr_opts_t::infile_name, INFO_message(), ISVALID_DSET, machdep(), mainENTRY, malloc, MCW_new_idcode, PRINT_VERSION, THD_anonymize_write(), THD_filename_ok(), THD_open_dataset(), THD_write_nifti(), and tt.
00005 { 00006 THD_3dim_dataset *dset ; 00007 char *prefix=NULL , *fname ; 00008 int narg=1 , flags=0 , ii , verb=0 , newid=1 , denote=0 , floatize=0 ; 00009 niftiwr_opts_t options ; 00010 00011 PRINT_VERSION("3dAFNItoNIFTI"); 00012 00013 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){ 00014 printf("Usage: 3dAFNItoNIFTI [options] dataset\n" 00015 "Reads an AFNI dataset, writes it out as a NIfTI-1.1 (.nii) file.\n" 00016 "\n" 00017 "NOTES:\n" 00018 "* The nifti_tool program can be used to manipulate\n" 00019 " the contents of a NIfTI-1.1 file.\n" 00020 "* The input dataset can actually be in any input format\n" 00021 " that AFNI can read directly (e.g., MINC-1).\n" 00022 "* There is no 3dNIFTItoAFNI program, since AFNI programs\n" 00023 " can directly read .nii files. If you wish to make such\n" 00024 " a conversion anyway, one way to do so is like so:\n" 00025 " 3dcalc -a ppp.nii -prefix ppp -expr 'a'\n" 00026 "\n" 00027 "OPTIONS:\n" 00028 " -prefix ppp = Write the NIfTI-1.1 file as 'ppp.nii'.\n" 00029 " Default: the dataset's prefix is used.\n" 00030 #ifdef HAVE_ZLIB 00031 " If you want a compressed file, try\n" 00032 " using a prefix like 'ppp.nii.gz'.\n" 00033 #endif 00034 " -verb = Be verbose = print progress messages.\n" 00035 " Repeating this increases the verbosity\n" 00036 " (maximum setting is 3 '-verb' options).\n" 00037 " -float = Force the output dataset to be 32-bit\n" 00038 " floats. This option should be used when\n" 00039 " the input AFNI dataset has different\n" 00040 " float scale factors for different sub-bricks,\n" 00041 " an option that NIfTI-1.1 does not support.\n" 00042 "\n" 00043 "The following options affect the contents of the AFNI extension\n" 00044 "field that is written by default into the NIfTI-1.1 header:\n" 00045 "\n" 00046 " -pure = Do NOT write an AFNI extension field into\n" 00047 " the output file. Only use this option if\n" 00048 " needed. You can also use the 'nifti_tool'\n" 00049 " program to strip extensions from a file.\n" 00050 " -denote = When writing the AFNI extension field, remove\n" 00051 " text notes that might contain subject\n" 00052 " identifying information.\n" 00053 " -oldid = Give the new dataset the input dataset's\n" 00054 " AFNI ID code.\n" 00055 " -newid = Give the new dataset a new AFNI ID code, to\n" 00056 " distinguish it from the input dataset.\n" 00057 " **** N.B.: -newid is now the default action.\n" 00058 ) ; 00059 exit(0) ; 00060 } 00061 00062 mainENTRY("3dAFNItoNIFTI main"); machdep(); 00063 00064 /*--- check options ---*/ 00065 00066 while( narg < argc && argv[narg][0] == '-' ){ 00067 00068 if( strcmp(argv[narg],"-newid") == 0 ){ /* 11 May 2005 - RWCox */ 00069 newid = 1 ; narg++ ; continue ; 00070 } 00071 00072 if( strcmp(argv[narg],"-oldid") == 0 ){ /* 15 Jul 2005 - RWCox */ 00073 newid = 0 ; narg++ ; continue ; 00074 } 00075 00076 if( strcmp(argv[narg],"-denote") == 0 ){ /* 11 Jul 2005 - RWCox */ 00077 denote = 1 ; narg++ ; continue ; 00078 } 00079 00080 if( strcmp(argv[narg],"-float") == 0 ){ /* 14 Jul 2005 - RWCox */ 00081 floatize = 1 ; narg++ ; continue ; 00082 } 00083 00084 if( strcmp(argv[narg],"-pure") == 0 ){ /* 11 May 2005 - RWCox */ 00085 putenv("AFNI_NIFTI_NOEXT=YES") ; 00086 narg++ ; continue ; 00087 } 00088 00089 if( strcmp(argv[narg],"-prefix") == 0 ){ 00090 prefix = argv[++narg] ; 00091 if( !THD_filename_ok(prefix) || prefix[0] == '-' ) 00092 ERROR_exit("-prefix is illegal: %s\n",prefix) ; 00093 narg++ ; continue ; 00094 } 00095 00096 if( strcmp(argv[narg],"-verb") == 0 ){ 00097 verb++ ; narg++ ; continue ; 00098 } 00099 00100 ERROR_exit("Unknown option: %s\n",argv[narg]); 00101 } 00102 00103 /*--- get the dataset ---*/ 00104 00105 if( narg >= argc ) 00106 ERROR_exit("No dataset on command line?\n"); 00107 00108 dset = THD_open_dataset( argv[narg] ) ; 00109 if( !ISVALID_DSET(dset) ) 00110 ERROR_exit("Can't open dataset %s\n",argv[narg]); 00111 00112 /*--- deal with the filename ---*/ 00113 00114 if( prefix == NULL ) prefix = DSET_PREFIX(dset) ; 00115 00116 if( newid ) dset->idcode = MCW_new_idcode() ; /* 11 May 2005 */ 00117 00118 fname = malloc( strlen(prefix)+16 ) ; 00119 strcpy(fname,prefix) ; 00120 if( strstr(fname,".nii") == NULL ) strcat(fname,".nii") ; 00121 00122 options.infile_name = nifti_strdup(fname) ; 00123 options.debug_level = verb ; 00124 00125 /*--- 14 Jul 2005: floatization ---*/ 00126 00127 if( floatize ){ 00128 int nvals=DSET_NVALS(dset) , nxyz=DSET_NVOX(dset) , tt ; 00129 float fac , *far ; 00130 00131 DSET_mallocize(dset); DSET_load(dset); 00132 if( !DSET_LOADED(dset) ) ERROR_exit("Can't load input dataset from disk") ; 00133 if( verb ) INFO_message("Converting dataset to floats (in memory)") ; 00134 00135 /* loop over sub-bricks */ 00136 00137 for( ii=0 ; ii < nvals ; ii++ ){ 00138 fac = DSET_BRICK_FACTOR(dset,ii) ; if( fac == 0.0f ) fac = 1.0f ; 00139 tt = DSET_BRICK_TYPE(dset,ii) ; 00140 00141 /* if already floats and scale fac is 1.0, don't need to do anything */ 00142 00143 if( fac == 1.0f && (tt == MRI_float || tt == MRI_complex) ) continue ; 00144 00145 /* create output space */ 00146 00147 far = (float *)calloc( nxyz , sizeof(float) ) ; 00148 00149 /* scale input to output */ 00150 00151 EDIT_coerce_scale_type( nxyz , fac , 00152 DSET_BRICK_TYPE(dset,ii),DSET_BRICK_ARRAY(dset,ii) , 00153 MRI_float , far ) ; 00154 00155 /* replace input with output, and fix scale factor */ 00156 00157 EDIT_substitute_brick( dset , ii , MRI_float , far ) ; 00158 EDIT_BRICK_FACTOR( dset , ii , 0.0 ) ; 00159 } /* end of loop over sub-bricks */ 00160 } /* end of floatizationing */ 00161 00162 /*--- Go Baby, Go! ---*/ 00163 00164 if( denote ) THD_anonymize_write(1) ; /* sets a flag for attribute output */ 00165 ii = THD_write_nifti( dset , options ) ; /* actually write the damn thing */ 00166 exit(0) ; 00167 } |