Doxygen Source Code Documentation
thd_get1D.c File Reference
#include "mrilib.h"
#include "thd.h"
Go to the source code of this file.
Defines | |
#define | NEWWAY |
Functions | |
MRI_IMARR * | THD_get_many_timeseries (THD_string_array *dlist) |
MRI_IMARR * | THD_get_all_timeseries (char *dname) |
Define Documentation
|
Definition at line 118 of file thd_get1D.c. |
Function Documentation
|
Definition at line 120 of file thd_get1D.c. References ADDTO_IMARR, AFNI_numenv(), THD_string_array::ar, DESTROY_IMARR, DESTROY_SARR, far, free, IMARR_COUNT, INIT_IMARR, malloc, mri_add_name(), MRI_FLOAT_PTR, mri_read_1D(), THD_string_array::num, MRI_IMAGE::nvox, pat, THD_extract_regular_files(), THD_filesize(), THD_get_all_filenames(), THD_get_wildcard_filenames(), and THD_trailname(). Referenced by THD_get_many_timeseries().
00121 { 00122 THD_string_array * flist , * rlist ; 00123 int ir , ll , ii ; 00124 char * fname , * tname ; 00125 float * far ; 00126 MRI_IMARR * outar ; 00127 MRI_IMAGE * outim , * flim ; 00128 00129 #ifdef NEWWAY 00130 char * pat ; 00131 #endif 00132 00133 unsigned long max_fsize ; /* 20 Jul 2004: max 1D file size to load */ 00134 00135 max_fsize = (unsigned long) AFNI_numenv( "AFNI_MAX_1DSIZE" ) ; 00136 if( max_fsize == 0 ) max_fsize = 123*1024 ; 00137 00138 /*----- sanity check and initialize -----*/ 00139 00140 if( dname == NULL || strlen(dname) == 0 ) return NULL ; 00141 INIT_IMARR( outar ) ; 00142 00143 /*----- find all *.1D files -----*/ 00144 00145 #ifdef NEWWAY 00146 ii = strlen(dname) ; 00147 pat = (char *) malloc(sizeof(char)*(ii+8)) ; 00148 strcpy(pat,dname) ; 00149 if( pat[ii-1] != '/' ) strcat(pat,"/") ; 00150 strcat(pat,"*.1D*") ; 00151 flist = THD_get_wildcard_filenames( pat ) ; 00152 free(pat) ; 00153 #else 00154 flist = THD_get_all_filenames( dname ) ; 00155 #endif 00156 00157 if( flist == NULL || flist->num <= 0 ){ 00158 DESTROY_SARR(flist) ; 00159 DESTROY_IMARR(outar) ; 00160 return NULL ; 00161 } 00162 00163 rlist = THD_extract_regular_files( flist ) ; 00164 DESTROY_SARR(flist) ; 00165 if( rlist == NULL || rlist->num <= 0 ){ 00166 DESTROY_SARR(rlist) ; 00167 DESTROY_IMARR(outar) ; 00168 return NULL ; 00169 } 00170 00171 for( ir=0 ; ir < rlist->num ; ir++ ){ 00172 fname = rlist->ar[ir] ; if( fname == NULL ) continue ; 00173 00174 ll = strlen(fname) - 3 ; if( ll < 1 ) continue ; 00175 00176 if( strcmp(fname+ll,".1D")==0 || 00177 strcmp(fname+ll,"1Dx")==0 || 00178 strcmp(fname+ll,"1Dv")==0 ){ 00179 00180 if( THD_filesize(fname) > max_fsize ) continue ; /* 20 Jul 2004 */ 00181 00182 flim = mri_read_1D( fname ) ; 00183 if( flim != NULL ){ 00184 far = MRI_FLOAT_PTR(flim) ; 00185 for( ii=0 ; ii < flim->nvox ; ii++ ) 00186 if( fabs(far[ii]) >= 33333.0 ) far[ii] = WAY_BIG ; 00187 00188 tname = THD_trailname(fname,1) ; 00189 mri_add_name( tname , flim ) ; 00190 ADDTO_IMARR( outar , flim ) ; 00191 } 00192 } 00193 } 00194 00195 DESTROY_SARR(rlist) ; 00196 00197 if( IMARR_COUNT(outar) == 0 ) DESTROY_IMARR(outar) ; 00198 00199 return outar ; 00200 } |
|
Definition at line 14 of file thd_get1D.c. References ADDTO_IMARR, ADDTO_SARR, THD_string_array::ar, DESTROY_IMARR, DESTROY_SARR, ENTRY, EXIT, free, FREE_IMARR, MRI_IMARR::imarr, IMARR_COUNT, INIT_IMARR, INIT_SARR, malloc, my_getenv(), MRI_IMARR::num, THD_string_array::num, RETURN, THD_equiv_files(), THD_get_all_timeseries(), THD_is_directory(), and THD_MAX_NAME. Referenced by AFNI_read_inputs(), and AFNI_rescan_timeseries_CB().
00015 { 00016 int id , ii , ndir ; 00017 MRI_IMARR * outar , * tmpar ; 00018 char * epath , * eee ; 00019 char efake[] = "./" ; 00020 THD_string_array *qlist ; /* 02 Feb 2002 */ 00021 00022 ENTRY("THD_get_many_timeseries") ; 00023 00024 /*----- sanity check and initialize -----*/ 00025 00026 epath = my_getenv( "AFNI_TSPATH" ) ; 00027 if( epath == NULL ) epath = my_getenv( "AFNI_TS_PATH" ) ; /* 07 Oct 1996 */ 00028 if( epath == NULL ) epath = efake ; /* 07 Oct 1996 */ 00029 00030 ndir = (dlist != NULL) ? dlist->num : 0 ; 00031 00032 if( ndir == 0 && epath == NULL ) RETURN( NULL ) ; 00033 00034 INIT_IMARR( outar ) ; 00035 INIT_SARR( qlist ) ; 00036 00037 /*----- for each input directory, find all *.1D files -----*/ 00038 00039 for( id=0 ; id < ndir ; id++ ){ 00040 00041 ADDTO_SARR(qlist,dlist->ar[id]) ; 00042 00043 tmpar = THD_get_all_timeseries( dlist->ar[id] ) ; 00044 if( tmpar == NULL ) continue ; 00045 00046 for( ii=0 ; ii < tmpar->num ; ii++ ) /* move images to output array */ 00047 ADDTO_IMARR( outar , tmpar->imarr[ii] ) ; 00048 00049 FREE_IMARR(tmpar) ; /* don't need this no more */ 00050 } 00051 00052 /*----- also do directories in environment path, if any -----*/ 00053 00054 if( epath != NULL ){ 00055 int epos =0 , ll = strlen(epath) ; 00056 char * elocal ; 00057 char ename[THD_MAX_NAME] ; 00058 00059 /* copy path list into local memory */ 00060 00061 elocal = (char *) malloc( sizeof(char) * (ll+2) ) ; 00062 if( elocal == NULL ){ 00063 fprintf(stderr, 00064 "\n*** THD_get_many_timeseries malloc failure - is memory full? ***\n"); 00065 EXIT(1) ; 00066 } 00067 strcpy( elocal , epath ) ; elocal[ll] = ' ' ; elocal[ll+1] = '\0' ; 00068 00069 /* replace colons with blanks */ 00070 00071 for( ii=0 ; ii < ll ; ii++ ) 00072 if( elocal[ii] == ':' ) elocal[ii] = ' ' ; 00073 00074 /* extract blank delimited strings, 00075 use as directory names to get timeseries files */ 00076 00077 do{ 00078 ii = sscanf( elocal+epos , "%s%n" , ename , &id ) ; 00079 if( ii < 1 ) break ; /* no read --> end of work */ 00080 epos += id ; /* epos = char after last one scanned */ 00081 00082 ii = strlen(ename) ; /* make sure name has */ 00083 if( ename[ii-1] != '/' ){ /* a trailing '/' on it */ 00084 ename[ii] = '/' ; ename[ii+1] = '\0' ; 00085 } 00086 00087 if( !THD_is_directory(ename) ) continue ; /* 21 May 2002 - rcr */ 00088 00089 /* 02 Feb 2002: check if scanned this directory before */ 00090 00091 for( ii=0 ; ii < qlist->num ; ii++ ) 00092 if( THD_equiv_files(qlist->ar[ii],ename) ) break ; 00093 if( ii < qlist->num ) continue ; /* skip to end of do loop */ 00094 ADDTO_SARR(qlist,ename) ; 00095 00096 tmpar = THD_get_all_timeseries( ename ) ; /* read this directory */ 00097 if( tmpar != NULL ){ 00098 for( ii=0 ; ii < tmpar->num ; ii++ ) /* move images to output array */ 00099 ADDTO_IMARR( outar , tmpar->imarr[ii] ) ; 00100 00101 FREE_IMARR(tmpar) ; /* don't need this no more */ 00102 } 00103 } while( epos < ll ) ; /* scan until 'epos' is after end of epath */ 00104 00105 free(elocal) ; 00106 } 00107 00108 if( IMARR_COUNT(outar) == 0 ) DESTROY_IMARR(outar) ; 00109 00110 DESTROY_SARR(qlist) ; 00111 RETURN( outar ) ; 00112 } |