Doxygen Source Code Documentation
thd_writeatr.c File Reference
#include "mrilib.h"
#include "thd.h"
Go to the source code of this file.
Functions | |
Boolean | THD_write_atr (THD_datablock *blk) |
Boolean | THD_write_nimlatr (THD_datablock *blk) |
Function Documentation
|
Definition at line 12 of file thd_writeatr.c. References AFNI_yesenv(), THD_datablock::atr, ATR_FLOAT_TYPE, ATR_INT_TYPE, ATR_STRING_TYPE, ATR_string::ch, DBLK_IS_ANALYZE, DBLK_IS_CTFMRI, DBLK_IS_CTFSAM, DBLK_IS_MINC, DBLK_IS_MPEG, DBLK_IS_NIFTI, THD_datablock::diskptr, ENTRY, FAIL, ATR_float::fl, THD_diskptr::header_name, ATR_int::in, ISVALID_DATABLOCK, ISVALID_DISKPTR, ATR_string::name, ATR_int::name, ATR_float::name, THD_datablock::natr, ATR_string::nch, ATR_float::nfl, ATR_int::nin, RETURN, SUCCESS, THD_unzblock(), THD_write_nimlatr(), THD_zblock(), and ATR_any::type. Referenced by THD_write_datablock().
00013 { 00014 THD_diskptr *dkptr ; 00015 int ia , code , ii ; 00016 ATR_any *atr_any ; 00017 Boolean good = True ; 00018 FILE *header_file ; 00019 00020 ENTRY("THD_write_atr") ; 00021 00022 /*--- sanity checks ---*/ 00023 00024 if( ! ISVALID_DATABLOCK(blk) ) RETURN( False ); 00025 00026 dkptr = blk->diskptr ; 00027 if( ! ISVALID_DISKPTR(dkptr) || strlen(dkptr->header_name) == 0 ) RETURN( False ); 00028 00029 if( DBLK_IS_MINC(blk) ) RETURN( False ); /* 29 Oct 2001 */ 00030 if( DBLK_IS_ANALYZE(blk) ) RETURN( False ); /* 27 Aug 2002 */ 00031 if( DBLK_IS_NIFTI(blk) ) RETURN( False ); /* 28 Aug 2003 */ 00032 if( DBLK_IS_CTFMRI(blk) ) RETURN( False ); 00033 if( DBLK_IS_CTFSAM(blk) ) RETURN( False ); 00034 if( DBLK_IS_MPEG(blk) ) RETURN( False ); 00035 00036 /** 01 Jun 2005: perhaps write in the new NIML format? **/ 00037 00038 if( AFNI_yesenv("AFNI_WRITE_NIML") ){ 00039 return THD_write_nimlatr( blk ) ; 00040 } 00041 00042 /** Write the old AFNI format **/ 00043 00044 header_file = fopen( dkptr->header_name , "w" ) ; 00045 if( header_file == NULL ){ 00046 fprintf(stderr, 00047 "*** ERROR: failed to open file %s for attribute writing;\n" 00048 " - Do you have permission to write to this disk?\n" 00049 " - Is the disk full?\n" , 00050 dkptr->header_name) ; 00051 RETURN( False ); 00052 } 00053 00054 for( ia=0 ; ia < blk->natr ; ia++ ){ 00055 00056 atr_any = &(blk->atr[ia]) ; 00057 if( atr_any == NULL ) continue ; 00058 00059 code = SUCCESS ; 00060 switch( atr_any->type ){ 00061 00062 case ATR_FLOAT_TYPE:{ 00063 ATR_float * atr_flo = (ATR_float *) atr_any ; 00064 00065 code = fprintf( header_file , 00066 "\ntype = %s\nname = %s\ncount = %d\n" , 00067 ATR_typestr[ATR_FLOAT_TYPE] , 00068 atr_flo->name , atr_flo->nfl ) ; 00069 00070 if( code < 1 ){ code = FAIL ; break ; } 00071 00072 for( ii=0 ; ii < atr_flo->nfl ; ii++ ){ 00073 code = fprintf( header_file , " %14.7g" , atr_flo->fl[ii] ) ; 00074 if( ii % 5 == 4 && ii < atr_flo->nfl-1 ) 00075 fprintf( header_file , "\n" ) ; 00076 } 00077 00078 code = (code < 1 ) ? FAIL : SUCCESS ; 00079 } 00080 break ; 00081 00082 case ATR_INT_TYPE:{ 00083 ATR_int * atr_int = (ATR_int *) atr_any ; 00084 00085 code = fprintf( header_file , 00086 "\ntype = %s\nname = %s\ncount = %d\n" , 00087 ATR_typestr[ATR_INT_TYPE] , 00088 atr_int->name , atr_int->nin ) ; 00089 00090 if( code < 1 ){ code = FAIL ; break ; } 00091 00092 for( ii=0 ; ii < atr_int->nin ; ii++ ){ 00093 code = fprintf( header_file , " %d" , atr_int->in[ii] ) ; 00094 if( ii % 5 == 4 && ii < atr_int->nin-1 ) 00095 fprintf( header_file , "\n" ) ; 00096 } 00097 00098 code = (code < 1 ) ? FAIL : SUCCESS ; 00099 } 00100 break ; 00101 00102 case ATR_STRING_TYPE:{ 00103 ATR_string * atr_str = (ATR_string *) atr_any ; 00104 00105 code = fprintf( header_file , 00106 "\ntype = %s\nname = %s\ncount = %d\n" , 00107 ATR_typestr[ATR_STRING_TYPE] , 00108 atr_str->name , atr_str->nch ) ; 00109 00110 00111 if( code < 1 ){ code = FAIL ; break ; } 00112 00113 THD_zblock( atr_str->nch , atr_str->ch ) ; 00114 00115 fprintf( header_file , "'" ) ; 00116 for( ii=0 ; ii < atr_str->nch ; ii++ ){ 00117 code = fprintf( header_file , "%c" , atr_str->ch[ii] ) ; 00118 } 00119 00120 code = (code < 1) ? FAIL : SUCCESS ; 00121 00122 THD_unzblock( atr_str->nch , atr_str->ch ) ; 00123 } 00124 break ; 00125 00126 } /* end of switch on atr type */ 00127 00128 good = good && (code != FAIL) ; /* all must not FAIL */ 00129 fprintf(header_file,"\n") ; 00130 00131 } /* end of loop over all atr's */ 00132 00133 if( good == False ){ 00134 fprintf(stderr, 00135 "*** WARNING: error in output to attribute file %s;\n" 00136 " - Is the disk full?\n" , 00137 dkptr->header_name) ; 00138 } 00139 00140 /*--- close it down ---*/ 00141 00142 fclose( header_file ) ; 00143 RETURN( True ); 00144 } |
|
Write the old AFNI format * Definition at line 148 of file thd_writeatr.c. References THD_datablock::diskptr, ENTRY, THD_diskptr::header_name, ISVALID_DSET, NI_set_attribute(), NI_stream_close(), NI_stream_open(), NI_stream_writestring(), NI_TEXT_MODE, NI_write_element(), THD_datablock::parent, THD_diskptr::prefix, RETURN, STATUS, and THD_nimlize_dsetatr(). Referenced by THD_write_atr().
00149 { 00150 NI_stream ns ; 00151 NI_group *ngr ; 00152 char sname[2048] ; 00153 THD_3dim_dataset *dset ; 00154 00155 ENTRY("THD_write_nimlatr") ; 00156 00157 /* get dataset that contains this datablock */ 00158 00159 dset = (THD_3dim_dataset *)blk->parent ; 00160 if( !ISVALID_DSET(dset) ){ 00161 STATUS("parent is not valid dataset!"); RETURN(False); /* bad */ 00162 } 00163 00164 /* convert dataset struct AFNI attributes into a NIML element */ 00165 00166 ngr = THD_nimlize_dsetatr( dset ) ; 00167 if( ngr == NULL ){ 00168 STATUS("can't create NIML header element!"); RETURN(False); /* bad */ 00169 } 00170 NI_set_attribute( ngr , "self_prefix" , blk->diskptr->prefix ) ; 00171 00172 /* open output NIML stream (to file) */ 00173 00174 sprintf(sname,"file:%s",blk->diskptr->header_name) ; 00175 ns = NI_stream_open( sname , "w" ) ; 00176 if( ns == (NI_stream)NULL ){ 00177 STATUS("can't open output NIML stream!"); RETURN(False); /* bad */ 00178 } 00179 00180 /* write XML header and then the AFNI header element */ 00181 00182 STATUS("writing NIML header") ; 00183 NI_stream_writestring( ns , "<?xml version='1.0' ?>\n" ) ; 00184 NI_write_element( ns , ngr , NI_TEXT_MODE ) ; 00185 NI_stream_close( ns ) ; 00186 RETURN(True) ; 00187 } |