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  

3drefit.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 void Syntax(char *str)
00010 {
00011    int ii ;
00012 
00013    if( str != NULL ) ERROR_exit(str) ;  /* does not return */
00014 
00015    printf( "Changes some of the information inside a 3D dataset's header.\n"
00016            "Note that this program does NOT change the .BRIK file at all;\n"
00017            "the main purpose of 3drefit is to fix up errors made when\n"
00018            "using to3d.\n"
00019            "To see the current values stored in a .HEAD file, use the command\n"
00020            "'3dinfo dataset'.  Using 3dinfo both before and after 3drefit is\n"
00021            "a good idea to make sure the changes have been made correctly!\n\n"
00022          ) ;
00023 
00024    printf(
00025     "Usage: 3drefit [options] dataset ...\n"
00026     "where the options are\n"
00027     "  -orient code    Sets the orientation of the 3D volume(s) in the .BRIK.\n"
00028     "                  The code must be 3 letters, one each from the\n"
00029     "                  pairs {R,L} {A,P} {I,S}.  The first letter gives\n"
00030     "                  the orientation of the x-axis, the second the\n"
00031     "                  orientation of the y-axis, the third the z-axis:\n"
00032     "                     R = right-to-left         L = left-to-right\n"
00033     "                     A = anterior-to-posterior P = posterior-to-anterior\n"
00034     "                     I = inferior-to-superior  S = superior-to-inferior\n"
00035     "               ** WARNING: when changing the orientation, you must be sure\n"
00036     "                  to check the origins as well, to make sure that the volume\n"
00037     "                  is positioned correctly in space.\n"
00038     "\n"
00039     "  -xorigin distx  Puts the center of the edge voxel off at the given\n"
00040     "  -yorigin disty  distance, for the given axis (x,y,z); distances in mm.\n"
00041     "  -zorigin distz  (x=first axis, y=second axis, z=third axis).\n"
00042     "                  Usually, only -zorigin makes sense.  Note that this\n"
00043     "                  distance is in the direction given by the corresponding\n"
00044     "                  letter in the -orient code.  For example, '-orient RAI'\n"
00045     "                  would mean that '-zorigin 30' sets the center of the\n"
00046     "                  first slice at 30 mm Inferior.  See the to3d manual\n"
00047     "                  for more explanations of axes origins.\n"
00048     "               ** SPECIAL CASE: you can use the string 'cen' in place of\n"
00049     "                  a distance to force that axis to be re-centered.\n"
00050     "\n"
00051     "  -xorigin_raw xx Puts the center of the edge voxel at the given COORDINATE\n"
00052     "  -yorigin_raw yy rather than the given DISTANCE.  That is, these values\n"
00053     "  -zorigin_raw zz directly replace the offsets in the dataset header,\n"
00054     "                  without any possible sign changes.\n"
00055     "\n"
00056     "  -duporigin cset Copies the xorigin, yorigin, and zorigin values from\n"
00057     "                  the header of dataset 'cset'.\n"
00058     "\n"
00059     "  -dxorigin dx    Adds distance 'dx' (or 'dy', or 'dz') to the center\n"
00060     "  -dyorigin dy    coordinate of the edge voxel.  Can be used with the\n"
00061     "  -dzorigin dz    values input to the 'Nudge xyz' plugin.\n"
00062     "               ** WARNING: you can't use these options at the same\n"
00063     "                  time you use -orient.\n"
00064     "\n"
00065     "  -xdel dimx      Makes the size of the voxel the given dimension,\n"
00066     "  -ydel dimy      for the given axis (x,y,z); dimensions in mm.\n"
00067     "  -zdel dimz   ** WARNING: if you change a voxel dimension, you will\n"
00068     "                  probably have to change the origin as well.\n"
00069     "\n"
00070     "  -TR time        Changes the TR time to a new value (see 'to3d -help').\n"
00071     "  -notoff         Removes the slice-dependent time-offsets.\n"
00072     "  -Torg ttt       Set the time origin of the dataset to value 'ttt'.\n"
00073     "                  (Time origins are set to 0 in to3d.)\n"
00074     "               ** WARNING: these 3 options apply only to 3D+time datasets.\n"
00075     "\n"
00076     "  -newid          Changes the ID code of this dataset as well.\n"
00077     "\n"
00078     "  -nowarp         Removes all warping information from dataset.\n"
00079     "\n"
00080     "  -apar aset      Set the dataset's anatomy parent dataset to 'aset'\n"
00081     "               ** N.B.: The anatomy parent is the dataset from which the\n"
00082     "                  transformation from +orig to +acpc and +tlrc coordinates\n"
00083     "                  is taken.  It is appropriate to use -apar when there is\n"
00084     "                  more than 1 anatomical dataset in a directory that has\n"
00085     "                  been transformed.  In this way, you can be sure that\n"
00086     "                  AFNI will choose the correct transformation.  You would\n"
00087     "                  use this option on all the +orig dataset that are\n"
00088     "                  aligned with 'aset' (i.e., that were acquired in the\n"
00089     "                  same scanning session).\n"
00090     "               ** N.B.: Special cases of 'aset'\n"
00091     "                   aset = NULL --> remove the anat parent info from the dataset\n"
00092     "                   aset = SELF --> set the anat parent to be the dataset itself\n"
00093     "\n"
00094     "  -clear_bstat    Clears the statistics (min and max) stored for each sub-brick\n"
00095     "                  in the dataset.  This is useful if you have done something to\n"
00096     "                  modify the contents of the .BRIK file associated with this\n"
00097     "                  dataset.\n"
00098     "  -redo_bstat     Re-computes the statistics for each sub-brick.  Requires\n"
00099     "                  reading the .BRIK file, of course.  Also does -clear_bstat\n"
00100     "                  before recomputing statistics, so that if the .BRIK read\n"
00101     "                  fails for some reason, then you'll be left without stats.\n"
00102     "\n"
00103     "  -statpar v ...  Changes the statistical parameters stored in this\n"
00104     "                  dataset.  See 'to3d -help' for more details.\n"
00105     "\n"
00106     "  -markers        Adds an empty set of AC-PC markers to the dataset,\n"
00107     "                  if it can handle them (is anatomical, is in the +orig\n"
00108     "                  view, and isn't 3D+time).\n"
00109     "               ** WARNING: this will erase any markers that already exist!\n"
00110     "\n"
00111     "  -view code      Changes the 'view' to be 'code', where the string 'code'\n"
00112     "                  is one of 'orig', 'acpc', or 'tlrc'.\n"
00113     "               ** WARNING: The program will also change the .HEAD and .BRIK\n"
00114     "                  filenames to match.  If the dataset filenames already\n"
00115     "                  exist in the '+code' view, then this option will fail.\n"
00116     "                  You will have to rename the dataset files before trying\n"
00117     "                  to use '-view'.  If you COPY the files and then use\n"
00118     "                  '-view', don't forget to use '-newid' as well!\n"
00119     "\n"
00120     "  -label2 llll    Set the 'label2' field in a dataset .HEAD file to the\n"
00121     "                  string 'llll'.  (Can be used as in AFNI window titlebars.)\n"
00122     "\n"
00123     "  -denote         Means to remove all possibly-identifying notes from\n"
00124     "                  the header.  This includes the History Note, other text\n"
00125     "                  Notes, keywords, and labels.\n"
00126     "\n"
00127     "  -byteorder bbb  Sets the byte order string in the header.\n"
00128     "                  Allowable values for 'bbb' are:\n"
00129     "                     LSB_FIRST   MSB_FIRST   NATIVE_ORDER\n"
00130     "                  Note that this does not change the .BRIK file!\n"
00131     "                  This is done by programs 2swap and 4swap.\n"
00132     "\n"
00133     "  -appkey ll      Appends the string 'll' to the keyword list for the\n"
00134     "                  whole dataset.\n"
00135     "  -repkey ll      Replaces the keyword list for the dataset with the\n"
00136     "                  string 'll'.\n"
00137     "  -empkey         Destroys the keyword list for the dataset.\n"
00138    ) ;
00139 
00140    printf(
00141     "\n"
00142     "  -atrcopy dd nn  Copy AFNI header attribute named 'nn' from dataset 'dd'\n"
00143     "                  into the header of the dataset(s) being modified.\n"
00144     "                  For more information on AFNI header attributes, see\n"
00145     "                  documentation file README.attributes. More than one\n"
00146     "                  '-atrcopy' option can be used.\n"
00147     "          **N.B.: This option is for those who know what they are doing!\n"
00148     "                  It can only be used to alter attributes that are NOT\n"
00149     "                  directly mapped into dataset internal structures, since\n"
00150     "                  those structures are mapped back into attribute values\n"
00151     "                  as the dataset is being written to disk.  If you want\n"
00152     "                  to change such an attribute, you have to use the\n"
00153     "                  corresponding 3drefit option directly.\n"
00154     "\n"
00155     "  -atrstring n 'x' Copy the string 'x' into the dataset(s) being\n"
00156     "                   modified, giving it the attribute name 'n'.\n"
00157     "                   To be safe, the 'x' string should be in quotes.\n"
00158     "          **N.B.: You can store attributes with almost any name in\n"
00159     "                  the .HEAD file.  AFNI will ignore those it doesn't\n"
00160     "                  know anything about.  This technique can be a way of\n"
00161     "                  communicating information between programs.  However,\n"
00162     "                  when most AFNI programs write a new dataset, they will\n"
00163     "                  not preserve any such non-standard attributes.\n"
00164    ) ;
00165 
00166    printf(
00167     "\n"
00168     "  -'type'         Changes the type of data that is declared for this\n"
00169     "                  dataset, where 'type' is chosen from the following:\n"
00170    ) ;
00171    printf("       ANATOMICAL TYPES\n") ;
00172    for( ii=FIRST_ANAT_TYPE ; ii <= LAST_ANAT_TYPE ; ii++ ){
00173       printf("     %8s == %-16.16s",ANAT_prefixstr[ii],ANAT_typestr[ii] ) ;
00174       if( (ii-FIRST_ANAT_TYPE)%2 == 1 ) printf("\n") ;
00175    }
00176    if( (ii-FIRST_ANAT_TYPE)%2 == 1 ) printf("\n") ;
00177    printf("       FUNCTIONAL TYPES\n") ;
00178    for( ii=FIRST_FUNC_TYPE ; ii <= LAST_FUNC_TYPE ; ii++ ){
00179       printf("     %8s == %-16.16s",FUNC_prefixstr[ii],FUNC_typestr[ii] ) ;
00180       if( (ii-FIRST_ANAT_TYPE)%2 == 1 ) printf("\n") ;
00181    }
00182    if( (ii-FIRST_ANAT_TYPE)%2 == 1 ) printf("\n") ;
00183 
00184    printf(           /* 08 Jun 2004 */
00185     "-copyaux auxset   Copies the 'auxiliary' data from dataset 'auxset'\n"
00186     "                  over the auxiliary data for the dataset being\n"
00187     "                  modified.  Auxiliary data comprises sub-brick labels,\n"
00188     "                  keywords, and statistics codes.\n"
00189     "                  '-copyaux' occurs BEFORE the '-sub' operations below,\n"
00190     "                  so you can use those to alter the auxiliary data\n"
00191     "                  that is copied from auxset.\n"
00192     "\n" ) ;
00193 
00194    printf(
00195     "The options below allow you to attach auxiliary data to sub-bricks\n"
00196     "in the dataset.  Each option may be used more than once so that\n"
00197     "multiple sub-bricks can be modified in a single run of 3drefit.\n"
00198     "\n"
00199     "  -sublabel  n ll  Attach to sub-brick #n the label string 'll'.\n"
00200     "  -subappkey n ll  Add to sub-brick #n the keyword string 'll'.\n"
00201     "  -subrepkey n ll  Replace sub-brick #n's keyword string with 'll'.\n"
00202     "  -subempkey n     Empty out sub-brick #n' keyword string\n"
00203     "\n"
00204     "  -substatpar n type v ...\n"
00205     "                  Attach to sub-brick #n the statistical type and\n"
00206     "                  the auxiliary parameters given by values 'v ...',\n"
00207     "                  where 'type' is one of the following:\n"
00208    ) ;
00209    printf("         type  Description  PARAMETERS\n"
00210           "         ----  -----------  ----------------------------------------\n" ) ;
00211    for( ii=FIRST_FUNC_TYPE ; ii <= LAST_FUNC_TYPE ; ii++ ){
00212      if( FUNC_IS_STAT(ii) )
00213        printf("         %4s  %-11.11s  %s\n",
00214               FUNC_prefixstr[ii] , FUNC_typestr[ii]+6 , FUNC_label_stat_aux[ii] ) ;
00215    }
00216    printf(
00217     "\n"
00218     "The following options allow you to modify VOLREG fields:\n"
00219     "  -vr_mat <val1> ... <val12>   Use these twelve values for VOLREG_MATVEC_index.\n"
00220     "  [-vr_mat_ind <index>]        Index of VOLREG_MATVEC_index field to be modified. Optional, default index is 0.\n"
00221     "                               Note: You can only modify one VOLREG_MATVEC_index at a time.\n"
00222     "  -vr_center_old <x> <y> <z>   Use these 3 values for VOLREG_CENTER_OLD.\n"
00223     "  -vr_center_base <x> <y> <z>  Use these 3 values for VOLREG_CENTER_BASE.\n"
00224     "\n"
00225    );
00226 
00227    printf("++ Last program update: 08 Jul 2005\n");
00228 
00229    exit(0) ;
00230 }
00231 
00232 #define ASET_NULL 1
00233 #define ASET_SELF 2
00234 
00235 int main( int argc , char * argv[] )
00236 {
00237    THD_3dim_dataset * dset , * aset = NULL ;
00238                       int aset_code = 0    ; /* 14 Dec 1999 */
00239    THD_dataxes      * daxes ;
00240    int new_stuff = 0 ;
00241    int new_orient = 0 ; char orient_code[4] ; int xxor,yyor,zzor ;
00242    int new_xorg   = 0 ; float xorg ; int cxorg=0, dxorg=0 , duporg=0 ;
00243    int new_yorg   = 0 ; float yorg ; int cyorg=0, dyorg=0 ;
00244    int new_zorg   = 0 ; float zorg ; int czorg=0, dzorg=0 ;
00245    int new_xdel   = 0 ; float xdel ;
00246    int new_ydel   = 0 ; float ydel ;
00247    int new_zdel   = 0 ; float zdel ;
00248    int new_TR     = 0 ; float TR ;
00249    int new_Torg   = 0 ; float Torg ; /* 29 Jan 2003 */
00250    int new_tunits = 0 ; int tunits ;
00251    int new_idcode = 0 ;
00252    int new_nowarp = 0 ;
00253    int new_stataux= 0 ; float stataux[MAX_STAT_AUX] ;
00254    int new_type   = 0 ; int dtype , ftype , nvals ;
00255    int new_markers= 0 ;
00256    int new_view   = 0 ; int vtype ;
00257    int new_key    = 0 ; char * key ;
00258    int new_byte_order = 0 ;          /* 25 Apr 1998 */
00259    int new_toff_sl    = 0 ;          /* 12 Feb 2001 */
00260    int clear_bstat    = 0 ;          /* 28 May 2002 */
00261    int redo_bstat     = 0 ;          /* 01 Feb 2005 */
00262    int copyaux        = 0 ;          /* 08 Jun 2004 */
00263    THD_3dim_dataset *auxset=NULL ;   /* 08 Jun 2004 */
00264    char *new_label2   = NULL ;       /* 21 Dec 2004 */
00265    int denote         = 0 ;          /* 08 Jul 2005 */
00266 
00267    char str[256] ;
00268    int  iarg , ii ;
00269 
00270    typedef struct { int iv ; char lab[32] ; }              SUBlabel   ;
00271    typedef struct { int iv ; float par[MAX_STAT_AUX+2] ; } SUBstatpar ;
00272    typedef struct { int iv , code ; char * keyword ; }     SUBkeyword ;
00273    int nsublab     = 0 ; SUBlabel *   sublab     = NULL ;
00274    int nsubstatpar = 0 ; SUBstatpar * substatpar = NULL ;
00275    int nsubkeyword = 0 ; SUBkeyword * subkeyword = NULL ;
00276    char *cpt ;
00277    int iv ;
00278 
00279    float volreg_mat[12];
00280    float center_old[3];
00281    float center_base[3];
00282    int Do_volreg_mat = 0, Do_center_old = 0, Do_center_base = 0,
00283        volreg_matind = 0, icnt = 0;
00284    char *lcpt=NULL;
00285 
00286    int   num_atrcopy = 0 ;    /* 03 Aug 2005 */
00287    ATR_any **atrcopy = NULL ;
00288 
00289    /*-------------------------- help me if you can? --------------------------*/
00290 
00291    if( argc < 2 || strncmp(argv[1],"-help",4) == 0 ) Syntax(NULL) ;
00292 
00293    iarg = 1 ;
00294 
00295    /*-- 20 Apr 2001: addto the arglist, if user wants to [RWCox] --*/
00296 
00297    mainENTRY("3drefit main"); machdep() ; PRINT_VERSION("3drefit") ;
00298 
00299    { int new_argc ; char ** new_argv ;
00300      addto_args( argc , argv , &new_argc , &new_argv ) ;
00301      if( new_argv != NULL ){ argc = new_argc ; argv = new_argv ; }
00302    }
00303 
00304    AFNI_logger("3drefit",argc,argv) ;
00305 
00306    while( iarg < argc && argv[iarg][0] == '-' ){
00307 
00308 #if 0
00309       if( strncmp(argv[iarg],"-v",5) == 0 ){ verbose = 1 ; iarg++ ; continue ; }
00310 #endif
00311 
00312       /*----- -atrcopy dd nn [03 Aug 2005] -----*/
00313 
00314       if( strcmp(argv[iarg],"-atrcopy") == 0 ){
00315         THD_3dim_dataset *qset ; ATR_any *atr ;
00316 
00317         if( iarg+2 >= argc ) Syntax("need 2 arguments after -atrcopy!") ;
00318 
00319         qset = THD_open_dataset( argv[++iarg] ) ;
00320         if( qset == NULL ){
00321           WARNING_message("Can't open -atrcopy dataset %s",argv[iarg]) ;
00322           iarg++ ; goto atrcopy_done ;
00323         }
00324         atr = THD_find_atr( qset->dblk , argv[++iarg] ) ;
00325         if( atr == NULL ){
00326           WARNING_message("Can't find attribute %s in -atrcopy dataset %s",
00327                           argv[iarg],argv[iarg-1]) ;
00328           DSET_delete(qset) ; goto atrcopy_done ;
00329         }
00330 
00331         atrcopy = (ATR_any **)realloc( (void *)atrcopy ,
00332                                        sizeof(ATR_any *)*(num_atrcopy+1) ) ;
00333         atrcopy[num_atrcopy++] = THD_copy_atr( atr ) ;
00334 
00335         DSET_delete(qset) ; new_stuff++ ;
00336 
00337        atrcopy_done:
00338         iarg++ ; continue ;
00339       }
00340 
00341       /*----- -atrstring nn xx [03 Aug 2005] -----*/
00342 
00343       if( strcmp(argv[iarg],"-atrstring") == 0 ){
00344         ATR_string *atr ; char *aname , *xx ;
00345 
00346         if( iarg+2 >= argc ) Syntax("need 2 arguments after -atrstring!") ;
00347 
00348         aname = argv[++iarg] ;
00349         if( !THD_filename_pure(aname) ){
00350           WARNING_message("Illegal -atrstring name %s",aname) ;
00351           iarg++ ; goto atrstring_done ;
00352         }
00353         xx  = argv[++iarg] ;
00354         atr = (ATR_string *)XtMalloc(sizeof(ATR_string)) ;
00355 
00356         atr->type = ATR_STRING_TYPE ;
00357         atr->name = XtNewString( aname ) ;
00358         atr->nch  = strlen(xx)+1 ; ;
00359         atr->ch   = (char *)XtMalloc( sizeof(char) * atr->nch ) ;
00360         memcpy( atr->ch , xx , sizeof(char) * atr->nch ) ;
00361 
00362         atrcopy = (ATR_any **)realloc( (void *)atrcopy ,
00363                                        sizeof(ATR_any *)*(num_atrcopy+1) ) ;
00364         atrcopy[num_atrcopy++] = (ATR_any *)atr ;
00365 
00366         new_stuff++ ;
00367        atrstring_done:
00368         iarg++ ; continue ;
00369       }
00370 
00371 
00372       /*----- -denote [08 Jul 2005] -----*/
00373 
00374       if( strcmp(argv[iarg],"-denote") == 0 ){
00375         denote = 1 ; new_stuff++ ; iarg++ ; continue ;
00376       }
00377 
00378       /*----- -copyaux auxset [08 Jun 2004] -----*/
00379 
00380       if( strcmp(argv[iarg],"-copyaux") == 0 ){
00381 
00382          if( iarg+1 >= argc ) Syntax("need 1 argument after -copyaux!") ;
00383 
00384          if( auxset != NULL ) Syntax("Can't have more than one -copyaux option!") ;
00385 
00386          iarg++ ; copyaux = 1 ;
00387          if( strcmp(argv[iarg],"NULL") == 0 ){  /* special case */
00388             auxset = NULL ;
00389          } else {
00390             auxset = THD_open_one_dataset( argv[iarg] ) ;
00391             if( auxset == NULL ) Syntax("Can't open -copyaux dataset!") ;
00392          }
00393 
00394          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00395       }
00396 
00397       /*----- -apar aset [14 Oct 1999] -----*/
00398 
00399       if( strcmp(argv[iarg],"-apar")       == 0 ||
00400           strcmp(argv[iarg],"-anatparent") == 0 ||
00401           strcmp(argv[iarg],"-aset")       == 0    ){
00402 
00403          if( iarg+1 >= argc )
00404             Syntax("need 1 argument after -apar!") ;
00405 
00406          if( aset != NULL || aset_code != 0 )                 /* 13-14 Dec 1999 */
00407             Syntax("Can't have more than one -apar option!");
00408 
00409          iarg++ ;
00410          if( strcmp(argv[iarg],"NULL") == 0 ){    /* 14 Dec 1999: special cases */
00411             aset_code = ASET_NULL ;
00412          } else if( strcmp(argv[iarg],"SELF") == 0 ){
00413             aset_code = ASET_SELF ;
00414          } else {
00415             aset = THD_open_one_dataset( argv[iarg] ) ;
00416             if( aset == NULL )
00417                Syntax("Can't open -apar dataset!") ;
00418          }
00419 
00420          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00421       }
00422 
00423       /*----- -clear_bstat option [28 May 2002] -----*/
00424 
00425       if( strcmp(argv[iarg],"-clear_bstat") == 0 ){
00426          clear_bstat = 1 ;
00427          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00428       }
00429 
00430       if( strcmp(argv[iarg],"-redo_bstat") == 0 ){  /* 01 Feb 2005 */
00431          clear_bstat = 1 ; redo_bstat = 1 ;
00432          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00433       }
00434 
00435       /*----- -byteorder option [25 April 1998] -----*/
00436 
00437       if( strncmp(argv[iarg],"-byteorder",7) == 0 ){
00438          if( iarg+1 >= argc )
00439             Syntax("need 1 argument after -byteorder!") ;
00440 
00441          iarg++ ;
00442          if( strcmp(argv[iarg],LSB_FIRST_STRING) == 0 )
00443             new_byte_order = LSB_FIRST ;
00444          else if( strcmp(argv[iarg],MSB_FIRST_STRING) == 0 )
00445             new_byte_order = MSB_FIRST ;
00446          else if( strcmp(argv[iarg],NATIVE_STRING) == 0 )
00447             new_byte_order = mri_short_order() ;
00448          else
00449             Syntax("illegal argument after -byteorder!") ;
00450 
00451          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00452       }
00453 
00454       /*----- -sublabel option -----*/
00455 
00456       if( strncmp(argv[iarg],"-sublabel",7) == 0 ){
00457          if( iarg+2 >= argc )
00458             Syntax("need 2 arguments after -sublabel!") ;
00459 
00460          iv = strtol( argv[++iarg] , &cpt , 10 ) ;
00461          if( iv < 0 || iv == 0 && cpt == argv[iarg] )
00462             Syntax("illegal sub-brick index after -sublabel!") ;
00463 
00464          sublab = (SUBlabel *) XtRealloc( (char *)sublab ,
00465                                           sizeof(SUBlabel) * (nsublab+1) ) ;
00466 
00467          sublab[nsublab].iv = iv ;
00468          MCW_strncpy( sublab[nsublab].lab , argv[++iarg] , 32 ) ;
00469          nsublab++ ; new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00470       }
00471 
00472       /*----- -subkeyword options -----*/
00473 
00474       if( strncmp(argv[iarg],"-subappkey",7) == 0 ||
00475           strncmp(argv[iarg],"-subrepkey",7) == 0 ||
00476           strncmp(argv[iarg],"-subempkey",7) == 0   ){
00477 
00478          int code , npl ;
00479               if( strncmp(argv[iarg],"-subappkey",7) == 0 ) code = 1 ;
00480          else if( strncmp(argv[iarg],"-subrepkey",7) == 0 ) code = 2 ;
00481          else                                               code = 3 ;
00482 
00483          npl = (code == 3) ? 1 : 2 ;
00484          if( iarg+npl >= argc )
00485             Syntax("need arguments after -sub...key!") ;
00486 
00487          iv = strtol( argv[++iarg] , &cpt , 10 ) ;
00488          if( iv < 0 || iv == 0 && cpt == argv[iarg] )
00489             Syntax("illegal sub-brick index after -sub...key!") ;
00490 
00491          subkeyword = (SUBkeyword *) XtRealloc( (char *)subkeyword ,
00492                                                 sizeof(SUBkeyword)*(nsubkeyword+1) ) ;
00493 
00494          subkeyword[nsubkeyword].iv   = iv ;
00495          subkeyword[nsubkeyword].code = code ;
00496          if( code != 3 ) subkeyword[nsubkeyword].keyword = argv[++iarg] ;
00497 
00498          nsubkeyword++ ; new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00499       }
00500 
00501       /*----- -keywords options -----*/
00502 
00503       if( strncmp(argv[iarg],"-appkey",4) == 0 ||
00504           strncmp(argv[iarg],"-repkey",4) == 0 ||
00505           strncmp(argv[iarg],"-empkey",4) == 0   ){
00506 
00507          int code , npl ;
00508               if( strncmp(argv[iarg],"-appkey",4) == 0 ) code = 1 ;
00509          else if( strncmp(argv[iarg],"-repkey",4) == 0 ) code = 2 ;
00510          else                                            code = 3 ;
00511 
00512          npl = (code == 3) ? 0 : 1 ;
00513          if( iarg+code >= argc )
00514             Syntax("need arguments after -...key!") ;
00515 
00516          new_key = code ;
00517          if( code != 3 ) key = argv[++iarg] ;
00518          new_stuff++ ; iarg++ ; continue ;  /* go to next arg */
00519       }
00520 
00521       /*----- -substatpar option -----*/
00522 
00523       if( strncmp(argv[iarg],"-substatpar",7) == 0 ){
00524          int fc ; float val ;
00525 
00526          if( iarg+2 >= argc )
00527             Syntax("need at least 2 arguments after -substatpar!") ;
00528 
00529          iv = strtol( argv[++iarg] , &cpt , 10 ) ;
00530          if( iv < 0 || iv == 0 && cpt == argv[iarg] )
00531             Syntax("illegal sub-brick index after -substatpar!") ;
00532 
00533          iarg++ ;
00534          if( strlen(argv[iarg]) < 3 )
00535             Syntax("illegal type code after -substatpar!") ;
00536          fc = (argv[iarg][0] == '-') ? 1 : 0 ;
00537 
00538          for( ii=FIRST_FUNC_TYPE ; ii <= LAST_FUNC_TYPE ; ii++ ){
00539             if( ! FUNC_IS_STAT(ii) ) continue ;
00540             if( strncmp( &(argv[iarg][fc]) ,
00541                          FUNC_prefixstr[ii] , THD_MAX_PREFIX ) == 0 ) break ;
00542          }
00543 
00544          if( ii > LAST_FUNC_TYPE )
00545             Syntax("unknown type code after -substatpar!") ;
00546 
00547          substatpar = (SUBstatpar *) XtRealloc( (char *)substatpar ,
00548                                                 sizeof(SUBstatpar) * (nsubstatpar+1) ) ;
00549 
00550          substatpar[nsubstatpar].iv     = iv ;
00551          substatpar[nsubstatpar].par[0] = ii ;
00552          substatpar[nsubstatpar].par[1] = MAX_STAT_AUX ;
00553 
00554          for( ii=0 ; ii < MAX_STAT_AUX ; ii++ )
00555             substatpar[nsubstatpar].par[ii+2] = 0.0 ;
00556 
00557          ii = 2 ; iarg++ ;
00558          do{
00559             val = strtod( argv[iarg] , &cpt ) ;
00560             if( *cpt != '\0' ) break ;
00561             substatpar[nsubstatpar].par[ii++] = val ;
00562             iarg++ ;
00563          } while( iarg < argc ) ;
00564 
00565          nsubstatpar++ ; new_stuff++ ; continue ;  /* go to next arg */
00566       }
00567 
00568       /*----- -orient code option -----*/
00569 
00570 #define ORCODE(aa) \
00571   ( (aa)=='R' ? ORI_R2L_TYPE : (aa)=='L' ? ORI_L2R_TYPE : \
00572     (aa)=='P' ? ORI_P2A_TYPE : (aa)=='A' ? ORI_A2P_TYPE : \
00573     (aa)=='I' ? ORI_I2S_TYPE : (aa)=='S' ? ORI_S2I_TYPE : ILLEGAL_TYPE )
00574 
00575 #define OR3OK(x,y,z) ( ((x)&6) + ((y)&6) + ((z)&6) == 6 )
00576 
00577       if( strncmp(argv[iarg],"-orient",4) == 0 ){
00578          char acod ;
00579 
00580          if( iarg+1 >= argc ) Syntax("need an argument after -orient!");
00581 
00582          MCW_strncpy(orient_code,argv[++iarg],4) ;
00583          if( strlen(orient_code) != 3 ) Syntax("Illegal -orient code") ;
00584 
00585          acod = toupper(orient_code[0]) ; xxor = ORCODE(acod) ;
00586          acod = toupper(orient_code[1]) ; yyor = ORCODE(acod) ;
00587          acod = toupper(orient_code[2]) ; zzor = ORCODE(acod) ;
00588 
00589         if( xxor<0 || yyor<0 || zzor<0 || ! OR3OK(xxor,yyor,zzor) )
00590            Syntax("Unusable -orient code!") ;
00591 
00592          new_orient = 1 ; new_stuff++ ;
00593          iarg++ ; continue ;  /* go to next arg */
00594       }
00595 
00596       /** -?origin dist **/
00597 
00598       if( strcmp(argv[iarg],"-xorigin") == 0 ){
00599          if( ++iarg >= argc ) Syntax("need an argument after -xorigin!");
00600          if( strncmp(argv[iarg],"cen",3) == 0 ) cxorg = 1 ;
00601          else                                   xorg  = strtod(argv[iarg],NULL) ;
00602          dxorg = 0 ; new_xorg = 1 ; new_stuff++ ;
00603          iarg++ ; continue ;  /* go to next arg */
00604       }
00605 
00606       if( strcmp(argv[iarg],"-yorigin") == 0 ){
00607          if( ++iarg >= argc ) Syntax("need an argument after -yorigin!");
00608          if( strncmp(argv[iarg],"cen",3) == 0 ) cyorg = 1 ;
00609          else                                   yorg  = strtod(argv[iarg],NULL) ;
00610          dyorg = 0 ; new_yorg = 1 ; new_stuff++ ;
00611          iarg++ ; continue ;  /* go to next arg */
00612       }
00613 
00614       if( strcmp(argv[iarg],"-zorigin") == 0 ){
00615          if( ++iarg >= argc ) Syntax("need an argument after -zorigin!");
00616          if( strncmp(argv[iarg],"cen",3) == 0 ) czorg = 1 ;
00617          else                                   zorg  = strtod(argv[iarg],NULL) ;
00618          dzorg = 0 ; new_zorg = 1 ; new_stuff++ ;
00619          iarg++ ; continue ;  /* go to next arg */
00620       }
00621 
00622       /* 13 Sep 2000: -duporigin */
00623 
00624       if( strcmp(argv[iarg],"-duporigin") == 0 ){
00625          THD_3dim_dataset * cset ;
00626          if( ++iarg >= argc ) Syntax("need an argument after -duporigin!");
00627          cset = THD_open_dataset( argv[iarg] ) ;
00628          if( cset == NULL ) Syntax("couldn't open -duporigin dataset!");
00629          daxes = cset->daxes ;
00630          xorg = daxes->xxorg ; yorg = daxes->yyorg ; zorg = daxes->zzorg ;
00631          cxorg = cyorg = czorg = dxorg = dyorg = dzorg = 0 ;
00632          new_xorg = new_yorg = new_zorg = duporg = 1 ; new_stuff++ ;
00633          DSET_delete(cset) ;
00634          iarg++ ; continue ;  /* go to next arg */
00635       }
00636 
00637       /* 02 Mar 2000: -d?origin stuff, to go with plug_nudge.c */
00638 
00639       if( strncmp(argv[iarg],"-dxorigin",4) == 0 ){
00640          if( ++iarg >= argc ) Syntax("need an argument after -dxorigin!");
00641          xorg = strtod(argv[iarg],NULL) ; dxorg = 1 ; cxorg = 0 ;
00642          new_xorg = 1 ; new_stuff++ ;
00643          iarg++ ; continue ;  /* go to next arg */
00644       }
00645 
00646       if( strncmp(argv[iarg],"-dyorigin",4) == 0 ){
00647          if( ++iarg >= argc ) Syntax("need an argument after -dyorigin!");
00648          yorg = strtod(argv[iarg],NULL) ; dyorg = 1 ; cyorg = 0 ;
00649          new_yorg = 1 ; new_stuff++ ;
00650          iarg++ ; continue ;  /* go to next arg */
00651       }
00652 
00653       if( strncmp(argv[iarg],"-dzorigin",4) == 0 ){
00654          if( ++iarg >= argc ) Syntax("need an argument after -dzorigin!");
00655          zorg = strtod(argv[iarg],NULL) ; dzorg = 1 ; czorg = 0 ;
00656          new_zorg = 1 ; new_stuff++ ;
00657          iarg++ ; continue ;  /* go to next arg */
00658       }
00659 
00660       /** 04 Oct 2002: _raw origins **/
00661 
00662       if( strcmp(argv[iarg],"-xorigin_raw") == 0 ){
00663          if( ++iarg >= argc ) Syntax("need an argument after -xorigin_raw!");
00664          xorg     = strtod(argv[iarg],NULL) ; cxorg = dxorg = 0 ;
00665          new_xorg = 2 ; new_stuff++ ;
00666          iarg++ ; continue ;  /* go to next arg */
00667       }
00668 
00669       if( strcmp(argv[iarg],"-yorigin_raw") == 0 ){
00670          if( ++iarg >= argc ) Syntax("need an argument after -yorigin_raw!");
00671          yorg     = strtod(argv[iarg],NULL) ; cyorg = dyorg = 0 ;
00672          new_yorg = 2 ; new_stuff++ ;
00673          iarg++ ; continue ;  /* go to next arg */
00674       }
00675 
00676       if( strcmp(argv[iarg],"-zorigin_raw") == 0 ){
00677          if( ++iarg >= argc ) Syntax("need an argument after -zorigin_raw!");
00678          zorg     = strtod(argv[iarg],NULL) ; czorg = dzorg = 0 ;
00679          new_zorg = 2 ; new_stuff++ ;
00680          iarg++ ; continue ;  /* go to next arg */
00681       }
00682 
00683       /** 04 Oct 2002: zadd VOLREG fields **/
00684       if( strcmp(argv[iarg],"-vr_mat") == 0 ){
00685          if( iarg+12 >= argc ) Syntax("need 12 arguments after -vr_mat!");
00686          icnt = 0;
00687          while (icnt < 12) {
00688             ++iarg;
00689             volreg_mat[icnt] = strtod(argv[iarg], &lcpt) ; if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00690             ++icnt;
00691          }
00692          Do_volreg_mat = 1; new_stuff++ ;
00693          ++iarg;
00694          continue ;  /* go to next arg */
00695       }
00696 
00697       if( strcmp(argv[iarg],"-vr_mat_ind") == 0) {
00698          if (++iarg >= argc) Syntax("need 1 argument after -vr_mat_ind!");
00699          volreg_matind = (int)strtol(argv[iarg], &lcpt, 10); if (*lcpt != '\0') Syntax("Bad syntax in number argument!");
00700          ++iarg;
00701          continue ;  /* go to next arg */
00702       }
00703 
00704       if( strcmp(argv[iarg],"-vr_cen_old") == 0) {
00705          if (iarg+3 >= argc) Syntax("need 3 arguments after -vr_cen_old");
00706          ++iarg;
00707          center_old[0] = strtod(argv[iarg],&lcpt) ; ++iarg; if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00708          center_old[1] = strtod(argv[iarg],&lcpt) ; ++iarg; if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00709          center_old[2] = strtod(argv[iarg],&lcpt) ;  if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00710          Do_center_old = 1; new_stuff++ ;
00711          ++iarg;
00712          continue ;  /* go to next arg */
00713       }
00714 
00715       if( strcmp(argv[iarg],"-vr_cen_base") == 0) {
00716          if (iarg+3 >= argc) Syntax("need 3 arguments after -vr_cen_base");
00717          ++iarg;
00718          center_base[0] = strtod(argv[iarg],&lcpt) ; ++iarg; if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00719          center_base[1] = strtod(argv[iarg],&lcpt) ; ++iarg; if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00720          center_base[2] = strtod(argv[iarg],&lcpt) ;  if (*lcpt != '\0') Syntax("Bad syntax in list of numbers!");
00721          Do_center_base = 1; new_stuff++ ;
00722          ++iarg;
00723          continue ;  /* go to next arg */
00724       }
00725 
00726       /** -?del dim **/
00727 
00728       if( strncmp(argv[iarg],"-xdel",4) == 0 ){
00729          if( iarg+1 >= argc ) Syntax("need an argument after -xdel!");
00730          xdel = strtod( argv[++iarg]  , NULL ) ;
00731          if( xdel <= 0.0 ) Syntax("argument after -xdel must be positive!") ;
00732          new_xdel = 1 ; new_stuff++ ;
00733          iarg++ ; continue ;  /* go to next arg */
00734       }
00735 
00736       if( strncmp(argv[iarg],"-ydel",4) == 0 ){
00737          if( iarg+1 >= argc ) Syntax("need an argument after -ydel!");
00738          ydel = strtod( argv[++iarg]  , NULL ) ;
00739          if( ydel <= 0.0 ) Syntax("argument after -ydel must be positive!") ;
00740          new_ydel = 1 ; new_stuff++ ;
00741          iarg++ ; continue ;  /* go to next arg */
00742       }
00743 
00744       if( strncmp(argv[iarg],"-zdel",4) == 0 ){
00745          if( iarg+1 >= argc ) Syntax("need an argument after -zdel!");
00746          zdel = strtod( argv[++iarg]  , NULL ) ;
00747          if( zdel <= 0.0 ) Syntax("argument after -zdel must be positive!") ;
00748          new_zdel = 1 ; new_stuff++ ;
00749          iarg++ ; continue ;  /* go to next arg */
00750       }
00751 
00752       /** -TR **/
00753 
00754       if( strncmp(argv[iarg],"-TR",3) == 0 ){
00755          char * eptr ;
00756          if( iarg+1 >= argc ) Syntax("need an argument after -TR!");
00757          TR = strtod( argv[++iarg]  , &eptr ) ;
00758          if( TR <= 0.0 ) Syntax("argument after -TR must be positive!") ;
00759 
00760          if( strcmp(eptr,"ms")==0 || strcmp(eptr,"msec")==0 ){
00761             new_tunits = 1 ; tunits = UNITS_MSEC_TYPE ;
00762          } else if( strcmp(eptr,"s")==0 || strcmp(eptr,"sec")==0 ){
00763             new_tunits = 1 ; tunits = UNITS_SEC_TYPE ;
00764          } else if( strcmp(eptr,"Hz")==0 || strcmp(eptr,"Hertz")==0 ){
00765             new_tunits = 1 ; tunits = UNITS_HZ_TYPE ;
00766          }
00767 
00768          new_TR = 1 ; new_stuff++ ;
00769          iarg++ ; continue ;  /* go to next arg */
00770       }
00771 
00772       /** -notoff (12 Feb 2001) **/
00773 
00774       if( strncmp(argv[iarg],"-notoff",7) == 0 ){
00775          new_toff_sl = 1 ; new_stuff++ ;
00776          iarg++ ; continue ;  /* go to next arg */
00777       }
00778 
00779       /** -Torg (29 Jan 2003) **/
00780 
00781       if( strncmp(argv[iarg],"-Torg",5) == 0 ){
00782         char *eptr ;
00783         if( iarg+1 >= argc ) Syntax("need an argument after -Torg!");
00784         Torg = strtod( argv[++iarg]  , &eptr ) ;
00785         if( *eptr != '\0' )
00786           WARNING_message("-Torg %s ends in unexpected character\n",argv[iarg]) ;
00787         new_Torg = 1 ; new_stuff++ ;
00788         iarg++ ; continue ;  /* go to next arg */
00789       }
00790 
00791       /** -newid **/
00792 
00793       if( strncmp(argv[iarg],"-newid",4) == 0 ){
00794          new_idcode = 1 ; new_stuff++ ;
00795          iarg++ ; continue ;  /* go to next arg */
00796       }
00797 
00798       /** -nowarp **/
00799 
00800       if( strncmp(argv[iarg],"-nowarp",6) == 0 ){
00801          new_nowarp = 1 ; new_stuff++ ;
00802          iarg++ ; continue ;  /* go to next arg */
00803       }
00804 
00805       /** -statpar x x x **/
00806 
00807       if( strncmp(argv[iarg],"-statpar",4) == 0 ){
00808          float val ; char * ptr ;
00809 
00810          if( ++iarg >= argc ) Syntax("need an argument after -statpar!") ;
00811 
00812          for( ii=0 ; ii < MAX_STAT_AUX ; ii++ ) stataux[ii] = 0.0 ;
00813 
00814          ii = 0 ;
00815          do{
00816             val = strtod( argv[iarg] , &ptr ) ;
00817             if( *ptr != '\0' ) break ;
00818             stataux[ii++] = val ;
00819             iarg++ ;
00820          } while( iarg < argc ) ;
00821 
00822          if( ii == 0 ) Syntax("No numbers given after -statpar?") ;
00823 
00824          new_stataux = 1 ; new_stuff++ ;
00825          continue ;
00826       }
00827 
00828       /** -markers **/
00829 
00830       if( strncmp(argv[iarg],"-markers",4) == 0 ){
00831          new_markers = 1 ; new_stuff++ ;
00832          iarg++ ; continue ;  /* go to next arg */
00833       }
00834 
00835       /** -label2 [21 Dec 2004] **/
00836 
00837       if( strcmp(argv[iarg],"-label2") == 0 ){
00838         new_label2 = argv[++iarg] ; new_stuff++ ;
00839         iarg++ ; continue ;  /* go to next arg */
00840       }
00841 
00842       /** -view code **/
00843 
00844       if( strncmp(argv[iarg],"-view",4) == 0 ){
00845          char * code ;
00846          if( iarg+1 >= argc ) Syntax("need an argument after -view!") ;
00847          code = argv[++iarg] ; if( code[0] == '+' ) code++ ;
00848          for( vtype=0 ; vtype <= LAST_VIEW_TYPE ; vtype++ )
00849             if( strcmp(code,VIEW_codestr[vtype]) == 0 ) break ;
00850          if( vtype > LAST_VIEW_TYPE ) Syntax("argument after -view is illegal!") ;
00851          new_view = 1 ; new_stuff++ ;
00852          iarg++ ; continue ;  /* go to next arg */
00853       }
00854 
00855       /** anything else must be a -type **/
00856       /*  try the anatomy prefixes */
00857 
00858       for( ii=FIRST_ANAT_TYPE ; ii <= LAST_ANAT_TYPE ; ii++ )
00859          if( strncmp( &(argv[iarg][1]) ,
00860                       ANAT_prefixstr[ii] , THD_MAX_PREFIX ) == 0 ) break ;
00861 
00862       if( ii <= LAST_ANAT_TYPE ){
00863          ftype = ii ;
00864          dtype = HEAD_ANAT_TYPE ;
00865          nvals = ANAT_nvals[ftype] ;
00866          new_type = 1 ; new_stuff++ ;
00867          iarg++ ; continue ;
00868       }
00869 
00870       /* try the function prefixes */
00871 
00872       for( ii=FIRST_FUNC_TYPE ; ii <= LAST_FUNC_TYPE ; ii++ )
00873          if( strncmp( &(argv[iarg][1]) ,
00874                       FUNC_prefixstr[ii] , THD_MAX_PREFIX ) == 0 ) break ;
00875 
00876       if( ii <= LAST_FUNC_TYPE ){
00877          ftype = ii ;
00878          dtype = HEAD_FUNC_TYPE ;
00879          nvals = FUNC_nvals[ftype] ;
00880          new_type = 1 ; new_stuff++ ;
00881          iarg++ ; continue ;
00882       }
00883 
00884       /** error **/
00885 
00886       { char str[256] ;
00887         sprintf(str,"Unknown option %s",argv[iarg]) ;
00888         Syntax(str) ;
00889       }
00890 
00891    }  /* end of loop over switches */
00892 
00893    if( new_stuff == 0 ) Syntax("No options given!?") ;
00894    if( iarg >= argc   ) Syntax("No datasets given!?") ;
00895 
00896    if( new_orient && (dxorg || dyorg || dzorg) )     /* 02 Mar 2000 */
00897       Syntax("Can't use -orient with -d?origin!?") ;
00898 
00899    /*--- process datasets ---*/
00900 
00901    for( ; iarg < argc ; iarg++ ){
00902       dset = THD_open_one_dataset( argv[iarg] ) ;
00903       if( dset == NULL ){
00904          ERROR_message("Can't open dataset %s\n",argv[iarg]) ;
00905          continue ;
00906       }
00907       if( DSET_IS_MINC(dset) ){
00908          ERROR_message("Can't process MINC dataset %s\n",argv[iarg]);
00909          continue ;
00910       }
00911       if( DSET_IS_ANALYZE(dset) ){
00912          ERROR_message("Can't process ANALYZE dataset %s\n",argv[iarg]);
00913          continue ;
00914       }
00915       if( DSET_IS_1D(dset) ){
00916          ERROR_message("Can't process 1D dataset %s\n",argv[iarg]);
00917          continue ;
00918       }
00919       if( DSET_IS_CTFMRI(dset) || DSET_IS_CTFSAM(dset) ){
00920          ERROR_message("Can't process CTF dataset %s\n",argv[iarg]);
00921          continue ;
00922       }
00923       if( DSET_IS_NIFTI(dset) ){
00924          ERROR_message("Can't process NIFTI dataset %s\n",argv[iarg]);
00925          continue ;
00926       }
00927       if( DSET_IS_MPEG(dset) ){
00928          ERROR_message("Can't process MPEG dataset %s\n",argv[iarg]);
00929          continue ;
00930       }
00931       INFO_message("Processing AFNI dataset %s\n",argv[iarg]) ;
00932 
00933       tross_Make_History( "3drefit" , argc,argv, dset ) ;
00934 
00935       /* 21 Dec 2004: -label2 option */
00936 
00937       if( new_label2 != NULL )
00938         EDIT_dset_items( dset , ADN_label2 , new_label2 , ADN_none ) ;
00939 
00940       /* 14 Oct 1999: change anat parent */
00941       /* 14 Dec 1999: allow special cases: SELF and NULL */
00942 
00943       if( aset != NULL ){
00944          EDIT_dset_items( dset , ADN_anat_parent , aset , ADN_none ) ;
00945       } else if( aset_code == ASET_SELF ){
00946          EDIT_dset_items( dset , ADN_anat_parent , dset , ADN_none ) ;
00947       } else if( aset_code == ASET_NULL ){
00948          EDIT_ZERO_ANATOMY_PARENT_ID( dset ) ;
00949          dset->anat_parent_name[0] = '\0' ;
00950       }
00951 
00952       /* Oct 04/02: zmodify volreg fields */
00953       if (Do_volreg_mat) {
00954          sprintf(str,"VOLREG_MATVEC_%06d", volreg_matind) ;
00955          INFO_message("Modifying %s ...\n", str);
00956          THD_set_float_atr( dset->dblk , str , 12 , volreg_mat ) ;
00957       }
00958 
00959       if (Do_center_old) {
00960          INFO_message("Modifying VOLREG_CENTER_OLD ...\n");
00961          THD_set_float_atr( dset->dblk , "VOLREG_CENTER_OLD" , 3 , center_old ) ;
00962       }
00963 
00964       if (Do_center_base) {
00965         INFO_message("Modifying VOLREG_CENTER_BASE ...\n");
00966         THD_set_float_atr( dset->dblk , "VOLREG_CENTER_BASE" , 3 , center_base ) ;
00967       }
00968 
00969       /* 28 May 2002: clear brick stats */
00970 
00971       if( clear_bstat ){
00972         if( !ISVALID_STATISTIC(dset->stats) ){
00973           WARNING_message("-clear_bstat: dataset has no brick statistics\n") ;
00974         } else {
00975           KILL_STATISTIC(dset->stats) ;
00976           REMOVEFROM_KILL( dset->kl , dset->stats ) ;
00977           REMOVEFROM_KILL( dset->kl , dset->stats->bstat ) ;
00978           dset->stats = NULL ;
00979         }
00980       }
00981 
00982       if( redo_bstat ){
00983         THD_load_statistics( dset ) ;   /* 01 Feb 2005 */
00984       }
00985 
00986       /* 25 April 1998 */
00987 
00988       if( new_byte_order > 0 )
00989          dset->dblk->diskptr->byte_order = new_byte_order ;
00990 
00991       daxes = dset->daxes ;
00992 
00993       if( new_orient ){
00994          daxes->xxorient = xxor ;
00995          daxes->yyorient = yyor ;
00996          daxes->zzorient = zzor ;
00997       }
00998 
00999       if( !new_xorg ) xorg = fabs(daxes->xxorg) ;
01000       if( !new_yorg ) yorg = fabs(daxes->yyorg) ;
01001       if( !new_zorg ) zorg = fabs(daxes->zzorg) ;
01002 
01003       if( !new_xdel ) xdel = fabs(daxes->xxdel) ;
01004       if( !new_ydel ) ydel = fabs(daxes->yydel) ;
01005       if( !new_zdel ) zdel = fabs(daxes->zzdel) ;
01006 
01007       if( cxorg ) xorg = 0.5 * (daxes->nxx - 1) * xdel ;
01008       if( cyorg ) yorg = 0.5 * (daxes->nyy - 1) * ydel ;
01009       if( czorg ) zorg = 0.5 * (daxes->nzz - 1) * zdel ;
01010 
01011       if( dxorg )
01012          daxes->xxorg += xorg ;
01013       else if( duporg || new_xorg==2 )
01014          daxes->xxorg = xorg ;
01015       else if( new_xorg==1 || new_orient )
01016          daxes->xxorg = (ORIENT_sign[daxes->xxorient] == '+') ? (-xorg) : (xorg) ;
01017 
01018       if( dyorg )
01019          daxes->yyorg += yorg ;
01020       else if( duporg || new_yorg==2 )
01021          daxes->yyorg = yorg ;
01022       else if( new_yorg==1 || new_orient )
01023          daxes->yyorg = (ORIENT_sign[daxes->yyorient] == '+') ? (-yorg) : (yorg) ;
01024 
01025       if( dzorg )
01026          daxes->zzorg += zorg ;
01027       else if( duporg || new_zorg==2 )
01028          daxes->zzorg = zorg ;
01029       else if( new_zorg==1 || new_orient )
01030          daxes->zzorg = (ORIENT_sign[daxes->zzorient] == '+') ? (-zorg) : (zorg) ;
01031 
01032       if( new_xdel || new_orient )
01033          daxes->xxdel = (ORIENT_sign[daxes->xxorient] == '+') ? (xdel) : (-xdel) ;
01034 
01035       if( new_ydel || new_orient )
01036          daxes->yydel = (ORIENT_sign[daxes->yyorient] == '+') ? (ydel) : (-ydel) ;
01037 
01038       if( new_zdel || new_orient )
01039          daxes->zzdel = (ORIENT_sign[daxes->zzorient] == '+') ? (zdel) : (-zdel) ;
01040 
01041       if( new_TR ){
01042          if( dset->taxis == NULL ){
01043             WARNING_message("Can't process -TR for this dataset!\n") ;
01044          } else {
01045             float frac = TR / dset->taxis->ttdel ;
01046             int ii ;
01047 
01048             dset->taxis->ttdel = TR ;
01049             if( new_tunits ) dset->taxis->units_type = tunits ;
01050             if( dset->taxis->nsl > 0 ){
01051                for( ii=0 ; ii < dset->taxis->nsl ; ii++ )
01052                   dset->taxis->toff_sl[ii] *= frac ;
01053             }
01054          }
01055       }
01056 
01057       if( new_Torg ){                   /* 29 Jan 2003 */
01058         if( dset->taxis == NULL ){
01059           WARNING_message("Can't process -Torg for this dataset!\n") ;
01060         } else {
01061           dset->taxis->ttorg = Torg ;
01062         }
01063       }
01064 
01065       if( new_toff_sl ){              /* 12 Feb 2001 */
01066          if( dset->taxis == NULL ){
01067             WARNING_message("-notoff: dataset has no time axis to clear!\n") ;
01068          } else if( dset->taxis->nsl <= 0 ){
01069             WARNING_message("-notoff: dataset has no time-offsets to clear!\n") ;
01070          } else {
01071             EDIT_dset_items( dset , ADN_nsl,0 , ADN_none ) ;
01072          }
01073       }
01074 
01075       if( (new_orient || new_zorg) && dset->taxis != NULL && dset->taxis->nsl > 0 ){
01076          dset->taxis->zorg_sl = daxes->zzorg ;
01077       }
01078 
01079       if( (new_orient || new_zdel) && dset->taxis != NULL && dset->taxis->nsl > 0 ){
01080          dset->taxis->dz_sl = daxes->zzdel ;
01081       }
01082 
01083       if( new_idcode ) dset->idcode = MCW_new_idcode() ;
01084 
01085       if( new_nowarp ){
01086          ZERO_IDCODE( dset->warp_parent_idcode ) ;
01087          dset->warp_parent_name[0] = '\0' ;
01088          dset->warp = NULL ;
01089       }
01090 
01091       if( new_type ){
01092          if( nvals > 1 && dset->taxis != NULL ){
01093             ERROR_message("Can't change 3D+time dataset to new type:\n"
01094                           " *    new type has more than one value per voxel!\n") ;
01095          } else if( dset->taxis == NULL && nvals != dset->dblk->nvals &&
01096                     ((dtype==HEAD_FUNC_TYPE && ftype!=FUNC_BUCK_TYPE)||
01097                      (dtype==HEAD_ANAT_TYPE && ftype!=ANAT_BUCK_TYPE)  ) ){
01098 
01099             ERROR_message("Can't change dataset to new type:\n"
01100                           " *     mismatch in number of sub-bricks!\n") ;
01101          } else {
01102             dset->type      = dtype ;
01103             dset->func_type = ftype ;
01104 
01105             if( ISBUCKET(dset) && dset->taxis != NULL ){   /* 29 April 1998 */
01106               WARNING_message("changing 3D+time dataset to bucket\n") ;
01107               EDIT_dset_items( dset , ADN_ntt , 0 , ADN_none ) ;
01108             }
01109 
01110          }
01111       }
01112 
01113       if( new_stataux ){
01114          for( ii=0 ; ii < MAX_STAT_AUX ; ii++ ){
01115             dset->stat_aux[ii] = stataux[ii] ;
01116          }
01117       }
01118 
01119       if( new_view && dset->view_type != vtype ){
01120          int  old_vtype = dset->view_type ;
01121          char old_head[THD_MAX_NAME] , old_brik[THD_MAX_NAME] ;
01122          char new_head[THD_MAX_NAME] , new_brik[THD_MAX_NAME] ;
01123          int brick_ccode = COMPRESS_filecode( DSET_BRIKNAME(dset) ) ;
01124 
01125          strcpy(old_head,DSET_HEADNAME(dset)) ;
01126          strcpy(old_brik,DSET_BRIKNAME(dset)) ;
01127 
01128          dset->view_type = vtype ;
01129          THD_init_diskptr_names( dset->dblk->diskptr ,
01130                                  NULL , NULL , NULL , vtype , True ) ;
01131 
01132          strcpy(new_head,DSET_DIRNAME(dset)) ; strcat(new_head,DSET_HEADNAME(dset)) ;
01133          strcpy(new_brik,DSET_DIRNAME(dset)) ; strcat(new_brik,DSET_BRIKNAME(dset)) ;
01134 
01135          if( THD_is_file(new_head) ){
01136             dset->view_type = old_vtype ;
01137             THD_init_diskptr_names( dset->dblk->diskptr ,
01138                                     NULL , NULL , NULL , old_vtype , True ) ;
01139             ERROR_message("Can't change view: would overwrite existing files!\n") ;
01140          } else {
01141             rename( old_head , new_head ) ;
01142             { char * fff = COMPRESS_filename(old_brik) ;
01143               if( fff != NULL ){
01144                  char * ggg = malloc( sizeof(char) * (strlen(fff)+32) ) ;
01145                  strcpy(ggg,new_brik) ;
01146                  if( brick_ccode >= 0 ) strcat(ggg,COMPRESS_suffix[brick_ccode]) ;
01147                  rename( fff , ggg ) ;
01148                  free(fff) ; free(ggg) ;
01149               }
01150             }
01151             INFO_message("Changed dataset view type and filenames.\n") ;
01152          }
01153       }
01154 
01155       if( new_markers                           &&
01156           dset->type      == HEAD_ANAT_TYPE     &&
01157           dset->view_type == VIEW_ORIGINAL_TYPE &&
01158           DSET_NUM_TIMES(dset) == 1                ){  /* code copied from to3d.c */
01159 
01160          THD_marker_set * markers ;
01161          int ii , jj ;
01162 
01163          markers = dset->markers = myXtNew( THD_marker_set ) ;
01164          markers->numdef = 0 ;
01165 
01166          for( ii=0 ; ii < MARKS_MAXNUM ; ii++ ){       /* null all data out */
01167             markers->valid[ii] = 0 ;
01168             for( jj=0 ; jj < MARKS_MAXLAB  ; jj++ )
01169                markers->label[ii][jj] = '\0';
01170             for( jj=0 ; jj < MARKS_MAXHELP ; jj++ )
01171                markers->help[ii][jj]  = '\0';
01172          }
01173 
01174          for( ii=0 ; ii < NMARK_ALIGN ; ii++ ){       /* copy strings in */
01175             MCW_strncpy( &(markers->label[ii][0]) ,
01176                          THD_align_label[ii] , MARKS_MAXLAB ) ;
01177             MCW_strncpy( &(markers->help[ii][0]) ,
01178                          THD_align_help[ii] , MARKS_MAXHELP ) ;
01179          }
01180 
01181          for( ii=0 ; ii < MARKS_MAXFLAG ; ii++ )     /* copy flags in */
01182             markers->aflags[ii] = THD_align_aflags[ii] ;
01183 
01184       } else if( new_markers ){
01185             WARNING_message("Can't add markers to this dataset\n") ;
01186       } /* end of markers */
01187 
01188       /*-- 08 Jun 2004: copyaux? --*/
01189 
01190       if( copyaux ){
01191         if( auxset != NULL ){
01192           THD_copy_datablock_auxdata( auxset->dblk , dset->dblk );
01193           INIT_STAT_AUX( dset , MAX_STAT_AUX , auxset->stat_aux ) ;
01194         } else {
01195           THD_copy_datablock_auxdata( NULL , dset->dblk );
01196         }
01197       }
01198 
01199       /*-- new aux data? --*/
01200 
01201       if( nsublab > 0 ){
01202          for( ii=0 ; ii < nsublab ; ii++ ){
01203             iv = sublab[ii].iv ;
01204             if( iv < 0 || iv >= DSET_NVALS(dset) ){
01205                WARNING_message("Can't put label on sub-brick %d\n",iv) ;
01206             } else {
01207                EDIT_dset_items( dset ,
01208                                    ADN_brick_label_one + iv , sublab[ii].lab ,
01209                                 ADN_none ) ;
01210             }
01211          }
01212       }
01213 
01214       if( nsubkeyword > 0 ){
01215          int code ;
01216          for( ii=0 ; ii < nsubkeyword ; ii++ ){
01217             iv = subkeyword[ii].iv ; code = subkeyword[ii].code ;
01218             if( iv < 0 || iv >= DSET_NVALS(dset) ){
01219                WARNING_message("Can't put keyword on sub-brick %d\n",iv) ;
01220             } else if( code == 1 ){
01221                EDIT_dset_items( dset ,
01222                                    ADN_brick_keywords_append_one + iv ,
01223                                    subkeyword[ii].keyword ,
01224                                 ADN_none ) ;
01225             } else if( code == 2 ){
01226                EDIT_dset_items( dset ,
01227                                    ADN_brick_keywords_replace_one + iv ,
01228                                    subkeyword[ii].keyword ,
01229                                 ADN_none ) ;
01230             } else if( code == 3 && dset->dblk->brick_keywords != NULL ){
01231                EDIT_dset_items( dset ,
01232                                    ADN_brick_keywords_replace_one + iv ,
01233                                    NULL ,
01234                                 ADN_none ) ;
01235             }
01236          }
01237       }
01238 
01239       switch( new_key ){
01240         case 1: EDIT_dset_items(dset, ADN_keywords_append , key , ADN_none); break;
01241         case 2: EDIT_dset_items(dset, ADN_keywords_replace, key , ADN_none); break;
01242         case 3: EDIT_dset_items(dset, ADN_keywords_replace, NULL, ADN_none); break;
01243       }
01244 
01245       if( nsubstatpar > 0 ){
01246         for( ii=0 ; ii < nsubstatpar ; ii++ ){
01247           iv = substatpar[ii].iv ;
01248           if( iv < 0 || iv >= DSET_NVALS(dset) ){
01249             WARNING_message("Can't put statpar on sub-brick %d",iv) ;
01250           } else {
01251             EDIT_dset_items( dset ,
01252                                ADN_brick_stataux_one + iv , substatpar[ii].par ,
01253                              ADN_none ) ;
01254           }
01255         }
01256       }
01257 
01258       /* 03 Aug 2005: implement atrcopy */
01259 
01260       for( ii=0 ; ii < num_atrcopy ; ii++ )
01261         THD_insert_atr( dset->dblk , atrcopy[ii] ) ;
01262 
01263       if( denote ) THD_anonymize_write(1) ;   /* 08 Jul 2005 */
01264 
01265       THD_write_3dim_dataset( NULL,NULL , dset , False ) ;
01266       THD_delete_3dim_dataset( dset , False ) ;
01267    }
01268    exit(0) ;
01269 }
 

Powered by Plone

This site conforms to the following standards: