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_initprefix.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   given a prefix and a list of files,
00013   create a set of datablocks for all datasets that correspond;
00014   return an array of datablocks.
00015 ------------------------------------------------------------------*/
00016 
00017 THD_datablock_array * THD_init_prefix_datablocks(
00018                            char * prefixname , THD_string_array * regfile_list )
00019 {
00020    THD_datablock_array * dblk_arr ;
00021    THD_datablock       * dblk ;
00022    int nlast , nnext , plen , ii ;
00023    char prefixcode[THD_MAX_NAME] , dirname[THD_MAX_NAME] , ptemp[THD_MAX_NAME] ;
00024    char * fname ;
00025 
00026    /* initialize answer */
00027 
00028    INIT_DBARR( dblk_arr ) ;
00029 
00030    if( prefixname   == NULL || strlen(prefixname) == 0 ||
00031        regfile_list == NULL || regfile_list->num  <= 0   ) return dblk_arr ;
00032 
00033    strcpy(prefixcode,prefixname) ; strcat(prefixcode,"+") ;
00034 
00035    /* for each file that could be a dataset header, try to make a datablock */
00036 
00037    nlast = 0 ;  /* start first search at beginning of list */
00038 
00039    do{
00040 
00041       /* look for the correct type of filename */
00042 
00043       nnext = SARR_lookfor_substring( regfile_list ,
00044                                       DATASET_HEADER_SUFFIX , nlast ) ;
00045 
00046       if( nnext < 0 ) break ;  /* no more header files */
00047       nlast = nnext + 1 ;      /* start next search here */
00048 
00049       fname = regfile_list->ar[nnext] ;
00050       if( strstr(fname,prefixcode) == NULL ) continue ; /* wrong prefix */
00051       FILENAME_TO_PREFIX(fname,ptemp) ;
00052       if( strcmp(prefixname,ptemp) != 0 ) continue ;    /* wrong prefix */
00053 
00054       /* try to make datablock from this file */
00055 
00056       /*-- find directory in fname --*/
00057 
00058       plen = strlen(fname) ;
00059       for( ii=plen-1 ; ii >= 0 ; ii-- ) if( fname[ii] == '/' ) break ;
00060 
00061       if( ii < 0 ){
00062          strcpy( dirname , "./" ) ;      /* fake directory name */
00063       } else {
00064          strcpy( dirname , fname ) ;
00065          dirname[ii+1] = '\0' ;
00066       }
00067 
00068       /* try to make datablock from this file */
00069 
00070       dblk = THD_init_one_datablock( dirname , fname ) ;
00071       if( dblk != NULL ) ADDTO_DBARR(dblk_arr,dblk) ;
00072       REMOVEFROM_SARR( regfile_list , nnext ) ;
00073 
00074    } while(1) ;
00075 
00076    return dblk_arr ;
00077 }
 

Powered by Plone

This site conforms to the following standards: