Doxygen Source Code Documentation
thd_initalldir.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 given a directory name, create datablocks from all entries possible. 00012 return an array of datablock arrays 00013 ------------------------------------------------------------------------*/ 00014 00015 XtPointer_array * THD_init_alldir_datablocks( char * dirname ) 00016 { 00017 XtPointer_array * super_array ; 00018 THD_datablock_array * dblk_arr ; 00019 THD_string_array * flist , * rlist ; 00020 char prefix[THD_MAX_NAME] ; 00021 char * fname ; 00022 int ifile ; 00023 00024 /* initialize answer */ 00025 00026 INIT_XTARR( super_array ) ; 00027 00028 /* get list of all regular files in the directory */ 00029 00030 flist = THD_get_all_filenames( dirname ) ; 00031 if( flist == NULL || flist->num <= 0 ){ 00032 DESTROY_SARR(flist) ; 00033 return super_array ; 00034 } 00035 00036 rlist = THD_extract_regular_files( flist ) ; 00037 DESTROY_SARR(flist) ; 00038 if( rlist == NULL || rlist->num <= 0 ){ 00039 DESTROY_SARR(rlist) ; 00040 return super_array ; 00041 } 00042 00043 /* for each header/prefix combination 00044 in the list, try to get all datablocks within */ 00045 00046 for( ifile=0 ; ifile < rlist->num ; ifile++ ){ 00047 00048 fname = rlist->ar[ifile] ; 00049 if( fname == NULL || 00050 strstr(fname,DATASET_HEADER_SUFFIX) == NULL ) continue ; 00051 00052 FILENAME_TO_PREFIX(fname,prefix) ; 00053 if( strlen(prefix) == 0 ) continue ; 00054 00055 dblk_arr = THD_init_prefix_datablocks( prefix , rlist ) ; 00056 00057 if( dblk_arr != NULL && dblk_arr->num > 0 ){ 00058 ADDTO_XTARR(super_array,dblk_arr) ; /* store in output */ 00059 } else { 00060 FREE_DBARR(dblk_arr) ; /* throw it away */ 00061 } 00062 00063 } 00064 00065 /* done! */ 00066 00067 DESTROY_SARR(rlist) ; 00068 return super_array ; 00069 }