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  

edt_dsetitems.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 
00009 /*-----------------------------------------------------------------------
00010   Edit some internals of a dataset.  Notice that it is possible to
00011   create a dataset which is inconsistent.  Note also that some operations
00012   cannot be performed on a dataset containing actual data -- for example,
00013   you cannot change the types of sub-bricks if they already are attached
00014   to data arrays!
00015 
00016   This routine uses the <stdarg.h> variable argument interface.
00017   The first argument is a pointer to the dataset to edit.
00018   All succeeding arguments are pairs indicating which internal item
00019   to edit, and the new value for that item.  The first entry of a pair
00020   must be one of the ADN_ entries defined in editvol.h.  The type of the
00021   second entry of a pair depends on the particular item.
00022   [*** WARNING: due to C automatic 'type promotion', you cannot use
00023        float as the type to extract from the list -- you must use double!]
00024 
00025   Finally, the end of the argument list is found by the last argument
00026   being the special code ADN_none.
00027 
00028   The return value is the number of errors detected (hopefully, 0).
00029 -------------------------------------------------------------------------*/
00030 
00031 #define EDERR(str) \
00032    do{ fprintf(stderr,"*** EDIT_dset_items: %s\n",str) ; errnum++ ; } while(0)
00033 
00034 int EDIT_dset_items( THD_3dim_dataset * dset , ... )
00035 {
00036    va_list vararg_ptr ;
00037    int     flag_arg , errnum = 0 ;
00038    int     redo_bricks , redo_daxes , redo_taxis , ii ;
00039    void *  dummy ;
00040    int     iarg ;
00041 
00042    /**----- variables to flag and store presence of arguments -----**/
00043 
00044    int new_prefix         = 0 ; char *              prefix         = NULL ;
00045    int new_directory_name = 0 ; char *              directory_name = NULL ;
00046    int new_brick_fac      = 0 ; float *             brick_fac      = NULL ;
00047    int new_malloc_type    = 0 ; int                 malloc_type    = ILLEGAL_TYPE ;
00048    int new_datum_all      = 0 ; int                 datum_all      = ILLEGAL_TYPE ;
00049    int new_datum_array    = 0 ; int *               datum_array    = NULL ;
00050    int new_nvals          = 0 ; int                 nvals          = 0 ;
00051    int new_nxyz           = 0 ; THD_ivec3           nxyz           ;
00052    int new_xyzdel         = 0 ; THD_fvec3           xyzdel         ;
00053    int new_xyzorg         = 0 ; THD_fvec3           xyzorg         ;
00054    int new_xyzorient      = 0 ; THD_ivec3           xyzorient      ;
00055    int new_to_dicomm      = 0 ; THD_mat33           to_dicomm      ;
00056    int new_ntt            = 0 ; int                 ntt            = 0 ;
00057    int new_ttorg          = 0 ; float               ttorg          = 0.0 ;
00058    int new_ttdel          = 0 ; float               ttdel          = 0.0 ;
00059    int new_ttdur          = 0 ; float               ttdur          = 0.0 ;
00060    int new_nsl            = 0 ; int                 nsl            = 0 ;
00061    int new_zorg_sl        = 0 ; float               zorg_sl        = 0.0 ;
00062    int new_dz_sl          = 0 ; float               dz_sl          = 0.0 ;
00063    int new_toff_sl        = 0 ; float *             toff_sl        = NULL ;
00064    int new_type           = 0 ; int                 type           = ILLEGAL_TYPE ;
00065    int new_view_type      = 0 ; int                 view_type      = ILLEGAL_TYPE ;
00066    int new_func_type      = 0 ; int                 func_type      = ILLEGAL_TYPE ;
00067    int new_label1         = 0 ; char *              label1         = NULL ;
00068    int new_label2         = 0 ; char *              label2         = NULL ;
00069    int new_self_name      = 0 ; char *              self_name      = NULL ;
00070    int new_warp_parent    = 0 ; THD_3dim_dataset *  warp_parent    = NULL ;
00071    int new_anat_parent    = 0 ; THD_3dim_dataset *  anat_parent    = NULL ;
00072    int new_stat_aux       = 0 ; float *             stat_aux       = NULL ;
00073    int new_warp           = 0 ; THD_warp *          warp           = NULL ;
00074    int new_tunits         = 0 ; int                 tunits         = ILLEGAL_TYPE ;
00075    int new_keywords       = 0 ; char *              keywords       = NULL ;
00076 
00077    /* 30 Nov 1997 */
00078 
00079    int new_brick_label_one = 0 ; char * brick_label_one    = NULL ;
00080                                  int    brick_label_one_iv = -1 ;
00081 
00082    int new_brick_fac_one = 0 ; float brick_fac_one    = 0.0 ;
00083                                int   brick_fac_one_iv = -1 ;
00084 
00085    int new_brick_stataux_one = 0 ; float * brick_stataux_one    = NULL ;
00086                                    int     brick_stataux_one_iv = -1 ;
00087 
00088    int new_brick_keywords_one = 0 ; char * brick_keywords_one    = NULL ;
00089                                     int    brick_keywords_one_iv = -1 ;
00090 
00091    /****---------------------- Sanity Check ----------------------****/
00092 
00093 ENTRY("EDIT_dset_items") ;
00094 
00095    if( ! ISVALID_3DIM_DATASET(dset) ) RETURN(1) ;  /* bad data */
00096 
00097    /****----------- Scan input argument list;
00098                   - Load data into locals (va_arg);
00099                   - Check for legal values;
00100                   - Flag its presence (the new_ variables);
00101                   - Carry out simple processing that doesn't
00102                       depend on the presence of other arguments. ---------****/
00103 
00104    va_start( vararg_ptr , dset ) ;              /** Initialize arg reading **/
00105    iarg = 1 ;
00106 
00107    do{
00108       flag_arg = va_arg( vararg_ptr , int ) ;   /** Get next arg  **/
00109       if( flag_arg == ADN_none ) break ;        /** No more args! **/
00110 #if 0
00111 fprintf(stderr,"EDIT_dset_items: iarg=%d flag_arg=%d\n",iarg,flag_arg) ;
00112 #endif
00113       iarg++ ;
00114 
00115       switch( flag_arg ){
00116 
00117          default:{
00118             int iv ;
00119             char str[128] ;
00120 
00121             /** 30 Nov 1997: check for special cases **/
00122 
00123             iv = flag_arg - ADN_brick_label_one ;
00124             if( iv >= 0 && iv < ADN_ONE_STEP ){
00125                brick_label_one_iv  = iv ;
00126                brick_label_one     = va_arg( vararg_ptr , char * ) ;
00127                if( brick_label_one != NULL ) new_brick_label_one = 1 ;
00128                break ; /* exit switch */
00129             }
00130 
00131             iv = flag_arg - ADN_brick_fac_one ;
00132             if( iv >= 0 && iv < ADN_ONE_STEP ){
00133                brick_fac_one_iv  = iv ;
00134                brick_fac_one     = va_arg( vararg_ptr , double ) ;
00135                new_brick_fac_one = 1 ;
00136                break ; /* exit switch */
00137             }
00138 
00139             iv = flag_arg - ADN_brick_stataux_one ;
00140             if( iv >= 0 && iv < ADN_ONE_STEP ){
00141                brick_stataux_one_iv = iv ;
00142                brick_stataux_one    = va_arg( vararg_ptr , float * ) ;
00143                if( brick_stataux_one != NULL ) new_brick_stataux_one = 1 ;
00144                break ; /* exit switch */
00145             }
00146 
00147             iv = flag_arg - ADN_brick_keywords_replace_one ;
00148             if( iv >= 0 && iv < ADN_ONE_STEP ){
00149                brick_keywords_one_iv  = iv ;
00150                brick_keywords_one     = va_arg( vararg_ptr , char * ) ;
00151                new_brick_keywords_one = 1 ;
00152                break ; /* exit switch */
00153             }
00154 
00155             iv = flag_arg - ADN_brick_keywords_append_one ;
00156             if( iv >= 0 && iv < ADN_ONE_STEP ){
00157                brick_keywords_one_iv  = iv ;
00158                brick_keywords_one     = va_arg( vararg_ptr , char * ) ;
00159                new_brick_keywords_one = 2 ;
00160                break ; /* exit switch */
00161             }
00162 
00163             /** not a special case? error! **/
00164 
00165             sprintf(str,"illegal opcode = %d at arg #%d",flag_arg,iarg) ;
00166             EDERR(str) ; if( errnum > 9 ) RETURN(errnum) ;
00167             dummy = va_arg( vararg_ptr , void * ) ;  /* skip next arg */
00168          }
00169          break ;
00170 
00171          /** these two commands affect the disk file names **/
00172 
00173          case ADN_prefix:  /* processed later */
00174             prefix = va_arg( vararg_ptr , char * ) ;
00175             if( prefix != NULL ) new_prefix = 1 ;
00176             else EDERR("illegal new prefix") ;
00177          break ;
00178 
00179          case ADN_directory_name:  /* processed later */
00180             directory_name = va_arg( vararg_ptr , char * ) ;
00181             if( directory_name != NULL ) new_directory_name = 1 ;
00182             else EDERR("illegal new directory_name") ;
00183          break ;
00184 
00185          /** change the memory allocation type (mmap or malloc) **/
00186 
00187          case ADN_malloc_type:  /* processed now */
00188             malloc_type = va_arg( vararg_ptr , int ) ;
00189             if( ISVALID_MEM_CODE(malloc_type) ){
00190                new_malloc_type = 1 ;
00191                THD_force_malloc_type( dset->dblk , malloc_type ) ;
00192             }
00193             else EDERR("illegal new malloc_type") ;
00194          break ;
00195 
00196          /** these commands affect the data in the bricks **/
00197 
00198          case ADN_brick_fac:  /* processed later */
00199             brick_fac = va_arg( vararg_ptr , float * ) ;
00200             new_brick_fac = 1 ;
00201          break ;
00202 
00203          case ADN_datum_all:  /* processed later */
00204             datum_all = va_arg( vararg_ptr , int ) ;
00205             if( AFNI_GOOD_DTYPE(datum_all) ) new_datum_all = 1 ;
00206             else EDERR("illegal new datum_all") ;
00207          break ;
00208 
00209          case ADN_datum_array:  /* processed later */
00210             datum_array = va_arg( vararg_ptr , int * ) ;
00211             if( datum_array != NULL ) new_datum_array = 1 ;
00212             else EDERR("illegal new datum_array") ;
00213          break ;
00214 
00215          case ADN_nvals:  /* processed later */
00216             nvals = va_arg( vararg_ptr , int ) ;
00217             if( nvals > 0 ) new_nvals = 1 ;
00218             else EDERR("illegal new nvals") ;
00219          break ;
00220 
00221          /** these commands affect the spatial axes,
00222              which may also influence size of the data bricks **/
00223 
00224          case ADN_nxyz:  /* processed later */
00225             nxyz = va_arg( vararg_ptr , THD_ivec3 ) ;
00226             if( nxyz.ijk[0] >= 1 && nxyz.ijk[1] >= 1 && nxyz.ijk[2] >= 1 )
00227                new_nxyz = 1 ;
00228                else EDERR("illegal new nxyz") ;
00229          break ;
00230 
00231          case ADN_xyzdel:  /* processed later */
00232             xyzdel = va_arg( vararg_ptr , THD_fvec3 ) ;
00233             if( xyzdel.xyz[0]!=0.0 && xyzdel.xyz[1]!=0.0 && xyzdel.xyz[2]!=0.0 )
00234                new_xyzdel = 1 ;
00235                else EDERR("illegal new xyzdel") ;
00236          break ;
00237 
00238          case ADN_xyzorg:  /* processed later */
00239             xyzorg = va_arg( vararg_ptr , THD_fvec3 ) ;
00240             new_xyzorg = 1 ;
00241          break ;
00242 
00243          case ADN_xyzorient:  /* processed later */
00244             xyzorient = va_arg( vararg_ptr , THD_ivec3 ) ;
00245             if( xyzorient.ijk[0] >= FIRST_ORIENT_TYPE &&
00246                 xyzorient.ijk[0] <= LAST_ORIENT_TYPE  &&
00247                 xyzorient.ijk[1] >= FIRST_ORIENT_TYPE &&
00248                 xyzorient.ijk[1] <= LAST_ORIENT_TYPE  &&
00249                 xyzorient.ijk[2] >= FIRST_ORIENT_TYPE &&
00250                 xyzorient.ijk[2] <= LAST_ORIENT_TYPE  &&
00251                   ORIENT_xyzint[xyzorient.ijk[0]]
00252                 + ORIENT_xyzint[xyzorient.ijk[1]]
00253                 + ORIENT_xyzint[xyzorient.ijk[2]] == 6  )
00254 
00255                new_xyzorient = 1 ;
00256             else EDERR("illegal new xyzorient") ;
00257          break ;
00258 
00259          case ADN_to_dicomm:   /* illegal at this time */
00260             EDERR("to_dicomm not implemented") ;
00261          break ;
00262 
00263          /** these commands affect the time axis of the dataset **/
00264 
00265          case ADN_ntt:  /* processed later */
00266             ntt = va_arg( vararg_ptr , int ) ;
00267             if( ntt >= 0 ) new_ntt = 1 ;
00268             else EDERR("illegal new taxis ntt") ;
00269          break ;
00270 
00271          case ADN_tunits:  /* processed later */
00272             tunits = va_arg( vararg_ptr , int ) ;
00273             if( tunits >= 0 ) new_tunits = 1 ;
00274             else EDERR("illegal new taxis tunits") ;
00275          break ;
00276 
00277          case ADN_nsl:  /* processed later */
00278             nsl = va_arg( vararg_ptr , int ) ;
00279             if( nsl >= 0 ) new_nsl = 1 ;
00280             else EDERR("illegal new taxis nsl") ;
00281          break ;
00282 
00283          case ADN_ttorg:  /* processed later */
00284             ttorg = (float) va_arg( vararg_ptr , double ) ;
00285             new_ttorg = 1 ;
00286          break ;
00287 
00288          case ADN_ttdel:  /* processed later */
00289             ttdel = (float) va_arg( vararg_ptr , double ) ;
00290             new_ttdel = 1 ;
00291          break ;
00292 
00293          case ADN_ttdur:  /* processed later */
00294             ttdur = (float) va_arg( vararg_ptr , double ) ;
00295             new_ttdur = 1 ;
00296          break ;
00297 
00298          case ADN_zorg_sl:  /* processed later */
00299             zorg_sl = (float) va_arg( vararg_ptr , double ) ;
00300             new_zorg_sl = 1 ;
00301          break ;
00302 
00303          case ADN_dz_sl:  /* processed later */
00304             dz_sl = (float) va_arg( vararg_ptr , double ) ;
00305             if( dz_sl != 0.0 ) new_dz_sl = 1 ;
00306             else EDERR("illegal new taxis dz_sl") ;
00307          break ;
00308 
00309          case ADN_toff_sl:  /* processed later */
00310             toff_sl = va_arg( vararg_ptr , float * ) ;
00311             new_toff_sl = 1 ;
00312          break ;
00313 
00314          /** these commands affect the interpretation of the dataset
00315              (e.g., is it functional or anatomical, which view type, ...) **/
00316 
00317          case ADN_type:  /* processed later */
00318             type = va_arg( vararg_ptr , int ) ;
00319             if( type >= FIRST_3DIM_TYPE && type <= LAST_3DIM_TYPE )
00320                new_type = 1 ;
00321             else EDERR("illegal new type") ;
00322          break ;
00323 
00324          case ADN_view_type:  /* processed later */
00325             view_type = va_arg( vararg_ptr , int ) ;
00326             if( view_type >= FIRST_VIEW_TYPE && view_type <= LAST_VIEW_TYPE )
00327                new_view_type = 1 ;
00328             else EDERR("illegal new view_type") ;
00329          break ;
00330 
00331          case ADN_func_type:  /* processed later */
00332             func_type = va_arg( vararg_ptr , int ) ;
00333             if( func_type >= 0 ) new_func_type = 1 ;
00334             else EDERR("illegal new func_type") ;
00335          break ;
00336 
00337          /** auxiliary statistical data, for interpretation of functions **/
00338 
00339          case ADN_stat_aux:  /* processed now */
00340             stat_aux = va_arg( vararg_ptr , float * ) ;
00341             if( stat_aux != NULL ){
00342                new_stat_aux = 1 ;
00343                for( ii=0 ; ii < MAX_STAT_AUX ; ii++ )
00344                   dset->stat_aux[ii] = stat_aux[ii] ;
00345             } else EDERR("illegal new stat_aux") ;
00346          break ;
00347 
00348          /** dataset keywords **/
00349 
00350          case ADN_keywords_replace: /* processed now */
00351             keywords = va_arg( vararg_ptr , char * ) ;
00352             new_keywords = 1 ;
00353             THD_store_dataset_keywords( dset , keywords ) ;
00354          break ;
00355 
00356          case ADN_keywords_append: /* processed now */
00357             keywords = va_arg( vararg_ptr , char * ) ;
00358             new_keywords = 1 ;
00359             THD_append_dataset_keywords( dset , keywords ) ;
00360          break ;
00361 
00362          /** various labeling options **/
00363 
00364          case ADN_label1:  /* processed now */
00365             label1 = va_arg( vararg_ptr , char * ) ;
00366             if( label1 != NULL ){
00367                MCW_strncpy( dset->label1 , label1 , THD_MAX_LABEL ) ;
00368                new_label1 = 1 ;
00369             }
00370             else EDERR("illegal new label1") ;
00371          break ;
00372 
00373          case ADN_label2:  /* processed now */
00374             label2 = va_arg( vararg_ptr , char * ) ;
00375             if( label2 != NULL ){
00376                MCW_strncpy( dset->label2 , label2 , THD_MAX_LABEL ) ;
00377                new_label2 = 1 ;
00378             }
00379             else EDERR("illegal new label2") ;
00380          break ;
00381 
00382          case ADN_self_name:  /* processed now */
00383             self_name = va_arg( vararg_ptr , char * ) ;
00384             if( self_name != NULL ){
00385                MCW_strncpy( dset->self_name , self_name , THD_MAX_NAME ) ;
00386                new_self_name = 1 ;
00387             }
00388             else EDERR("illegal new self_name") ;
00389          break ;
00390 
00391          /** relationships to other datasets **/
00392 
00393          case ADN_warp_parent:  /* processed now */
00394             warp_parent = va_arg( vararg_ptr , THD_3dim_dataset * ) ;
00395             if( ISVALID_3DIM_DATASET(warp_parent) ){
00396                new_warp_parent = 1 ;
00397                dset->warp_parent = warp_parent ;
00398                MCW_strncpy(dset->warp_parent_name,warp_parent->self_name,THD_MAX_NAME) ;
00399                dset->warp_parent_idcode = warp_parent->idcode ;
00400             }
00401             else EDERR("illegal new warp_parent") ;
00402          break ;
00403 
00404          case ADN_warp:  /* processed now */
00405             warp = va_arg( vararg_ptr , THD_warp * ) ;
00406             if( ISVALID_WARP(warp) ){
00407                new_warp = 1 ;
00408                if( dset->warp == NULL ) dset->warp = myXtNew(THD_warp) ;
00409                *(dset->warp) =* warp ;
00410             } else EDERR("illegal new warp") ;
00411          break ;
00412 
00413          case ADN_anat_parent:  /* processed now */
00414             anat_parent = va_arg( vararg_ptr , THD_3dim_dataset * ) ;
00415             if( ISVALID_3DIM_DATASET(anat_parent) ){
00416                new_anat_parent = 1 ;
00417                dset->anat_parent = anat_parent ;
00418                MCW_strncpy(dset->anat_parent_name,anat_parent->self_name,THD_MAX_NAME) ;
00419                dset->anat_parent_idcode = anat_parent->idcode ;
00420             }
00421             else EDERR("illegal new anat_parent") ;
00422          break ;
00423 
00424          case ADN_anatpar_idcode:{ /* processed now [13 Dec 1999] */
00425             MCW_idcode * idc ;
00426             idc = va_arg( vararg_ptr , MCW_idcode * ) ;
00427             if( idc != NULL )
00428                dset->anat_parent_idcode = *idc ;
00429             else
00430                EDERR("illegal new anatpar_idcode") ;
00431          }
00432          break ;
00433 
00434       }  /*- end of switch on flag_arg -*/
00435 
00436       iarg++ ;
00437    } while( 1 ) ;  /* end of loop over arguments */
00438    va_end( vararg_ptr ) ;
00439    if( errnum > 0 ) RETURN(errnum) ;
00440 
00441    /**** carry out edits that were flagged above ****/
00442 
00443    /**---------- Need to reset the disk filename? ------------**/
00444    /** 22 Nov 2002: remove +orig etc. from prefix, if present **/
00445 
00446    if( new_prefix || new_directory_name || new_view_type ){
00447       char *nprefix = THD_deplus_prefix( prefix ) ;
00448 
00449       THD_init_diskptr_names( dset->dblk->diskptr ,
00450                               directory_name , NULL ,
00451                               nprefix , view_type , True ) ;
00452 
00453       if( DSET_IS_1D(dset) || DSET_IS_3D(dset) ){         /* 21 Mar 2003 */
00454         char *fname = dset->dblk->diskptr->brick_name ;
00455         int  ll = strlen(fname) ;
00456         fname[ll-10] = '\0' ;
00457         if( DSET_IS_1D(dset) || (DSET_NY(dset)==1 && DSET_NZ(dset)==1) )
00458           strcat(fname,".1D");
00459         else
00460           strcat(fname,".3D");
00461       }
00462 
00463       /** output of NIfTI-1.1 dataset: 06 May 2005 **/
00464 
00465       if( nprefix != NULL && ( STRING_HAS_SUFFIX(nprefix,".nii") ||
00466                                STRING_HAS_SUFFIX(nprefix,".nii.gz") ) ){
00467         char *fname = dset->dblk->diskptr->brick_name ;
00468         int  ll = strlen(fname) ;
00469         fname[ll-10] = '\0' ;
00470         if( STRING_HAS_SUFFIX(nprefix,".nii") ) strcat(fname,".nii") ;
00471         else                                    strcat(fname,".nii.gz") ;
00472       }
00473 
00474       if( nprefix != NULL ) free(nprefix) ;
00475    }
00476 
00477    /**----------- Need to reconfigure the spatial axes? -----------**/
00478    /**    Most of this code is from routine THD_3dim_from_block    **/
00479 
00480    redo_daxes = ( new_nxyz || new_xyzorg || new_xyzdel || new_xyzorient ) ;
00481 
00482    if( redo_daxes ){
00483       THD_dataxes * daxes = dset->daxes ;
00484       THD_diskptr * dkptr = dset->dblk->diskptr ;
00485 
00486       /** copy new stuff into the daxes structure **/
00487 
00488       if( new_nxyz ){
00489          daxes->nxx  = dkptr->dimsizes[0] = nxyz.ijk[0] ;
00490          daxes->nyy  = dkptr->dimsizes[1] = nxyz.ijk[1] ;
00491          daxes->nzz  = dkptr->dimsizes[2] = nxyz.ijk[2] ;
00492       }
00493 
00494       if( new_xyzorg ){
00495          daxes->xxorg = xyzorg.xyz[0] ;
00496          daxes->yyorg = xyzorg.xyz[1] ;
00497          daxes->zzorg = xyzorg.xyz[2] ;
00498       }
00499 
00500       if( new_xyzdel ){
00501          daxes->xxdel = xyzdel.xyz[0] ;
00502          daxes->yydel = xyzdel.xyz[1] ;
00503          daxes->zzdel = xyzdel.xyz[2] ;
00504       }
00505 
00506       if( new_xyzorient ){
00507          daxes->xxorient = xyzorient.ijk[0] ;
00508          daxes->yyorient = xyzorient.ijk[1] ;
00509          daxes->zzorient = xyzorient.ijk[2] ;
00510       }
00511 
00512       /*---------------------------------------*/
00513       /*-- set bounding box for this dataset --*/
00514       /*---------------------------------------*/
00515 
00516       daxes->xxmin = daxes->xxorg ;
00517       daxes->xxmax = daxes->xxorg + (daxes->nxx-1) * daxes->xxdel ;
00518       if( daxes->xxmin > daxes->xxmax ){
00519          float temp   = daxes->xxmin ;
00520          daxes->xxmin = daxes->xxmax ; daxes->xxmax = temp ;
00521       }
00522 
00523       daxes->yymin = daxes->yyorg ;
00524       daxes->yymax = daxes->yyorg + (daxes->nyy-1) * daxes->yydel ;
00525       if( daxes->yymin > daxes->yymax ){
00526          float temp   = daxes->yymin ;
00527          daxes->yymin = daxes->yymax ; daxes->yymax = temp ;
00528       }
00529 
00530       daxes->zzmin = daxes->zzorg ;
00531       daxes->zzmax = daxes->zzorg + (daxes->nzz-1) * daxes->zzdel ;
00532       if( daxes->zzmin > daxes->zzmax ){
00533          float temp   = daxes->zzmin ;
00534          daxes->zzmin = daxes->zzmax ; daxes->zzmax = temp ;
00535       }
00536 
00537 #ifdef EXTEND_BBOX
00538       daxes->xxmin -= 0.5 * daxes->xxdel ;  /* pushes edges back by 1/2  */
00539       daxes->xxmax += 0.5 * daxes->xxdel ;  /* voxel dimensions (the box */
00540       daxes->yymin -= 0.5 * daxes->yydel ;  /* defined above is based on */
00541       daxes->yymax += 0.5 * daxes->yydel ;  /* voxel centers, not edges) */
00542       daxes->zzmin -= 0.5 * daxes->zzdel ;
00543       daxes->zzmax += 0.5 * daxes->zzdel ;
00544 #endif
00545 
00546       /*----------------------------------------------------------------*/
00547       /*--  matrix that transforms to Dicom (left-posterior-superior) --*/
00548       /*----------------------------------------------------------------*/
00549 
00550       LOAD_ZERO_MAT(daxes->to_dicomm) ;
00551 
00552       switch( daxes->xxorient ){
00553          case ORI_R2L_TYPE:
00554          case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][0] = 1.0 ; break ;
00555          case ORI_P2A_TYPE:
00556          case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][0] = 1.0 ; break ;
00557          case ORI_I2S_TYPE:
00558          case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][0] = 1.0 ; break ;
00559       }
00560 
00561       switch( daxes->yyorient ){
00562          case ORI_R2L_TYPE:
00563          case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][1] = 1.0 ; break ;
00564          case ORI_P2A_TYPE:
00565          case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][1] = 1.0 ; break ;
00566          case ORI_I2S_TYPE:
00567          case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][1] = 1.0 ; break ;
00568       }
00569 
00570       switch( daxes->zzorient ){
00571          case ORI_R2L_TYPE:
00572          case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][2] = 1.0 ; break ;
00573          case ORI_P2A_TYPE:
00574          case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][2] = 1.0 ; break ;
00575          case ORI_I2S_TYPE:
00576          case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][2] = 1.0 ; break ;
00577       }
00578    }
00579 
00580    /**---------- Need to reconfigure the sub-bricks? ----------**/
00581 
00582    if( new_datum_all && new_datum_array ){
00583        EDERR("datum_all and datum_array can't be used together") ;
00584        RETURN(errnum) ;
00585    }
00586 
00587    redo_bricks = ( new_datum_all || new_datum_array ||
00588                    new_nvals     || new_nxyz          ) ;
00589 
00590    if( redo_bricks && THD_count_databricks(dset->dblk) > 0 ){
00591       EDERR("cannot reconfigure bricks that already are full") ;
00592       RETURN(errnum) ;
00593    }
00594 
00595    if( redo_bricks ){
00596       int old_nvals = dset->dblk->nvals ;
00597 #if 0
00598 fprintf(stderr,"EDIT_dset_items: about to redo_bricks\n") ;
00599 #endif
00600       if( ! new_nvals ) nvals = old_nvals ;
00601 
00602       /** make an array of data types, if one not provided **/
00603 
00604       if( ! new_datum_array ){
00605          datum_array = (int *) XtMalloc( sizeof(int) * nvals ) ;
00606 
00607 #if 0
00608 fprintf(stderr,"EDIT_dset_items: about to make datum_array\n") ;
00609 #endif
00610          for( ii=0 ; ii < nvals ; ii++ )
00611             datum_array[ii] =  (new_datum_all)  ? datum_all
00612                              : (ii < old_nvals) ? DSET_BRICK_TYPE(dset,ii)
00613                                                 : DSET_BRICK_TYPE(dset,0) ;
00614       }                                           /* 06 Apr 2005 [rickr] */
00615 
00616       if( new_nvals ){
00617          if( dset->dblk->nvals != nvals )
00618             THD_copy_datablock_auxdata( NULL , dset->dblk ) ; /* 30 Nov 1997 */
00619 
00620          myXtFree( dset->dblk->brick_bytes ) ;
00621          myXtFree( dset->dblk->brick_fac   ) ;
00622 
00623          dset->dblk->nvals = dset->dblk->diskptr->nvals = nvals ;
00624       }
00625 
00626       THD_init_datablock_brick( dset->dblk , nvals , datum_array ) ;
00627 
00628       if( ! new_datum_array ) myXtFree(datum_array) ;
00629    }
00630 
00631    /**---------- Need to add new brick_fac values? ----------**/
00632 
00633    if( new_brick_fac ){
00634       if( brick_fac != NULL ){
00635          for( ii=0 ; ii < dset->dblk->nvals ; ii++ )
00636             dset->dblk->brick_fac[ii] = brick_fac[ii] ;
00637       } else {
00638          for( ii=0 ; ii < dset->dblk->nvals ; ii++ )
00639             dset->dblk->brick_fac[ii] = 0.0 ;
00640       }
00641    }
00642 
00643    /** 30 Nov 1997: do just one brick_fac value **/
00644 
00645    if( new_brick_fac_one ){
00646       if( brick_fac_one_iv < 0 || brick_fac_one_iv >= dset->dblk->nvals ){
00647          EDERR("illegal index for ADN_brick_fac_one") ;
00648          RETURN(errnum) ;
00649       }
00650       dset->dblk->brick_fac[ brick_fac_one_iv ] = brick_fac_one ;
00651    }
00652 
00653    /**--------- 30 Nov 1997: add a single brick label value --------**/
00654 
00655    if( new_brick_label_one ){
00656       if( brick_label_one_iv < 0 || brick_label_one_iv >= dset->dblk->nvals ){
00657          EDERR("illegal index for ADN_brick_label_one") ;
00658          RETURN(errnum) ;
00659       }
00660 
00661       THD_store_datablock_label( dset->dblk, brick_label_one_iv, brick_label_one ) ;
00662    }
00663 
00664    /*---- add a single brick keywords value ----*/
00665 
00666    if( new_brick_keywords_one ){
00667       if( brick_keywords_one_iv < 0 || brick_keywords_one_iv >= dset->dblk->nvals ){
00668          EDERR("illegal index for ADN_brick_keywords_one") ;
00669          RETURN(errnum) ;
00670       }
00671 
00672       if( new_brick_keywords_one == 1 )
00673          THD_store_datablock_keywords( dset->dblk, brick_keywords_one_iv,
00674                                                    brick_keywords_one    );
00675       else if( new_brick_keywords_one == 2 )
00676          THD_append_datablock_keywords( dset->dblk, brick_keywords_one_iv,
00677                                                     brick_keywords_one    );
00678    }
00679 
00680    /*---- Add a single brick stataux value.
00681           The input is a float array formatted like so:
00682             <statcode> <npar> <value> ... <value>
00683           where <statcode> is a FUNC_*_TYPE code
00684                 <npar>     is the number of values to follow (may be 0);
00685                              normally is FUNC_need_stat_aux[<statcode>]
00686                 <value>    is an auxiliary statistical parameter needed
00687                              for data of type <statcode>                ----*/
00688 
00689    if( new_brick_stataux_one ){
00690       int jv , npar , kv , iv ;
00691 
00692       iv = brick_stataux_one_iv ;
00693 
00694       if( iv < 0 || iv >= dset->dblk->nvals ){
00695          EDERR("illegal index for ADN_brick_stataux_one") ;
00696          RETURN(errnum) ;
00697       }
00698 
00699       jv = brick_stataux_one[0] ;  /* statcode */
00700 
00701       npar = brick_stataux_one[1] ;  /* # of values present */
00702       if( npar < 0 ){
00703          EDERR("illegal npar for ADN_brick_stataux_one") ;
00704          RETURN(errnum) ;
00705       }
00706 
00707       kv = FUNC_need_stat_aux[jv] ;  /* # of values needed */
00708       if( npar > kv ) npar = kv ;
00709 
00710       THD_store_datablock_stataux( dset->dblk ,
00711                                    iv , jv , npar , brick_stataux_one + 2 ) ;
00712    }
00713 
00714    /**---------- Need to reconfigure the time axis? ----------**/
00715 
00716    redo_taxis = ( new_ntt   || new_nsl     || new_ttorg || new_ttdel ||
00717                   new_ttdur || new_zorg_sl || new_dz_sl || new_toff_sl ) ;
00718 
00719    if( ! new_ntt ) ntt = ISVALID_TIMEAXIS(dset->taxis) ? dset->taxis->ntt : 0 ;
00720 
00721    if( ntt == 0 && dset->taxis != NULL ){
00722       myXtFree( dset->taxis->toff_sl ) ;
00723       myXtFree( dset->taxis ) ;
00724       dset->taxis = NULL ;
00725    }
00726 
00727    redo_taxis = ( redo_taxis && ntt > 0 ) ;
00728 
00729    if( (new_nsl && nsl > 0) && !new_toff_sl ){    /* if we have new slice count */
00730       EDERR("have new_nsl but not new_toff_sl") ; /* but no new slice offsets */
00731       RETURN(errnum) ;
00732    }
00733 
00734    if( redo_taxis ){
00735       THD_timeaxis * taxis = dset->taxis ;
00736 
00737       if( taxis == NULL ){
00738          taxis          = dset->taxis     = myXtNew( THD_timeaxis ) ;
00739          taxis->type    = TIMEAXIS_TYPE ;
00740          taxis->toff_sl = NULL ;
00741          taxis->nsl     = 0 ;
00742          taxis->ttorg   = taxis->ttdel = taxis->ttdur = 0.0 ;
00743          taxis->ntt     = ntt ;
00744       }
00745 
00746       if( new_ntt     ) taxis->ntt     = ntt ;
00747       if( new_ttorg   ) taxis->ttorg   = ttorg ;
00748       if( new_ttdel   ) taxis->ttdel   = ttdel ;
00749       if( new_ttdur   ) taxis->ttdur   = ttdur ;
00750       if( new_zorg_sl ) taxis->zorg_sl = zorg_sl ;
00751       if( new_dz_sl   ) taxis->dz_sl   = dz_sl ;
00752 
00753       if( new_nsl ){
00754          taxis->nsl = nsl ;
00755          if( nsl > 0 )
00756             taxis->toff_sl = (float *) XtRealloc( (char *) taxis->toff_sl ,
00757                                                   sizeof(float) * nsl      ) ;
00758          else
00759             myXtFree(taxis->toff_sl) ;
00760       }
00761 
00762       if( new_toff_sl )
00763          for( ii=0 ; ii < taxis->nsl ; ii++ ) taxis->toff_sl[ii] = toff_sl[ii] ;
00764    }
00765 
00766    if( new_tunits ){
00767       THD_timeaxis * taxis = dset->taxis ;
00768 
00769       if( taxis == NULL ){
00770          EDERR("have new_tunits but have no time axis") ;
00771          RETURN(errnum) ;
00772       }
00773 
00774       taxis->units_type = tunits ;
00775    }
00776 
00777    /**--------------- Need to redo dataset type codes? ------------**/
00778    /**  Note that changing the type codes by themselves won't fix  **/
00779    /**  nvals or other such stuff -- that must be done separately. **/
00780 
00781    if( new_type      ) dset->type      = type ;
00782    if( new_view_type ) dset->view_type = view_type ;
00783 
00784    if( new_func_type ){
00785       if( (ISANAT(dset) && func_type <= LAST_ANAT_TYPE) ||
00786           (ISFUNC(dset) && func_type <= LAST_FUNC_TYPE)   ){
00787 
00788          dset->func_type = func_type ;
00789 
00790       } else{
00791          EDERR("illegal new_func type combination") ; RETURN(errnum) ;
00792       }
00793    }
00794 
00795    /****--------------- hopefully, we are done! ---------------****/
00796 
00797    RETURN(errnum) ;
00798 }
00799 
00800 
00801 /*-------------------------------------------------------------------*/
00802 /*! Remove any +???? suffix from a prefix, returning a new one.
00803     -- 22 Nov 2002 - RWCox
00804 ---------------------------------------------------------------------*/
00805 
00806 char * THD_deplus_prefix( char *prefix )
00807 {
00808    char *newprefix ;
00809    int nn ;
00810 
00811    if( prefix == NULL ) return NULL ;
00812 
00813    nn = strlen(prefix); newprefix = strdup(prefix);
00814 
00815    /* only remove the basic 3: +orig, +acpc +tlrc   17 May 2004 [rickr] */
00816    /* (blame Shruti) */
00817    if( nn > 4 &&   ( (strcmp(newprefix+nn-5,"+orig") == 0) ||
00818                      (strcmp(newprefix+nn-5,"+acpc") == 0) ||
00819                      (strcmp(newprefix+nn-5,"+tlrc") == 0)   ) )
00820       newprefix[nn-5] = '\0' ;
00821 
00822 /* old check
00823        isalpha(newprefix[nn-4]) &&
00824        isalpha(newprefix[nn-3]) &&
00825        isalpha(newprefix[nn-2]) &&
00826        isalpha(newprefix[nn-1])   ) newprefix[nn-5] = '\0' ;
00827 */
00828 
00829    return newprefix ;
00830 }
 

Powered by Plone

This site conforms to the following standards: