Doxygen Source Code Documentation
thd_opentcat.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
THD_3dim_dataset * | THD_open_tcat (char *dlist) |
void | THD_load_tcat (THD_datablock *dblk) |
Function Documentation
|
Load from disk the impromptu catenation. Definition at line 129 of file thd_opentcat.c. References DSET_ARRAY, DSET_BRICK, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_delete, DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_unload, EDIT_BRICK_FACTOR, EDIT_substitute_brick(), ENTRY, ISVALID_DBLK, ISVALID_DSET, mri_fix_data_pointer(), NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, THD_datablock::parent, NI_str_array::str, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, and THD_open_dataset(). Referenced by THD_load_datablock().
00130 { 00131 int ivout , dd , iv ; 00132 THD_3dim_dataset *dset_in , *dset_out ; 00133 NI_str_array *sar ; 00134 00135 ENTRY("THD_load_tcat") ; 00136 00137 if( !ISVALID_DBLK(dblk) ) EXRETURN ; 00138 dset_out = (THD_3dim_dataset *)dblk->parent ; 00139 if( !ISVALID_DSET(dset_out) ) EXRETURN ; 00140 sar = NI_decode_string_list( dset_out->tcat_list , "~" ) ; 00141 if( sar == NULL ) EXRETURN ; 00142 if( sar->num != dset_out->tcat_num ){ NI_delete_str_array(sar); EXRETURN; } 00143 00144 ivout = 0 ; 00145 for( dd=0 ; dd < sar->num ; dd++ ){ 00146 dset_in = THD_open_dataset( sar->str[dd] ) ; 00147 if( dset_in == NULL ){ 00148 NI_delete_str_array(sar) ; DSET_unload(dset_out) ; 00149 EXRETURN ; 00150 } 00151 DSET_mallocize(dset_in) ; DSET_load(dset_in) ; 00152 if( !DSET_LOADED(dset_in) ){ 00153 NI_delete_str_array(sar) ; DSET_unload(dset_out) ; DSET_delete(dset_in) ; 00154 EXRETURN ; 00155 } 00156 00157 for( iv=0 ; iv < DSET_NVALS(dset_in) ; iv++ ){ 00158 EDIT_substitute_brick( dset_out , ivout , 00159 DSET_BRICK_TYPE(dset_in,iv), DSET_ARRAY(dset_in,iv) ); 00160 mri_fix_data_pointer( NULL , DSET_BRICK(dset_in,iv) ) ; 00161 EDIT_BRICK_FACTOR( dset_out , ivout , DSET_BRICK_FACTOR(dset_in,iv) ) ; 00162 ivout++ ; 00163 } 00164 DSET_delete(dset_in) ; 00165 } 00166 00167 NI_delete_str_array(sar) ; EXRETURN ; 00168 } |
|
Open a dataset that is an impromptu catenation of multiple dataset. Definition at line 7 of file thd_opentcat.c. References ADN_func_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_ttdel, ADN_ttdur, ADN_ttorg, ADN_tunits, ANAT_EPI_TYPE, DSET_delete, DSET_mallocize, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_TIMESTEP, EDIT_dset_items(), EDIT_empty_copy(), ENTRY, EQUIV_DATAXES, free, FUNC_FIM_TYPE, ISANAT, malloc, NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, RETURN, NI_str_array::str, THD_3dim_dataset::tcat_len, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, THD_open_dataset(), TR, and UNITS_SEC_TYPE. Referenced by THD_open_dataset().
00008 { 00009 THD_3dim_dataset *dset_out , **dset_in ; 00010 int ndset_in , dd , nerr , new_nvals ; 00011 NI_str_array *sar ; 00012 00013 ENTRY("THD_open_tcat") ; 00014 00015 if( dlist == NULL || *dlist == '\0' ) RETURN(NULL) ; 00016 00017 if( strchr(dlist,' ') == NULL ){ 00018 dset_out = THD_open_dataset(dlist) ; RETURN(dset_out) ; 00019 } 00020 00021 sar = NI_decode_string_list( dlist , "~" ) ; 00022 if( sar == NULL ) RETURN(NULL) ; 00023 00024 ndset_in = sar->num ; 00025 dset_in = (THD_3dim_dataset **)malloc(sizeof(THD_3dim_dataset *)*sar->num) ; 00026 for( nerr=dd=0 ; dd < ndset_in ; dd++ ){ 00027 dset_in[dd] = THD_open_dataset( sar->str[dd] ) ; 00028 if( dset_in[dd] == NULL ){ 00029 fprintf(stderr,"** THD_open_tcat: can't open dataset %s\n",sar->str[dd]) ; 00030 nerr++ ; 00031 } 00032 } 00033 if( nerr > 0 ){ 00034 for( dd=0 ; dd < ndset_in ; dd++ ) 00035 if( dset_in[dd] != NULL ) DSET_delete(dset_in[dd]) ; 00036 free((void *)dset_in) ; 00037 NI_delete_str_array(sar) ; 00038 RETURN(NULL) ; 00039 } 00040 if( ndset_in == 1 ){ 00041 dset_out = dset_in[0] ; 00042 free((void *)dset_in) ; 00043 NI_delete_str_array(sar) ; 00044 RETURN(dset_out) ; 00045 } 00046 00047 for( nerr=0,dd=1 ; dd < ndset_in ; dd++ ){ 00048 if( DSET_NX(dset_in[0]) != DSET_NX(dset_in[dd]) || 00049 DSET_NY(dset_in[0]) != DSET_NY(dset_in[dd]) || 00050 DSET_NZ(dset_in[0]) != DSET_NZ(dset_in[dd]) ){ 00051 fprintf(stderr, 00052 "** THD_open_tcat: %s [%dx%dx%d] doesn't match %s [%dx%dx%d]\n", 00053 sar->str[0] ,DSET_NX(dset_in[0]) , 00054 DSET_NY(dset_in[0]) ,DSET_NZ(dset_in[0]) , 00055 sar->str[dd],DSET_NX(dset_in[dd]), 00056 DSET_NY(dset_in[dd]),DSET_NZ(dset_in[dd]) ) ; 00057 nerr++ ; 00058 } else if( !EQUIV_DATAXES(dset_in[dd]->daxes,dset_in[0]->daxes) ){ 00059 fprintf(stderr, 00060 "++ THD_open_tcat: %s grid mismatch with %s\n", 00061 sar->str[0] , sar->str[dd] ) ; 00062 } 00063 } 00064 if( nerr > 0 ){ 00065 for( dd=0 ; dd < ndset_in ; dd++ ) 00066 if( dset_in[dd] != NULL ) DSET_delete(dset_in[dd]) ; 00067 free((void *)dset_in) ; 00068 NI_delete_str_array(sar) ; 00069 RETURN(NULL) ; 00070 } 00071 00072 /*-- OK, start making new dataset --*/ 00073 00074 new_nvals = 0 ; 00075 for( dd=0 ; dd < ndset_in ; dd++ ) 00076 new_nvals += DSET_NVALS(dset_in[dd]) ; 00077 00078 for( dd=0 ; dd < ndset_in ; dd++ ) 00079 if( DSET_TIMESTEP(dset_in[dd]) > 0.0 ) break ; /* 1st 3D+time */ 00080 if( dd == ndset_in ) dd = 0 ; 00081 00082 dset_out = EDIT_empty_copy( dset_in[dd] ) ; 00083 00084 EDIT_dset_items( dset_out , 00085 ADN_prefix , "tcat" , 00086 ADN_func_type , ISANAT(dset_in[dd]) ? ANAT_EPI_TYPE 00087 : FUNC_FIM_TYPE , 00088 ADN_ntt , new_nvals , 00089 ADN_nvals , new_nvals , 00090 ADN_none ) ; 00091 DSET_mallocize( dset_out ) ; 00092 00093 /* check if we have a valid time axis; if not, make one up */ 00094 00095 if( DSET_TIMESTEP(dset_out) <= 0.0f ){ 00096 float TR=1.0f , torg=0.0f , tdur=0.0f ; 00097 int tunits=UNITS_SEC_TYPE ; 00098 EDIT_dset_items( dset_out , 00099 ADN_tunits , tunits , 00100 ADN_ttdel , TR , 00101 ADN_ttorg , torg , 00102 ADN_ttdur , tdur , 00103 ADN_none ) ; 00104 } 00105 00106 dset_out->tcat_list = strdup( dlist ) ; 00107 dset_out->tcat_num = ndset_in ; 00108 dset_out->tcat_len = (int *)malloc(sizeof(int)*ndset_in) ; 00109 for( dd=0 ; dd < ndset_in ; dd++ ){ 00110 dset_out->tcat_len[dd] = DSET_NVALS(dset_in[dd]) ; 00111 DSET_delete(dset_in[dd]) ; 00112 } 00113 free((void *)dset_in) ; 00114 NI_delete_str_array(sar) ; 00115 00116 #if 0 00117 fprintf(stderr,"THD_open_tcat('%s'):",dset_out->tcat_list); 00118 for(dd=0;dd<ndset_in;dd++)fprintf(stderr," %d",dset_out->tcat_len[dd]); 00119 fprintf(stderr,"\n"); 00120 #endif 00121 00122 RETURN(dset_out) ; 00123 } |