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  

3dAttribute.c

Go to the documentation of this file.
00001 #include "mrilib.h"
00002 
00003 /*---------------------------------------------------------------------------
00004   01 Feb 2001: Program to print out the value of any given attribute
00005   from an AFNI header.
00006 -----------------------------------------------------------------------------*/
00007 
00008 void atr_print( ATR_any * atr ) ;
00009 
00010 static int do_all  = 0 ;
00011 static int do_name = 0 ;
00012 
00013 int main( int argc , char * argv[] )
00014 {
00015    int nopt=1 , ia ;
00016    THD_3dim_dataset * dset ;
00017    char * aname ;
00018    ATR_any * atr ;
00019 
00020    if( argc < 3 || strcmp(argv[1],"-help") == 0 ){
00021       printf("Usage: 3dAttribute [options] aname dset\n"
00022              "Prints (to stdout) the value of the attribute 'aname' from\n"
00023              "the header of dataset 'dset'.  If the attribute doesn't exist,\n"
00024              "prints nothing and sets the exit status to 1.\n"
00025              "\n"
00026              "Options:\n"
00027              "  -name = Include attribute name in printout\n"
00028              "  -all  = Print all attributes [don't put aname on command line]\n"
00029              "          Also implies '-name'.  Attributes print in whatever order\n"
00030              "          they are in the .HEAD file, one per line.  You may want\n"
00031              "          to do '3dAttribute -all elvis+orig | sort' to get them\n"
00032              "          in alphabetical order.\n"
00033             ) ;
00034       exit(0) ;
00035    }
00036 
00037    while( nopt < argc && argv[nopt][0] == '-' ){
00038 
00039       if( strcmp(argv[nopt],"-all") == 0 ){
00040          do_all = do_name = 1 ;
00041          nopt++ ; continue ;
00042       }
00043 
00044       if( strcmp(argv[nopt],"-name") == 0 ){
00045          do_name = 1 ;
00046          nopt++ ; continue ;
00047       }
00048 
00049       fprintf(stderr,"*** Illegal option: %s\n",argv[nopt]) ; exit(1) ;
00050    }
00051 
00052    if( !do_all ) aname = argv[nopt++] ;
00053 
00054    dset  = THD_open_one_dataset( argv[nopt] ) ;
00055    if( !ISVALID_DSET(dset) ){
00056       fprintf(stderr,"*** Can't open dataset %s\n",argv[nopt]); exit(1);
00057    }
00058 
00059    if( !do_all ){
00060       atr = THD_find_atr( dset->dblk , aname ) ;
00061       if( atr == NULL ) exit(1) ;                  /* failure */
00062       atr_print( atr ) ;
00063       exit(0) ;
00064    }
00065 
00066    for( ia=0 ; ia < dset->dblk->natr ; ia++ ){
00067       atr = &(dset->dblk->atr[ia]) ;
00068       atr_print(atr) ;
00069    }
00070 
00071    exit(0) ;
00072 }
00073 
00074 /*----------------------------------------------------------------------*/
00075 
00076 void atr_print( ATR_any * atr )
00077 {
00078    int ii ;
00079 
00080    switch( atr->type ){
00081 
00082       default:
00083          fprintf(stderr,"*** Illegal attribute type found: %d\n",atr->type);
00084       exit(1) ;
00085 
00086       case ATR_FLOAT_TYPE:{
00087          ATR_float * aa = (ATR_float *) atr ;
00088          if( do_name ) printf("%s = ",aa->name) ;
00089          for( ii=0 ; ii < aa->nfl ; ii++ )
00090             printf("%s ",MV_format_fval(aa->fl[ii])) ;
00091          printf("\n") ;
00092       }
00093       return ;
00094 
00095       case ATR_INT_TYPE:{
00096          ATR_int * aa = (ATR_int *) atr ;
00097          if( do_name ) printf("%s = ",aa->name) ;
00098          for( ii=0 ; ii < aa->nin ; ii++ )
00099             printf("%d ",aa->in[ii]) ;
00100          printf("\n") ;
00101       }
00102       return ;
00103 
00104       case ATR_STRING_TYPE:{
00105          ATR_string * aa = (ATR_string *) atr ;
00106          char *str = (char *)malloc(sizeof(char)*(aa->nch+1)) ;
00107          char *eee ;
00108          memcpy(str,aa->ch,aa->nch) ; str[aa->nch] = '\0' ;
00109 #if 0
00110          eee = tross_Expand_String(str) ;
00111 #else
00112          eee = NULL ;
00113 #endif
00114          if( do_name ) printf("%s = ",aa->name) ;
00115          if( eee != NULL ){
00116             printf("%s\n",eee) ; free(eee) ;
00117          } else if( str[0] != '\0' ){
00118             printf("%s\n",str) ;
00119          } else {
00120             printf("(null)\n") ;
00121          }
00122          free(str) ;
00123       }
00124       return ;
00125    }
00126 }
 

Powered by Plone

This site conforms to the following standards: