Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

thd_get1D.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 #include "thd.h"
00009 
00010 /*=============================================================================*/
00011 
00012 /***  Read all *.1D (time series) files from a list of directories ***/
00013 
00014 MRI_IMARR * THD_get_many_timeseries( THD_string_array * dlist )
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 }
00113 
00114 /*---------------------------------------------------*/
00115 /*  Read all *.1D (time series) files from directory */
00116 /*---------------------------------------------------*/
00117 
00118 #define NEWWAY
00119 
00120 MRI_IMARR * THD_get_all_timeseries( char * dname )
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 }
 

Powered by Plone

This site conforms to the following standards: