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  

3dANOVA.h

Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003    Major portions of this software are copyrighted by the Medical College
00004    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00005    License, Version 2.  See the file README.Copyright for details.
00006 ******************************************************************************/
00007 
00008 /*
00009    This is the header file for the 3dANOVA.lib library routines.
00010 
00011    File:    3dANOVA.h
00012    Author:  B. D. Ward
00013    Date:    20 January 1997
00014    
00015    Mod:     Added command -diskspace to print out how much disk space is
00016             required to execute the problem.
00017    Date:    23 January 1997
00018 
00019    Mod:     Change to routine write_afni_data to reduce truncation error.    
00020    Date:    27 January 1997
00021             
00022    Mod:     Added machine specific code for checking disk space.
00023    Date:    29 January 1997
00024             
00025    Mod:     Extensive changes required to implement the 'bucket' dataset.
00026    Date:    30 December 1997
00027 
00028    Mod:     Library routines moved to 3dANOVA.lib.
00029    Date:    5 January 1998
00030 
00031    Mod:     Added software for statistical tests of individual cell means,
00032             cell differences, and cell contrasts.
00033    Date:    27 October 1998
00034 
00035    Mod:     Added changes for incorporating History notes.
00036    Date:    09 September 1999
00037 
00038    Mod:     Replaced dataset input code with calls to THD_open_dataset,
00039             to allow operator selection of individual sub-bricks for input.
00040    Date:    02 December 1999
00041 
00042    Mod:     Increased maximum number of user requested means, differences, 
00043             and contrasts.
00044    Date:    31 January 2000
00045 
00046    Mod:     Set MAX_NAME_LENGTH equal to THD_MAX_NAME.
00047    Date:    02 December 2002
00048 */
00049 
00050 /*---------------------------------------------------------------------------*/
00051 
00052 #include "mrilib.h"
00053 
00054 static char * commandline = NULL ;         /* command line for history notes */
00055 
00056 
00057 /*** HP-UX ***/
00058 #ifdef HP
00059 # define DF "bdf ."
00060 #endif
00061 
00062 /*** SGI IRIX ***/
00063 #ifdef SGI
00064 # define DF "df -k ."
00065 #endif
00066 
00067 /*** DEC OSF1 ***/
00068 #ifdef OSF1
00069 # define DF "df -k ."
00070 #endif
00071 
00072 /*** SunOS or Solaris ***/
00073 #if defined(SOLARIS) || defined(SUN)
00074 # define DF "df -k"
00075 #endif
00076 
00077 /*** IBM RS6000  ***/
00078 #ifdef RS6000
00079 #endif
00080 
00081 /*** Linux 1.2.x ***/
00082 #ifdef LINUX
00083 # define DF "df -k ."
00084 #endif
00085 
00086 /*** other? ***/
00087 #ifndef DF
00088 # define DF "df"
00089 #endif
00090 
00091 
00092 #define MAX_LEVELS 300           /* max. number of factor levels */  
00093 #define MAX_OBSERVATIONS 100     /* max. number of observations per cell */
00094 #define MAX_MEANS 20             /* max. number of user requested means */
00095 #define MAX_DIFFS 20             /* max. number of user requested diffs. */
00096 #define MAX_CONTR 40             /* max. number of user requested contrasts */
00097 #define MAX_NAME_LENGTH THD_MAX_NAME  /* max. string length for file names */
00098 
00099 
00100 typedef struct anova_options
00101 { 
00102   int   datum;                  /* data type for "intensity" data subbrick */
00103   char  session[MAX_NAME_LENGTH];     /* name of output directory */
00104 
00105   int   diskspace;              /* if positive, print out how much disk space
00106                                    is required for program execution */
00107   
00108   int   nvoxel;                 /* number of voxel for special output */
00109 
00110   int   model;                  /* indicates type of ANOVA model to be used:
00111                                   model=1   A,B,C fixed;          AxBxC
00112                                   model=2   A,B,C random;         AxBxC
00113                                   model=3   A fixed; B,C random;  AxBxC 
00114                                   model=4   A,B fixed; C random;  AxBxC
00115                                   model=5   A,B fixed; C random;  AxB,BxC,C(A)
00116                                 */
00117 
00118   int   a;                      /* number of levels for factor A */
00119   int   b;                      /* number of levels for factor B */
00120   int   c;                      /* number of levels for factor C */
00121   int   n;                      /* number of observations in each cell */
00122   int   nt;                     /* total number of observations */
00123   
00124   int   na[MAX_LEVELS];         /* number of observations at each level
00125                                    of factor A (for 3dANOVA only) */
00126 
00127   char  ***** xname;            /* names of the input data files */
00128   char  * first_dataset;        /* name of the first data set */
00129    
00130   int   nx, ny, nz;             /* data set dimensions */
00131   int   nxyz;                   /* number of voxels per image */
00132 
00133   int   nftr;                   /* if positive, calculate F for treatment */
00134   char  * ftrname;              /* name of output file of F for treatment */
00135 
00136   int   nfa;                    /* if positive, calculate F for A effect */
00137   char  * faname;               /* name of output file of F for A effect */
00138   int   nfb;                    /* if positive, calculate F for B effect */
00139   char  * fbname;               /* name of output file of F for B effect */
00140   int   nfc;                    /* if positive, calculate F for C effect */
00141   char  * fcname;               /* name of output file of F for C effect */
00142   int   nfab;                   /* if pos., calculate F for A*B interaction */
00143   char  * fabname;              /* name of output file for A*B interaction */
00144   int   nfac;                   /* if pos., calculate F for A*C interaction */
00145   char  * facname;              /* name of output file for A*C interaction */
00146   int   nfbc;                   /* if pos., calculate F for B*C interaction */
00147   char  * fbcname;              /* name of output file for B*C interaction */
00148   int   nfabc;                  /* if pos, calculate F for A*B*C interaction */
00149   char  * fabcname;             /* name of output file for A*B*C interaction */
00150 
00151 
00152   int   num_ameans;             /* number of factor A level means */ 
00153   int   ameans[MAX_MEANS];      /* calc means for these factor A levels */
00154   char  * amname[MAX_MEANS];    /* names of output files for factor A means */
00155   
00156   int   num_bmeans;             /* number of factor B level means */ 
00157   int   bmeans[MAX_MEANS];      /* calc means for these factor B levels */
00158   char  * bmname[MAX_MEANS];    /* names of output files for factor B means */
00159   
00160   int   num_cmeans;             /* number of factor C level means */ 
00161   int   cmeans[MAX_MEANS];      /* calc means for these factor C levels */
00162   char  * cmname[MAX_MEANS];    /* names of output files for factor C means */
00163 
00164   int   num_xmeans;             /* number of cell means */
00165   int   xmeans[MAX_MEANS][3];   /* calc means for these cells */
00166   char  * xmname[MAX_MEANS];    /* name of output files for cell means */
00167 
00168   int   num_adiffs;             /* num of diffs in factor A level means */
00169   int   adiffs[MAX_DIFFS][2];   /* calc diffs in these factor A level means */
00170   char  * adname[MAX_DIFFS];    /* names of output files for A differences */
00171   
00172   int   num_bdiffs;             /* num of diffs in factor B level means */
00173   int   bdiffs[MAX_DIFFS][2];   /* calc diffs in these factor B level means */
00174   char  * bdname[MAX_DIFFS];    /* names of output files for B differences */
00175   
00176   int   num_cdiffs;             /* num of diffs in factor C level means */
00177   int   cdiffs[MAX_DIFFS][2];   /* calc diffs in these factor C level means */
00178   char  * cdname[MAX_DIFFS];    /* names of output files for C differences */
00179   
00180   int   num_xdiffs;               /* num of diffs in cell means */
00181   int   xdiffs[MAX_DIFFS][2][3];  /* calc diffs in these cell means */
00182   char  * xdname[MAX_DIFFS];      /* names of output files for cell diffs */
00183   
00184   int   num_acontr;             /* number of factor A contrasts */
00185   float acontr[MAX_CONTR][MAX_LEVELS];     /* factor A contrast vectors */
00186   char  * acname[MAX_CONTR];    /* names of output files for A contrasts */
00187   
00188   int   num_bcontr;             /* number of factor B contrasts */
00189   float bcontr[MAX_CONTR][MAX_LEVELS];     /* factor B contrast vectors */
00190   char  * bcname[MAX_CONTR];    /* names of output files for B contrasts */
00191   
00192   int   num_ccontr;             /* number of factor C contrasts */
00193   float ccontr[MAX_CONTR][MAX_LEVELS];     /* factor C contrast vectors */
00194   char  * ccname[MAX_CONTR];    /* names of output files for C contrasts */
00195 
00196   int   num_xcontr;             /* number of contrasts of cell means */
00197   float xcontr[MAX_CONTR][MAX_LEVELS][MAX_LEVELS];     
00198                                 /* cell means contrast vectors */
00199   char  * xcname[MAX_CONTR];    /* names of output files for cell contrasts */
00200 
00201   char * bucket_filename;       /* file name for bucket dataset */
00202 
00203 } anova_options;
00204 
00205 
00206 /*---------------------------------------------------------------------------*/
00207 /*
00208    Routine to initialize input options.
00209 */
00210 
00211 void initialize_options (anova_options * option_data);
00212 
00213    
00214 /*---------------------------------------------------------------------------*/
00215 
00216 /** macro to open a dataset and make it ready for processing **/
00217 
00218 #define DOPEN(ds,name)                                                        \
00219    do{ int pv ; (ds) = THD_open_dataset((name)) ;                             \
00220        if( !ISVALID_3DIM_DATASET((ds)) ){                                     \
00221           fprintf(stderr,"*** Can't open dataset: %s\n",(name)) ; exit(1) ; } \
00222        if( (ds)->daxes->nxx!=nx || (ds)->daxes->nyy!=ny ||                    \
00223           (ds)->daxes->nzz!=nz ){                                             \
00224           fprintf(stderr,"*** Axes mismatch: %s\n",(name)) ; exit(1) ; }      \
00225        if( DSET_NVALS((ds)) != 1 ){                                           \
00226          fprintf(stderr,"*** Must specify 1 sub-brick: %s\n",(name));exit(1);}\
00227        THD_load_datablock( (ds)->dblk ) ;                                     \
00228        pv = DSET_PRINCIPAL_VALUE((ds)) ;                                      \
00229        if( DSET_ARRAY((ds),pv) == NULL ){                                     \
00230           fprintf(stderr,"*** Can't access data: %s\n",(name)) ; exit(1); }   \
00231        if( DSET_BRICK_TYPE((ds),pv) == MRI_complex ){                         \
00232           fprintf(stderr,"*** Can't use complex data: %s\n",(name)) ; exit(1);\
00233        }                                                                      \
00234        break ; } while (0)
00235 
00236 
00237 /*---------------------------------------------------------------------------*/
00238 
00239 /** macro to return pointer to correct location in brick for current processing **/
00240 
00241 #define SUB_POINTER(ds,vv,ind,ptr)                                            \
00242    do{ switch( DSET_BRICK_TYPE((ds),(vv)) ){                                  \
00243          default: fprintf(stderr,"\n*** Illegal datum! ***\n");exit(1);       \
00244             case MRI_short:{ short * fim = (short *) DSET_ARRAY((ds),(vv)) ;  \
00245                             (ptr) = (void *)( fim + (ind) ) ;                 \
00246             } break ;                                                         \
00247             case MRI_byte:{ byte * fim = (byte *) DSET_ARRAY((ds),(vv)) ;     \
00248                             (ptr) = (void *)( fim + (ind) ) ;                 \
00249             } break ;                                                         \
00250             case MRI_float:{ float * fim = (float *) DSET_ARRAY((ds),(vv)) ;  \
00251                              (ptr) = (void *)( fim + (ind) ) ;                \
00252             } break ; } break ; } while(0)
00253 
00254 
00255 /*---------------------------------------------------------------------------*/
00256 /*
00257    Routine to print error message and stop.
00258 */
00259 
00260 void ANOVA_error (char * message);
00261 
00262 
00263 /*---------------------------------------------------------------------------*/
00264 /*
00265    Routine to write a 3d volume of floating point data to a (temporary)
00266    disk file.
00267 */
00268 
00269 int volume_write_count (char * filename,  float * fout,  int size);
00270 
00271 
00272 /*---------------------------------------------------------------------------*/
00273 /*
00274    Routine to write a 3d volume of floating point data to a (temporary)
00275    disk file. Error exit if cannot write entire file.
00276 */
00277 
00278 void volume_write (char * filename,  float * fout,  int size);
00279 
00280 
00281 /*---------------------------------------------------------------------------*/
00282 /*
00283    Routine to read a 3d volume of floating point data.
00284 */
00285 
00286 void volume_read (char * filename,  float * fin,  int size);
00287 
00288 
00289 /*---------------------------------------------------------------------------*/
00290 /*
00291   Routine to delete a file containing a 3d volume of floating point data.
00292 */
00293 
00294 void volume_delete (char * filename);
00295 
00296 
00297 /*---------------------------------------------------------------------------*/
00298 /*
00299   Routine to set a 3d volume of floating point data to zero.
00300 */
00301 
00302 void volume_zero (float * f,  int size);
00303 
00304 
00305 /*---------------------------------------------------------------------------*/
00306 /*
00307    Routine to get the dimensions of the 3d AFNI data sets.
00308 */
00309 
00310 void get_dimensions (anova_options * option_data);
00311 
00312 
00313 /*---------------------------------------------------------------------------*/
00314 /*
00315   Routine to check whether one temporary file already exists.
00316 */
00317 
00318 void check_one_temporary_file (char * filename);
00319 
00320 
00321 /*---------------------------------------------------------------------------*/
00322 /*
00323   Routine to check whether one output file already exists.
00324 */
00325 
00326 void check_one_output_file (anova_options * option_data, char * filename);
00327 
00328 
00329 /*---------------------------------------------------------------------------*/
00330 /*
00331   Return maximum of two integers.
00332 */
00333 
00334 int max (int n1, int n2);
00335 
00336    
00337 /*---------------------------------------------------------------------------*/
00338 /*
00339   Routine to determine if sufficient disk space exists for storing
00340   the temporary data files.
00341 */
00342 
00343 void check_disk_space (anova_options * option_data);
00344 
00345 
00346 /*---------------------------------------------------------------------------*/
00347 /*
00348   Routine to read one AFNI data set from file 'filename'. 
00349   The data is converted to floating point (in ffim).
00350 */
00351 
00352 void read_afni_data (anova_options * option_data, 
00353                      char * filename, float * ffim);
00354 
00355 
00356 /*---------------------------------------------------------------------------*/
00357 /*
00358   Convert one volume to another type, autoscaling:
00359      nxy   = # voxels
00360      itype = input datum type
00361      ivol  = pointer to input volume
00362      otype = output datum type
00363      ovol  = pointer to output volume (again, must be pre-malloc-ed)
00364   Return value is the scaling factor used (0.0 --> no scaling).
00365 */
00366 
00367 float EDIT_coerce_autoscale_new( int nxyz ,
00368                                  int itype,void *ivol , int otype,void *ovol );
00369 
00370 
00371 /*---------------------------------------------------------------------------*/
00372 /*
00373   Routine to write one AFNI data set.
00374   
00375   This data set may be either 'fitt' type (intensity + t-statistic)
00376                            or 'fift' type (intensity + F-statistic).
00377   
00378   The intensity data is in ffim, and the corresponding statistic is in ftr.
00379   
00380   numdof = numerator degrees of freedom
00381   dendof = denominator degrees of freedom
00382   
00383   Note:  if dendof = 0, then write 'fitt' type data set;
00384          if dendof > 0, then write 'fift' type data set.
00385 */
00386 
00387 void write_afni_data (anova_options * option_data,  char * filename,  
00388                       float * ffim,  float * ftr,  int numdof,  int dendof);
00389 
00390 
00391 /*---------------------------------------------------------------------------*/
00392 /*
00393    Routine to add file name to command string.
00394 */
00395 
00396 void add_file_name (THD_3dim_dataset * new_dset, char * filename, 
00397                     char * command_str);
00398 
00399 
00400 /*---------------------------------------------------------------------------*/
00401 /*
00402    Routine to remove AFNI .HEAD and .BRIK dataset files.
00403 */
00404 
00405 void remove_dataset (THD_3dim_dataset * new_dset, char * filename);
00406 
00407 
00408 /*---------------------------------------------------------------------------*/
00409 /*
00410   Routine to release memory allocated for anova_options.
00411 */
00412 
00413 void destroy_anova_options (anova_options * option_data);
00414 
00415 
00416 /*---------------------------------------------------------------------------*/
00417 
00418 
00419 
00420 
00421 
00422 
00423 
00424 
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 
 

Powered by Plone

This site conforms to the following standards: