int Seg_ClssAndKeys_from_dset(THD_3dim_dataset *dset, NI_str_array **nstrp, int **keysp) { ATR_string *atr=NULL; NI_str_array *nstr=NULL; int *keys=NULL; NI_stream ns ; NI_element *nel ; int nn , ii ; Dtable *dt ; char **la , **lb ; if (!(atr = THD_find_string_atr( dset->dblk , "VALUE_LABEL_DTABLE" ))) return(0); if (!(nel = (NI_element *)NI_read_element_fromstring(atr->ch))) { return (0); } /* see if element is OK for this purpose */ if( NI_element_type(nel) != NI_ELEMENT_TYPE ){ NI_free_element(nel) ; return (0) ; } if( nel->vec_len < 1 || /* empty element? */ nel->vec_filled < 1 || /* no data was filled in? */ nel->vec_num < 2 || /* less than 4 columns? */ nel->vec_typ[0] != NI_STRING || /* must be String, String */ nel->vec_typ[1] != NI_STRING ){ NI_free_element(nel) ; return (0) ; } la = (char **) nel->vec[0] ; /* first column of String */ lb = (char **) nel->vec[1] ; /* second column of String */ nn = nel->vec_filled ; ii = rint(sqrt(2*nn+1.0l)) ; if( ii < 7 ) ii = 7 ; else if( ii%2 == 0 ) ii++ ; /* make array, insert strings */ nstr = SUMA_NI_string_vec_to_str_array(lb, nn); /* get keys */ keys = (int *)calloc(nn, sizeof(int)); for( ii=0 ; ii < nn ; ii++ ) keys[ii] = strtol(la[ii], NULL, 10); NI_free_element(nel) ; if (nstrp) {*nstrp = nstr; nstr=NULL;} else { nstr = SUMA_free_NI_str_array(nstr); } if (keysp) { *keysp = keys; keys=NULL; } else { free(keys); keys=NULL; } return (1) ; }
char * THD_dataset_info( THD_3dim_dataset *dset , int verbose ) { THD_dataxes *daxes ; THD_fvec3 fv1 , fv2 , fv3 ; int ival , ntimes , nval_per , n1,n2,n3 , kv,npar ; float tf, angle=0.0; long long tb ; static char *RR="[R]" , *LL="[L]" , *PP="[P]" , *AA="[A]" , *SS="[S]" , *II="[I]" , *ZZ=" " ; char *xlbot , *xltop , *ylbot , *yltop , *zlbot , *zltop , *cpt ; char str[1024], soblq[1024] ; int nstr , obliquity; char *outbuf = NULL ; /* output buffer */ ENTRY("THD_dataset_info") ; if( ! ISVALID_3DIM_DATASET(dset) ) RETURN(NULL) ; daxes = dset->daxes ; if( DSET_IS_BRIK(dset) ) outbuf = THD_zzprintf(outbuf,"Dataset File: %s\n" , DSET_FILECODE(dset) ) ; else outbuf = THD_zzprintf(outbuf,"Dataset File: %s\n" , DSET_BRIKNAME(dset) ) ; outbuf = THD_zzprintf(outbuf,"Identifier Code: %s Creation Date: %s\n" , dset->idcode.str , dset->idcode.date ) ; outbuf = THD_zzprintf(outbuf, "Template Space: %s\n", dset->atlas_space); if( ISANAT(dset) ){ outbuf = THD_zzprintf(outbuf,"Dataset Type: %s (-%s)\n", ANAT_typestr[dset->func_type] , ANAT_prefixstr[dset->func_type] ) ; } else { outbuf = THD_zzprintf(outbuf,"Dataset Type: %s (-%s)\n", FUNC_typestr[dset->func_type] , FUNC_prefixstr[dset->func_type] ) ; } /* 25 April 1998: do byte order stuff */ switch( DSET_BYTEORDER(dset) ){ case LSB_FIRST: outbuf = THD_zzprintf(outbuf,"Byte Order: %s" , LSB_FIRST_STRING) ; break ; case MSB_FIRST: outbuf = THD_zzprintf(outbuf,"Byte Order: %s" , MSB_FIRST_STRING) ; break ; } if( THD_find_string_atr(dset->dblk,ATRNAME_BYTEORDER) == NULL ) /* 19 Sep 1999 */ outbuf = THD_zzprintf(outbuf," {assumed}") ; kv = mri_short_order() ; switch( kv ){ case LSB_FIRST: outbuf = THD_zzprintf(outbuf," [this CPU native = %s]\n" , LSB_FIRST_STRING) ; break ; case MSB_FIRST: outbuf = THD_zzprintf(outbuf," [this CPU native = %s]\n" , MSB_FIRST_STRING) ; break ; } /*-- 21 Jun 2002: print storage mode --*/ if( dset->dblk->diskptr != NULL ){ outbuf = THD_zzprintf(outbuf,"Storage Mode: %s\n", storage_mode_str(dset->dblk->diskptr->storage_mode)); } tb = dset->dblk->total_bytes ; if( tb > 0 ) outbuf = THD_zzprintf(outbuf,"Storage Space: %s (%s) bytes\n", commaized_integer_string(dset->dblk->total_bytes) , approximate_number_string(dset->dblk->total_bytes) ) ; /*-- keywords --*/ if( verbose >= 0 ){ cpt = DSET_KEYWORDS(dset) ; if( cpt != NULL && cpt[0] != '\0' ){ int j = strlen(cpt) ; if( j < 99 ){ outbuf = THD_zzprintf(outbuf,"Keywords: %s\n" , cpt ) ; } else { int k ; outbuf = THD_zzprintf(outbuf,"\n----- KEYWORDS -----\n") ; for( k=0 ; k < j ; k += ZMAX ) outbuf = THD_zzprintf(outbuf,SZMAX,cpt+k) ; outbuf = THD_zzprintf(outbuf,"\n") ; } } } /*-- idcodes --*/ if( verbose >= 0 ){ if( ! ISZERO_IDCODE(dset->anat_parent_idcode) ) outbuf = THD_zzprintf(outbuf,"Anatomy Parent: %s [%s]\n" , dset->anat_parent_name , dset->anat_parent_idcode.str ) ; else if( strlen(dset->anat_parent_name) > 0 ) outbuf = THD_zzprintf(outbuf,"Anatomy Parent: %s\n" , dset->anat_parent_name ) ; if( ! ISZERO_IDCODE(dset->warp_parent_idcode) ) outbuf = THD_zzprintf(outbuf,"Warp Parent: %s [%s]\n" , dset->warp_parent_name , dset->warp_parent_idcode.str) ; else if( strlen(dset->warp_parent_name) > 0 ) outbuf = THD_zzprintf(outbuf,"Warp Parent: %s\n" , dset->warp_parent_name ) ; } /*-- tagset --*/ if( verbose > 0 && dset->tagset != NULL && dset->tagset->num > 0 ){ int ii , ns=0 ; for( ii=0 ; ii < dset->tagset->num ; ii++ ) if( dset->tagset->tag[ii].set ) ns++ ; outbuf = THD_zzprintf(outbuf,"Tagset: %d set [out of %d total]\n", ns , dset->tagset->num ) ; } /* are we oblique ? */ if((obliquity = dset_obliquity(dset, &angle)) >= 0) { if(angle>0.0) { sprintf (soblq, "Data Axes Tilt: Oblique (%.3f deg. from plumb)\n" "Data Axes Approximate Orientation:", angle); } else { sprintf (soblq, "Data Axes Tilt: Plumb\n" "Data Axes Orientation:"); } { char *gstr = EDIT_get_geometry_string(dset) ; if( gstr != NULL && *gstr != '\0' ) outbuf = THD_zzprintf(outbuf,"Geometry String: \"%s\"\n",gstr) ; } } else { sprintf (soblq, "Data Axes Tilt: Unspecified, assumed plumb\n" "Data Axes Orientation:"); } outbuf = THD_zzprintf(outbuf, "%s\n" " first (x) = %s\n" " second (y) = %s\n" " third (z) = %s [-orient %c%c%c]\n" , soblq, ORIENT_typestr[daxes->xxorient] , ORIENT_typestr[daxes->yyorient] , ORIENT_typestr[daxes->zzorient] , ORIENT_typestr[daxes->xxorient][0] , ORIENT_typestr[daxes->yyorient][0] , ORIENT_typestr[daxes->zzorient][0] ) ; LOAD_FVEC3(fv1 , daxes->xxorg , daxes->yyorg , daxes->zzorg) ; fv1 = THD_3dmm_to_dicomm( dset , fv1 ) ; LOAD_FVEC3(fv2 , daxes->xxorg + (daxes->nxx-1)*daxes->xxdel , daxes->yyorg + (daxes->nyy-1)*daxes->yydel , daxes->zzorg + (daxes->nzz-1)*daxes->zzdel ) ; fv2 = THD_3dmm_to_dicomm( dset , fv2 ) ; if( fv1.xyz[0] > fv2.xyz[0] ) FSWAP( fv1.xyz[0] , fv2.xyz[0] ) ; if( fv1.xyz[1] > fv2.xyz[1] ) FSWAP( fv1.xyz[1] , fv2.xyz[1] ) ; if( fv1.xyz[2] > fv2.xyz[2] ) FSWAP( fv1.xyz[2] , fv2.xyz[2] ) ; LOAD_FVEC3(fv3 , daxes->xxdel , daxes->yydel , daxes->zzdel) ; fv3 = THD_3dmm_to_dicomm( dset , fv3 ) ; XLAB(xlbot,fv1.xyz[0]) ; YLAB(ylbot,fv1.xyz[1]) ; ZLAB(zlbot,fv1.xyz[2]) ; XLAB(xltop,fv2.xyz[0]) ; YLAB(yltop,fv2.xyz[1]) ; ZLAB(zltop,fv2.xyz[2]) ; n1 = DAXES_NUM(daxes,ORI_R2L_TYPE) ; n2 = DAXES_NUM(daxes,ORI_A2P_TYPE) ; n3 = DAXES_NUM(daxes,ORI_I2S_TYPE) ; outbuf = THD_zzprintf(outbuf, "R-to-L extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n" "A-to-P extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n" "I-to-S extent: %9.3f %s -to- %9.3f %s -step- %9.3f mm [%3d voxels]\n" , fv1.xyz[0],xlbot , fv2.xyz[0],xltop , fabs(fv3.xyz[0]) , n1 , fv1.xyz[1],ylbot , fv2.xyz[1],yltop , fabs(fv3.xyz[1]) , n2 , fv1.xyz[2],zlbot , fv2.xyz[2],zltop , fabs(fv3.xyz[2]) , n3 ) ; /*-- 01 Feb 2001: print the center of the dataset as well --*/ if( verbose > 0 ){ fv1.xyz[0] = 0.5*(fv1.xyz[0]+fv2.xyz[0]) ; XLAB(xlbot,fv1.xyz[0]) ; fv1.xyz[1] = 0.5*(fv1.xyz[1]+fv2.xyz[1]) ; YLAB(ylbot,fv1.xyz[1]) ; fv1.xyz[2] = 0.5*(fv1.xyz[2]+fv2.xyz[2]) ; ZLAB(zlbot,fv1.xyz[2]) ; outbuf = THD_zzprintf(outbuf, "R-to-L center: %9.3f %s\n" "A-to-P center: %9.3f %s\n" "I-to-S center: %9.3f %s\n" , fv1.xyz[0],xlbot , fv1.xyz[1],ylbot , fv1.xyz[2],zlbot ) ; } ntimes = DSET_NUM_TIMES(dset) ; nval_per = DSET_NVALS_PER_TIME(dset) ; if( ntimes > 1 ){ outbuf = THD_zzprintf(outbuf, "Number of time steps = %d" , ntimes ) ; STATUS("timestep") ; outbuf = THD_zzprintf(outbuf, " Time step = %.5f%s Origin = %.5f%s" , dset->taxis->ttdel , UNITS_TYPE_LABEL(dset->taxis->units_type) , dset->taxis->ttorg , UNITS_TYPE_LABEL(dset->taxis->units_type) ) ; if( dset->taxis->nsl > 0 ) outbuf = THD_zzprintf(outbuf," Number time-offset slices = %d Thickness = %.3f", dset->taxis->nsl , fabs(dset->taxis->dz_sl) ) ; outbuf = THD_zzprintf(outbuf,"\n") ; STATUS("nsl done") ; if( verbose > 0 && dset->taxis->nsl > 0 && dset->taxis->toff_sl != NULL ){ outbuf = THD_zzprintf(outbuf,"Time-offsets per slice:") ; for( ival=0 ; ival < dset->taxis->nsl ; ival++ ) outbuf = THD_zzprintf(outbuf, " %.3f" , dset->taxis->toff_sl[ival] ) ; outbuf = THD_zzprintf(outbuf,"\n") ; } } else { outbuf = THD_zzprintf(outbuf, "Number of values stored at each pixel = %d\n" , nval_per ) ; } #if 0 if( verbose > 0 && ntimes > 1 ) nval_per = dset->dblk->nvals ; else nval_per = 1 ; /* 12 Feb 2002 */ #else nval_per = dset->dblk->nvals ; if( verbose < 0 && nval_per > 5 ) nval_per = 3 ; #endif /* print out stuff for each sub-brick */ for( ival=0 ; ival < nval_per ; ival++ ){ STATUS("ival a") ; sprintf( str , " -- At sub-brick #%d '%s' datum type is %s" , ival , DSET_BRICK_LAB(dset,ival) , MRI_TYPE_name[DSET_BRICK_TYPE(dset,ival)] ) ; nstr = strlen(str) ; tf = DSET_BRICK_FACTOR(dset,ival) ; if( ISVALID_STATISTIC(dset->stats) ){ if( tf != 0.0 ){ sprintf( str+nstr , ":%13.6g to %13.6g [internal]\n" "%*s[*%13.6g] %13.6g to %13.6g [scaled]\n" , dset->stats->bstat[ival].min/tf , dset->stats->bstat[ival].max/tf , nstr-16," " , tf , dset->stats->bstat[ival].min , dset->stats->bstat[ival].max ) ; } else { sprintf( str+nstr , ":%13.6g to %13.6g\n" , dset->stats->bstat[ival].min , dset->stats->bstat[ival].max ) ; } } else if( tf != 0.0 ){ sprintf( str+nstr , " [*%g]\n",tf) ; } else { sprintf( str+nstr , "\n") ; } STATUS("ival b") ; outbuf = THD_zzprintf(outbuf,"%s",str) ; /** 30 Nov 1997: print sub-brick stat params **/ kv = DSET_BRICK_STATCODE(dset,ival) ; if( FUNC_IS_STAT(kv) ){ STATUS("ival c") ; outbuf = THD_zzprintf(outbuf," statcode = %s",FUNC_prefixstr[kv] ) ; npar = FUNC_need_stat_aux[kv] ; if( npar > 0 ){ outbuf = THD_zzprintf(outbuf,"; statpar =") ; for( kv=0 ; kv < npar ; kv++ ) outbuf = THD_zzprintf(outbuf," %g",DSET_BRICK_STATPAR(dset,ival,kv)) ; } outbuf = THD_zzprintf(outbuf,"\n") ; STATUS("ival d") ; } cpt = DSET_BRICK_KEYWORDS(dset,ival) ; if( cpt != NULL && cpt[0] != '\0' ){ outbuf = THD_zzprintf(outbuf," keywords = %.66s\n",cpt) ; } STATUS("ival z") ; } if( verbose < 0 && nval_per < dset->dblk->nvals ) /* 21 Sep 2007 */ outbuf = THD_zzprintf(outbuf, "** For info on all %d sub-bricks, use '3dinfo -verb' **\n", dset->dblk->nvals) ; /** print out dataset global statistical parameters **/ if( ISFUNC(dset) && FUNC_need_stat_aux[dset->func_type] > 0 ){ outbuf = THD_zzprintf(outbuf,"Auxiliary functional statistical parameters:\n %s\n", FUNC_label_stat_aux[dset->func_type] ) ; for( ival=0 ; ival < FUNC_need_stat_aux[dset->func_type] ; ival++ ) outbuf = THD_zzprintf(outbuf," %g",dset->stat_aux[ival]) ; outbuf = THD_zzprintf(outbuf,"\n") ; } /** If present, print out History **/ { char *chn ; int j,k ; chn = tross_Get_History(dset) ; if( chn != NULL ){ j = strlen(chn) ; outbuf = THD_zzprintf(outbuf,"\n----- HISTORY -----\n") ; for( k=0 ; k < j ; k += ZMAX ) outbuf = THD_zzprintf(outbuf,SZMAX,chn+k) ; free(chn) ; outbuf = THD_zzprintf(outbuf,"\n") ; } } /** If present, print out Notes **/ if( verbose >= 0 ){ ATR_int *notecount; int num_notes, i, j, mmm ; char *chn , *chd ; notecount = THD_find_int_atr(dset->dblk, "NOTES_COUNT"); if( notecount != NULL ){ num_notes = notecount->in[0] ; if( verbose == 0 && num_notes > 5 ) num_notes = 5 ; mmm = (verbose > 0) ? ZMAX : 1200 ; /* 400 it was! Come on Bob, have a heart! -ZSS */ for (i=1; i<= num_notes; i++) { chn = tross_Get_Note( dset , i ) ; if( chn != NULL ){ j = strlen(chn) ; if( j > mmm ) chn[mmm] = '\0' ; chd = tross_Get_Notedate(dset,i) ; if( chd == NULL ){ chd = AFMALL(char,16) ; strcpy(chd,"no date") ; } outbuf = THD_zzprintf(outbuf,"\n----- NOTE %d [%s] -----\n%s\n",i,chd,chn) ; free(chn) ; free(chd) ; }
int main( int argc , char *argv[] ) { THD_3dim_dataset *dset=NULL; int iarg , verbose = -1 ; char *outbuf, *stmp=NULL; char *labelName = NULL; char *sbdelim = {"|"}; char *NAflag = {"NA"}; char *atrdelim = {"\t"}, *form=NULL; INFO_FIELDS sing[512]; int iis=0, N_sing = 0, isb=0, withhead = 0, itmp=0; int ip=0, needpair = 0, namelen=0, monog_pairs = 0; THD_3dim_dataset *tttdset=NULL, *dsetp=NULL; char *tempstr = NULL; int extinit = 0; float RL_AP_IS[6]; mainENTRY("3dinfo main") ; machdep() ; if( argc < 2) { Syntax(TXT,1) ; RETURN(0); } iarg = 1 ; while (iarg < argc && argv[iarg][0] == '-') { CHECK_HELP(argv[iarg],Syntax); if( strncmp(argv[iarg],"-verb" ,5) == 0 ){ verbose = 0; iarg++; continue; } else if( strncmp(argv[iarg],"-VERB" ,5) == 0 ){ verbose = 1; iarg++; continue; } else if( strncmp(argv[iarg],"-short",5) == 0 ){ verbose = -1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-header_line") == 0 || strcasecmp(argv[iarg],"-hdr") == 0 ){ withhead = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-monog_pairs") == 0 ){ monog_pairs = 1; iarg++; continue; } else if ( strncmp(argv[iarg],"-label2",7) == 0 ) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs an argument after -label2number\n"); labelName = malloc(sizeof(char) * 2048); strcpy(labelName, argv[iarg]); iarg++; continue; } else if( strcasecmp(argv[iarg],"-sb_delim") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -sb_delim\n"); sbdelim = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-NA_flag") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -NA_flag\n"); NAflag = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-atr_delim") == 0) { iarg++; if (iarg >= argc) ERROR_exit( "3dinfo needs a string after -atr_delim\n"); atrdelim = argv[iarg]; iarg++; continue; } else if( strcasecmp(argv[iarg],"-space") == 0) { sing[N_sing++] = DSET_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-av_space") == 0) { sing[N_sing++] = AV_DSET_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-gen_space") == 0) { sing[N_sing++] = DSET_GEN_SPACE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_nifti") == 0) { sing[N_sing++] = IS_NIFTI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_atlas") == 0) { sing[N_sing++] = IS_ATLAS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-exists") == 0) { sing[N_sing++] = DSET_EXISTS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-is_oblique") == 0) { sing[N_sing++] = IS_OBLIQUE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-obliquity") == 0) { sing[N_sing++] = OBLIQUITY; iarg++; continue; } else if( strcasecmp(argv[iarg],"-handedness") == 0) { sing[N_sing++] = HANDEDNESS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-prefix") == 0) { sing[N_sing++] = PREFIX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-prefix_noext") == 0) { sing[N_sing++] = PREFIX_NOEXT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ni") == 0) { sing[N_sing++] = NI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nj") == 0) { sing[N_sing++] = NJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nk") == 0) { sing[N_sing++] = NK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-n4") == 0) { sing[N_sing++] = NI; sing[N_sing++] = NJ; sing[N_sing++] = NK; sing[N_sing++] = NV; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Rextent") == 0) { sing[N_sing++] = EXTENT_R; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Lextent") == 0) { sing[N_sing++] = EXTENT_L; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Aextent") == 0) { sing[N_sing++] = EXTENT_A; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Pextent") == 0) { sing[N_sing++] = EXTENT_P; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Iextent") == 0) { sing[N_sing++] = EXTENT_I; iarg++; continue; } else if( strcasecmp(argv[iarg],"-Sextent") == 0) { sing[N_sing++] = EXTENT_S; iarg++; continue; } else if( strcasecmp(argv[iarg],"-extent") == 0) { sing[N_sing++] = EXTENT_R; sing[N_sing++] = EXTENT_L; sing[N_sing++] = EXTENT_A; sing[N_sing++] = EXTENT_P; sing[N_sing++] = EXTENT_I; sing[N_sing++] = EXTENT_S; iarg++; continue; } else if( strcasecmp(argv[iarg],"-di") == 0) { sing[N_sing++] = DI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dj") == 0) { sing[N_sing++] = DJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dk") == 0) { sing[N_sing++] = DK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-d3") == 0) { sing[N_sing++] = DI; sing[N_sing++] = DJ; sing[N_sing++] = DK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adi") == 0) { sing[N_sing++] = ADI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adj") == 0) { sing[N_sing++] = ADJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-adk") == 0) { sing[N_sing++] = ADK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ad3") == 0) { sing[N_sing++] = ADI; sing[N_sing++] = ADJ; sing[N_sing++] = ADK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-voxvol") == 0) { sing[N_sing++] = VOXVOL; iarg++; continue; } else if( strcasecmp(argv[iarg],"-iname") == 0) { sing[N_sing++] = INAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-oi") == 0) { sing[N_sing++] = OI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-oj") == 0) { sing[N_sing++] = OJ; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ok") == 0) { sing[N_sing++] = OK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-o3") == 0) { sing[N_sing++] = OI; sing[N_sing++] = OJ; sing[N_sing++] = OK; iarg++; continue; }else if( strcasecmp(argv[iarg],"-nt") == 0) { sing[N_sing++] = NT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nti") == 0) { sing[N_sing++] = NTI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nv") == 0) { sing[N_sing++] = NV; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nvi") == 0) { sing[N_sing++] = NVI; iarg++; continue; } else if( strcasecmp(argv[iarg],"-ntimes") == 0) { sing[N_sing++] = NTIMES; iarg++; continue; } else if( strcasecmp(argv[iarg],"-max_node") == 0) { sing[N_sing++] = MAX_NODE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-nijk") == 0) { sing[N_sing++] = NIJK; iarg++; continue; } else if( strcasecmp(argv[iarg],"-labeltable") == 0) { sing[N_sing++] = LTABLE; iarg++; continue; } else if( strcasecmp(argv[iarg],"-labeltable_as_atlas_points") == 0) { sing[N_sing++] = LTABLE_AS_ATLAS_POINT_LIST; iarg++; continue; } else if( strcasecmp(argv[iarg],"-atlas_points") == 0) { sing[N_sing++] = ATLAS_POINTS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-fac") == 0) { sing[N_sing++] = FAC; iarg++; continue; } else if( strcasecmp(argv[iarg],"-datum") == 0) { sing[N_sing++] = DATUM; iarg++; continue; } else if( strcasecmp(argv[iarg],"-label") == 0) { sing[N_sing++] = LABEL; iarg++; continue; } else if( strcasecmp(argv[iarg],"-min") == 0) { sing[N_sing++] = MIN; iarg++; continue; } else if( strcasecmp(argv[iarg],"-max") == 0) { sing[N_sing++] = MAX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-minus") == 0) { sing[N_sing++] = MINUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-maxus") == 0) { sing[N_sing++] = MAXUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmin") == 0) { sing[N_sing++] = DMIN; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmax") == 0) { sing[N_sing++] = DMAX; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dminus") == 0) { sing[N_sing++] = DMINUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-dmaxus") == 0) { sing[N_sing++] = DMAXUS; iarg++; continue; } else if( strcasecmp(argv[iarg],"-TR") == 0) { sing[N_sing++] = TR; iarg++; continue; } else if( strcasecmp(argv[iarg],"-header_name") == 0) { sing[N_sing++] = HEADER_NAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-brick_name") == 0) { sing[N_sing++] = BRICK_NAME; iarg++; continue; } else if( strcasecmp(argv[iarg],"-history") == 0) { sing[N_sing++] = HISTORY; iarg++; continue; } else if( strcasecmp(argv[iarg],"-all_names") == 0) { sing[N_sing++] = ALL_NAMES; iarg++; continue; } else if( strcasecmp(argv[iarg],"-orient") == 0) { sing[N_sing++] = ORIENT; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_grid") == 0) { sing[N_sing++] = SAME_GRID; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_dim") == 0) { sing[N_sing++] = SAME_DIM; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_delta") == 0) { sing[N_sing++] = SAME_DELTA; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_orient") == 0) { sing[N_sing++] = SAME_ORIENT; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_center") == 0) { sing[N_sing++] = SAME_CENTER; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_obl") == 0) { sing[N_sing++] = SAME_OBL; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-slice_timing") == 0) { sing[N_sing++] = SLICE_TIMING; iarg++; continue; } else if( strcasecmp(argv[iarg],"-sval_diff") == 0) { sing[N_sing++] = SVAL_DIFF; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-val_diff") == 0) { sing[N_sing++] = VAL_DIFF; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-same_all_grid") == 0) { sing[N_sing++] = SAME_DIM; sing[N_sing++] = SAME_DELTA; sing[N_sing++] = SAME_ORIENT; sing[N_sing++] = SAME_CENTER; sing[N_sing++] = SAME_OBL; needpair = 1; iarg++; continue; } else if( strcasecmp(argv[iarg],"-id") == 0) { sing[N_sing++] = ID; iarg++; continue; } else if( strcasecmp(argv[iarg],"-smode") == 0) { sing[N_sing++] = SMODE; iarg++; continue; } else { ERROR_message("Option %s unknown", argv[iarg]); suggest_best_prog_option(argv[0], argv[iarg]); exit(1); } } if (N_sing == 0) { sing[N_sing++] = CLASSIC; } if (sing[iis] == CLASSIC) PRINT_VERSION("3dinfo") ; THD_allow_empty_dataset(1) ; /* 21 Mar 2007 */ if (iarg == argc) { ERROR_message("No dsets on command line? I have nothing to do.\n"); exit(1); } if (needpair && monog_pairs) needpair = 2; /* pair each couple separately */ if (needpair==2 && (argc-iarg) % 2) { ERROR_message("Using options requiring dset pairs but have odd number\n" "of dsets (%d) on command line.\n", (argc-iarg)); exit (1); } else if (needpair==1 && (argc-iarg) < 2) { ERROR_message("Using options requiring dset pairs but have less than\n" "two dsets (%d) on command line.\n", (argc-iarg)); exit (1); } ip = 0; for( ; iarg < argc ; iarg++ ){ if (ip == 0) { int kkk, nml; char *etr; namelen = 0; for (kkk=iarg; kkk<argc; ++kkk) { if ((etr = THD_trailname(argv[kkk],0))) { nml=strlen(etr); if (nml < 48 && nml > namelen) namelen = nml; } } if (namelen < 6) namelen = 6; if (withhead) { int havenew=0; for (iis = 0; iis < N_sing; ++iis) { if (sing[iis] != CLASSIC) { ++havenew; form = PrintForm(sing[iis], namelen, 1); /*fprintf(stderr,"ZSS: %d %s >%s<\n", sing[iis], Field_Names[sing[iis]], form);*/ fprintf(stdout, form, Field_Names[sing[iis]]); } if (havenew) { if (N_sing > 1 && iis < N_sing-1) fprintf(stdout,"%s",atrdelim); else fprintf(stdout,"\n"); } } } } if( argv[iarg][0] == '\0' ) continue ; /* bad filename */ set_obliquity_report(0); /* silence obliquity */ if (!needpair) { if (!(dset = load_3dinfo_dataset(argv[iarg]))) { /* exit(1); */ } } else { if (needpair == 2) { /* Crazy idea of comparing each pair separately */ if (ip % 2 == 0) { if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /* exit(1); */ } if (iarg+1==argc || argv[iarg+1][0] == '\0') { ERROR_message("Bad dset pair for %s\n", argv[iarg]); exit(1); } if (!(dsetp = load_3dinfo_dataset(argv[iarg+1] ))) { /* exit(1); */ } } else { /* swap the pair - this allows non pair requiring functions to work as before.*/ tttdset = dsetp; dsetp = dset; dset = tttdset; tttdset=NULL; } } else { /* always compare to very first dset */ if (ip==0) { if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /*exit(1);*/ } if (!(dsetp = load_3dinfo_dataset(argv[iarg+1] ))) { /*exit(1);*/ } } else if (ip==1) { /* switch order of first two */ tttdset = dsetp; dsetp = dset; /* now dsetp is the very first dset */ dset = tttdset; tttdset=NULL; } else { /* pair with very first, which is dsetp */ if (!(dset = load_3dinfo_dataset(argv[iarg] ))) { /*exit(1);*/ } } } } ++ip; if (0 && !dset) { /* allow for DSET_EXISTS option */ ERROR_exit("Should not get here"); } /* we should re-capture this per dataset 5 Feb 2019 [rickr] */ extinit = 0; for (iis = 0; iis < N_sing; ++iis) { if (!dset) { if (sing[iis] == CLASSIC) { if( dset == NULL ){ /* still not open? */ ERROR_exit("Can't open dataset %s\n", argv[iarg]) ; } } else if (sing[iis] != DSET_EXISTS && sing[iis] != INAME) { fprintf(stdout, "NO-DSET"); SPIT_DELIM(iis, N_sing, atrdelim); continue; } } switch (sing[iis]) { case CLASSIC: if (labelName == NULL ) /*** get and output info ***/ { outbuf = THD_dataset_info( dset , verbose ) ; if( outbuf != NULL ){ printf("\n") ; puts(outbuf) ; free(outbuf) ; outbuf = NULL ; } else { ERROR_exit("Can't get info for dataset %s",argv[iarg]) ; } } else /*** get and output label ***/ { int nval_per = dset->dblk->nvals; int foundLabel = 0; int ival=0; for (ival=0 ; ival < nval_per && !foundLabel; ival++ ) { if (strcmp(DSET_BRICK_LAB(dset,ival), labelName) == 0) { printf("%d\n", ival); foundLabel = 1; } } /* end of for (ival=0 ; ival < nval_per ; ival++ ) */ if (!foundLabel) printf("\n"); } THD_delete_3dim_dataset( dset , False ) ; free(labelName); break; case DSET_EXISTS: fprintf(stdout, "%d", dset ? 1:0); break; case DSET_SPACE: tempstr = THD_get_space(dset); if(tempstr==NULL) fprintf(stdout, "-----"); else fprintf(stdout, "%s", tempstr); break; case DSET_GEN_SPACE: tempstr = THD_get_generic_space(dset); if(tempstr==NULL) fprintf(stdout, "-----"); else fprintf(stdout, "%s", tempstr); break; case AV_DSET_SPACE: /* don't allow anything but the three AFNI views */ tempstr = THD_get_view_space(dset); if(tempstr==NULL) fprintf(stdout, "+orig"); else if (!strncasecmp(tempstr,"ORIG",4)) fprintf(stdout, "+orig"); else if (!strncasecmp(tempstr,"ACPC",4)) fprintf(stdout, "+acpc"); else if (!strncasecmp(tempstr,"TLRC",4)) fprintf(stdout, "+tlrc"); else /* shouldn't get here */ fprintf(stdout, "+orig"); break; case IS_NIFTI: if ( dset->dblk->diskptr && dset->dblk->diskptr->storage_mode == STORAGE_BY_NIFTI ) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case IS_ATLAS: if ( is_Dset_Atlasy(dset, NULL) ) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case IS_OBLIQUE: if (dset_obliquity(dset,NULL) > 0) { fprintf(stdout,"1"); } else { fprintf(stdout,"0"); } break; case HANDEDNESS: if (THD_handedness(dset) > 0) { fprintf(stdout,"R"); } else { fprintf(stdout,"L"); } break; case OBLIQUITY: fprintf(stdout,"%.3f", THD_compute_oblique_angle(dset->daxes->ijk_to_dicom_real, 0)); break; case PREFIX: form = PrintForm(sing[iis], namelen, 1); fprintf(stdout,form, DSET_PREFIX(dset)); break; case PREFIX_NOEXT: { form = PrintForm(sing[iis], namelen, 1); stmp=DSET_prefix_noext(dset); fprintf(stdout,form, stmp); free(stmp); stmp=NULL; } break; case HEADER_NAME: fprintf(stdout,"%s", dset->dblk->diskptr->header_name); break; case BRICK_NAME: fprintf(stdout,"%s", dset->dblk->diskptr->brick_name); break; case ALL_NAMES: THD_show_dataset_names(dset, "FOR_3DINFO", stdout); break; case HISTORY: stmp = tross_Get_History(dset); fprintf(stdout,"%s", stmp ? stmp:NAflag); if (stmp) free(stmp); stmp=NULL; break; case NI: fprintf(stdout,"%d", DSET_NX(dset)); break; case NJ: fprintf(stdout,"%d", DSET_NY(dset)); break; case NK: fprintf(stdout,"%d", DSET_NZ(dset)); break; case NIJK: fprintf(stdout,"%d", DSET_NVOX(dset)); break; case NTIMES: fprintf(stdout,"%d", DSET_NUM_TIMES(dset)); break; case MAX_NODE: DSET_MAX_NODE(dset,itmp); fprintf(stdout,"%d", itmp); break; case NT: case NV: fprintf(stdout,"%d", DSET_NVALS(dset)); break; case NTI: case NVI: fprintf(stdout,"%d", DSET_NVALS(dset)-1); break; case DI: fprintf(stdout,"%f", DSET_DX(dset)); break; case DJ: fprintf(stdout,"%f", DSET_DY(dset)); break; case DK: fprintf(stdout,"%f", DSET_DZ(dset)); break; case OI: fprintf(stdout,"%f", DSET_XORG(dset)); break; case OJ: fprintf(stdout,"%f", DSET_YORG(dset)); break; case OK: fprintf(stdout,"%f", DSET_ZORG(dset)); break; case ADI: fprintf(stdout,"%f", fabs(DSET_DX(dset))); break; case EXTENT_R: case EXTENT_L: case EXTENT_A: case EXTENT_P: case EXTENT_I: case EXTENT_S: { if (!extinit) { THD_dset_extent(dset, '-', RL_AP_IS); extinit = 1; } fprintf(stdout,"%f", RL_AP_IS[sing[iis]-EXTENT_R]); } break; case ADJ: fprintf(stdout,"%f", fabs(DSET_DY(dset))); break; case ADK: fprintf(stdout,"%f", fabs(DSET_DZ(dset))); break; case VOXVOL: fprintf(stdout,"%f", fabs(DSET_DX(dset))* fabs(DSET_DY(dset))*fabs(DSET_DZ(dset))); break; case INAME: fprintf(stdout,"%s", argv[iarg]); break; case LTABLE: { char *str; if ((str = Dtable_to_nimlstring(DSET_Label_Dtable(dset), "VALUE_LABEL_DTABLE"))) { fprintf(stdout,"%s", str); free(str); } else { fprintf(stdout,"NO_LABEL_TABLE"); } } break; case LTABLE_AS_ATLAS_POINT_LIST: { ATLAS_POINT_LIST *apl=NULL; if ((apl = label_table_to_atlas_point_list(DSET_Label_Dtable(dset)))) { atlas_list_to_niml(apl,NULL); free_atlas_point_list(apl); } else { fprintf(stdout,"NO_LABEL_TABLE"); } } break; case ATLAS_POINTS: { ATR_string *atr = THD_find_string_atr( dset->dblk, "ATLAS_LABEL_TABLE"); if (atr) { fprintf(stdout,"%s", atr->ch); } else { fprintf(stdout,"NO_APL"); } } break; case FAC: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%f%s", DSET_BRICK_FACTOR(dset,isb), (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case DATUM: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%s%s", MRI_TYPE_name[DSET_BRICK_TYPE(dset,isb)], (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case LABEL: { for (isb=0; isb<DSET_NVALS(dset); ++isb) { fprintf(stdout,"%s%s", DSET_BRICK_LABEL(dset,isb) ? DSET_BRICK_LABEL(dset,isb):NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case MIN: case MINUS: case MAX: case MAXUS: { float vv=0.0, min, max; for (isb=0; isb<DSET_NVALS(dset); ++isb) { if (!THD_subbrick_minmax(dset, isb, (sing[iis] == MINUS || sing[iis] == MAXUS) ? 0:1, &min, &max)) { fprintf(stdout,"%s%s", NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } else { if (sing[iis] == MINUS) vv = min; else if (sing[iis] == MAXUS) vv = max; else if (sing[iis] == MIN) vv = min; else if (sing[iis] == MAX) vv = max; fprintf(stdout,"%g%s", vv, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } } break; } case DMIN: case DMINUS: case DMAX: case DMAXUS: { float vv=0.0, min, max; if (!THD_dset_minmax(dset, (sing[iis] == DMINUS || sing[iis] == DMAXUS) ? 0:1, &min, &max)) { fprintf(stdout,"%s%s", NAflag, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } else { if (sing[iis] == DMINUS) vv = min; else if (sing[iis] == DMAXUS) vv = max; else if (sing[iis] == DMIN) vv = min; else if (sing[iis] == DMAX) vv = max; fprintf(stdout,"%g%s", vv, (isb == (DSET_NVALS(dset)-1)) ? "" : sbdelim); } break; } case TR: #if 0 fprintf(stdout,"%f", DSET_TR_SEC(dset)); #else fprintf(stdout,"%f", DSET_TR(dset)); #endif break; case ORIENT: { /* fprintf(stdout,"%c%c%c", * ORIENT_typestr[dset->daxes->xxorient][0], ... ); */ char ostr[4]; /* just to show 23 Jan 2013 [rickr] */ THD_fill_orient_str_3(dset->daxes, ostr); fprintf(stdout,"%3s", ostr); } break; case SAME_GRID: fprintf(stdout,"%d", !THD_dataset_mismatch( dset , dsetp )); break; case SAME_DIM: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_DIMEN)); break; case SAME_DELTA: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_DELTA)); break; case SAME_ORIENT: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_ORIENT)); break; case SAME_CENTER: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_CENTER)); break; case SAME_OBL: fprintf(stdout,"%d", !(THD_dataset_mismatch( dset , dsetp ) & MISMATCH_OBLIQ)); break; case SLICE_TIMING: /* 6 May 2013 [rickr] */ { if( DSET_HAS_SLICE_TIMING(dset) ) { DSET_UNMSEC(dset); /* make sure times are in seconds */ for (isb=0; isb<dset->taxis->nsl; ++isb) { fprintf(stdout,"%s%f", (isb > 0) ? sbdelim : "", dset->taxis->toff_sl[isb]); } } else { /* all slices times are at t=0.0 */ for (isb=0; isb<DSET_NZ(dset); ++isb) { fprintf(stdout,"%s%f", (isb > 0) ? sbdelim : "", 0.0); } } } break; case SVAL_DIFF: fprintf(stdout,"%f",THD_diff_vol_vals(dset, dsetp, 1)); break; case VAL_DIFF: fprintf(stdout,"%f",THD_diff_vol_vals(dset, dsetp, 0)); break; case ID: fprintf(stdout,"%s", DSET_IDCODE_STR(dset)); break; case SMODE: fprintf(stdout,"%s", DSET_STORAGE_MODE_STR(dset)); break; default: ERROR_message("Info field not set properly (%d)\n", sing[iis]); exit(1); } if (sing[iis] != CLASSIC) { SPIT_DELIM(iis, N_sing, atrdelim); } } } exit(0) ; }
int THD_datablock_from_atr( THD_datablock *dblk, char *dirname, char *headname ) { THD_diskptr *dkptr ; ATR_int *atr_rank , *atr_dimen , *atr_scene , *atr_btype ; ATR_float *atr_flt ; ATR_string *atr_labs ; int ii , view_type , func_type , dset_type , nx,ny,nz,nvox , nvals , ibr,typ ; Boolean ok ; char prefix[THD_MAX_NAME]="Unknown" ; MRI_IMAGE *qim ; int brick_ccode ; char name[666] ; ENTRY("THD_datablock_from_atr") ; if( dblk == NULL || dblk->natr <= 0 ) RETURN(0) ; /* bad input */ dkptr = dblk->diskptr ; /*-- get relevant attributes: rank, dimensions, view_type & func_type --*/ atr_rank = THD_find_int_atr( dblk , ATRNAME_DATASET_RANK ) ; atr_dimen = THD_find_int_atr( dblk , ATRNAME_DATASET_DIMENSIONS ) ; atr_scene = THD_find_int_atr( dblk , ATRNAME_SCENE_TYPE ) ; /*-- missing an attribute ==> quit now --*/ if( atr_rank == NULL || atr_dimen == NULL || atr_scene == NULL ) RETURN(0) ; /*-- load type codes from SCENE attribute --*/ STATUS("loading *_type from SCENE") ; view_type = atr_scene->in[0] ; func_type = atr_scene->in[1] ; dset_type = atr_scene->in[2] ; /*-- load other values from attributes into relevant places --*/ ok = True ; nvox = 1 ; STATUS("loading from RANK") ; dkptr->rank = atr_rank->in[0] ; /* N.B.: rank isn't used much */ dkptr->nvals = dblk->nvals = nvals = atr_rank->in[1] ; /* but nvals is used */ STATUS("loading from DIMENSIONS") ; for( ii=0 ; ii < dkptr->rank ; ii++ ){ dkptr->dimsizes[ii] = atr_dimen->in[ii] ; ok = ( ok && dkptr->dimsizes[ii] >= 1 ) ; nvox *= dkptr->dimsizes[ii] ; } #if 0 if( PRINT_TRACING ){ char str[256] ; sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d nvox=%d", dkptr->rank , dkptr->nvals , dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] , nvox ) ; STATUS(str) ; } #endif if( !ok || nvals < 1 || dkptr->rank < THD_MIN_RANK || dkptr->rank > THD_MAX_RANK ){ STATUS("bad rank!!??") ; RETURN(0) ; } /*-- create the storage filenames --*/ STATUS("creating storage filenames") ; if( headname != NULL && strchr(headname,'+') != NULL ){ FILENAME_TO_PREFIX(headname,prefix) ; THD_init_diskptr_names( dkptr, dirname,NULL,prefix , view_type , True ) ; } else { if( headname != NULL ) MCW_strncpy(prefix,headname,THD_MAX_NAME) ; THD_init_diskptr_names( dkptr, dirname,NULL,prefix , view_type , True ) ; } /*-- determine if the BRIK file exists --*/ STATUS("checking if .BRIK file exists") ; brick_ccode = COMPRESS_filecode(dkptr->brick_name) ; if (dkptr->storage_mode == STORAGE_UNDEFINED) { /* ZSS: Oct. 2011 the next line was being called all the time before */ if( brick_ccode != COMPRESS_NOFILE ) dkptr->storage_mode = STORAGE_BY_BRICK ; /* a .BRIK file */ } /*-- if VOLUME_FILENAMES attribute exists, make it so [20 Jun 2002] --*/ if( headname != NULL && dkptr->storage_mode == STORAGE_UNDEFINED ){ atr_labs = THD_find_string_atr(dblk,"VOLUME_FILENAMES") ; if( atr_labs != NULL ){ dkptr->storage_mode = STORAGE_BY_VOLUMES ; dblk->malloc_type = DATABLOCK_MEM_MALLOC ; } } /*-- now set the memory allocation codes, etc. --*/ dblk->brick_fac = (float *) XtMalloc( sizeof(float) * nvals ) ; for( ibr=0 ; ibr < nvals ; ibr++ ) dblk->brick_fac[ibr] = 0.0 ; /* scaling factors from short type to float type, if nonzero */ if( !AFNI_yesenv("AFNI_IGNORE_BRICK_FLTFAC") ){ atr_flt = THD_find_float_atr( dblk , ATRNAME_BRICK_FLTFAC ) ; if( atr_flt != NULL ){ for( ibr=0 ; ibr < nvals && ibr < atr_flt->nfl ; ibr++ ) dblk->brick_fac[ibr] = atr_flt->fl[ibr] ; } } /** Now create an empty shell of the "brick" == the data structure that will hold all the voxel data. Note that all datablocks will have a brick, even if they never actually contain data themselves (are only warp-on-demand). If the BRICK_TYPES input attribute doesn't exist, then all sub-bricks are shorts. This makes the code work with old-style datasets, which were always made up of shorts. **/ atr_btype = THD_find_int_atr( dblk , ATRNAME_BRICK_TYPES ) ; if( atr_btype == NULL ){ THD_init_datablock_brick( dblk , MRI_short , NULL ) ; } else { THD_init_datablock_brick( dblk , atr_btype->nin , atr_btype->in ) ; } if( !THD_datum_constant(dblk) ){ /* 15 Sep 2004 */ fprintf(stderr, "\n** WARNING: File %s has mixed-type sub-bricks. ", MYHEAD ) ; } /* 25 April 1998: check if the byte order is stored inside */ atr_labs = THD_find_string_atr( dblk , ATRNAME_BYTEORDER ) ; if( atr_labs != NULL && atr_labs->nch > 0 ){ if( strncmp(atr_labs->ch,LSB_FIRST_STRING,ORDER_LEN) == 0 ) dkptr->byte_order = LSB_FIRST ; else if( strncmp(atr_labs->ch,MSB_FIRST_STRING,ORDER_LEN) == 0 ) dkptr->byte_order = MSB_FIRST ; else fprintf(stderr,"*** Unknown %s found in dataset %s\n", ATRNAME_BYTEORDER , MYHEAD ) ; } else if( !no_ordwarn && DBLK_BRICK_TYPE(dblk,0) != MRI_byte && dblk->diskptr->storage_mode == STORAGE_BY_BRICK ){ /* 20 Sep 1999 */ static int first=1 ; if( first ){ fprintf(stderr, "\n*** The situation below can be rectified with program '3drefit -byteorder':\n"); first = 0 ; } fprintf(stderr," ** Dataset %s: assuming byteorder %s\n", MYHEAD , BYTE_ORDER_STRING(dkptr->byte_order) ) ; } /* if the data is not on disk, the flag remains at DATABLOCK_MEM_UNDEFINED, otherwise the flag says how the memory for the bricks is to be created. */ if( dkptr->storage_mode == STORAGE_BY_BRICK ){ #if MMAP_THRESHOLD > 0 dblk->malloc_type = (dblk->total_bytes > MMAP_THRESHOLD) ? DATABLOCK_MEM_MMAP : DATABLOCK_MEM_MALLOC ; DBLK_mmapfix(dblk) ; /* 18 Mar 2005 */ #else dblk->malloc_type = DATABLOCK_MEM_MALLOC ; #endif /* must be malloc-ed if: data is compressed, data is not in native byte order, or user explicity forbids use of mmap */ if( brick_ccode >= 0 || dkptr->byte_order != native_order || no_mmap ) dblk->malloc_type = DATABLOCK_MEM_MALLOC ; } /* 30 Nov 1997: create the labels for sub-bricks */ THD_init_datablock_labels( dblk ) ; atr_labs = THD_find_string_atr( dblk , ATRNAME_BRICK_LABS ) ; if( atr_labs != NULL && atr_labs->nch > 0 ){ /* create labels from attribute */ int ipos = -1 , ipold , ngood ; for( ibr=0 ; ibr < nvals ; ibr++ ){ /* loop over bricks */ for( ipold = ipos++ ; /* skip to */ ipos < atr_labs->nch && atr_labs->ch[ipos] != '\0' ; /* next \0 */ ipos++ ) /* nada */ ; /* or end. */ ngood = ipos - ipold - 1 ; /* number of good chars */ if( ngood > 0 ){ XtFree(dblk->brick_lab[ibr]) ; /* 27 Oct 2011 - increase to 64 */ if( ngood > THD_MAX_SBLABEL ) ngood = THD_MAX_SBLABEL; dblk->brick_lab[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ; memcpy( dblk->brick_lab[ibr] , atr_labs->ch+(ipold+1) , ngood ) ; dblk->brick_lab[ibr][ngood] = '\0' ; } if( ipos >= atr_labs->nch ) break ; /* nothing more to do */ } /* end of loop over sub-bricks */ } /* create the keywords for sub-bricks */ THD_init_datablock_keywords( dblk ) ; atr_labs = THD_find_string_atr( dblk , ATRNAME_BRICK_KEYWORDS ) ; if( atr_labs != NULL && atr_labs->nch > 0 ){ /* create keywords from attribute */ int ipos = -1 , ipold , ngood ; for( ibr=0 ; ibr < nvals ; ibr++ ){ /* loop over bricks */ for( ipold = ipos++ ; /* skip to */ ipos < atr_labs->nch && atr_labs->ch[ipos] != '\0' ; /* next \0 */ ipos++ ) /* nada */ ; /* or end. */ ngood = ipos - ipold - 1 ; /* number of good chars */ if( ngood > 0 ){ XtFree(dblk->brick_keywords[ibr]) ; dblk->brick_keywords[ibr] = (char *) XtMalloc(sizeof(char)*(ngood+2)) ; memcpy( dblk->brick_keywords[ibr] , atr_labs->ch+(ipold+1) , ngood ) ; dblk->brick_keywords[ibr][ngood] = '\0' ; } if( ipos >= atr_labs->nch ) break ; /* nothing more to do */ } /* end of loop over sub-bricks */ } /* create the auxiliary statistics stuff for each brick, if present */ atr_labs = THD_find_string_atr( dblk , "BRICK_STATSYM" ) ; /* 01 Jun 2005 */ if( atr_labs != NULL && atr_labs->nch > 0 ){ NI_str_array *sar ; int scode,np ; float parm[3] ; sar = NI_decode_string_list( atr_labs->ch , ";" ) ; if( sar != NULL && sar->num > 0 ){ for( ibr=0 ; ibr < nvals && ibr < sar->num ; ibr++ ){ NI_stat_decode( sar->str[ibr] , &scode , parm,parm+1,parm+2 ) ; if( scode >= AFNI_FIRST_STATCODE && scode <= AFNI_LAST_STATCODE ){ np = NI_stat_numparam(scode) ; THD_store_datablock_stataux( dblk , ibr,scode,np,parm ) ; } } NI_delete_str_array(sar) ; } } else { /*--- the olde way to get ye brick stataux parameters ---*/ atr_flt = THD_find_float_atr( dblk , ATRNAME_BRICK_STATAUX ) ; if( atr_flt != NULL && atr_flt->nfl >= 3 ){ int ipos=0 , iv,nv,jv ; /* attribute stores all stataux stuff as follows: sub-brick-index statcode no.-of-values value ... value sub-brick-index statcode no.-of-values value ... value, etc. */ while( ipos <= atr_flt->nfl - 3 ){ iv = (int) ( atr_flt->fl[ipos++] ) ; /* which sub-brick */ jv = (int) ( atr_flt->fl[ipos++] ) ; /* statcode */ nv = (int) ( atr_flt->fl[ipos++] ) ; /* # of values that follow */ if( nv > atr_flt->nfl - ipos ) nv = atr_flt->nfl - ipos ; THD_store_datablock_stataux( dblk , iv , jv , nv , atr_flt->fl + ipos ) ; ipos += nv ; } } } #if 0 if( PRINT_TRACING ){ char str[256] ; sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d", dkptr->rank , dkptr->nvals , dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] ) ; STATUS(str) ; } #endif /*-- FDR curves [23 Jan 2008] --*/ for( ibr=0 ; ibr < dblk->nvals ; ibr++ ){ sprintf(name,"FDRCURVE_%06d",ibr) ; atr_flt = THD_find_float_atr( dblk , name ) ; if( atr_flt != NULL && atr_flt->nfl > 3 ){ int nv = atr_flt->nfl - 2 ; floatvec *fv ; MAKE_floatvec(fv,nv) ; fv->x0 = atr_flt->fl[0] ; fv->dx = atr_flt->fl[1] ; memcpy( fv->ar , atr_flt->fl + 2 , sizeof(float)*nv ) ; if( dblk->brick_fdrcurve == NULL ) dblk->brick_fdrcurve = (floatvec **)calloc(sizeof(floatvec *),dblk->nvals); dblk->brick_fdrcurve[ibr] = fv ; } } for( ibr=0 ; ibr < dblk->nvals ; ibr++ ){ sprintf(name,"MDFCURVE_%06d",ibr) ; atr_flt = THD_find_float_atr( dblk , name ) ; if( atr_flt != NULL && atr_flt->nfl > 3 ){ int nv = atr_flt->nfl - 2 ; floatvec *fv ; MAKE_floatvec(fv,nv) ; fv->x0 = atr_flt->fl[0] ; fv->dx = atr_flt->fl[1] ; memcpy( fv->ar , atr_flt->fl + 2 , sizeof(float)*nv ) ; if( dblk->brick_mdfcurve == NULL ) dblk->brick_mdfcurve = (floatvec **)calloc(sizeof(floatvec *),dblk->nvals); dblk->brick_mdfcurve[ibr] = fv ; } } RETURN(1) ; }