Doxygen Source Code Documentation
3dDeconvolve.c File Reference
#include "mrilib.h"
#include "thd_iochan.h"
#include "matrix.h"
#include "parser.h"
#include "Deconvolve.c"
#include <signal.h>
#include "coxplot.h"
#include "niml.h"
Go to the source code of this file.
Data Structures | |
struct | basis_expansion |
struct | basis_func |
struct | basis_irc |
struct | DC_options |
struct | floatpair |
Defines | |
#define | PROGRAM_NAME "3dDeconvolve" |
#define | PROGRAM_AUTHOR "B. Douglas Ward, et al." |
#define | PROGRAM_INITIAL "02 September 1998" |
#define | PROGRAM_LATEST "04 March 2005 - RWCox" |
#define | RA_error DC_error |
#define | USE_GET |
#define | PROC_MAX 32 |
#define | MTYPE double |
#define | XSAVE_version "0.5" |
#define | USE_BASIS /*** for Deconvolve.c ***/ |
#define | basis_funceval(bf, x) ((bf).f( (x), (bf).a,(bf).b,(bf).c,(bf).q )*(bf).ffac) |
#define | basis_filler 3.e+33 |
#define | denom_BASELINE (1) |
#define | ALLOW_EXTEND |
#define | free proc_free |
#define | NGET 128 |
#define | TSGRAY_SEPARATE_YSCALE (1<<0) |
#define | TSGRAY_FLIP_XY (1<<1) |
#define | DPR(s) fprintf(stderr,"%s\n",(s)) |
#define | NGET 32 |
#define | GLT_ERR |
#define | SPM_A1 0.0083333333 |
#define | SPM_P1 4.0 |
#define | SPM_A2 1.274527e-13 |
#define | SPM_P2 15.0 |
#define | TPEAK4(TT) ((TT)/(1.0-exp(-0.25*(TT)))) |
#define | TPEAK5(TT) ((TT)/(1.0-exp(-0.2*(TT)))) |
#define | POLY_MAX 9 |
#define | ITT 19 |
#define | IXX 23 |
#define | IZZ 25 |
#define | BNSUB 999 |
Typedefs | |
typedef DC_options | DC_options |
Functions | |
void | JPEG_matrix_gray (matrix X, char *fname) |
void | XSAVE_output (char *) |
float | baseline_mean (vector coef) |
void | do_xrestore_stuff (int, char **, struct DC_options *) |
void | read_glt_matrix (char *fname, int *nrows, int ncol, matrix *cmat) |
void | vstep_print (void) |
basis_expansion * | basis_parser (char *sym) |
float | basis_evaluation (basis_expansion *be, float *wt, float x) |
void | basis_write_iresp (int argc, char *argv[], struct DC_options *option_data, basis_expansion *be, float dt, float **wtar, char *output_filename) |
void | basis_write_sresp (int argc, char *argv[], struct DC_options *option_data, basis_expansion *be, float dt, float *mse, int pbot, matrix cvar, char *output_filename) |
floatpair | evaluate_irc (basis_irc *birc, vector coef, float base, float mse, matrix cvar) |
void | DC_error (char *message) |
void | identify_software () |
void | display_help_menu () |
void | initialize_options (DC_options *option_data) |
void | initialize_stim_options (DC_options *option_data, int num_stimts) |
void | initialize_glt_options (DC_options *option_data, int num_glt) |
void | get_options (int argc, char **argv, DC_options *option_data) |
float * | read_time_series (char *ts_filename, int *ts_length) |
void | read_input_data (DC_options *option_data, THD_3dim_dataset **dset_time, byte **mask_vol, float **fmri_data, int *fmri_length, float **censor_array, int *censor_length, int **block_list, int *num_blocks, float ***stimulus, int **stim_length, matrix **glt_cmat) |
void | remove_zero_stimfns (DC_options *option_data, float **stimulus, int *stim_length, matrix *glt_cmat) |
void | check_one_output_file (THD_3dim_dataset *dset_time, char *filename) |
void | check_output_files (DC_options *option_data, THD_3dim_dataset *dset_time) |
void | check_for_valid_inputs (DC_options *option_data, THD_3dim_dataset *dset_time, int fmri_length, float *censor_array, int censor_length, int *block_list, int num_blocks, int *stim_length, float **stimulus, int **good_list) |
void | zero_fill_volume (float **fvol, int nxyz) |
void | proc_sigfunc (int sig) |
void | proc_atexit (void) |
void | proc_finalize_shm_volumes (void) |
void | proc_free (void *ptr) |
void | allocate_memory (DC_options *option_data, float ***coef_vol, float ***scoef_vol, float ***tcoef_vol, float ***fpart_vol, float ***rpart_vol, float **mse_vol, float **ffull_vol, float **rfull_vol, float ****glt_coef_vol, float ****glt_tcoef_vol, float ***glt_fstat_vol, float ***glt_rstat_vol, float ***fitts_vol, float ***errts_vol) |
void | initialize_program (int argc, char **argv, DC_options **option_data, THD_3dim_dataset **dset_time, byte **mask_vol, float **fmri_data, int *fmri_length, float **censor_array, int *censor_length, int **good_list, int **block_list, int *num_blocks, float ***stimulus, int **stim_length, matrix **glt_cmat, float ***coef_vol, float ***scoef_vol, float ***tcoef_vol, float ***fpart_vol, float ***rpart_vol, float **mse_vol, float **ffull_vol, float **rfull_vol, float ****glt_coef_vol, float ****glt_tcoef_vol, float ***glt_fstat_vol, float ***glt_rstat_vol, float ***fitts_vol, float ***errts_vol) |
void | save_voxel (DC_options *option_data, int iv, vector coef, vector scoef, vector tcoef, float *fpart, float *rpart, float mse, float ffull, float rfull, vector *glt_coef, vector *glt_tcoef, float *fglt, float *rglt, int nt, float *ts_array, int *good_list, float *fitts, float *errts, float **coef_vol, float **scoef_vol, float **tcoef_vol, float **fpart_vol, float **rpart_vol, float *mse_vol, float *ffull_vol, float *rfull_vol, float ***glt_coef_vol, float ***glt_tcoef_vol, float **glt_fstat_vol, float **glt_rstat_vol, float **fitts_vol, float **errts_vol) |
void | report_evaluation (int qp, int num_stimts, char **stim_label, int *min_lag, int *max_lag, matrix x_full, matrix xtxinv_full, int num_glt, char **glt_label, int *glt_rows, matrix *cxtxinvct) |
void | calculate_results (DC_options *option_data, THD_3dim_dataset *dset, byte *mask_vol, float *fmri_data, int fmri_length, int *good_list, int *block_list, int num_blocks, float **stimulus, int *stim_length, matrix *glt_cmat, float **coef_vol, float **scoef_vol, float **tcoef_vol, float **fpart_vol, float **rpart_vol, float *mse_vol, float *ffull_vol, float *rfull_vol, float ***glt_coef_vol, float ***glt_tcoef_vol, float **glt_fstat_vol, float **glt_rstat_vol, float **fitts_vol, float **errts_vol) |
float | EDIT_coerce_autoscale_new (int nxyz, int itype, void *ivol, int otype, void *ovol) |
void | cubic_spline (DC_options *option_data, int ts_length, float **vol_array) |
void | write_ts_array (int argc, char **argv, DC_options *option_data, int ts_length, int nptr, int tshift, float **vol_array, char *output_filename) |
void | attach_sub_brick (THD_3dim_dataset *new_dset, int ibrick, float *volume, int nxyz, int brick_type, char *brick_label, int dof, int ndof, int ddof, short **bar) |
void | write_bucket_data (int argc, char **argv, DC_options *option_data, float **coef_vol, float **tcoef_vol, float **fpart_vol, float **rpart_vol, float *mse_vol, float *ffull_vol, float *rfull_vol, float ***glt_coef_vol, float ***glt_tcoef_vol, float **glt_fstat_vol, float **glt_rstat_vol) |
void | write_one_ts (char *prefix, int ts_length, float **vol_array) |
void | output_results (int argc, char **argv, DC_options *option_data, float **coef_vol, float **scoef_vol, float **tcoef_vol, float **fpart_vol, float **rpart_vol, float *mse_vol, float *ffull_vol, float *rfull_vol, float ***glt_coef_vol, float ***glt_tcoef_vol, float **glt_fstat_vol, float **glt_rstat_vol, float **fitts_vol, float **errts_vol) |
int | main (int argc, char **argv) |
MEM_plotdata * | PLOT_tsgray (int npt, int nts, int ymask, float **y) |
MRI_IMAGE * | PLOT_matrix_gray (matrix X) |
NI_element * | matrix_to_niml (matrix a, char *ename) |
void | niml_to_matrix (NI_element *nel, matrix *a) |
NI_element * | intvec_to_niml (int nvec, int *vec, char *ename) |
void | niml_to_intvec (NI_element *nel, int *nvec, int **vec) |
NI_element * | stringvec_to_niml (int nstr, char **str, char *ename) |
void | niml_to_stringvec (NI_element *nel, int *nstr, char ***str) |
NI_element * | symvec_to_niml (int ns, SYM_irange *sv, char *ename) |
void | niml_to_symvec (NI_element *nel, int *ns, SYM_irange **sv) |
void | XSAVE_input (char *xname) |
void | check_xrestore_data (void) |
void | do_xrestore_stuff (int argc, char **argv, DC_options *option_data) |
float | basis_tent (float x, float bot, float mid, float top, void *q) |
float | basis_one (float x, float bot, float top, float junk, void *q) |
float | basis_cos (float x, float bot, float top, float freq, void *q) |
float | basis_sin (float x, float bot, float top, float freq, void *q) |
float | basis_gam (float x, float b, float c, float top, void *q) |
float | basis_spmg1 (float x, float a, float b, float c, void *q) |
float | basis_spmg2 (float x, float a, float b, float c, void *q) |
float | basis_block_hrf4 (float tt, float TT) |
float | basis_block4 (float t, float T, float peak, float junk, void *q) |
float | basis_block_hrf5 (float tt, float TT) |
float | basis_block5 (float t, float T, float peak, float junk, void *q) |
float | basis_legendre (float x, float bot, float top, float n, void *q) |
float | basis_expr (float x, float bot, float top, float dtinv, void *q) |
void | basis_write_iresp (int argc, char *argv[], DC_options *option_data, basis_expansion *be, float dt, float **wtar, char *output_filename) |
Variables | |
int | proc_numjob = 1 |
pid_t | proc_pid [PROC_MAX] |
int | proc_shmid = 0 |
char * | proc_shmptr = NULL |
int | proc_shmsize = 0 |
int | proc_shm_arnum = 0 |
float *** | proc_shm_ar = NULL |
int * | proc_shm_arsiz = NULL |
int | proc_vox_bot [PROC_MAX] |
int | proc_vox_top [PROC_MAX] |
int | proc_ind |
int | proc_use_jobs = 0 |
int | xsave = 0 |
int | nGoodList = 0 |
int * | GoodList = NULL |
int | nParam = 0 |
int * | ParamIndex = NULL |
int * | ParamStim = NULL |
char ** | ParamLabel = NULL |
char * | InputFilename = NULL |
char * | BucketFilename = NULL |
char * | CoefFilename = NULL |
matrix | X |
matrix | XtXinv |
matrix | XtXinvXt |
int * | Xcol_inbase |
float * | Xcol_mean |
int | voxel_num |
float * | voxel_base = NULL |
int | xrestore = 0 |
char * | xrestore_filename = NULL |
int | NumTimePoints = 0 |
int | NumRegressors = 0 |
int | verb = 1 |
int | nSymStim = 0 |
SYM_irange * | SymStim = NULL |
int | show_singvals = 0 |
basis_expansion ** | basis_stim = NULL |
MRI_IMAGE ** | basis_times = NULL |
MRI_IMAGE ** | basis_vect = NULL |
float | basis_TR = 1.0f |
int | basis_count = 0 |
float | basis_dtout = 0.0f |
float | irc_dt = 0.0f |
int | basis_need_mse = 0 |
float | basis_normall = 0.0f |
int | num_irc = 0 |
basis_irc ** | irc = NULL |
Define Documentation
|
|
|
Definition at line 445 of file 3dDeconvolve.c. Referenced by get_options(). |
|
Macro to evaluate a basis_func at a particular point. Definition at line 406 of file 3dDeconvolve.c. Referenced by basis_evaluation(), basis_parser(), basis_write_iresp(), basis_write_sresp(), and read_input_data(). |
|
|
|
Definition at line 459 of file 3dDeconvolve.c. Referenced by evaluate_irc(). |
|
Definition at line 6226 of file 3dDeconvolve.c. Referenced by ISQ_drawing_EV(), ISQ_make_montage(), ISQ_process_mri(), ISQ_show_bar(), and ISQ_show_image(). |
|
|
Value: do{ fprintf(stderr,"** ERROR: Can't read GLT matrix from file %s\n",fname); \ exit(1) ; } while(0) Definition at line 6814 of file 3dDeconvolve.c. Referenced by read_glt_matrix(). |
|
Definition at line 7173 of file 3dDeconvolve.c. Referenced by basis_expr(). |
|
Definition at line 7174 of file 3dDeconvolve.c. Referenced by basis_expr(). |
|
Definition at line 7175 of file 3dDeconvolve.c. Referenced by basis_expr(). |
|
Definition at line 340 of file 3dDeconvolve.c. Referenced by matrix_to_niml(), and niml_to_matrix(). |
|
|
|
|
|
Definition at line 7169 of file 3dDeconvolve.c. Referenced by basis_parser(). |
|
Definition at line 310 of file 3dDeconvolve.c. Referenced by display_help_menu(), and get_options(). |
|
Definition at line 288 of file 3dDeconvolve.c. Referenced by identify_software(). |
|
Definition at line 289 of file 3dDeconvolve.c. Referenced by identify_software(). |
|
Definition at line 290 of file 3dDeconvolve.c. Referenced by identify_software(). |
|
for Solaris * Definition at line 283 of file 3dDeconvolve.c. Referenced by basis_write_iresp(), basis_write_sresp(), DC_error(), display_help_menu(), do_xrestore_stuff(), get_options(), identify_software(), write_bucket_data(), and write_ts_array(). |
|
Definition at line 294 of file 3dDeconvolve.c. |
|
Definition at line 6996 of file 3dDeconvolve.c. Referenced by basis_spmg1(), and basis_spmg2(). |
|
Definition at line 6998 of file 3dDeconvolve.c. Referenced by basis_spmg1(), and basis_spmg2(). |
|
Definition at line 6997 of file 3dDeconvolve.c. Referenced by basis_spmg1(), and basis_spmg2(). |
|
Definition at line 6999 of file 3dDeconvolve.c. Referenced by basis_spmg1(), and basis_spmg2(). |
|
Definition at line 7022 of file 3dDeconvolve.c. Referenced by basis_block4(). |
|
Definition at line 7075 of file 3dDeconvolve.c. Referenced by basis_block5(). |
|
Definition at line 5700 of file 3dDeconvolve.c. Referenced by PLOT_tsgray(). |
|
Definition at line 5699 of file 3dDeconvolve.c. Referenced by PLOT_matrix_gray(), and PLOT_tsgray(). |
|
Definition at line 393 of file 3dDeconvolve.c. |
|
Definition at line 296 of file 3dDeconvolve.c. |
|
Definition at line 377 of file 3dDeconvolve.c. Referenced by XSAVE_output(). |
Typedef Documentation
|
|
Function Documentation
|
Definition at line 3046 of file 3dDeconvolve.c. References basis_need_mse, CoefFilename, ENTRY, fout, malloc, MTEST, basis_expansion::nfunc, p, proc_finalize_shm_volumes(), proc_numjob, q, and zero_fill_volume().
03067 { 03068 int ip; /* parameter index */ 03069 int qp; /* number of polynomial trend baseline parameters */ 03070 int q; /* number of baseline model parameters */ 03071 int p; /* number of full model parameters */ 03072 int nxyz; /* total number of voxels */ 03073 int ixyz; /* voxel index */ 03074 int is; /* stimulus index */ 03075 int num_stimts; /* number of stimulus time series */ 03076 int num_glt; /* number of general linear tests */ 03077 int iglt; /* general linear test index */ 03078 int nlc; /* number of linear combinations in a GLT */ 03079 int ilc; /* linear combination index */ 03080 int it; /* time point index */ 03081 int nt; /* number of images in input 3d+time dataset */ 03082 int * min_lag; /* minimum time delay for impulse response */ 03083 int * max_lag; /* maximum time delay for impulse response */ 03084 03085 int fout; /* flag to output F-statistics */ 03086 int rout; /* flag to output R^2 statistics */ 03087 int tout; /* flag to output t-statistics */ 03088 int vout; /* flag to output variance map */ 03089 int bout; /* flag to output baseline coefficients */ 03090 int cout; /* flag to output fit coefficients */ 03091 int ibot,itop ; 03092 03093 03094 ENTRY("allocate_memory") ; 03095 03096 /*----- Initialize local variables -----*/ 03097 nxyz = option_data->nxyz; 03098 num_stimts = option_data->num_stimts; 03099 num_glt = option_data->num_glt; 03100 qp = option_data->qp; 03101 q = option_data->q; 03102 p = option_data->p; 03103 nt = option_data->nt; 03104 min_lag = option_data->stim_minlag; 03105 max_lag = option_data->stim_maxlag; 03106 03107 fout = option_data->fout; 03108 rout = option_data->rout; 03109 tout = option_data->tout; 03110 vout = option_data->vout; 03111 bout = 1 - (option_data->nobout || option_data->nocout); 03112 cout = 1 - option_data->nocout; 03113 03114 if( CoefFilename != NULL ){ bout = cout = 1 ; } /* 26 Jul 2004 */ 03115 03116 /*----- Allocate memory space for volume data -----*/ 03117 *coef_vol = (float **) malloc (sizeof(float *) * p); MTEST(*coef_vol); 03118 *scoef_vol = (float **) malloc (sizeof(float *) * p); MTEST(*scoef_vol); 03119 *tcoef_vol = (float **) malloc (sizeof(float *) * p); MTEST(*tcoef_vol); 03120 for (ip = 0; ip < p; ip++) 03121 { 03122 (*coef_vol)[ip] = NULL; 03123 (*scoef_vol)[ip] = NULL; 03124 (*tcoef_vol)[ip] = NULL; 03125 } 03126 03127 if (bout) 03128 for (ip = 0; ip < qp; ip++) 03129 { 03130 zero_fill_volume (&((*coef_vol)[ip]), nxyz); 03131 if (tout) zero_fill_volume (&((*tcoef_vol)[ip]), nxyz); 03132 } 03133 03134 ip = qp - 1; 03135 for (is = 0; is < num_stimts; is++) 03136 { 03137 if( basis_stim[is] != NULL ){ ibot=0 ; itop=basis_stim[is]->nfunc-1 ; } 03138 else { ibot=min_lag[is] ; itop=max_lag[is] ; } 03139 for (it = ibot; it <= itop; it++) 03140 { 03141 ip++; 03142 if (option_data->stim_base[is]) 03143 { 03144 if (bout || (option_data->iresp_filename[is] != NULL)) 03145 zero_fill_volume (&((*coef_vol)[ip]), nxyz); 03146 if (bout && tout) 03147 zero_fill_volume (&((*tcoef_vol)[ip]), nxyz); 03148 } 03149 else 03150 { 03151 if (cout || (option_data->iresp_filename[is] != NULL)) 03152 zero_fill_volume (&((*coef_vol)[ip]), nxyz); 03153 if (cout && tout) 03154 zero_fill_volume (&((*tcoef_vol)[ip]), nxyz); 03155 } 03156 if (option_data->sresp_filename[is] != NULL) 03157 zero_fill_volume (&((*scoef_vol)[ip]), nxyz); 03158 } 03159 } 03160 03161 03162 if (fout) 03163 { 03164 *fpart_vol = (float **) malloc (sizeof(float *) * num_stimts); 03165 MTEST(*fpart_vol); 03166 for (is = 0; is < num_stimts; is++) 03167 if ((! option_data->stim_base[is]) || (! option_data->nobout)) 03168 zero_fill_volume (&((*fpart_vol)[is]), nxyz); 03169 else 03170 (*fpart_vol)[is] = NULL; 03171 } 03172 03173 03174 if (rout) 03175 { 03176 *rpart_vol = (float **) malloc (sizeof(float *) * num_stimts); 03177 MTEST(*rpart_vol); 03178 for (is = 0; is < num_stimts; is++) 03179 if ((! option_data->stim_base[is]) || (! option_data->nobout)) 03180 zero_fill_volume (&((*rpart_vol)[is]), nxyz); 03181 else 03182 (*rpart_vol)[is] = NULL; 03183 } 03184 03185 03186 if (vout || basis_need_mse) zero_fill_volume (&(*mse_vol), nxyz); 03187 if (fout) zero_fill_volume (&(*ffull_vol), nxyz); 03188 if (rout) zero_fill_volume (&(*rfull_vol), nxyz); 03189 03190 03191 /*----- Allocate memory space for GLT volume data -----*/ 03192 if (num_glt > 0) 03193 { 03194 *glt_coef_vol = (float ***) malloc (sizeof(float **) * num_glt); 03195 MTEST(*glt_coef_vol); 03196 03197 if (tout) 03198 { 03199 *glt_tcoef_vol = (float ***) malloc (sizeof(float **) * num_glt); 03200 MTEST(*glt_tcoef_vol); 03201 } 03202 03203 if (fout) 03204 { 03205 *glt_fstat_vol = (float **) malloc (sizeof(float *) * num_glt); 03206 MTEST(*glt_fstat_vol); 03207 } 03208 03209 if (rout) 03210 { 03211 *glt_rstat_vol = (float **) malloc (sizeof(float *) * num_glt); 03212 MTEST(*glt_rstat_vol); 03213 } 03214 03215 for (iglt = 0; iglt < num_glt; iglt++) 03216 { 03217 nlc = option_data->glt_rows[iglt]; 03218 03219 (*glt_coef_vol)[iglt] = (float **) malloc (sizeof(float *) * nlc); 03220 MTEST((*glt_coef_vol)[iglt]); 03221 03222 if (tout) 03223 { 03224 (*glt_tcoef_vol)[iglt] 03225 = (float **) malloc (sizeof(float *) * nlc); 03226 MTEST((*glt_tcoef_vol)[iglt]); 03227 } 03228 03229 for (ilc = 0; ilc < nlc; ilc++) 03230 { 03231 zero_fill_volume (&((*glt_coef_vol)[iglt][ilc]), nxyz); 03232 if (tout) 03233 zero_fill_volume (&((*glt_tcoef_vol)[iglt][ilc]), nxyz); 03234 } 03235 03236 if (fout) zero_fill_volume (&((*glt_fstat_vol)[iglt]), nxyz); 03237 if (rout) zero_fill_volume (&((*glt_rstat_vol)[iglt]), nxyz); 03238 } 03239 } 03240 03241 03242 /*----- Allocate memory for fitted time series -----*/ 03243 if (option_data->fitts_filename != NULL) 03244 { 03245 *fitts_vol = (float **) malloc (sizeof(float **) * nt); 03246 MTEST (*fitts_vol); 03247 for (it = 0; it < nt; it++) 03248 { 03249 zero_fill_volume (&((*fitts_vol)[it]), nxyz); 03250 } 03251 } 03252 03253 /*----- Allocate memory for residual errors -----*/ 03254 if (option_data->errts_filename != NULL) 03255 { 03256 *errts_vol = (float **) malloc (sizeof(float **) * nt); 03257 MTEST (*errts_vol); 03258 for (it = 0; it < nt; it++) 03259 { 03260 zero_fill_volume (&((*errts_vol)[it]), nxyz); 03261 } 03262 } 03263 03264 #ifdef PROC_MAX 03265 if( proc_numjob > 1 ) proc_finalize_shm_volumes() ; /* RWCox */ 03266 #endif 03267 03268 EXRETURN ; 03269 } |
|
Definition at line 4671 of file 3dDeconvolve.c. References EDIT_BRICK_FACTOR, EDIT_BRICK_LABEL, EDIT_BRICK_TO_FIFT, EDIT_BRICK_TO_FITT, EDIT_coerce_autoscale_new(), EDIT_substitute_brick(), ENTRY, malloc, and MTEST.
04684 { 04685 const float EPSILON = 1.0e-10; 04686 float factor; /* factor is new scale factor for sub-brick #ib */ 04687 short *sbr ; 04688 04689 ENTRY("attach_sub_brick") ; 04690 04691 04692 /*----- allocate memory for output sub-brick -----*/ 04693 sbr = (short *) malloc (sizeof(short) * nxyz); 04694 MTEST (sbr); 04695 factor = EDIT_coerce_autoscale_new(nxyz, MRI_float,volume, MRI_short,sbr); 04696 04697 if (factor < EPSILON) factor = 0.0; 04698 else factor = 1.0 / factor; 04699 04700 /*----- edit the sub-brick -----*/ 04701 EDIT_BRICK_LABEL (new_dset, ibrick, brick_label); 04702 EDIT_BRICK_FACTOR(new_dset, ibrick, factor); 04703 04704 if (brick_type == FUNC_TT_TYPE) 04705 EDIT_BRICK_TO_FITT (new_dset, ibrick, dof); 04706 else if (brick_type == FUNC_FT_TYPE) 04707 EDIT_BRICK_TO_FIFT (new_dset, ibrick, ndof, ddof); 04708 04709 04710 /*----- attach sbr to be sub-brick #ibrick -----*/ 04711 EDIT_substitute_brick (new_dset, ibrick, MRI_short, sbr); 04712 if( bar != NULL ) bar[ibrick] = sbr ; 04713 04714 EXRETURN ; 04715 } |
|
Definition at line 7788 of file 3dDeconvolve.c. References vector::elts, nParam, Xcol_inbase, and Xcol_mean. Referenced by calculate_results().
07789 { 07790 register int jj ; 07791 register double sum ; 07792 07793 sum = 0.0 ; 07794 for( jj=0 ; jj < nParam ; jj++ ) 07795 if( Xcol_inbase[jj] == 2 ) sum += coef.elts[jj] * Xcol_mean[jj] ; 07796 07797 return (float)sum ; 07798 } |
|
Definition at line 7056 of file 3dDeconvolve.c. References basis_block_hrf4(), q, and TPEAK4. Referenced by basis_parser().
07057 { 07058 float w , tp , pp ; 07059 07060 w = basis_block_hrf4(t,T) ; 07061 if( w > 0.0f && peak > 0.0f ){ 07062 tp = TPEAK4(T) ; pp = basis_block_hrf4(tp,T) ; 07063 if( pp > 0.0f ) w *= peak / pp ; 07064 } 07065 return w ; 07066 } |
|
Definition at line 7120 of file 3dDeconvolve.c. References basis_block_hrf5(), q, and TPEAK5. Referenced by basis_parser().
07121 { 07122 float w , tp , pp ; 07123 07124 w = basis_block_hrf5(t,T) ; 07125 if( w > 0.0f && peak > 0.0f ){ 07126 tp = TPEAK5(T) ; pp = basis_block_hrf5(tp,T) ; 07127 if( pp > 0.0f ) w *= peak / pp ; 07128 } 07129 return w ; 07130 } |
|
Definition at line 7024 of file 3dDeconvolve.c. Referenced by basis_block4().
07025 { 07026 register double t26, t2, t4, t1, t42, t12, t34, t35, t16, t46, t,L ; 07027 double w ; 07028 07029 if( tt <= 0.0f || tt >= (TT+15.0f) ) return 0.0f ; 07030 07031 t = tt ; L = TT ; t4 = exp(0.4e1 - t); 07032 if( t < L ){ L = t ; t16 = 54.5982 ; } 07033 else { t16 = exp(4.0-t+L) ; } 07034 07035 t1 = t * t; 07036 t2 = t1 * t1; 07037 t4 = exp(4.0 - t); 07038 t12 = t1 * t; 07039 t26 = t16 * L; 07040 t34 = L * L; 07041 t35 = t16 * t34; 07042 t42 = t16 * t34 * L; 07043 t46 = t34 * t34; 07044 07045 w = -t2 * t4 / 0.256e3 - 0.3e1 / 0.32e2 * t4 - 0.3e1 / 0.32e2 * t4 * t 07046 - 0.3e1 / 0.64e2 * t4 * t1 - t4 * t12 / 0.64e2 + t16 * t2 / 0.256e3 07047 + 0.3e1 / 0.32e2 * t16 + 0.3e1 / 0.32e2 * t16 * t 07048 + 0.3e1 / 0.64e2 * t1 * t16 + t16 * t12 / 0.64e2 - 0.3e1 / 0.32e2 * t26 07049 - 0.3e1 / 0.32e2 * t26 * t - 0.3e1 / 0.64e2 * t1 * t26 07050 - t26 * t12 / 0.64e2 + 0.3e1 / 0.64e2 * t35 + 0.3e1 / 0.64e2 * t35 * t 07051 + 0.3e1 / 0.128e3 * t1 * t35 - t42 / 0.64e2 - t42 * t / 0.64e2 07052 + t16 * t46 / 0.256e3 ; 07053 return (float)w ; 07054 } |
|
Definition at line 7077 of file 3dDeconvolve.c. References tt. Referenced by basis_block5().
07078 { 07079 register double t , T ; 07080 register double t2,t3,t4,t5,t6,t7,t9,t10,t11,t14,t20,t25,t28,t37,t57 ; 07081 double w ; 07082 07083 if( tt <= 0.0f || tt >= (TT+15.0f) ) return 0.0f ; 07084 07085 t = tt ; T = TT ; 07086 07087 #if 1 07088 t2 = exp(-t) ; 07089 if( t <= T ){ t3 = t ; t4 = 1.0/t2 ; } 07090 else { t3 = T ; t4 = exp(T) ; } 07091 t2 *= 148.413 ; /* 148.413 = exp(5) */ 07092 #else 07093 t2 = exp(0.5e1 - t); 07094 t3 = (t <= T ? t : T); 07095 t4 = exp(t3); 07096 #endif 07097 t5 = t * t; 07098 t6 = t5 * t5; 07099 t7 = t6 * t; 07100 t9 = t3 * t3; 07101 t10 = t9 * t9; 07102 t11 = t4 * t10; 07103 t14 = t4 * t9 * t3; 07104 t20 = t4 * t3; 07105 t25 = t4 * t9; 07106 t28 = t5 * t; 07107 t37 = -0.120e3 + t4 * t7 + 0.5e1 * t11 - 0.20e2 * t14 - t4 * t10 * t3 07108 - 0.10e2 * t14 * t5 - 0.120e3 * t20 * t - 0.20e2 * t14 * t 07109 + 0.30e2 * t25 * t5 + 0.10e2 * t25 * t28 + 0.5e1 * t11 * t 07110 + 0.20e2 * t4 * t28 + 0.60e2 * t25 * t; 07111 t57 = -0.5e1 * t20 * t6 - 0.20e2 * t20 * t28 - 0.60e2 * t20 * t5 07112 - 0.5e1 * t6 - 0.20e2 * t28 + 0.120e3 * t4 - 0.120e3 * t 07113 - 0.120e3 * t20 + 0.60e2 * t25 - t7 - 0.60e2 * t5 + 0.120e3 * t4 * t 07114 + 0.60e2 * t4 * t5 + 0.5e1 * t4 * t6; 07115 w = t2 * (t37 + t57) / 0.3125e4; 07116 07117 return (float)w ; 07118 } |
|
Definition at line 6959 of file 3dDeconvolve.c. Referenced by basis_parser().
|
|
Evaluate a basis expansion, given the weights for each function in wt[] and the point of evaluation. ---------------------------------------------------------------------------- Definition at line 6917 of file 3dDeconvolve.c. References basis_funceval, basis_expansion::bfunc, basis_expansion::nfunc, basis_expansion::tbot, and basis_expansion::ttop.
06918 { 06919 float sum=0.0 ; 06920 int ii ; 06921 06922 if( x >= be->tbot && x <= be->ttop ){ 06923 for( ii=0 ; ii < be->nfunc ; ii++ ) 06924 sum += wt[ii] * basis_funceval( be->bfunc[ii] , x ) ; 06925 } 06926 06927 return sum ; 06928 } |
|
Basis function given by a user-supplied expression. Definition at line 7180 of file 3dDeconvolve.c. References ITT, IXX, IZZ, PARSER_evaluate_one(), q, and top. Referenced by basis_parser().
07181 { 07182 PARSER_code *pc = (PARSER_code *)q ; 07183 double atoz[26] , val ; 07184 07185 if( x < bot || x > top ) return 0.0f ; 07186 atoz[ITT] = x ; /* t = true time from stim */ 07187 atoz[IXX] = (x-bot)*dtinv ; /* x = scaled to [0,1] */ 07188 atoz[IZZ] = 2.0*atoz[IXX] - 1.0 ; /* z = scaled to [-1,1] */ 07189 val = PARSER_evaluate_one( pc , atoz ) ; 07190 return (float)val ; 07191 } |
|
Definition at line 6983 of file 3dDeconvolve.c. Referenced by basis_parser().
|
|
Definition at line 7138 of file 3dDeconvolve.c. Referenced by basis_parser().
07139 { 07140 float xq ; 07141 07142 x = 2.0f*(x-bot)/(top-bot) - 1.0f ; /* now in range -1..1 */ 07143 07144 if( x < -1.0f || x > 1.0f ) return 0.0f ; 07145 07146 xq = x*x ; 07147 07148 switch( (int)n ){ 07149 case 0: return 1.0f ; 07150 case 1: return x ; 07151 case 2: return (3.0f*xq-1.0f)/2.0f ; 07152 case 3: return (5.0f*xq-3.0f)*x/2.0f ; 07153 case 4: return ((35.0f*xq-30.0f)*xq+3.0f)/8.0f ; 07154 case 5: return ((63.0f*xq-70.0f)*xq+15.0f)*x/8.0f ; 07155 case 6: return (((231.0f*xq-315.0f)*xq+105.0f)*xq-5.0f)/16.0f ; 07156 case 7: return (((429.0f*xq-693.0f)*xq+315.0f)*xq-35.0f)*x/16.0f ; 07157 07158 case 8: return ((((6435.0f*xq-12012.0f)*xq+6930.0f)*xq-1260.0f)*xq+35.0f) 07159 /128.0f; 07160 07161 case 9: return ((((12155.0f*xq-25740.0f)*xq+18018.0f)*xq-4620.0f)*xq+315.0f) 07162 *x/128.0f ; 07163 } 07164 07165 return 0.0f ; /* should never be reached */ 07166 } |
|
Definition at line 6947 of file 3dDeconvolve.c. Referenced by basis_parser().
06948 { 06949 if( x < bot || x > top ) return 0.0f ; 06950 return 1.0f ; 06951 } |
|
Prototypes for some basis expansion functions appearing (much) later. * Definition at line 7197 of file 3dDeconvolve.c. References basis_func::a, basis_func::b, basis_block4(), basis_block5(), basis_cos(), basis_expr(), basis_funceval, basis_gam(), basis_legendre(), basis_normall, basis_one(), basis_sin(), basis_spmg1(), basis_spmg2(), basis_tent(), basis_expansion::bfunc, basis_func::c, calloc, dt, basis_func::f, basis_func::ffac, free, malloc, basis_expansion::name, basis_expansion::nfunc, NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, PARSER_generate_code(), PARSER_has_symbol(), PARSER_set_printout(), POLY_MAX, basis_func::q, NI_str_array::str, basis_expansion::tbot, top, and basis_expansion::ttop. Referenced by get_options().
07198 { 07199 basis_expansion *be ; 07200 char *cpt , *scp ; 07201 float bot=0.0f, top=0.0f ; 07202 int nn , nord=0 ; 07203 07204 if( sym == NULL ) return NULL ; 07205 07206 scp = strdup(sym) ; /* duplicate, for editing */ 07207 cpt = strchr(scp,'(') ; /* find opening '(' */ 07208 if( cpt != NULL ){ *cpt = '\0' ; cpt++ ; } /* cut string there */ 07209 07210 be = (basis_expansion *)malloc(sizeof(basis_expansion)) ; 07211 be->name = NULL ; /* will be fixed later */ 07212 07213 /*--- GAM(b,c) ---*/ 07214 07215 if( strcmp(scp,"GAM") == 0 ){ 07216 07217 be->nfunc = 1 ; 07218 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07219 be->bfunc[0].f = basis_gam ; 07220 if( cpt == NULL ){ 07221 be->bfunc[0].a = 8.6f ; /* Mark Cohen's parameters */ 07222 be->bfunc[0].b = 0.547f ; /* t_peak=4.7 FWHM=3.7 */ 07223 be->bfunc[0].c = 11.1f ; /* return to zero-ish */ 07224 } else { 07225 sscanf(cpt,"%f,%f",&bot,&top) ; 07226 if( bot <= 0.0f || top <= 0.0f ){ 07227 fprintf(stderr,"** ERROR: 'GAM(%s' is illegal\n",cpt) ; 07228 fprintf(stderr, 07229 " Correct format: 'GAM(b,c)' with b > 0 and c > 0.\n"); 07230 free((void *)be->bfunc); free((void *)be); free(scp); return NULL; 07231 } 07232 be->bfunc[0].a = bot ; /* t_peak = bot*top */ 07233 be->bfunc[0].b = top ; /* FWHM = 2.3*sqrt(bot)*top */ 07234 be->bfunc[0].c = bot*top + 4.0f*sqrt(bot)*top ; /* long enough */ 07235 } 07236 be->tbot = 0.0f ; be->ttop = be->bfunc[0].c ; 07237 07238 /*--- TENT(bot,top,order) ---*/ 07239 07240 } else if( strcmp(scp,"TENT") == 0 ){ 07241 float dx ; 07242 07243 if( cpt == NULL ){ 07244 fprintf(stderr,"** ERROR: 'TENT' by itself is illegal\n") ; 07245 fprintf(stderr, 07246 " Correct format: 'TENT(bot,top,n)' with bot < top and n > 0.\n") ; 07247 free((void *)be); free(scp); return NULL; 07248 } 07249 sscanf(cpt,"%f,%f,%d",&bot,&top,&nord) ; 07250 if( bot >= top || nord < 2 ){ 07251 fprintf(stderr,"** ERROR: 'TENT(%s' is illegal\n",cpt) ; 07252 fprintf(stderr, 07253 " Correct format: 'TENT(bot,top,n)' with bot < top and n > 1.\n") ; 07254 free((void *)be); free(scp); return NULL; 07255 } 07256 be->nfunc = nord ; 07257 be->tbot = bot ; be->ttop = top ; 07258 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07259 dx = (top-bot) / (nord-1) ; 07260 07261 be->bfunc[0].f = basis_tent ; 07262 be->bfunc[0].a = bot-0.001*dx ; 07263 be->bfunc[0].b = bot ; 07264 be->bfunc[0].c = bot+dx ; 07265 for( nn=1 ; nn < nord-1 ; nn++ ){ 07266 be->bfunc[nn].f = basis_tent ; 07267 be->bfunc[nn].a = bot + (nn-1)*dx ; 07268 be->bfunc[nn].b = bot + nn *dx ; 07269 be->bfunc[nn].c = bot + (nn+1)*dx ; 07270 } 07271 be->bfunc[nord-1].f = basis_tent ; 07272 be->bfunc[nord-1].a = bot + (nord-2)*dx ; 07273 be->bfunc[nord-1].b = top ; 07274 be->bfunc[nord-1].c = top + 0.001*dx ; 07275 07276 /*--- TRIG(bot,top,order) ---*/ 07277 07278 } else if( strcmp(scp,"TRIG") == 0 ){ 07279 07280 if( cpt == NULL ){ 07281 fprintf(stderr,"** ERROR: 'TRIG' by itself is illegal\n") ; 07282 fprintf(stderr, 07283 " Correct format: 'TRIG(bot,top,n)' with bot < top and n > 2.\n") ; 07284 free((void *)be); free(scp); return NULL; 07285 } 07286 sscanf(cpt,"%f,%f,%d",&bot,&top,&nord) ; 07287 if( bot >= top || nord < 3 ){ 07288 fprintf(stderr,"** ERROR: 'TRIG(%s' is illegal\n",cpt) ; 07289 fprintf(stderr, 07290 " Correct format: 'TRIG(bot,top,n)' with bot < top and n > 2.\n") ; 07291 free((void *)be); free(scp); return NULL; 07292 } 07293 be->nfunc = nord ; 07294 be->tbot = bot ; be->ttop = top ; 07295 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07296 07297 be->bfunc[0].f = basis_one ; 07298 be->bfunc[0].a = bot ; 07299 be->bfunc[0].b = top ; 07300 be->bfunc[0].c = 0.0f ; 07301 for( nn=1 ; nn < nord ; nn++ ){ 07302 be->bfunc[nn].f = basis_cos ; 07303 be->bfunc[nn].a = bot ; 07304 be->bfunc[nn].b = top ; 07305 be->bfunc[nn].c = (2.0*PI)*((nn+1)/2)/(top-bot) ; 07306 nn++ ; if( nn >= nord ) break ; 07307 be->bfunc[nn].f = basis_sin ; 07308 be->bfunc[nn].a = bot ; 07309 be->bfunc[nn].b = top ; 07310 be->bfunc[nn].c = (2.0*PI)*((nn+1)/2)/(top-bot) ; 07311 } 07312 07313 /*--- SIN(bot,top,order) ---*/ 07314 07315 } else if( strcmp(scp,"SIN") == 0 ){ 07316 07317 if( cpt == NULL ){ 07318 fprintf(stderr,"** ERROR: 'SIN' by itself is illegal\n") ; 07319 fprintf(stderr, 07320 " Correct format: 'SIN(bot,top,n)' with bot < top and n > 0.\n") ; 07321 free((void *)be); free(scp); return NULL; 07322 } 07323 sscanf(cpt,"%f,%f,%d",&bot,&top,&nord) ; 07324 if( bot >= top || nord < 1 ){ 07325 fprintf(stderr,"** ERROR: 'SIN(%s' is illegal\n",cpt) ; 07326 fprintf(stderr, 07327 " Correct format: 'SIN(bot,top,n)' with bot < top and n > 0.\n") ; 07328 free((void *)be); free(scp); return NULL; 07329 } 07330 be->nfunc = nord ; 07331 be->tbot = bot ; be->ttop = top ; 07332 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07333 07334 for( nn=0 ; nn < nord ; nn++ ){ 07335 be->bfunc[nn].f = basis_sin ; 07336 be->bfunc[nn].a = bot ; 07337 be->bfunc[nn].b = top ; 07338 be->bfunc[nn].c = PI*(nn+1)/(top-bot) ; 07339 } 07340 07341 /*--- POLY(bot,top,order) ---*/ 07342 07343 } else if( strcmp(scp,"POLY") == 0 ){ 07344 07345 if( cpt == NULL ){ 07346 fprintf(stderr,"** ERROR: 'POLY' by itself is illegal\n") ; 07347 fprintf(stderr, 07348 " Correct format: 'POLY(bot,top,n)' with bot < top and n > 0.\n") ; 07349 free((void *)be); free(scp); return NULL; 07350 } 07351 sscanf(cpt,"%f,%f,%d",&bot,&top,&nord) ; 07352 if( bot >= top || nord < 1 || nord > POLY_MAX ){ 07353 fprintf(stderr,"** ERROR: 'POLY(%s' is illegal\n",cpt) ; 07354 fprintf(stderr, 07355 " Correct format: 'POLY(bot,top,n)' with bot < top and n > 0.\n") ; 07356 free((void *)be); free(scp); return NULL; 07357 } 07358 be->nfunc = nord ; 07359 be->tbot = bot ; be->ttop = top ; 07360 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07361 be->bfunc[0].f = basis_one ; 07362 be->bfunc[0].a = bot ; 07363 be->bfunc[0].b = top ; 07364 be->bfunc[0].c = 0.0f ; 07365 for( nn=1 ; nn < nord ; nn++ ){ 07366 be->bfunc[nn].f = basis_legendre ; 07367 be->bfunc[nn].a = bot ; 07368 be->bfunc[nn].b = top ; 07369 be->bfunc[nn].c = (float)nn ; 07370 } 07371 07372 /*--- SPMG ---*/ 07373 07374 } else if( strncmp(scp,"SPMG",4) == 0 ){ 07375 07376 be->nfunc = 2 ; 07377 be->tbot = 0.0f ; be->ttop = 25.0f ; 07378 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07379 be->bfunc[0].f = basis_spmg1 ; 07380 be->bfunc[0].a = 0.0f ; 07381 be->bfunc[0].b = 0.0f ; 07382 be->bfunc[0].c = 0.0f ; 07383 be->bfunc[1].f = basis_spmg2 ; 07384 be->bfunc[1].a = 0.0f ; 07385 be->bfunc[1].b = 0.0f ; 07386 be->bfunc[1].c = 0.0f ; 07387 07388 /*--- BLOCKn(duration,peak) for n=4 or 5 ---*/ 07389 07390 } else if( strncmp(scp,"BLOCK",5) == 0 || strncmp(scp,"IGFUN",5) == 0 ){ 07391 int nb=4 ; 07392 07393 if( scp[5] != '\0' ){ 07394 nb = strtol( scp+5 , NULL , 10 ) ; 07395 if( nb != 4 && nb != 5 ){ 07396 fprintf(stderr, 07397 "** ERROR: '%s' has illegal power: only 4 or 5 allowed\n",scp) ; 07398 free((void *)be); free(scp); return NULL; 07399 } 07400 } 07401 07402 if( cpt == NULL ){ 07403 fprintf(stderr,"** ERROR: '%s' by itself is illegal\n",scp) ; 07404 fprintf(stderr, 07405 " Correct format: 'BLOCKn(dur)' with dur > 0, n=4 or 5\n" 07406 " *OR* 'BLOCKn(dur,peak)' with peak > 0 too.\n") ; 07407 free((void *)be); free(scp); return NULL; 07408 } 07409 sscanf(cpt,"%f,%f",&top,&bot) ; 07410 if( top <= 0.0f ){ 07411 fprintf(stderr,"** ERROR: '%s(%s' is illegal\n",scp,cpt) ; 07412 fprintf(stderr, 07413 " Correct format: 'BLOCKn(dur)' with dur > 0, n=4 or 4\n" 07414 " or: 'BLOCKn(dur,peak)' with peak > 0 too.\n") ; 07415 free((void *)be); free(scp); return NULL; 07416 } 07417 if( bot < 0.0f ) bot = 0.0f ; 07418 07419 be->nfunc = 1 ; 07420 be->tbot = 0.0f ; be->ttop = top+15.0f ; 07421 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07422 be->bfunc[0].f = (nb==5) ? basis_block5 : basis_block4 ; 07423 be->bfunc[0].a = top ; 07424 be->bfunc[0].b = bot ; 07425 be->bfunc[0].c = 0.0f ; 07426 07427 /*--- EXPR(bot,top) exp1 exp2 ... ---*/ 07428 07429 } else if( strcmp(scp,"EXPR") == 0 ){ /* 28 Aug 2004 */ 07430 char *ept ; 07431 NI_str_array *sar ; 07432 int nexpr , ie ; 07433 PARSER_code *pc ; 07434 07435 if( cpt == NULL ){ 07436 fprintf(stderr,"** ERROR: 'EXPR' by itself is illegal\n") ; 07437 free((void *)be); free(scp); return NULL; 07438 } 07439 sscanf(cpt,"%f,%f",&bot,&top) ; 07440 if( top <= bot ){ 07441 fprintf(stderr,"** ERROR: 'EXPR(%f,%f)' has illegal time range\n",bot,top) ; 07442 free((void *)be); free(scp); return NULL; 07443 } 07444 ept = strchr( cpt , ')' ) ; 07445 if( ept == NULL ){ 07446 fprintf(stderr,"** ERROR: 'EXPR(%f,%f)' has no expressions!?\n",bot,top); 07447 free((void *)be); free(scp); return NULL; 07448 } 07449 sar = NI_decode_string_list( ept+1 , "~" ) ; 07450 if( sar == NULL || sar->num == 0 ){ 07451 fprintf(stderr,"** ERROR: 'EXPR(%f,%f)' has no expressions!?\n",bot,top); 07452 free((void *)be); free(scp); return NULL; 07453 } 07454 be->nfunc = nexpr = sar->num ; 07455 be->tbot = bot ; be->ttop = top ; 07456 be->bfunc = (basis_func *)calloc(sizeof(basis_func),be->nfunc) ; 07457 PARSER_set_printout(1) ; 07458 for( ie=0 ; ie < nexpr ; ie++ ){ 07459 pc = PARSER_generate_code( sar->str[ie] ) ; 07460 if( pc == NULL ){ 07461 fprintf(stderr,"** ERROR: unparsable EXPRession '%s'\n",sar->str[ie]) ; 07462 free((void *)be); free(scp); return NULL; 07463 } 07464 if( strcmp(sar->str[ie],"1") != 0 && /* must either be "1" */ 07465 !PARSER_has_symbol("t",pc) && /* or contain symbol */ 07466 !PARSER_has_symbol("x",pc) && /* 't', 'x', or 'z' */ 07467 !PARSER_has_symbol("z",pc) ){ 07468 fprintf(stderr, 07469 "** ERROR: illegal EXPRession '%s' lacks symbol t, x, or z\n", 07470 sar->str[ie]) ; 07471 free((void *)be); free(scp); return NULL; 07472 } 07473 be->bfunc[ie].f = basis_expr ; 07474 be->bfunc[ie].a = bot ; 07475 be->bfunc[ie].b = top ; 07476 be->bfunc[ie].c = 1.0f/(top-bot) ; /* for ease of scaling */ 07477 be->bfunc[ie].q = (void *)pc ; 07478 } 07479 PARSER_set_printout(0) ; 07480 07481 NI_delete_str_array(sar) ; 07482 07483 /*--- NO MORE BASIS FUNCTION CHOICES ---*/ 07484 07485 } else { 07486 fprintf(stderr,"** ERROR: '%s' is unknown response function type\n",scp) ; 07487 free((void *)be); free(scp); return NULL; 07488 } 07489 07490 /* 28 Apr 2005: set scaling factors */ 07491 07492 for( nn=0 ; nn < be->nfunc ; nn++ ) /* initialize factors to 1.0 */ 07493 be->bfunc[nn].ffac = 1.0 ; 07494 07495 /* for each basis function, find its peak value, then 07496 set ffac so that the peak value becomes basis_normall */ 07497 07498 #undef BNSUB 07499 #define BNSUB 999 07500 if( basis_normall > 0.0f ){ 07501 int jj ; float dt , ftop , val ; 07502 bot = be->tbot ; top = be->ttop ; dt = (top-bot)/BNSUB ; 07503 for( nn=0 ; nn < be->nfunc ; nn++ ){ 07504 ftop = 0.0f ; 07505 for( jj=0 ; jj <= BNSUB ; jj++ ){ 07506 val = basis_funceval( be->bfunc[nn] , bot+jj*dt ) ; 07507 val = fabs(val) ; if( val > ftop ) ftop = val ; 07508 } 07509 if( ftop > 0.0f ) be->bfunc[nn].ffac = basis_normall / ftop ; 07510 } 07511 } 07512 07513 free(scp); return be; 07514 } |
|
Definition at line 6971 of file 3dDeconvolve.c. Referenced by basis_parser().
|
|
Definition at line 7001 of file 3dDeconvolve.c. References a, c, q, SPM_A1, SPM_A2, SPM_P1, and SPM_P2. Referenced by basis_parser().
|
|
Definition at line 7008 of file 3dDeconvolve.c. References a, c, q, SPM_A1, SPM_A2, SPM_P1, and SPM_P2. Referenced by basis_parser().
|
|
Tent basis function:
Definition at line 6936 of file 3dDeconvolve.c. Referenced by basis_parser().
|
|
For IRFs defined by -stim_times basis function expansion, write out a 3D+time dataset with time spacing dt. ------------------------------------------------------------------------ Definition at line 7521 of file 3dDeconvolve.c. References ADN_datum_all, ADN_label1, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_self_name, ADN_ttdel, ADN_ttorg, argc, basis_funceval, basis_expansion::bfunc, calloc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_BRIKNAME, DSET_delete, DSET_TR, DSET_write, dt, EDIT_BRICK_FACTOR, EDIT_coerce_autoscale_new(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), free, THD_diskptr::header_name, DC_options::input_filename, malloc, basis_expansion::nfunc, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, PROGRAM_NAME, basis_expansion::tbot, THD_is_file(), THD_open_dataset(), tross_Append_History(), tross_commandline(), tross_Copy_History(), tross_multi_Append_History(), tt, and basis_expansion::ttop. Referenced by output_results().
07525 { 07526 int nvox, ii, nf, allz, ts_length ; 07527 register int pp, ib ; 07528 float *wt , *tt , **hout , factor , **bb ; 07529 short *bar ; 07530 THD_3dim_dataset *in_dset = NULL; 07531 THD_3dim_dataset *out_dset = NULL; 07532 char *commandline , label[512] ; 07533 const float EPSILON = 1.0e-10 ; 07534 07535 /* open input 3D+time dataset to get some parameters */ 07536 07537 in_dset = THD_open_dataset(option_data->input_filename); 07538 nvox = in_dset->daxes->nxx * in_dset->daxes->nyy * in_dset->daxes->nzz; 07539 07540 if( dt <= 0.0f ) dt = DSET_TR(in_dset) ; 07541 if( dt <= 0.0f ) dt = 1.0f ; 07542 07543 /* create output dataset on the input as a model, then close the input */ 07544 07545 out_dset = EDIT_empty_copy( in_dset ) ; 07546 tross_Copy_History( in_dset , out_dset ) ; 07547 DSET_delete( in_dset ) ; 07548 07549 /* historicize the output */ 07550 07551 commandline = tross_commandline( PROGRAM_NAME , argc , argv ) ; 07552 sprintf( label , "Impulse response: %s" , output_filename ) ; 07553 if( commandline != NULL ) 07554 tross_multi_Append_History( out_dset , commandline,label,NULL ) ; 07555 else 07556 tross_Append_History ( out_dset, label); 07557 free((void *)commandline) ; 07558 07559 ts_length = 1 + (int)ceil( (be->ttop - be->tbot)/dt ) ; /* 13 Apr 2005: +1 */ 07560 07561 /* modify the output dataset appropriately */ 07562 07563 (void ) EDIT_dset_items( out_dset, 07564 ADN_prefix, output_filename, 07565 ADN_label1, output_filename, 07566 ADN_self_name, output_filename, 07567 ADN_malloc_type, DATABLOCK_MEM_MALLOC, 07568 ADN_datum_all, MRI_short, 07569 ADN_nvals, ts_length, 07570 ADN_ntt, ts_length, 07571 ADN_ttdel, dt , 07572 ADN_ttorg, be->tbot, 07573 ADN_none ) ; 07574 07575 if( THD_is_file(out_dset->dblk->diskptr->header_name) ){ 07576 fprintf(stderr, 07577 "** ERROR: Output dataset file %s already exists - won't overwrite\n", 07578 out_dset->dblk->diskptr->header_name ) ; 07579 DSET_delete(out_dset) ; return ; 07580 } 07581 07582 /* create output bricks (float for now, will scale to shorts later) */ 07583 07584 hout = (float **) malloc( sizeof(float *) * ts_length ) ; 07585 for( ib=0 ; ib < ts_length ; ib++ ) 07586 hout[ib] = (float *)calloc(sizeof(float),nvox) ; 07587 07588 /* create basis vectors for the expansion on the dt time grid */ 07589 07590 nf = be->nfunc ; 07591 wt = (float *) malloc( sizeof(float) * nf ) ; 07592 tt = (float *) malloc( sizeof(float) * ts_length ) ; 07593 07594 for( ib=0 ; ib < ts_length ; ib++ ) /* output time grid */ 07595 tt[ib] = be->tbot + ib*dt ; 07596 07597 bb = (float **) malloc( sizeof(float *) * nf ) ; 07598 for( pp=0 ; pp < nf ; pp++ ){ 07599 bb[pp] = (float *) malloc( sizeof(float) * ts_length ) ; 07600 for( ib=0 ; ib < ts_length ; ib++ ) 07601 bb[pp][ib] = basis_funceval( be->bfunc[pp] , tt[ib] ) ; 07602 } 07603 07604 /* loop over voxels: 07605 extract coefficient (weights) for each basis function into wt 07606 sum up basis vectors times wt to get result, save into output arrays */ 07607 07608 for( ii=0 ; ii < nvox ; ii++ ){ 07609 allz = 1 ; 07610 for( pp=0 ; pp < nf ; pp++ ){ 07611 wt[pp] = wtar[pp][ii] ; allz = ( allz && (wt[pp] == 0.0f) ); 07612 } 07613 07614 if( allz ){ 07615 for( ib=0 ; ib < ts_length ; ib++ ) hout[ib][ii] = 0.0f ; 07616 } else { 07617 register float sum ; 07618 for( ib=0 ; ib < ts_length ; ib++ ){ 07619 sum = 0.0f ; 07620 for( pp=0 ; pp < nf ; pp++ ) sum += wt[pp] * bb[pp][ib] ; 07621 hout[ib][ii] = sum ; 07622 } 07623 } 07624 } 07625 07626 /* toss some trash */ 07627 07628 for( pp=0 ; pp < nf ; pp++ ) free((void *)bb[pp]) ; 07629 free((void *)bb) ; free((void *)tt) ; free((void *)wt) ; 07630 07631 /* scale floating point bricks to shorts and insert into output dataset */ 07632 07633 for( ib=0 ; ib < ts_length ; ib++ ){ 07634 bar = (short *) malloc( sizeof(short) * nvox ) ; 07635 factor = EDIT_coerce_autoscale_new(nvox, MRI_float,hout[ib], MRI_short,bar) ; 07636 if( factor < EPSILON ) factor = 0.0f ; /* if brick is all zero */ 07637 else factor = 1.0f / factor ; 07638 EDIT_BRICK_FACTOR( out_dset , ib , factor ) ; 07639 EDIT_substitute_brick( out_dset , ib , MRI_short , bar ) ; 07640 free((void *)hout[ib]) ; 07641 } 07642 free((void *)hout) ; 07643 07644 /* and save the results to disk! */ 07645 07646 DSET_write( out_dset ) ; 07647 if( verb ) 07648 fprintf(stderr,"++ Wrote iresp 3D+time dataset into %s\n",DSET_BRIKNAME(out_dset)) ; 07649 07650 DSET_delete( out_dset ) ; 07651 return ; 07652 } |
|
|
|
Definition at line 7656 of file 3dDeconvolve.c. References ADN_datum_all, ADN_label1, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_self_name, ADN_ttdel, ADN_ttorg, argc, basis_funceval, basis_expansion::bfunc, calloc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_BRIKNAME, DSET_delete, DSET_TR, DSET_write, dt, EDIT_BRICK_FACTOR, EDIT_coerce_autoscale_new(), EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), matrix::elts, free, THD_diskptr::header_name, DC_options::input_filename, malloc, basis_expansion::nfunc, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, PROGRAM_NAME, basis_expansion::tbot, THD_is_file(), THD_open_dataset(), tross_Append_History(), tross_commandline(), tross_Copy_History(), tross_multi_Append_History(), tt, and basis_expansion::ttop. Referenced by output_results().
07661 { 07662 int nvox, ii, nf, allz, ts_length ; 07663 register int pp,qq, ib ; 07664 register float sum ; 07665 float *vv , *tt , **hout , factor , **bb ; 07666 short *bar ; 07667 THD_3dim_dataset *in_dset = NULL; 07668 THD_3dim_dataset *out_dset = NULL; 07669 char *commandline , label[512] ; 07670 const float EPSILON = 1.0e-10 ; 07671 07672 /* open input 3D+time dataset to get some parameters */ 07673 07674 in_dset = THD_open_dataset(option_data->input_filename); 07675 nvox = in_dset->daxes->nxx * in_dset->daxes->nyy * in_dset->daxes->nzz; 07676 07677 if( dt <= 0.0f ) dt = DSET_TR(in_dset) ; 07678 if( dt <= 0.0f ) dt = 1.0f ; 07679 07680 /* create output dataset on the input as a model, then close the input */ 07681 07682 out_dset = EDIT_empty_copy( in_dset ) ; 07683 tross_Copy_History( in_dset , out_dset ) ; 07684 DSET_delete( in_dset ) ; 07685 07686 /* historicize the output */ 07687 07688 commandline = tross_commandline( PROGRAM_NAME , argc , argv ) ; 07689 sprintf( label , "Sigma response: %s" , output_filename ) ; 07690 if( commandline != NULL ) 07691 tross_multi_Append_History( out_dset , commandline,label,NULL ) ; 07692 else 07693 tross_Append_History ( out_dset, label); 07694 free((void *)commandline) ; 07695 07696 ts_length = 1 + (int)ceil( (be->ttop - be->tbot)/dt ) ; 07697 07698 /* modify the output dataset appropriately */ 07699 07700 (void ) EDIT_dset_items( out_dset, 07701 ADN_prefix, output_filename, 07702 ADN_label1, output_filename, 07703 ADN_self_name, output_filename, 07704 ADN_malloc_type, DATABLOCK_MEM_MALLOC, 07705 ADN_datum_all, MRI_short, 07706 ADN_nvals, ts_length, 07707 ADN_ntt, ts_length, 07708 ADN_ttdel, dt , 07709 ADN_ttorg, be->tbot, 07710 ADN_none ) ; 07711 07712 if( THD_is_file(out_dset->dblk->diskptr->header_name) ){ 07713 fprintf(stderr, 07714 "** ERROR: Output dataset file %s already exists - won't overwrite\n", 07715 out_dset->dblk->diskptr->header_name ) ; 07716 DSET_delete(out_dset) ; return ; 07717 } 07718 07719 /* create output bricks (float for now, will scale to shorts later) */ 07720 07721 hout = (float **) malloc( sizeof(float *) * ts_length ) ; 07722 for( ib=0 ; ib < ts_length ; ib++ ) 07723 hout[ib] = (float *)calloc(sizeof(float),nvox) ; 07724 07725 nf = be->nfunc ; 07726 tt = (float *) malloc( sizeof(float) * ts_length ) ; 07727 07728 for( ib=0 ; ib < ts_length ; ib++ ) /* output time grid */ 07729 tt[ib] = be->tbot + ib*dt ; 07730 07731 /* evaluate basis vectors for output on dt time grid */ 07732 07733 bb = (float ** ) malloc( sizeof(float *) * nf ) ; 07734 for( pp=0 ; pp < nf ; pp++ ){ 07735 bb[pp] = (float * ) malloc( sizeof(float ) * ts_length ) ; 07736 for( ib=0 ; ib < ts_length ; ib++ ) 07737 bb[pp][ib] = basis_funceval( be->bfunc[pp] , tt[ib] ) ; 07738 } 07739 free((void *)tt) ; 07740 07741 /* evaluate unscaled variance on dt time grid */ 07742 07743 vv = (float *) malloc( sizeof(float) * ts_length ) ; 07744 for( ib=0 ; ib < ts_length ; ib++ ){ 07745 sum = 0.0f ; 07746 for( pp=0 ; pp < nf ; pp++ ){ 07747 for( qq=0 ; qq < nf ; qq++ ) 07748 sum += cvar.elts[pbot+pp][pbot+qq] * bb[pp][ib] * bb[qq][ib] ; 07749 } 07750 vv[ib] = (sum >= 0.0f) ? sum : 0.0f ; 07751 } 07752 for( pp=0 ; pp < nf ; pp++ ) free((void *)bb[pp]) ; 07753 free((void *)bb) ; 07754 07755 /* loop over voxels, scale by mse to get variance */ 07756 07757 for( ii=0 ; ii < nvox ; ii++ ){ 07758 for( ib=0 ; ib < ts_length ; ib++ ) 07759 hout[ib][ii] = sqrt( vv[ib] * mse[ii] ) ; 07760 } 07761 free((void *)vv) ; 07762 07763 /* scale floating point bricks to shorts and insert into output dataset */ 07764 07765 for( ib=0 ; ib < ts_length ; ib++ ){ 07766 bar = (short *) malloc( sizeof(short) * nvox ) ; 07767 factor = EDIT_coerce_autoscale_new(nvox, MRI_float,hout[ib], MRI_short,bar) ; 07768 if( factor < EPSILON ) factor = 0.0f ; /* if brick is all zero */ 07769 else factor = 1.0f / factor ; 07770 EDIT_BRICK_FACTOR( out_dset , ib , factor ) ; 07771 EDIT_substitute_brick( out_dset , ib , MRI_short , bar ) ; 07772 free((void *)hout[ib]) ; 07773 } 07774 free((void *)hout) ; 07775 07776 /* and save the results to disk! */ 07777 07778 DSET_write( out_dset ) ; 07779 if( verb ) 07780 fprintf(stderr,"++ Wrote sresp 3D+time dataset into %s\n",DSET_BRIKNAME(out_dset)) ; 07781 07782 DSET_delete( out_dset ) ; 07783 return ; 07784 } |
|
Definition at line 3669 of file 3dDeconvolve.c. References AFNI_yesenv(), baseline_mean(), calloc, matrix::cols, COX_clock_time(), DESTROY_IMARR, DSET_load, DSET_unload, vector::elts, matrix::elts, ENTRY, ev, extract_ts_array(), free, glt_analysis(), i, IMARR_SUBIM, init_glt_analysis(), init_indep_var_matrix(), init_regression_analysis(), iochan_sleep(), JPEG_matrix_gray(), malloc, matrix_check_columns(), matrix_destroy(), matrix_initialize(), matrix_singvals(), matrix_sprint(), matrix_transpose(), MRI_FLOAT_PTR, MTEST, basis_expansion::nfunc, p, proc_ind, proc_numjob, proc_pid, proc_vox_bot, proc_vox_top, q, regression_analysis(), report_evaluation(), report_results(), matrix::rows, save_voxel(), show_singvals, THD_extract_many_series(), vector_create(), vector_destroy(), vector_initialize(), voxel_base, vstep_print(), Xcol_inbase, and Xcol_mean.
03698 { 03699 float * ts_array = NULL; /* array of measured data for one voxel */ 03700 03701 #ifdef USE_GET 03702 int do_get = 0 ; /* flag to use multi-gets */ 03703 #endif 03704 03705 int qp; /* number of poly. trend baseline parameters */ 03706 int q; /* number of baseline model parameters */ 03707 int p; /* number of full model parameters */ 03708 int polort; /* degree of polynomial for baseline model */ 03709 int m; /* parameter index */ 03710 int n; /* data point index */ 03711 03712 vector coef; /* regression parameters */ 03713 vector scoef; /* std. devs. for regression parameters */ 03714 vector tcoef; /* t-statistics for regression parameters */ 03715 float * fpart = NULL; /* partial F-statistics for the stimuli */ 03716 float * rpart = NULL; /* partial R^2 stats. for the stimuli */ 03717 float ffull; /* full model F-statistic */ 03718 float rfull; /* full model R^2 stat. */ 03719 float mse; /* mean square error from full model */ 03720 03721 matrix xdata; /* independent variable matrix */ 03722 matrix x_full; /* extracted X matrix for full model */ 03723 matrix xtxinv_full; /* matrix: 1/(X'X) for full model */ 03724 matrix xtxinvxt_full; /* matrix: (1/(X'X))X' for full model */ 03725 matrix x_base; /* extracted X matrix for baseline model */ 03726 matrix xtxinvxt_base; /* matrix: (1/(X'X))X' for baseline model */ 03727 matrix * x_rdcd = NULL; /* extracted X matrices for reduced models */ 03728 matrix * xtxinvxt_rdcd = NULL; 03729 /* matrix: (1/(X'X))X' for reduced models */ 03730 vector y; /* vector of measured data */ 03731 03732 int ixyz; /* voxel index */ 03733 int nxyz; /* number of voxels per dataset */ 03734 03735 int nt; /* number of images in input 3d+time dataset */ 03736 int N; /* number of usable data points */ 03737 03738 int num_stimts; /* number of stimulus time series */ 03739 int * baseline; /* flag for stim function in baseline model */ 03740 int * min_lag; /* minimum time delay for impulse response */ 03741 int * max_lag; /* maximum time delay for impulse response */ 03742 int * nptr; /* number of stim fn. time points per TR */ 03743 char ** stim_label; /* label for stimulus time series */ 03744 03745 int i; /* data point index */ 03746 int is; /* stimulus index */ 03747 int ilag; /* time lag index */ 03748 float stddev; /* normalized parameter standard deviation */ 03749 float rms_min; /* minimum variation in data to fit full model */ 03750 char * label; /* string containing stat. summary of results */ 03751 int nodata; /* flag for 'no data' option */ 03752 int novar; /* flag for insufficient variation in data */ 03753 03754 int iglt; /* general linear test index */ 03755 int ilc; /* linear combination index */ 03756 int num_glt; /* number of general linear tests */ 03757 char ** glt_label; /* label for general linear test */ 03758 int * glt_rows; /* number of linear constraints in glt */ 03759 matrix * cxtxinvct = NULL; /* matrices: C(1/(X'X))C' for GLT */ 03760 matrix * glt_amat = NULL; /* constant GLT matrices for later use */ 03761 vector * glt_coef = NULL; /* linear combinations from GLT matrices */ 03762 vector * glt_tcoef = NULL; /* t-statistics for GLT linear combinations */ 03763 float * fglt = NULL; /* F-statistics for the general linear tests */ 03764 float * rglt = NULL; /* R^2 stats. for the general linear tests */ 03765 03766 float * fitts = NULL; /* full model fitted time series */ 03767 float * errts = NULL; /* full model residual error time series */ 03768 03769 int vstep ; /* interval progress meter dots */ 03770 double ct ; /* clock time */ 03771 03772 ENTRY("calculate_results") ; 03773 03774 /*----- Initialize local variables -----*/ 03775 nodata = option_data->nodata; 03776 nxyz = option_data->nxyz; 03777 nt = option_data->nt; 03778 rms_min = option_data->rms_min; 03779 num_stimts = option_data->num_stimts; 03780 stim_label = option_data->stim_label; 03781 baseline = option_data->stim_base; 03782 min_lag = option_data->stim_minlag; 03783 max_lag = option_data->stim_maxlag; 03784 nptr = option_data->stim_nptr; 03785 num_glt = option_data->num_glt; 03786 glt_label = option_data->glt_label; 03787 glt_rows = option_data->glt_rows; 03788 03789 polort = option_data->polort; 03790 qp = option_data->qp; 03791 q = option_data->q; 03792 p = option_data->p; 03793 03794 N = option_data->N; 03795 03796 03797 /*----- Initialize matrices and vectors -----*/ 03798 matrix_initialize (&xdata); 03799 matrix_initialize (&x_full); 03800 matrix_initialize (&xtxinv_full); 03801 matrix_initialize (&xtxinvxt_full); 03802 matrix_initialize (&x_base); 03803 matrix_initialize (&xtxinvxt_base); 03804 vector_initialize (&coef) ; 03805 vector_initialize (&scoef); 03806 vector_initialize (&tcoef); 03807 vector_initialize (&y); 03808 03809 if (num_stimts > 0) 03810 { 03811 x_rdcd = (matrix *) malloc (sizeof(matrix) * num_stimts); 03812 MTEST (x_rdcd); 03813 xtxinvxt_rdcd = (matrix *) malloc (sizeof(matrix) * num_stimts); 03814 MTEST (xtxinvxt_rdcd); 03815 03816 for (is =0; is < num_stimts; is++) 03817 { 03818 matrix_initialize (&x_rdcd[is]); 03819 matrix_initialize (&xtxinvxt_rdcd[is]); 03820 } 03821 } 03822 03823 if (num_glt > 0) 03824 { 03825 cxtxinvct = (matrix *) malloc (sizeof(matrix) * num_glt); 03826 glt_amat = (matrix *) malloc (sizeof(matrix) * num_glt); 03827 glt_coef = (vector *) malloc (sizeof(vector) * num_glt); 03828 glt_tcoef = (vector *) malloc (sizeof(vector) * num_glt); 03829 03830 for (iglt =0; iglt < num_glt; iglt++) 03831 { 03832 matrix_initialize (&cxtxinvct[iglt]); 03833 matrix_initialize (&glt_amat[iglt]); 03834 vector_initialize (&glt_coef[iglt]); 03835 vector_initialize (&glt_tcoef[iglt]); 03836 } 03837 } 03838 03839 03840 /*----- Allocate memory -----*/ 03841 if (num_stimts > 0) 03842 { 03843 fpart = (float *) malloc (sizeof(float) * num_stimts); MTEST (fpart); 03844 rpart = (float *) malloc (sizeof(float) * num_stimts); MTEST (rpart); 03845 } 03846 if (num_glt > 0) 03847 { 03848 fglt = (float *) malloc (sizeof(float) * num_glt); MTEST (fglt); 03849 rglt = (float *) malloc (sizeof(float) * num_glt); MTEST (rglt); 03850 } 03851 03852 if (option_data->input1D_filename == NULL) 03853 { 03854 #ifdef USE_GET 03855 do_get = 1 ; /* don't need a pre-malloc-ed array for multi-gets */ 03856 #else 03857 ts_array = (float *) malloc (sizeof(float) * nt); MTEST (ts_array); 03858 #endif 03859 } 03860 fitts = (float *) malloc (sizeof(float) * nt); MTEST (fitts); 03861 errts = (float *) malloc (sizeof(float) * nt); MTEST (errts); 03862 03863 03864 /*----- Initialize the independent variable matrix -----*/ 03865 03866 ct = COX_clock_time() ; 03867 03868 init_indep_var_matrix (p, qp, polort, nt, N, good_list, block_list, 03869 num_blocks, num_stimts, stimulus, stim_length, 03870 min_lag, max_lag, nptr, option_data->stim_base , &xdata); 03871 if (option_data->xout) matrix_sprint ("X matrix:", xdata); 03872 03873 if( option_data->xjpeg_filename != NULL ) /* 21 Jul 2004 */ 03874 JPEG_matrix_gray( xdata , option_data->xjpeg_filename ) ; 03875 03876 03877 /*-- 14 Jul 2004: check matrix for bad columns - RWCox --*/ 03878 03879 { int *iar , k , nerr=0 ; 03880 iar = matrix_check_columns( xdata , 1.e-7 ) ; 03881 if( iar != NULL ){ 03882 fprintf(stderr,"** WARNING: Problems with the X matrix columns:\n") ; 03883 for( k=0 ; iar[2*k] >= 0 ; k++ ){ 03884 if( iar[2*k+1] >= 0 ){ 03885 fprintf(stderr," * Columns %d and %d are nearly collinear!\n", 03886 iar[2*k],iar[2*k+1] ) ; nerr++ ; 03887 } else { 03888 fprintf(stderr," * Column %d is all zeros: %s\n", 03889 iar[2*k] , 03890 use_psinv ? "SVD on => will be kept" 03891 : "SVD off => will be excised" ) ; 03892 } 03893 } 03894 if( nerr > 0 && AFNI_yesenv("AFNI_3dDeconvolve_nodup") ){ 03895 fprintf(stderr,"** ERROR: can't continue after above warnings!\n"); 03896 exit(1) ; 03897 } 03898 free(iar) ; 03899 } 03900 } 03901 03902 /*-- 14 Jul 2004: calculate matrix condition number - RWCox --*/ 03903 03904 #ifndef PSINV_EPS 03905 #define PSINV_EPS 1.e-12 03906 #endif 03907 if( !option_data->nocond ){ 03908 double *ev , ebot,emin,emax ; int i,nsmall=0 ; 03909 ev = matrix_singvals( xdata ) ; 03910 emax = 1.e-38 ; 03911 for( i=0 ; i < xdata.cols ; i++ ){ 03912 if( ev[i] > emax ) emax = ev[i] ; 03913 } 03914 ebot = sqrt(PSINV_EPS)*emax ; emin = 1.e+38 ; 03915 for( i=0 ; i < xdata.cols ; i++ ){ 03916 if( ev[i] >= ebot && ev[i] < emin ) emin = ev[i] ; 03917 if( ev[i] < ebot ) nsmall++ ; 03918 } 03919 if( nsmall > 0 ){ 03920 fprintf(stderr, 03921 "** WARNING: Largest singular value=%g;" 03922 " %d %s less than cutoff=%g\n" 03923 " Implies strong collinearity in the input regressors\n", 03924 emax , nsmall , (nsmall==1)?"is":"are" , ebot ) ; 03925 show_singvals = 1 ; 03926 } 03927 if( show_singvals ){ 03928 fprintf(stderr,"++ Matrix singular values:") ; 03929 for( i=0; i < xdata.cols ; i++ ) fprintf(stderr," %g",ev[i]) ; 03930 fprintf(stderr,"\n") ; 03931 } 03932 free((void *)ev) ; 03933 if( emin <= 0.0 || emax <= 0.0 ){ 03934 fprintf(stderr,"** Matrix condition: UNDEFINED: " 03935 "min ev=%g max ev=%g ** VERY BAD **\n",emin,emax ) ; 03936 } else { 03937 double cond = sqrt(emax/emin) ; 03938 if( !use_psinv ) cond = cond*cond ; /* Gaussian elim is twice as bad */ 03939 fprintf(stderr,"++ (%dx%d) Matrix condition [%s]: %g", 03940 xdata.rows,xdata.cols , (use_psinv) ? "X" : "XtX" , cond ) ; 03941 #ifdef FLOATIZE 03942 if( cond > 100.0 ) fprintf(stderr," ** BEWARE **") ; 03943 #else 03944 if( cond > 1.e6 ) fprintf(stderr," ** BEWARE **") ; 03945 #endif 03946 fprintf(stderr,"\n") ; 03947 } 03948 } 03949 03950 /*----- Initialization for the regression analysis -----*/ 03951 init_regression_analysis (p, qp, num_stimts, baseline, min_lag, max_lag, 03952 xdata, &x_full, &xtxinv_full, &xtxinvxt_full, 03953 &x_base, &xtxinvxt_base, x_rdcd, xtxinvxt_rdcd); 03954 if ((option_data->xout) || nodata) 03955 matrix_sprint ("(X'X) inverse matrix:", xtxinv_full); 03956 03957 /*----- Save some of this stuff for later, dude -----*/ 03958 X = x_full ; /* 25 Jul 2004 (RWCox) */ 03959 XtXinv = xtxinv_full ; 03960 XtXinvXt = xtxinvxt_full ; 03961 03962 { int m , npar , j ; /* 31 Aug 2004 (RWCox) */ 03963 register double sum ; 03964 float mmax ; 03965 03966 Xcol_inbase = (int *) calloc(sizeof(int) ,p) ; 03967 Xcol_mean = (float *)calloc(sizeof(float),p) ; 03968 03969 for( is=0 ; is < qp ; is++ ) Xcol_inbase[is] = 1 ; /* mark baseline columns */ 03970 m = qp ; 03971 for( is=0 ; is < num_stimts ; is++ ){ 03972 npar = (basis_stim[is] != NULL) 03973 ? basis_stim[is]->nfunc 03974 : option_data->stim_maxlag[is] - option_data->stim_minlag[is] + 1 ; 03975 03976 if( baseline[is] ) for( j=0 ; j < npar ; j++ ) Xcol_inbase[m+j] = 1 ; 03977 m += npar ; 03978 } 03979 03980 mmax = 0.0f ; 03981 for( j=0 ; j < p ; j++ ){ /* compute mean of each column */ 03982 sum = 0.0 ; 03983 for( i=0 ; i < X.rows ; i++ ) sum += X.elts[i][j] ; 03984 Xcol_mean[j] = (float)(sum/X.rows) ; 03985 if( Xcol_inbase[j] && fabs(Xcol_mean[j]) > mmax ) /* find largest */ 03986 mmax = fabs(Xcol_mean[j]) ; /* mean of baseline cols */ 03987 } 03988 03989 if( mmax > 0.0f ){ /* mark baseline cols that have nontrivial means */ 03990 mmax *= 9.99e-6 ; 03991 for( j=0 ; j < p ; j++ ) 03992 if( Xcol_inbase[j] && fabs(Xcol_mean[j]) > mmax ) Xcol_inbase[j] = 2 ; 03993 } 03994 } 03995 03996 /*--- Compute abs sum of matrix [xtxinvxt][xdata]-I [19 Aug 2004]---*/ 03997 if( !option_data->nocond ){ 03998 double esum , sum ; 03999 int nn=xdata.rows , mm=xdata.cols , ii,jj,kk ; 04000 char *www = "\0" ; 04001 fprintf(stderr,"++ Matrix inverse average error = ") ; 04002 esum = 0.0 ; 04003 for( ii=0 ; ii < mm ; ii++ ){ 04004 for( jj=0 ; jj < mm ; jj++ ){ 04005 sum = (ii==jj) ? -1.0 : 0.0 ; 04006 for( kk=0 ; kk < nn ; kk++ ) 04007 sum += xtxinvxt_full.elts[ii][kk]*xdata.elts[kk][jj] ; 04008 esum += fabs(sum) ; 04009 } 04010 } 04011 esum /= (mm*mm) ; 04012 if( esum > 1.e-3 ) www = " ** WARNING!!! **" ; 04013 fprintf(stderr,"%g %s\n",esum,www) ; 04014 } 04015 04016 /*-- 19 Aug 2004: plot matrix pseudoinverse as well --*/ 04017 if( option_data->xjpeg_filename != NULL ){ 04018 char *jpt , *jsuf=".jpg" ; 04019 char *fn = calloc( sizeof(char) , strlen(option_data->xjpeg_filename)+16 ) ; 04020 matrix xpsinv ; 04021 04022 matrix_initialize( &xpsinv ) ; 04023 matrix_transpose( xtxinvxt_full , &xpsinv ) ; 04024 04025 strcpy(fn,option_data->xjpeg_filename) ; 04026 jpt = strstr(fn,".jpg") ; 04027 if( jpt == NULL ){ jpt = strstr(fn,".JPG") ; jsuf = ".JPG" ; } 04028 if( jpt == NULL ) jpt = fn + strlen(fn) ; 04029 strcpy(jpt,"_psinv") ; strcat(fn,jsuf) ; 04030 04031 JPEG_matrix_gray( xpsinv , fn ) ; 04032 free((void *)fn) ; matrix_destroy( &xpsinv ) ; 04033 } 04034 04035 /*----- Initialization for the general linear test analysis -----*/ 04036 if (num_glt > 0) 04037 init_glt_analysis (xtxinv_full, num_glt, glt_cmat, glt_amat, cxtxinvct); 04038 04039 ct = COX_clock_time() - ct ; 04040 fprintf(stderr,"++ Matrix setup time = %.2f s\n",ct) ; /* 25 Apr 2005 */ 04041 04042 04043 vector_create (N, &y); 04044 04045 04046 if (nodata) 04047 { 04048 report_evaluation(qp, num_stimts, stim_label, min_lag, max_lag, 04049 x_full, xtxinv_full, 04050 num_glt, glt_label, glt_rows, cxtxinvct); 04051 } 04052 04053 else 04054 { /*============== actually process data ====================*/ 04055 04056 int ixyz_bot=0 , ixyz_top=nxyz ; /* voxel indexes to process */ 04057 04058 #ifdef USE_GET 04059 #define NGET 128 /* number to get at one time */ 04060 int nget=0 , /* number of time series current gotten */ 04061 cget=0 , /* index of next timeseries in iget & imget */ 04062 jget , /* loop index for iget */ 04063 iget[NGET] ; /* voxel index of timeseries */ 04064 MRI_IMARR *imget=NULL ; /* array of timeseries */ 04065 #endif 04066 04067 #ifdef PROC_MAX 04068 if( proc_numjob > 1 ){ /*---- set up multiple processes ----*/ 04069 int vv , nvox=nxyz , nper , pp , nv ; 04070 pid_t newpid ; 04071 04072 /* count number of voxels to compute with into nvox */ 04073 04074 if( mask_vol != NULL ){ 04075 for( vv=nvox=0 ; vv < nxyz ; vv++ ) 04076 if( mask_vol[vv] != 0 ) nvox++ ; 04077 } 04078 04079 if( nvox < proc_numjob ){ /* too few voxels for multiple jobs? */ 04080 04081 proc_numjob = 1 ; 04082 04083 } else { /* prepare jobs */ 04084 04085 /* split voxels between jobs evenly */ 04086 04087 nper = nvox / proc_numjob ; /* # voxels per job */ 04088 if( mask_vol == NULL ){ 04089 proc_vox_bot[0] = 0 ; 04090 for( pp=0 ; pp < proc_numjob ; pp++ ){ 04091 proc_vox_top[pp] = proc_vox_bot[pp] + nper ; 04092 if( pp < proc_numjob-1 ) proc_vox_bot[pp+1] = proc_vox_top[pp] ; 04093 } 04094 proc_vox_top[proc_numjob-1] = nxyz ; 04095 } else { 04096 proc_vox_bot[0] = 0 ; 04097 for( pp=0 ; pp < proc_numjob ; pp++ ){ 04098 for( nv=0,vv=proc_vox_bot[pp] ; /* count ahead until */ 04099 nv < nper && vv < nxyz ; vv++ ){ /* find nper voxels */ 04100 if( mask_vol[vv] != 0 ) nv++ ; /* inside the mask */ 04101 } 04102 proc_vox_top[pp] = vv ; 04103 if( pp < proc_numjob-1 ) proc_vox_bot[pp+1] = proc_vox_top[pp] ; 04104 } 04105 proc_vox_top[proc_numjob-1] = nxyz ; 04106 } 04107 04108 /* make sure dataset is in memory before forks */ 04109 04110 DSET_load(dset) ; /* so dataset will be common */ 04111 04112 /* start processes */ 04113 04114 if( !option_data->quiet ) fprintf(stderr,"++ Voxels in dataset: %d\n",nxyz) ; 04115 if( nvox < nxyz ) 04116 if( !option_data->quiet ) fprintf(stderr,"++ Voxels in mask: %d\n",nvox) ; 04117 if( !option_data->quiet ) fprintf(stderr,"++ Voxels per job: %d\n",nper) ; 04118 04119 for( pp=1 ; pp < proc_numjob ; pp++ ){ 04120 ixyz_bot = proc_vox_bot[pp] ; /* these 3 variables */ 04121 ixyz_top = proc_vox_top[pp] ; /* are for the process */ 04122 proc_ind = pp ; /* we're about to fork */ 04123 newpid = fork() ; 04124 if( newpid == -1 ){ 04125 fprintf(stderr,"** Can't fork job #%d! Error exit!\n",pp); 04126 exit(1) ; 04127 } 04128 if( newpid == 0 ) break ; /* I'm the child */ 04129 proc_pid[pp] = newpid ; /* I'm the parent */ 04130 iochan_sleep(10) ; /* 10 ms, to let the child get going */ 04131 } 04132 if( pp == proc_numjob ){ /* only in the parent */ 04133 ixyz_bot = proc_vox_bot[0] ; /* set the 3 control */ 04134 ixyz_top = proc_vox_top[0] ; /* variables needed */ 04135 proc_ind = 0 ; /* below */ 04136 } 04137 if( !option_data->quiet ) 04138 fprintf(stderr,"++ Job #%d: processing voxels %d to %d; elapsed time=%.3f\n", 04139 proc_ind,ixyz_bot,ixyz_top-1,COX_clock_time()) ; 04140 } 04141 } 04142 #endif /* PROC_MAX */ 04143 04144 if( proc_numjob == 1 && !option_data->quiet ) 04145 fprintf(stderr,"++ Calculations starting; elapsed time=%.3f\n",COX_clock_time()) ; 04146 04147 vstep = nxyz / 50 ; 04148 if( option_data->quiet || 04149 option_data->fdisp >= 0.0 || 04150 option_data->progress > 0 || 04151 proc_numjob > 1 ) vstep = 0 ; 04152 04153 if( vstep > 0 ) fprintf(stderr,"++ voxel loop:") ; 04154 04155 /*----- Loop over all voxels -----*/ 04156 for (ixyz = ixyz_bot; ixyz < ixyz_top; ixyz++) 04157 { 04158 04159 if( vstep > 0 && ixyz%vstep==vstep-1 ) vstep_print() ; 04160 04161 /*----- Apply mask? -----*/ 04162 if (mask_vol != NULL) 04163 if (mask_vol[ixyz] == 0) continue; 04164 04165 #ifdef USE_GET 04166 /*** race ahead and extract a bunch of voxel time series at once ***/ 04167 04168 if( do_get && cget == nget ){ 04169 if( imget != NULL ) DESTROY_IMARR(imget) ; 04170 iget[0] = ixyz ; nget = 1 ; 04171 for( jget=ixyz+1 ; jget < nxyz && nget < NGET ; jget++ ){ 04172 if( mask_vol == NULL || mask_vol[jget] != 0 ) 04173 iget[nget++] = jget ; 04174 } 04175 imget = THD_extract_many_series( nget, iget, dset ) ; 04176 cget = 0 ; /* the next one to take out of imget */ 04177 } 04178 #endif 04179 04180 /*----- Extract Y-data for this voxel -----*/ 04181 if (option_data->input1D_filename != NULL) 04182 ts_array = fmri_data; 04183 else { 04184 #ifdef USE_GET 04185 ts_array = MRI_FLOAT_PTR(IMARR_SUBIM(imget,cget)); /* the GET way */ 04186 cget++ ; /* take this one next time */ 04187 #else 04188 extract_ts_array (dset, ixyz, ts_array); /* the OLD way */ 04189 #endif 04190 } 04191 04192 for (i = 0; i < N; i++) 04193 y.elts[i] = ts_array[good_list[i]]; 04194 04195 04196 /*----- Perform the regression analysis for this voxel-----*/ 04197 regression_analysis (N, p, q, num_stimts, min_lag, max_lag, 04198 x_full, xtxinv_full, xtxinvxt_full, x_base, 04199 xtxinvxt_base, x_rdcd, xtxinvxt_rdcd, 04200 y, rms_min, &mse, &coef, &scoef, &tcoef, 04201 fpart, rpart, &ffull, &rfull, &novar, 04202 fitts, errts); 04203 04204 if( voxel_base != NULL ) 04205 voxel_base[ixyz] = baseline_mean( coef ) ; /* 31 Aug 2004 */ 04206 04207 04208 /*----- Perform the general linear tests for this voxel -----*/ 04209 if (num_glt > 0) 04210 glt_analysis (N, p, x_full, y, mse*(N-p), coef, novar, cxtxinvct, 04211 num_glt, glt_rows, glt_cmat, glt_amat, 04212 glt_coef, glt_tcoef, fglt, rglt); 04213 04214 04215 /*----- Save results for this voxel into arrays -----*/ 04216 save_voxel (option_data, ixyz, coef, scoef, tcoef, fpart, rpart, mse, 04217 ffull, rfull, glt_coef, glt_tcoef, fglt, rglt, 04218 nt, ts_array, good_list, fitts, errts, 04219 coef_vol, scoef_vol, tcoef_vol, fpart_vol, rpart_vol, 04220 mse_vol, ffull_vol, rfull_vol, glt_coef_vol, 04221 glt_tcoef_vol, glt_fstat_vol, glt_rstat_vol, 04222 fitts_vol, errts_vol); 04223 04224 04225 /*----- Report results for this voxel -----*/ 04226 if ( ((ffull > option_data->fdisp) && (option_data->fdisp >= 0.0)) 04227 || ((option_data->progress > 0) 04228 && (ixyz % option_data->progress == 0)) 04229 || (option_data->input1D_filename != NULL) ) 04230 { 04231 04232 if( proc_ind == 0 ){ 04233 printf ("\n\nResults for Voxel #%d: \n", ixyz); 04234 report_results (N, qp, q, p, polort, block_list, num_blocks, 04235 num_stimts, stim_label, baseline, min_lag, max_lag, 04236 coef, tcoef, fpart, rpart, ffull, rfull, mse, 04237 num_glt, glt_label, glt_rows, glt_coef, 04238 glt_tcoef, fglt, rglt, &label); 04239 printf ("%s \n", label); fflush(stdout); 04240 } 04241 } 04242 04243 } /*----- Loop over voxels -----*/ 04244 04245 if( vstep > 0 ) fprintf(stderr,"\n") ; 04246 04247 #ifdef USE_GET 04248 if( do_get ){ 04249 if( imget != NULL ) DESTROY_IMARR(imget) ; 04250 ts_array = NULL ; 04251 } 04252 #endif 04253 04254 /*-- if this is a child process, we're done. 04255 if this is the parent process, wait for the children --*/ 04256 04257 #ifdef PROC_MAX 04258 if( proc_numjob > 1 ){ 04259 if( proc_ind > 0 ){ /* death of child */ 04260 if( !option_data->quiet ) 04261 fprintf(stderr,"++ Job #%d finished; elapsed time=%.3f\n",proc_ind,COX_clock_time()) ; 04262 _exit(0) ; 04263 04264 } else { /* parent waits for children */ 04265 int pp ; 04266 if( !option_data->quiet ) 04267 fprintf(stderr,"++ Job #0 waiting for children to finish; elapsed time=%.3f\n",COX_clock_time()) ; 04268 for( pp=1 ; pp < proc_numjob ; pp++ ) 04269 waitpid( proc_pid[pp] , NULL , 0 ) ; 04270 if( !option_data->quiet ) 04271 fprintf(stderr,"++ Job #0 now finishing up; elapsed time=%.3f\n",COX_clock_time()) ; 04272 } 04273 04274 /* when get to here, only parent process is left alive, 04275 and all the results are in the shared memory segment arrays */ 04276 } 04277 #endif 04278 if( proc_numjob == 1 && !option_data->quiet ) 04279 fprintf(stderr,"++ Calculations finished; elapsed time=%.3f\n",COX_clock_time()) ; 04280 04281 if( option_data->input1D_filename == NULL) /* don't need data anymore */ 04282 DSET_unload(dset) ; 04283 04284 } /*----- NOT nodata -----*/ 04285 04286 04287 /*----- Dispose of matrices and vectors -----*/ 04288 vector_destroy (&y); 04289 vector_destroy (&tcoef); 04290 vector_destroy (&scoef); 04291 vector_destroy (&coef); 04292 04293 if (num_stimts > 0) 04294 { 04295 for (is = 0; is < num_stimts; is++) 04296 { 04297 matrix_destroy (&x_rdcd[is]); 04298 matrix_destroy (&xtxinvxt_rdcd[is]); 04299 } 04300 free (x_rdcd); x_rdcd = NULL; 04301 free (xtxinvxt_rdcd); xtxinvxt_rdcd = NULL; 04302 } 04303 04304 matrix_destroy (&xtxinvxt_base); 04305 matrix_destroy (&x_base); 04306 matrix_destroy (&xdata); 04307 04308 if (num_glt > 0) 04309 { 04310 for (iglt = 0; iglt < num_glt; iglt++) 04311 { 04312 matrix_destroy (&cxtxinvct[iglt]); 04313 matrix_destroy (&glt_amat[iglt]); 04314 vector_destroy (&glt_coef[iglt]); 04315 vector_destroy (&glt_tcoef[iglt]); 04316 } 04317 free (cxtxinvct); cxtxinvct = NULL; 04318 free (glt_amat); glt_amat = NULL; 04319 free (glt_coef); glt_coef = NULL; 04320 free (glt_tcoef); glt_tcoef = NULL; 04321 } 04322 04323 04324 if (fpart != NULL) { free (fpart); fpart = NULL; } 04325 if (rpart != NULL) { free (rpart); rpart = NULL; } 04326 if (fglt != NULL) { free (fglt); fglt = NULL; } 04327 if (rglt != NULL) { free (rglt); rglt = NULL; } 04328 if (ts_array != NULL) { free (ts_array); ts_array = NULL; } 04329 if (fitts != NULL) { free (fitts); fitts = NULL; } 04330 if (errts != NULL) { free (errts); errts = NULL; } 04331 04332 EXRETURN ; 04333 } |
|
Definition at line 2590 of file 3dDeconvolve.c. References check_output_files(), DC_error(), getenv(), GoodList, malloc, MTEST, basis_expansion::nfunc, nGoodList, nParam, p, q, realloc, THD_MAX_NAME, and xsave.
02599 : stimulus time series arrays */ 02600 int ** good_list /* list of usable time points */ 02601 ) 02602 02603 { 02604 char message[THD_MAX_NAME]; /* error message */ 02605 int is; /* stimulus index */ 02606 int num_stimts; /* number of stimulus time series */ 02607 int * min_lag; /* minimum time delay for impulse response */ 02608 int * max_lag; /* maximum time delay for impulse response */ 02609 int * nptr; /* number of stim fn. time points per TR */ 02610 int m; /* number of time delays for impulse response */ 02611 int qp; /* number of polynomial trend baseline parameters */ 02612 int q; /* number of baseline model parameters */ 02613 int p; /* number of full model parameters */ 02614 int nbricks; /* number of sub-bricks in bucket dataset output */ 02615 int it; /* time point index */ 02616 int nt; /* number of images in input 3d+time dataset */ 02617 int NFirst; /* first image from input 3d+time dataset to use */ 02618 int NLast; /* last image from input 3d+time dataset to use */ 02619 int N; /* number of usable time points */ 02620 int ib; /* block (run) index */ 02621 int irb; /* time index relative to start of block (run) */ 02622 int num_glt; /* number of general linear tests */ 02623 int * glt_rows; /* number of linear constraints in glt */ 02624 int iglt; /* general linear test index */ 02625 int nerr=0 ; /* 22 Oct 2003 */ 02626 02627 02628 /*----- Initialize local variables -----*/ 02629 nt = option_data->nt; 02630 num_stimts = option_data->num_stimts; 02631 min_lag = option_data->stim_minlag; 02632 max_lag = option_data->stim_maxlag; 02633 num_glt = option_data->num_glt; 02634 glt_rows = option_data->glt_rows; 02635 nptr = option_data->stim_nptr; 02636 p = option_data->p; 02637 q = option_data->q; 02638 qp = option_data->qp; 02639 02640 /*----- Check if -xsave was given without -bucket ------*/ 02641 if( xsave && option_data->bucket_filename == NULL ){ 02642 fprintf(stderr,"** WARNING: -xsave given without -bucket; -xsave is disabled!\n") ; 02643 xsave = 0 ; 02644 } 02645 02646 /*----- Check length of censor array -----*/ 02647 if (censor_length < nt) 02648 { 02649 sprintf (message, "Input censor time series file %s is too short", 02650 option_data->censor_filename); 02651 DC_error (message); 02652 } 02653 02654 02655 /*----- Check validity of concatenated runs list -----*/ 02656 for (ib = 0; ib < num_blocks; ib++) 02657 if ((block_list[ib] < 0) || (block_list[ib] >= nt)) 02658 { 02659 sprintf (message, "Invalid -concat input: %d ", block_list[ib]); 02660 DC_error (message); 02661 } 02662 if (num_blocks > 1) 02663 for (ib = 1; ib < num_blocks; ib++) 02664 if (block_list[ib] <= block_list[ib-1]) 02665 DC_error ("Invalid concatenated runs list"); 02666 02667 02668 /*----- Create list of good (usable) time points -----*/ 02669 *good_list = (int *) malloc (sizeof(int) * nt); MTEST (*good_list); 02670 NFirst = option_data->NFirst; 02671 if (NFirst < 0){ 02672 for (is = 0; is < num_stimts; is++) 02673 if( basis_stim[is] == NULL && NFirst < (max_lag[is]+nptr[is]-1)/nptr[is] ) 02674 NFirst = (max_lag[is]+nptr[is]-1)/nptr[is]; 02675 } 02676 NLast = option_data->NLast; 02677 if (NLast < 0) NLast = nt; 02678 02679 N = 0; 02680 ib = 0; 02681 for (it = block_list[0]; it < nt; it++) 02682 { 02683 if (ib+1 < num_blocks) 02684 if (it >= block_list[ib+1]) ib++; 02685 02686 irb = it - block_list[ib]; 02687 02688 if ((irb >= NFirst) && (irb <= NLast) && (censor_array[it])) 02689 { 02690 (*good_list)[N] = it; 02691 N++; 02692 } 02693 } 02694 02695 02696 /*----- Check for sufficient data -----*/ 02697 if (N == 0) DC_error ("No usable time points?"); 02698 if (N <= p) 02699 { 02700 sprintf (message, "Insufficient data for estimating %d parameters", p); 02701 DC_error (message); 02702 } 02703 option_data->N = N; 02704 02705 GoodList = *good_list ; 02706 nGoodList = N ; 02707 nParam = p ; 02708 02709 /*----- Check number of stimulus time series -----*/ 02710 if (num_stimts < 0) 02711 { 02712 DC_error ("Require: 0 <= num_stimts (DUH! --or-- D'oh!)"); 02713 } 02714 02715 02716 /*----- Check lengths of stimulus time series -----*/ 02717 02718 #define ALLOW_EXTEND 02719 for (is = 0; is < num_stimts; is++) 02720 { 02721 if( basis_stim[is] != NULL ) continue ; /* 12 Aug 2004 */ 02722 02723 if (stim_length[is] < nt*nptr[is]) 02724 { 02725 #ifndef ALLOW_EXTEND 02726 sprintf (message, "Input stimulus time series file %s is too short", 02727 option_data->stim_filename[is]); 02728 DC_error (message); 02729 #else 02730 int nlen=nt*nptr[is], qq ; 02731 fprintf(stderr, 02732 "** WARNING: input stimulus time series file %s is too short:\n" 02733 " length = %d, but should be at least %d.\n" , 02734 option_data->stim_filename[is] , stim_length[is] , nlen ) ; 02735 stimulus[is] = (float *) realloc( stimulus[is] , sizeof(float)*nlen ) ; 02736 for( qq=stim_length[is] ; qq < nlen ; qq++ ) stimulus[is][qq] = 0.0 ; 02737 stim_length[is] = nlen ; nerr++ ; 02738 #endif 02739 } 02740 } 02741 #ifdef ALLOW_EXTEND 02742 if( nerr > 0 ){ 02743 char *eee = getenv("AFNI_3dDeconvolve_extend") ; 02744 if( eee != NULL && (*eee=='n' || *eee=='N') ){ 02745 fprintf(stderr,"** ERROR: Can't continue with too short files!\n" 02746 " AFNI_3dDeconvolve_extend = %s\n",eee ) ; 02747 exit(1) ; 02748 } 02749 fprintf(stderr,"++ EXTENDING short files with zero values\n" 02750 " (to stop this behavior, setenv AFNI_3dDeconvolve_extend NO)\n") ; 02751 } 02752 #endif 02753 02754 02755 /*----- Check whether time lags are reasonable -----*/ 02756 for (is = 0; is < num_stimts; is++) 02757 { 02758 if( basis_stim[is] != NULL ) continue ; /* 12 Aug 2004 */ 02759 02760 m = max_lag[is] - min_lag[is] + 1; 02761 if (m < 2) 02762 { 02763 if (option_data->iresp_filename[is] != NULL) 02764 { 02765 sprintf (message, "Only %d time point for output dataset %s ", 02766 m, option_data->iresp_filename[is]); 02767 DC_error (message); 02768 } 02769 02770 if (option_data->sresp_filename[is] != NULL) 02771 { 02772 sprintf (message, "Only %d time point for output dataset %s", 02773 m, option_data->sresp_filename[is]); 02774 DC_error (message); 02775 } 02776 } 02777 if ((m < 4) && (option_data->tshift)) 02778 { 02779 if (option_data->iresp_filename[is] != NULL) 02780 { 02781 sprintf (message, "Only %d time points for 3d+time dataset %s\n", 02782 m, option_data->iresp_filename[is]); 02783 strcat (message, "Require >= 4 data points for -tshift option"); 02784 DC_error (message); 02785 } 02786 } 02787 } 02788 02789 02790 /*----- Calculate number of sub-bricks in the bucket dataset, 02791 and check for illegal number of sub-bricks -----*/ 02792 nbricks = 0; 02793 if (option_data->bucket_filename != NULL) 02794 { 02795 if (! option_data->nocout) 02796 { 02797 if (! option_data->nobout) 02798 nbricks += qp * (1 + option_data->tout); 02799 02800 for (is = 0; is < num_stimts; is++) 02801 { 02802 if ((!option_data->stim_base[is]) || (!option_data->nobout)) 02803 { 02804 if( basis_stim[is] != NULL ) m = basis_stim[is]->nfunc ; 02805 else m = max_lag[is] - min_lag[is] + 1; 02806 nbricks += m * (1 + option_data->tout); 02807 nbricks += option_data->rout + option_data->fout; 02808 } 02809 } 02810 } 02811 02812 nbricks += option_data->rout + option_data->fout + option_data->vout; 02813 02814 if (num_glt > 0) 02815 for (iglt = 0; iglt < num_glt; iglt++) 02816 { 02817 nbricks += glt_rows[iglt] * (1 + option_data->tout); 02818 nbricks += option_data->rout + option_data->fout; 02819 } 02820 02821 if (nbricks <= 0) 02822 { 02823 sprintf (message, 02824 "User requested bucket dataset with only %d sub-bricks", 02825 nbricks); 02826 DC_error (message); 02827 } 02828 02829 } 02830 option_data->nbricks = nbricks; 02831 02832 02833 /*----- Check for zero slice offsets with nptr option -----*/ 02834 if (dset_time != NULL) 02835 if (dset_time->taxis->nsl > 0) 02836 for (is = 0; is < num_stimts; is++) 02837 if (nptr[is] > 1) 02838 { 02839 sprintf (message, "Must align all slices to 0 offset time, \n "); 02840 strcat (message, "before using -stim_nptr option. "); 02841 strcat (message, "See program 3dTshift. "); 02842 DC_error (message); 02843 } 02844 02845 02846 /*----- Check for -tshift and -input1D option -----*/ 02847 if ((option_data->tshift) && (option_data->input1D_filename != NULL)) 02848 DC_error ("-tshift option is not compatible with -input1D option"); 02849 02850 02851 /*----- Check whether any of the output files already exist -----*/ 02852 if (option_data->input_filename != NULL) 02853 check_output_files (option_data, dset_time); 02854 02855 } |
|
Definition at line 2503 of file 3dDeconvolve.c. References ADN_label1, ADN_none, ADN_prefix, ADN_self_name, ADN_type, THD_3dim_dataset::dblk, DC_error(), THD_datablock::diskptr, EDIT_dset_items(), EDIT_empty_copy(), GEN_FUNC_TYPE, HEAD_FUNC_TYPE, THD_diskptr::header_name, ISHEAD, THD_delete_3dim_dataset(), THD_is_file(), and THD_MAX_NAME.
02508 { 02509 char message[THD_MAX_NAME]; /* error message */ 02510 THD_3dim_dataset * new_dset=NULL; /* output afni data set pointer */ 02511 int ierror; /* number of errors in editing data */ 02512 02513 02514 /*----- make an empty copy of input dataset -----*/ 02515 new_dset = EDIT_empty_copy( dset_time ) ; 02516 02517 02518 ierror = EDIT_dset_items( new_dset , 02519 ADN_prefix , filename , 02520 ADN_label1 , filename , 02521 ADN_self_name , filename , 02522 ADN_type , ISHEAD(dset_time) ? HEAD_FUNC_TYPE : 02523 GEN_FUNC_TYPE , 02524 ADN_none ) ; 02525 02526 if( ierror > 0 ) 02527 { 02528 sprintf (message, 02529 "*** %d errors in attempting to create output dataset!\n", 02530 ierror); 02531 DC_error (message); 02532 } 02533 02534 if( THD_is_file(new_dset->dblk->diskptr->header_name) ) 02535 { 02536 sprintf (message, 02537 "Output dataset file %s already exists " 02538 " -- cannot continue! ", 02539 new_dset->dblk->diskptr->header_name); 02540 DC_error (message); 02541 } 02542 02543 /*----- deallocate memory -----*/ 02544 THD_delete_3dim_dataset( new_dset , False ) ; new_dset = NULL ; 02545 02546 } |
|
Definition at line 2555 of file 3dDeconvolve.c. References check_one_output_file().
02560 { 02561 int is; /* stimulus time series index */ 02562 02563 02564 if (option_data->bucket_filename != NULL) 02565 check_one_output_file (dset_time, option_data->bucket_filename); 02566 02567 if (option_data->fitts_filename != NULL) 02568 check_one_output_file (dset_time, option_data->fitts_filename); 02569 02570 if (option_data->errts_filename != NULL) 02571 check_one_output_file (dset_time, option_data->errts_filename); 02572 02573 for (is = 0; is < option_data->num_stimts; is++) 02574 { 02575 if (option_data->iresp_filename[is] != NULL) 02576 check_one_output_file (dset_time, option_data->iresp_filename[is]); 02577 02578 if (option_data->sresp_filename[is] != NULL) 02579 check_one_output_file (dset_time, option_data->sresp_filename[is]); 02580 } 02581 } |
|
Definition at line 6325 of file 3dDeconvolve.c. References matrix::cols, GoodList, InputFilename, nGoodList, nParam, ParamLabel, ParamStim, matrix::rows, and xrestore_filename. Referenced by do_xrestore_stuff().
06326 { 06327 int nerr = 0 ; 06328 06329 if( X.rows < 1 || X.cols < 1 ){ 06330 fprintf(stderr, 06331 "** ERROR: -xrestore %s has bad X matrix\n",xrestore_filename) ; 06332 nerr++ ; 06333 } 06334 if( XtXinv.rows < 1 || XtXinv.cols < 1 ){ 06335 fprintf(stderr, 06336 "** ERROR: -xrestore %s has bad XtXinv matrix\n",xrestore_filename) ; 06337 nerr++ ; 06338 } 06339 if( XtXinvXt.rows < 1 || XtXinvXt.cols < 1 ){ 06340 fprintf(stderr, 06341 "** ERROR: -xrestore %s has bad XtXinvXt matrix\n",xrestore_filename) ; 06342 nerr++ ; 06343 } 06344 if( nParam > 0 && X.cols != nParam ){ 06345 fprintf(stderr, 06346 "** ERROR: -xrestore %s X matrix cols mismatch: %d != %d\n", 06347 xrestore_filename, X.cols , nParam ) ; 06348 nerr++ ; 06349 } 06350 if( GoodList == NULL ){ 06351 fprintf(stderr, 06352 "** ERROR: -xrestore %s missing GoodList field\n",xrestore_filename) ; 06353 nerr++ ; 06354 } else if( nGoodList != X.rows ){ 06355 fprintf(stderr, 06356 "** ERROR: -xrestore %s X matrix rows mismatch: %d != %d\n", 06357 xrestore_filename, X.cols , nGoodList ) ; 06358 nerr++ ; 06359 } 06360 #if 0 06361 if( ParamStim == NULL ){ 06362 fprintf(stderr, 06363 "** ERROR: -xrestore %s missing ParamStim field\n",xrestore_filename) ; 06364 nerr++ ; 06365 } 06366 if( ParamLabel == NULL ){ 06367 fprintf(stderr, 06368 "** ERROR: -xrestore %s missing ParamLabel field\n",xrestore_filename) ; 06369 nerr++ ; 06370 } 06371 #endif 06372 if( InputFilename == NULL ){ 06373 fprintf(stderr, 06374 "** ERROR: -xrestore %s missing InputFilename field\n",xrestore_filename) ; 06375 nerr++ ; 06376 } 06377 06378 if( nerr > 0 ) exit(1) ; /** bad bad bad **/ 06379 return ; 06380 } |
|
Definition at line 4373 of file 3dDeconvolve.c. References a, c, THD_3dim_dataset::daxes, vector::elts, matrix::elts, free, i, malloc, matrix_create(), matrix_destroy(), matrix_initialize(), matrix_inverse(), THD_dataxes::nxx, THD_dataxes::nyy, nz, THD_dataxes::nzz, THD_3dim_dataset::taxis, THD_delete_3dim_dataset(), THD_open_dataset(), THD_timeof_slice(), THD_timeaxis::ttdel, v, vector_create(), vector_destroy(), vector_initialize(), and vector_multiply(). Referenced by output_results().
04379 { 04380 THD_3dim_dataset * dset = NULL; /* input afni data set pointer */ 04381 int nx, ny, nz, nxyz; /* dataset dimensions in voxels */ 04382 int ixyz; /* voxel index */ 04383 int isl; /* slice index */ 04384 int i; /* data point index */ 04385 float * yarray = NULL; /* impulse response function for a single voxel */ 04386 float * sarray = NULL; /* second derivative of the cubic in each interval */ 04387 matrix m, minv; /* matrices for cubic spline interpolation */ 04388 vector v, sv; /* vectors for cubic spline interpolation */ 04389 int n; /* number of intervals = ts_length-1 */ 04390 float * a = NULL, 04391 * b = NULL, 04392 * c = NULL, 04393 * d = NULL; /* cubic spline interpolation polynomial coefs. */ 04394 float tslice; /* slice acquisition time offset */ 04395 float tdelta; /* time between same slice acquisitons */ 04396 float frac; /* fraction of interval for slice acq. time offset */ 04397 int k; /* interval to use for interpolation */ 04398 float t; /* time in fractions of TR */ 04399 float delt; /* time offset relative to interpolation interval */ 04400 float y; /* interpolated value */ 04401 04402 04403 /*----- Initialize matrices and vectors -----*/ 04404 matrix_initialize (&m); 04405 matrix_initialize (&minv); 04406 vector_initialize (&v); 04407 vector_initialize (&sv); 04408 04409 04410 /*----- Initialize local variables -----*/ 04411 dset = THD_open_dataset (option_data->input_filename); 04412 n = ts_length - 1; 04413 tdelta = dset->taxis->ttdel; 04414 nx = dset->daxes->nxx; ny = dset->daxes->nyy; nz = dset->daxes->nzz; 04415 nxyz = nx * ny * nz; 04416 04417 04418 /*----- Allocate space for data and interpolation polynomials -----*/ 04419 yarray = (float *) malloc (sizeof(float) * ts_length); 04420 sarray = (float *) malloc (sizeof(float) * (n+1)); 04421 a = (float *) malloc (sizeof(float) * n); 04422 b = (float *) malloc (sizeof(float) * n); 04423 c = (float *) malloc (sizeof(float) * n); 04424 d = (float *) malloc (sizeof(float) * n); 04425 04426 04427 /*----- Calculate matrix for cubic spline interpolation -----*/ 04428 matrix_create (n-1, n-1, &m); 04429 m.elts[0][0] = 4.0; 04430 m.elts[0][1] = 1.0; 04431 m.elts[n-2][n-3] = 1.0; 04432 m.elts[n-2][n-2] = 4.0; 04433 for (i = 1; i < n-2; i++) 04434 { 04435 m.elts[i][i] = 4.0; 04436 m.elts[i][i-1] = 1.0; 04437 m.elts[i][i+1] = 1.0; 04438 } 04439 matrix_inverse (m, &minv); 04440 04441 04442 vector_create (n-1, &v); 04443 04444 04445 /*----- Loop over all voxels -----*/ 04446 for (ixyz = 0; ixyz < nxyz; ixyz++) 04447 { 04448 04449 /*----- Get time offset for this slice -----*/ 04450 isl = ixyz / (nx*ny); 04451 tslice = THD_timeof_slice (0, isl, dset); 04452 frac = -((tslice/tdelta) - 0.5); 04453 04454 /*----- Get impulse response function for this voxel -----*/ 04455 for (i = 0; i < ts_length; i++) 04456 yarray[i] = vol_array[i][ixyz]; 04457 04458 04459 /*----- Calculate vector for cubic spline interpolation -----*/ 04460 for (i = 1; i < n; i++) 04461 v.elts[i-1] = 6.0 * (yarray[i+1] - 2.0 * yarray[i] + yarray[i-1]); 04462 vector_multiply (minv, v, &sv); 04463 04464 04465 /*----- Set array of second derivatives -----*/ 04466 for (i = 1; i < n; i++) 04467 { 04468 sarray[i] = sv.elts[i-1]; 04469 } 04470 sarray[0] = 0.0; 04471 sarray[n] = 0.0; 04472 04473 04474 /*----- Calculate cubic spline polynomial coefficients -----*/ 04475 for (i = 0; i < n; i++) 04476 { 04477 a[i] = (sarray[i+1] - sarray[i]) / 6.0; 04478 b[i] = sarray[i] / 2; 04479 c[i] = (yarray[i+1]-yarray[i]) - (2.0*sarray[i]+sarray[i+1]) / 6.0; 04480 d[i] = yarray[i]; 04481 } 04482 04483 04484 /*----- Apply time shift to impulse response function -----*/ 04485 for (i = 0; i < ts_length; i++) 04486 { 04487 t = i + frac; 04488 04489 if (frac < 0.0) k = i-1; 04490 else k = i; 04491 04492 if (k < 0) k = 0; 04493 if (k > n-1) k = n-1; 04494 04495 delt = t - k; 04496 04497 yarray[i] = a[k]*delt*delt*delt + b[k]*delt*delt + c[k]*delt + d[k]; 04498 } 04499 04500 04501 /*----- Save interpolated impulse response function -----*/ 04502 for (i = 0; i < ts_length; i++) 04503 vol_array[i][ixyz] = yarray[i]; 04504 04505 04506 04507 } /* Loop over voxels */ 04508 04509 04510 /*----- Deallocate memory -----*/ 04511 THD_delete_3dim_dataset (dset, False); dset = NULL ; 04512 04513 matrix_destroy (&m); 04514 matrix_destroy (&minv); 04515 vector_destroy (&v); 04516 vector_destroy (&sv); 04517 04518 free (sarray); sarray = NULL; 04519 free (yarray); yarray = NULL; 04520 free (a); a = NULL; 04521 free (b); b = NULL; 04522 free (c); c = NULL; 04523 free (d); d = NULL; 04524 } |
|
Definition at line 542 of file 3dDeconvolve.c. References PROGRAM_NAME. Referenced by remove_zero_stimfns().
00543 { 00544 fprintf (stderr, "%s Error: %s \a\n\n", PROGRAM_NAME, message); 00545 exit(1); 00546 } |
|
Definition at line 579 of file 3dDeconvolve.c. References identify_software(), PROC_MAX, and PROGRAM_NAME.
00580 { 00581 identify_software(); 00582 00583 printf ( 00584 "Program to calculate the deconvolution of a measurement 3d+time dataset \n" 00585 "with a specified input stimulus time series. This program will also \n" 00586 "perform multiple linear regression using multiple input stimulus time \n" 00587 "series. Output consists of an AFNI 'bucket' type dataset containing the \n" 00588 "least squares estimates of the linear regression coefficients, t-statistics\n" 00589 "for significance of the coefficients, partial F-statistics for significance\n" 00590 "of the individual input stimuli, and the F-statistic for significance of \n" 00591 "the overall regression. Additional output consists of a 3d+time dataset \n" 00592 "containing the estimated system impulse response function. \n" 00593 " \n" 00594 "Usage: \n" 00595 PROGRAM_NAME "\n" 00596 " \n" 00597 "**** Input data and control options: \n" 00598 "-input fname fname = filename of 3d+time input dataset \n" 00599 " (more than one filename can be given) \n" 00600 " (here, and these datasets will be) \n" 00601 " (catenated in time; if you do this, ) \n" 00602 " ('-concat' is not needed and is ignored) \n" 00603 "[-input1D dname] dname = filename of single (fMRI) .1D time series \n" 00604 "[-nodata [NT [TR]] Evaluate experimental design only (no input data) \n" 00605 "[-mask mname] mname = filename of 3d mask dataset \n" 00606 "[-automask] build a mask automatically from input data \n" 00607 " (will be slow for long time series datasets) \n" 00608 "[-censor cname] cname = filename of censor .1D time series \n" 00609 "[-concat rname] rname = filename for list of concatenated runs \n" 00610 "[-nfirst fnum] fnum = number of first dataset image to use in the\n" 00611 " deconvolution procedure. (default = max maxlag) \n" 00612 "[-nlast lnum] lnum = number of last dataset image to use in the \n" 00613 " deconvolution procedure. (default = last point) \n" 00614 "[-polort pnum] pnum = degree of polynomial corresponding to the \n" 00615 " null hypothesis (default: pnum = 1) \n" 00616 "[-legendre] use Legendre polynomials for null hypothesis \n" 00617 "[-nolegendre] use power polynomials for null hypotheses \n" 00618 " (default is -legendre) \n" 00619 "[-nodmbase] don't de-mean baseline time series \n" 00620 " (i.e., polort>1 and -stim_base inputs) \n" 00621 "[-dmbase] de-mean baseline time series (default if polort>0)\n" 00622 "[-nocond] don't calculate matrix condition number \n" 00623 "[-svd] Use SVD instead of Gaussian elimination (default) \n" 00624 "[-nosvd] Use Gaussian elimination instead of SVD \n" 00625 "[-rmsmin r] r = minimum rms error to reject reduced model \n" 00626 " \n" 00627 "**** Input stimulus options: \n" 00628 "-num_stimts num num = number of input stimulus time series \n" 00629 " (0 <= num) (default: num = 0) \n" 00630 "-stim_file k sname sname = filename of kth time series input stimulus\n" 00631 "[-stim_label k slabel] slabel = label for kth input stimulus \n" 00632 "[-stim_base k] kth input stimulus is part of the baseline model \n" 00633 "[-stim_minlag k m] m = minimum time lag for kth input stimulus \n" 00634 " (default: m = 0) \n" 00635 "[-stim_maxlag k n] n = maximum time lag for kth input stimulus \n" 00636 " (default: n = 0) \n" 00637 "[-stim_nptr k p] p = number of stimulus function points per TR \n" 00638 " Note: This option requires 0 slice offset times \n" 00639 " (default: p = 1) \n" 00640 " \n" 00641 "[-stim_times k tname Rmodel] \n" 00642 " Generate the k-th response model from a set of stimulus times \n" 00643 " given in file 'tname'. The response model is specified by the \n" 00644 " 'Rmodel' argument, which can be one of \n" 00645 " 'GAM(p,q)' = 1 parameter gamma variate \n" 00646 " 'SPMG' = 2 parameter SPM gamma variate + derivative \n" 00647 " 'POLY(b,c,n)' = n parameter polynomial expansion \n" 00648 " 'SIN(b,c,n)' = n parameter sine series expansion \n" 00649 " 'TENT(b,c,n)' = n parameter tent function expansion \n" 00650 " 'BLOCK(d,p)' = 1 parameter block stimulus of duration 'd' \n" 00651 " (can also be called 'IGFUN' which stands) \n" 00652 " (for 'incomplete gamma function' ) \n" 00653 " 'EXPR(b,c) exp1 ... expn' = n parameter; arbitrary expressions \n" 00654 " \n" 00655 "[-basis_normall a] \n" 00656 " Normalize all basis functions for '-stim_times' to have \n" 00657 " amplitude 'a' (must have a > 0). The peak absolute value \n" 00658 " of each basis function will be scaled to be 'a'. \n" 00659 " NOTE: -basis_normall only affect -stim_times options that \n" 00660 " appear LATER on the command line \n" 00661 " \n" 00662 "**** General linear test (GLT) options: \n" 00663 "-num_glt num num = number of general linear tests (GLTs) \n" 00664 " (0 <= num) (default: num = 0) \n" 00665 "[-glt s gltname] Perform s simultaneous linear tests, as specified \n" 00666 " by the matrix contained in file gltname \n" 00667 "[-glt_label k glabel] glabel = label for kth general linear test \n" 00668 "[-gltsym gltname] Read the GLT with symbolic names from the file \n" 00669 " \n" 00670 "[-TR_irc dt] \n" 00671 " Use 'dt' as the stepsize for computation of integrals in -IRC_times \n" 00672 " options. Default is to use value given in '-TR_times'. \n" 00673 " \n" 00674 "**** Options for output 3d+time datasets: \n" 00675 "[-iresp k iprefix] iprefix = prefix of 3d+time output dataset which \n" 00676 " will contain the kth estimated impulse response \n" 00677 "[-tshift] Use cubic spline interpolation to time shift the \n" 00678 " estimated impulse response function, in order to\n" 00679 " correct for differences in slice acquisition \n" 00680 " times. Note that this effects only the 3d+time \n" 00681 " output dataset generated by the -iresp option. \n" 00682 "[-sresp k sprefix] sprefix = prefix of 3d+time output dataset which \n" 00683 " will contain the standard deviations of the \n" 00684 " kth impulse response function parameters \n" 00685 "[-fitts fprefix] fprefix = prefix of 3d+time output dataset which \n" 00686 " will contain the (full model) time series fit \n" 00687 " to the input data \n" 00688 "[-errts eprefix] eprefix = prefix of 3d+time output dataset which \n" 00689 " will contain the residual error time series \n" 00690 " from the full model fit to the input data \n" 00691 "[-TR_times dt] \n" 00692 " Use 'dt' as the stepsize for output of -iresp and -sresp file \n" 00693 " for response models generated by '-stim_times' options. \n" 00694 " Default is same as time spacing in the '-input' 3D+time dataset. \n" 00695 " \n" 00696 "**** Options to control the contents of the output bucket dataset: \n" 00697 "[-fout] Flag to output the F-statistics \n" 00698 "[-rout] Flag to output the R^2 statistics \n" 00699 "[-tout] Flag to output the t-statistics \n" 00700 "[-vout] Flag to output the sample variance (MSE) map \n" 00701 "[-nobout] Flag to suppress output of baseline coefficients \n" 00702 " (and associated statistics) \n" 00703 "[-nocout] Flag to suppress output of regression coefficients \n" 00704 " (and associated statistics) \n" 00705 "[-full_first] Flag to specify that the full model statistics will \n" 00706 " appear first in the bucket dataset output \n" 00707 "[-bucket bprefix] Create one AFNI 'bucket' dataset containing various \n" 00708 " parameters of interest, such as the estimated IRF \n" 00709 " coefficients, and full model fit statistics. \n" 00710 " Output 'bucket' dataset is written to bprefix. \n" 00711 " \n" 00712 "[-xsave] Flag to save X matrix into file bprefix.xsave \n" 00713 " (only works if -bucket option is also given) \n" 00714 "[-noxsave] Don't save X matrix (this is the default) \n" 00715 "[-cbucket cprefix] Save the regression coefficients (no statistics) \n" 00716 " into a dataset named 'cprefix'. This dataset \n" 00717 " will be used in a -xrestore run instead of the \n" 00718 " bucket dataset, if possible. \n" 00719 " \n" 00720 "[-xrestore f.xsave] Restore the X matrix, etc. from a previous run \n" 00721 " that was saved into file 'f.xsave'. You can \n" 00722 " then carry out new -glt tests. When -xrestore \n" 00723 " is used, most other command line options are \n" 00724 " ignored. \n" 00725 " \n" 00726 "**** The following options control the screen output only: \n" 00727 "[-quiet] Flag to suppress most screen output \n" 00728 "[-xout] Flag to write X and inv(X'X) matrices to screen \n" 00729 "[-xjpeg filename] Write a JPEG file graphing the X matrix \n" 00730 "[-progress n] Write statistical results for every nth voxel \n" 00731 "[-fdisp fval] Write statistical results for those voxels \n" 00732 " whose full model F-statistic is > fval \n" 00733 ); 00734 00735 #ifdef PROC_MAX 00736 printf( "\n" 00737 " -jobs J Run the program with 'J' jobs (sub-processes).\n" 00738 " On a multi-CPU machine, this can speed the\n" 00739 " program up considerably. On a single CPU\n" 00740 " machine, using this option is silly.\n" 00741 " J should be a number from 1 up to the\n" 00742 " number of CPU sharing memory on the system.\n" 00743 " J=1 is normal (single process) operation.\n" 00744 " The maximum allowed value of J is %d.\n" 00745 " * For more information on parallelizing, see\n" 00746 " http://afni.nimh.nih.gov/afni/doc/misc/parallize.html \n" 00747 " * Use -mask to get more speed; cf. 3dAutomask.\n" 00748 , PROC_MAX ) ; 00749 #endif 00750 00751 printf("\n" 00752 "** NOTE **\n" 00753 "This version of the program has been compiled to use\n" 00754 #ifdef FLOATIZE 00755 "single precision arithmetic for most internal calculations.\n" 00756 #else 00757 "double precision arithmetic for most internal calculations.\n" 00758 #endif 00759 ) ; 00760 00761 exit(0); 00762 } |
|
bad bad bad * Definition at line 6384 of file 3dDeconvolve.c. References ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_type, argc, attach_sub_brick(), DC_options::bucket_filename, BucketFilename, calc_sse(), calloc, check_xrestore_data(), CoefFilename, matrix::cols, DATABLOCK_MEM_MALLOC, DESTROY_IMARR, DSET_delete, DSET_HEADNAME, DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_NVOX, DSET_unload, DSET_write, EDIT_add_bricklist(), EDIT_dset_items(), EDIT_empty_copy(), vector::elts, matrix::elts, FILENAME_TO_PREFIX, DC_options::fout, fout, free, FUNC_BUCK_TYPE, FUNC_FIM_TYPE, FUNC_THR_TYPE, glt_analysis(), DC_options::glt_filename, DC_options::glt_label, DC_options::glt_rows, GoodList, HEAD_FUNC_TYPE, IMARR_SUBIM, init_glt_analysis(), InputFilename, ISVALID_DSET, malloc, matrix_file_read(), matrix_initialize(), MRI_FLOAT_PTR, nGoodList, nParam, DC_options::num_glt, ParamIndex, ParamLabel, ParamStim, PROGRAM_NAME, read_glt_matrix(), DC_options::rout, matrix::rows, THD_extract_array(), THD_extract_many_series(), THD_MAX_NAME, THD_open_dataset(), DC_options::tout, tross_Make_History(), vector_create(), vector_initialize(), vector_multiply(), verb, THD_3dim_dataset::view_type, vstep_print(), xrestore_filename, and XSAVE_input(). Referenced by main().
06385 { 06386 THD_3dim_dataset *dset_time , *dset_coef, *dset_buck ; 06387 int nt , np , ii, nxyz, tout,rout,fout, ixyz,novar,view ; 06388 char *buck_prefix , *buck_name ; 06389 char brick_label[THD_MAX_NAME] ; 06390 06391 float *ts_array = NULL; /* array of measured data for one voxel */ 06392 #undef NGET 06393 #define NGET 32 /* number to get at one time */ 06394 int nget=0 , /* number of time series current gotten */ 06395 cget=0 , /* index of next timeseries in iget & imget */ 06396 jget , /* loop index for iget */ 06397 iget[NGET] ; /* voxel index of timeseries */ 06398 MRI_IMARR *imget=NULL ; /* array of timeseries */ 06399 06400 int num_glt , iglt , ilc,nlc ; 06401 matrix *glt_cmat , *glt_amat , *cxtxinvct ; 06402 vector *glt_coef , *glt_tcoef, y , coef ; 06403 float *fglt , *rglt ; 06404 char **glt_label ; 06405 int *glt_rows ; 06406 float ***glt_coef_vol , 06407 ***glt_tcoef_vol=NULL , 06408 ** glt_fstat_vol=NULL , 06409 ** glt_rstat_vol=NULL ; 06410 float *cdar=NULL , ssef , *volume ; 06411 int ivol , nvol , nbuck , vstep ; 06412 06413 /*----- Check for GLT options -----*/ 06414 06415 num_glt = option_data->num_glt ; 06416 glt_label = option_data->glt_label ; 06417 glt_rows = option_data->glt_rows ; 06418 06419 tout = option_data->tout ; 06420 rout = option_data->rout ; 06421 fout = option_data->fout ; 06422 06423 if( num_glt < 1 ){ 06424 fprintf(stderr,"** ERROR: -xrestore with no new GLTs???\n"); exit(1); 06425 } 06426 06427 /*----- initialize values to be read from xsave file -----*/ 06428 06429 matrix_initialize( &X ) ; 06430 matrix_initialize( &XtXinv ) ; 06431 matrix_initialize( &XtXinvXt ) ; 06432 nGoodList = 0 ; GoodList = NULL ; 06433 nParam = 0 ; ParamIndex = NULL ; ParamStim = NULL ; ParamLabel = NULL ; 06434 06435 /*----- read xsave file -----*/ 06436 06437 if( verb ) fprintf(stderr,"++ Starting -xrestore %s\n",xrestore_filename) ; 06438 06439 XSAVE_input( xrestore_filename ) ; 06440 check_xrestore_data() ; 06441 06442 nt = X.rows ; np = X.cols ; /* number of time points and parameters */ 06443 06444 /*----- read input time series dataset -----*/ 06445 06446 if( verb ) fprintf(stderr,"++ loading time series dataset '%s'\n",InputFilename); 06447 dset_time = THD_open_dataset( InputFilename ) ; 06448 if( dset_time == NULL ){ 06449 fprintf(stderr, 06450 "** ERROR: -xrestore can't open time series dataset '%s'\n" , 06451 InputFilename ) ; 06452 exit(1) ; 06453 } 06454 DSET_load( dset_time ) ; 06455 if( !DSET_LOADED(dset_time) ){ 06456 fprintf(stderr, 06457 "** ERROR: -xrestore can't load time series dataset '%s'\n" , 06458 InputFilename ) ; 06459 exit(1) ; 06460 } 06461 nxyz = DSET_NVOX(dset_time) ; /* number of voxels */ 06462 view = dset_time->view_type ; /* +orig, +acpc, +tlrc ? */ 06463 06464 /*----- read coefficient dataset (if possible) -----*/ 06465 06466 dset_coef = NULL ; 06467 if( CoefFilename != NULL ){ 06468 if( verb) fprintf(stderr,"++ loading coefficient dataset %s\n",CoefFilename); 06469 dset_coef = THD_open_dataset( CoefFilename ) ; 06470 if( dset_coef == NULL ){ 06471 fprintf(stderr, 06472 "** WARNING: -xrestore can't open coefficient dataset %s\n", 06473 CoefFilename); 06474 } else { 06475 DSET_load(dset_coef) ; 06476 if( !DSET_LOADED(dset_coef) ){ 06477 fprintf(stderr, 06478 "** WARNING: -xrestore can't load coefficient dataset %s\n", 06479 CoefFilename); 06480 DSET_delete(dset_coef) ; dset_coef = NULL ; 06481 } 06482 } 06483 if( dset_coef != NULL && DSET_NVALS(dset_coef) < np ){ 06484 fprintf(stderr, 06485 "** WARNING: -xrestore coefficient dataset %s too short\n", 06486 CoefFilename); 06487 DSET_delete(dset_coef) ; dset_coef = NULL ; 06488 } 06489 if( dset_coef != NULL ){ 06490 if( ParamIndex != NULL ) free((void *)ParamIndex) ; 06491 ParamIndex = (int *)malloc(sizeof(int)*np) ; 06492 for( ii=0 ; ii < np ; ii++ ) ParamIndex[ii] = ii ; 06493 } 06494 } 06495 06496 /*----- if above failed, try the old bucket dataset -----*/ 06497 06498 if( dset_coef == NULL && BucketFilename != NULL && ParamIndex != NULL ){ 06499 if( verb ) fprintf(stderr,"++ loading original bucket dataset %s\n",BucketFilename) ; 06500 dset_coef = THD_open_dataset( BucketFilename ) ; 06501 if( dset_coef == NULL ){ 06502 fprintf(stderr, 06503 "** WARNING: -xrestore can't open old bucket dataset %s\n", 06504 BucketFilename); 06505 } else { 06506 DSET_load(dset_coef) ; 06507 if( !DSET_LOADED(dset_coef) ){ 06508 fprintf(stderr, 06509 "** WARNING: -xrestore can't load old bucket dataset %s\n", 06510 BucketFilename); 06511 DSET_delete(dset_coef) ; dset_coef = NULL ; 06512 } 06513 } 06514 if( dset_coef != NULL && DSET_NVALS(dset_coef) < ParamIndex[np-1] ){ 06515 fprintf(stderr, 06516 "** WARNING: -xrestore old bucket dataset %s too short\n", 06517 BucketFilename); 06518 DSET_delete(dset_coef) ; dset_coef = NULL ; 06519 } 06520 } 06521 06522 if( ISVALID_DSET(dset_coef) && DSET_NVOX(dset_coef) != nxyz ){ 06523 fprintf(stderr, 06524 "** ERROR: dataset mismatch between time series and coef!\n") ; 06525 exit(1) ; 06526 } 06527 06528 /*----- neither worked ==> must recompute from input data time series -----*/ 06529 06530 if( dset_coef == NULL && verb ) 06531 fprintf(stderr, 06532 "++ -xrestore recomputing coefficients from time series\n"); 06533 06534 /*----- read new GLT matrices -----*/ 06535 06536 glt_cmat = (matrix *) malloc( sizeof(matrix) * num_glt ) ; 06537 06538 for( iglt=0; iglt < num_glt ; iglt++){ 06539 matrix_initialize( glt_cmat + iglt ) ; 06540 #if 1 06541 read_glt_matrix( option_data->glt_filename[iglt] , 06542 option_data->glt_rows + iglt , 06543 np , glt_cmat + iglt ) ; 06544 #else 06545 matrix_file_read ( option_data->glt_filename[iglt] , 06546 option_data->glt_rows[iglt] , 06547 np , glt_cmat+iglt , 1 ) ; 06548 if( glt_cmat[iglt].elts == NULL ){ 06549 fprintf(stderr, 06550 "** ERROR: Can't read GLT matrix from file %s\n", 06551 option_data->glt_filename[iglt] ) ; 06552 exit(1) ; 06553 } 06554 #endif 06555 } 06556 06557 /*----- initialize new GLT calculations: 06558 - setup space for matrices and vectors 06559 - calculate matrices 06560 - malloc space for output bricks -----*/ 06561 06562 cxtxinvct = (matrix *) malloc( sizeof(matrix) * num_glt ) ; 06563 glt_amat = (matrix *) malloc( sizeof(matrix) * num_glt ) ; 06564 glt_coef = (vector *) malloc( sizeof(vector) * num_glt ) ; 06565 glt_tcoef = (vector *) malloc( sizeof(vector) * num_glt ) ; 06566 06567 for( iglt=0 ; iglt < num_glt ; iglt++ ){ 06568 matrix_initialize( cxtxinvct+iglt ) ; /* will be loaded in */ 06569 matrix_initialize( glt_amat +iglt ) ; /* init_glt_analysis() */ 06570 vector_initialize( glt_coef +iglt ) ; 06571 vector_initialize( glt_tcoef+iglt ) ; 06572 } 06573 06574 fglt = (float *) malloc( sizeof(float) * num_glt ) ; 06575 rglt = (float *) malloc( sizeof(float) * num_glt ) ; 06576 06577 vector_initialize( &y ) ; vector_create( nt, &y ); /* time series */ 06578 vector_initialize( &coef ); vector_create( np, &coef ); /* parameters */ 06579 06580 if( dset_coef != NULL ) 06581 cdar = (float *)malloc( sizeof(float) * DSET_NVALS(dset_coef) ) ; 06582 06583 init_glt_analysis( XtXinv , num_glt , glt_cmat , glt_amat , cxtxinvct ) ; 06584 06585 /*-- malloc output bricks --*/ 06586 06587 glt_coef_vol = (float ***) malloc( sizeof(float **) * num_glt ) ; 06588 if( tout ) 06589 glt_tcoef_vol = (float ***) malloc( sizeof(float **) * num_glt ) ; 06590 if( fout ) 06591 glt_fstat_vol = (float **) malloc( sizeof(float *) * num_glt ) ; 06592 if( rout ) 06593 glt_rstat_vol = (float **) malloc( sizeof(float *) * num_glt ) ; 06594 06595 nvol = 0 ; 06596 for( iglt=0 ; iglt < num_glt ; iglt++ ){ 06597 nlc = glt_rows[iglt]; 06598 glt_coef_vol[iglt] = (float **) malloc( sizeof(float *) * nlc ) ; 06599 if( tout ) 06600 glt_tcoef_vol[iglt] = (float **) malloc( sizeof(float *) * nlc ) ; 06601 for( ilc=0 ; ilc < nlc ; ilc++ ){ 06602 glt_coef_vol[iglt][ilc] = (float *)calloc(sizeof(float),nxyz); nvol++; 06603 if( tout ){ 06604 glt_tcoef_vol[iglt][ilc] = (float *)calloc(sizeof(float),nxyz); nvol++; 06605 } 06606 } 06607 if( fout ){ 06608 glt_fstat_vol[iglt] = (float *)calloc( sizeof(float), nxyz ); nvol++; 06609 } 06610 if( rout ){ 06611 glt_rstat_vol[iglt] = (float *)calloc( sizeof(float), nxyz ); nvol++; 06612 } 06613 } 06614 06615 /*----- loop over voxels: 06616 - fetch coefficients (check for all zero), or recompute them 06617 - fetch time series 06618 - compute SSE of full model 06619 - compute and store new GLT results in arrays -----*/ 06620 06621 vstep = nxyz / 50 ; if( !verb ) vstep = 0 ; 06622 if( vstep > 0 ) fprintf(stderr,"++ voxel loop:") ; 06623 for( ixyz=0 ; ixyz < nxyz ; ixyz++ ){ 06624 06625 if( vstep > 0 && ixyz%vstep == vstep-1 ) vstep_print() ; 06626 06627 /*** race ahead and extract a bunch of voxel time series at once ***/ 06628 06629 if( cget == nget ){ 06630 if( imget != NULL ) DESTROY_IMARR(imget) ; 06631 iget[0] = ixyz ; nget = 1 ; 06632 for( jget=ixyz+1 ; jget < nxyz && nget < NGET ; jget++ ) 06633 iget[nget++] = jget ; 06634 imget = THD_extract_many_series( nget, iget, dset_time ) ; 06635 cget = 0 ; /* the next one to take out of imget */ 06636 } 06637 06638 /*** Extract Y-data for this voxel ***/ 06639 06640 ts_array = MRI_FLOAT_PTR(IMARR_SUBIM(imget,cget)) ; cget++ ; 06641 for( ii=0 ; ii < nt ; ii++ ) y.elts[ii] = ts_array[GoodList[ii]]; 06642 06643 /*** Extract or recompute coefficients for this voxel ***/ 06644 06645 if( dset_coef != NULL ){ 06646 (void) THD_extract_array( ixyz , dset_coef , 0 , cdar ) ; 06647 for( ii=0 ; ii < np ; ii++ ) coef.elts[ii] = cdar[ParamIndex[ii]] ; 06648 } else { 06649 vector_multiply( XtXinvXt , y , &coef ) ; 06650 } 06651 06652 /*** if coef is all zero, skip this voxel ***/ 06653 06654 for( ii=0 ; ii < np ; ii++ ) if( coef.elts[ii] != 0.0 ) break ; 06655 novar = (ii==np) ; 06656 06657 if( !novar ) ssef = calc_sse( X , coef , y ) ; 06658 06659 /************************************/ 06660 /*** Do the work we came here for ***/ 06661 /************************************/ 06662 06663 glt_analysis( nt , np , 06664 X , y , ssef , coef , novar , 06665 cxtxinvct , num_glt , glt_rows , glt_cmat , glt_amat , 06666 glt_coef , glt_tcoef , fglt , rglt ) ; 06667 06668 /*** save results into output bricks ***/ 06669 06670 if (glt_coef_vol != NULL) 06671 for (iglt = 0; iglt < num_glt; iglt++) 06672 if (glt_coef_vol[iglt] != NULL) 06673 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 06674 glt_coef_vol[iglt][ilc][ixyz] = glt_coef[iglt].elts[ilc]; 06675 06676 if (glt_tcoef_vol != NULL) 06677 for (iglt = 0; iglt < num_glt; iglt++) 06678 if (glt_tcoef_vol[iglt] != NULL) 06679 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 06680 glt_tcoef_vol[iglt][ilc][ixyz] = glt_tcoef[iglt].elts[ilc]; 06681 06682 if (glt_fstat_vol != NULL) 06683 for (iglt = 0; iglt < num_glt; iglt++) 06684 if (glt_fstat_vol[iglt] != NULL) 06685 glt_fstat_vol[iglt][ixyz] = fglt[iglt]; 06686 06687 if (glt_rstat_vol != NULL) 06688 for (iglt = 0; iglt < num_glt; iglt++) 06689 if (glt_rstat_vol[iglt] != NULL) 06690 glt_rstat_vol[iglt][ixyz] = rglt[iglt]; 06691 06692 } /*** end of loop over voxels */ 06693 06694 if( vstep > 0 ) fprintf(stderr,"\n") ; /* end of progress meter */ 06695 06696 /*** unload input datasets to save memory ***/ 06697 06698 DSET_unload( dset_time ) ; 06699 if( dset_coef != NULL ) DSET_delete( dset_coef ) ; 06700 06701 /*----- open old dataset for output if 06702 (a) -bucket was given for an existing dataset, or 06703 (b) no -bucket option was given; 06704 otherwise, open a new dataset for output of the GLT results -----*/ 06705 06706 if( option_data->bucket_filename != NULL ){ 06707 buck_prefix = strdup(option_data->bucket_filename) ; 06708 } else if( BucketFilename != NULL ){ 06709 buck_prefix = (char *)malloc(strlen(BucketFilename)+4) ; 06710 FILENAME_TO_PREFIX( BucketFilename , buck_prefix ) ; 06711 } else { 06712 buck_prefix = strdup("X") ; /* bad user, bad bad bad */ 06713 } 06714 06715 /*** try to open dataset as an old one **/ 06716 06717 buck_name = (char *)malloc(strlen(buck_prefix)+32) ; 06718 strcpy(buck_name,buck_prefix) ; 06719 strcat(buck_name,"+") ; strcat(buck_name,VIEW_codestr[view]) ; 06720 06721 dset_buck = THD_open_dataset( buck_name ) ; 06722 06723 if( dset_buck != NULL ){ 06724 06725 if( verb) fprintf(stderr,"++ -xrestore appending to dataset %s\n",buck_name) ; 06726 DSET_mallocize( dset_buck ) ; 06727 if( DSET_NVOX(dset_buck) != nxyz ){ 06728 fprintf(stderr, 06729 "** ERROR: dataset %s mismatch with time series '%s'\n" , 06730 buck_name , DSET_HEADNAME(dset_time) ); 06731 exit(0) ; 06732 } 06733 DSET_load( dset_buck ) ; 06734 if( !DSET_LOADED(dset_buck) ){ 06735 fprintf(stderr, 06736 "** ERROR: can't load dataset %s from disk\n" , buck_name ) ; 06737 exit(1) ; 06738 } 06739 06740 /* add nvol empty bricks at the end */ 06741 06742 ivol = DSET_NVALS(dset_buck) ; /* where to save first new brick */ 06743 06744 EDIT_add_bricklist( dset_buck , nvol, NULL, NULL, NULL ) ; 06745 06746 } else { /*** create a new dataset ***/ 06747 06748 if( verb ) fprintf(stderr,"++ -xrestore creating new dataset %s\n",buck_name) ; 06749 06750 dset_buck = EDIT_empty_copy( dset_time ) ; 06751 (void) EDIT_dset_items( dset_buck , 06752 ADN_prefix, buck_prefix , 06753 ADN_type, HEAD_FUNC_TYPE, 06754 ADN_func_type, FUNC_BUCK_TYPE, 06755 ADN_datum_all, MRI_short , 06756 ADN_ntt, 0, /* no time */ 06757 ADN_nvals, nvol , 06758 ADN_malloc_type, DATABLOCK_MEM_MALLOC , 06759 ADN_none ) ; 06760 ivol = 0 ; 06761 } 06762 06763 tross_Make_History( PROGRAM_NAME , argc , argv , dset_buck ) ; 06764 06765 nbuck = DSET_NVALS(dset_buck) ; 06766 06767 /*** attach sub-bricks to output ***/ 06768 06769 for( iglt=0 ; iglt < num_glt ; iglt++ ){ 06770 06771 for( ilc=0 ; ilc < glt_rows[iglt] ; ilc++ ){ 06772 sprintf( brick_label , "%s LC[%d] coef" , glt_label[iglt], ilc ) ; 06773 volume = glt_coef_vol[iglt][ilc]; 06774 attach_sub_brick( dset_buck, ivol, volume, nxyz, 06775 FUNC_FIM_TYPE, brick_label, 0, 0, 0, NULL); 06776 free((void *)volume) ; ivol++ ; 06777 06778 if( tout ){ 06779 sprintf( brick_label , "%s LC[%d] t-st" , glt_label[iglt], ilc ) ; 06780 volume = glt_tcoef_vol[iglt][ilc]; 06781 attach_sub_brick( dset_buck, ivol, volume, nxyz, 06782 FUNC_TT_TYPE, brick_label, nt-np, 0, 0, NULL); 06783 free((void *)volume) ; ivol++ ; 06784 } 06785 } 06786 06787 if( rout ){ 06788 sprintf( brick_label , "%s R^2" , glt_label[iglt] ) ; 06789 volume = glt_rstat_vol[iglt]; 06790 attach_sub_brick( dset_buck, ivol, volume, nxyz, 06791 FUNC_THR_TYPE, brick_label, 0, 0, 0, NULL); 06792 free((void *)volume) ; ivol++ ; 06793 } 06794 06795 if( fout ){ 06796 sprintf( brick_label , "%s F-stat" , glt_label[iglt] ) ; 06797 volume = glt_fstat_vol[iglt]; 06798 attach_sub_brick( dset_buck, ivol, volume, nxyz, 06799 FUNC_FT_TYPE, brick_label, 0, glt_rows[iglt], nt-np, NULL); 06800 free((void *)volume) ; ivol++ ; 06801 } 06802 } /** End loop over general linear tests **/ 06803 06804 /*----- Write dataset out! -----*/ 06805 06806 DSET_write( dset_buck ) ; 06807 return ; 06808 } |
|
|
|
compute start time of this timeseries * Definition at line 4347 of file 3dDeconvolve.c. References EDIT_coerce_scale_type(), ENTRY, MCW_vol_amax(), MRI_IS_INT_TYPE, RETURN, and top.
04349 { 04350 float fac=0.0 , top ; 04351 04352 ENTRY("EDIT_coerce_autoscale_new") ; 04353 04354 if( MRI_IS_INT_TYPE(otype) ){ 04355 top = MCW_vol_amax( nxyz,1,1 , itype,ivol ) ; 04356 if (top == 0.0) fac = 0.0; 04357 else fac = MRI_TYPE_maxval[otype]/top; 04358 } 04359 04360 EDIT_coerce_scale_type( nxyz , fac , itype,ivol , otype,ovol ) ; 04361 RETURN ( fac ); 04362 } |
|
Definition at line 7812 of file 3dDeconvolve.c. References floatpair::a, floatpair::b, base, denom_BASELINE, basis_irc::denom_flag, matrix::elts, vector::elts, basis_irc::npar, basis_irc::pbot, basis_irc::scale_fac, and basis_irc::ww.
07814 { 07815 floatpair vt={0.0f,0.0f} ; 07816 int ii,jj, np, pb ; 07817 double asum , bsum ; 07818 float *ww ; 07819 07820 np = birc->npar ; 07821 pb = birc->pbot ; 07822 ww = birc->ww ; 07823 07824 asum = 0.0 ; 07825 for( ii=0 ; ii < np ; ii++ ) 07826 asum += coef.elts[pb+ii] * ww[ii] ; 07827 07828 bsum = 0.0 ; 07829 for( ii=0 ; ii < np ; ii++ ) 07830 for( jj=0 ; jj < np ; jj++ ) 07831 bsum += cvar.elts[pb+ii][pb+jj] * ww[ii] * ww[jj] ; 07832 07833 bsum *= mse ; /* variance estimate */ 07834 07835 if( bsum > 0.0 ) vt.b = asum / sqrt(bsum) ; /* t statistic */ 07836 07837 vt.a = (float)(asum * birc->scale_fac) ; 07838 if( birc->denom_flag && denom_BASELINE ){ 07839 if( base == 0.0f ) vt.a = 0.0f ; 07840 else vt.a /= base ; 07841 } 07842 return vt ; 07843 } |
|
Definition at line 964 of file 3dDeconvolve.c. References addto_args(), AFNI_logger(), argc, basis_count, basis_dtout, basis_filler, basis_need_mse, basis_normall, basis_parser(), calloc, CoefFilename, DC_error(), display_help_menu(), initialize_glt_options(), initialize_options(), initialize_stim_options(), irc_dt, machdep(), mainENTRY, malloc, mri_read_ascii_ragged(), MTEST, basis_expansion::name, PROC_MAX, proc_numjob, proc_use_jobs, PROGRAM_NAME, show_singvals, strtod(), THD_is_file(), THD_MAX_NAME, verb, xrestore, xrestore_filename, and xsave.
00970 { 00971 int nopt = 1; /* input option argument counter */ 00972 int ival, index; /* integer input */ 00973 float fval; /* float input */ 00974 char message[THD_MAX_NAME]; /* error message */ 00975 int k; /* stimulus time series index */ 00976 int s; /* number of linear constraints in GLT */ 00977 int iglt = 0; /* general linear test index */ 00978 int nerr ; 00979 00980 /*-- addto the arglist, if user wants to --*/ 00981 mainENTRY("3dDeconvolve"); machdep() ; /* RWCox: 20 Apr 2001 */ 00982 { int new_argc ; char ** new_argv ; 00983 addto_args( argc , argv , &new_argc , &new_argv ) ; 00984 if( new_argv != NULL ){ argc = new_argc ; argv = new_argv ; } 00985 } 00986 00987 00988 /*----- does user request help menu? -----*/ 00989 if (argc < 2 || strcmp(argv[1], "-help") == 0) display_help_menu(); 00990 00991 00992 /*----- add to program log -----*/ 00993 AFNI_logger (PROGRAM_NAME,argc,argv); 00994 00995 00996 /*----- initialize the input options -----*/ 00997 initialize_options (option_data); 00998 00999 01000 /*----- main loop over input options -----*/ 01001 while (nopt < argc ) 01002 { 01003 01004 if( strcmp(argv[nopt],"-OK") == 0 ){ nopt++; continue; } /* 14 Jul 2004 */ 01005 01006 /*----- -nocond ------*/ 01007 01008 if( strcmp(argv[nopt],"-nocond") == 0 ){ /* 15 Jul 2004 */ 01009 #ifndef FLOATIZE 01010 option_data->nocond = 1 ; /* only allow this for double precision */ 01011 #else 01012 fprintf(stderr,"** WARNING: -nocond is ignored in 3dDeconvolve_f!\n") ; 01013 #endif 01014 nopt++ ; continue ; 01015 } 01016 01017 if( strcmp(argv[nopt],"-singvals") == 0 ){ /* 13 Aug 2004 */ 01018 show_singvals = 1 ; option_data->nocond = 0 ; 01019 nopt++ ; continue ; 01020 } 01021 01022 /*----- -xjpeg filename ------*/ 01023 if (strcmp(argv[nopt], "-xjpeg") == 0) /* 21 Jul 2004 */ 01024 { 01025 nopt++; 01026 if (nopt >= argc) DC_error ("need argument after -xjpeg "); 01027 option_data->xjpeg_filename = malloc (sizeof(char)*THD_MAX_NAME); 01028 MTEST (option_data->xjpeg_filename); 01029 strcpy (option_data->xjpeg_filename, argv[nopt]); 01030 if( strstr(option_data->xjpeg_filename,".jpg") == NULL && 01031 strstr(option_data->xjpeg_filename,".JPG") == NULL ) 01032 strcat( option_data->xjpeg_filename , ".jpg" ) ; 01033 nopt++; continue; 01034 } 01035 01036 01037 /*----- -input filename -----*/ 01038 if (strcmp(argv[nopt], "-input") == 0) 01039 { 01040 int iopt , slen ; 01041 nopt++; 01042 if (nopt >= argc) DC_error ("need argument after -input "); 01043 #if 0 01044 option_data->input_filename = malloc (sizeof(char)*THD_MAX_NAME); 01045 MTEST (option_data->input_filename); 01046 strcpy (option_data->input_filename, argv[nopt]); 01047 nopt++; 01048 #else /* 05 Aug 2004: multiple input datasets */ 01049 slen = 0 ; 01050 for( iopt=nopt ; iopt < argc && argv[iopt][0] != '-' ; iopt++ ) 01051 slen += strlen(argv[iopt])+8 ; 01052 option_data->input_filename = calloc(sizeof(char),slen) ; 01053 MTEST (option_data->input_filename); 01054 for( iopt=nopt ; iopt < argc && argv[iopt][0] != '-' ; iopt++ ){ 01055 strcat( option_data->input_filename , argv[iopt] ) ; 01056 strcat( option_data->input_filename , " " ) ; 01057 } 01058 slen = strlen(option_data->input_filename) ; 01059 option_data->input_filename[slen-1] = '\0' ; /* trim last blank */ 01060 nopt = iopt ; 01061 #endif 01062 continue; 01063 } 01064 01065 01066 /*----- -mask filename -----*/ 01067 if (strcmp(argv[nopt], "-mask") == 0) 01068 { 01069 nopt++; 01070 if (nopt >= argc) DC_error ("need argument after -mask "); 01071 if( option_data->automask ) DC_error("can't use -mask AND -automask!") ; 01072 option_data->mask_filename = malloc (sizeof(char)*THD_MAX_NAME); 01073 MTEST (option_data->mask_filename); 01074 strcpy (option_data->mask_filename, argv[nopt]); 01075 nopt++; 01076 continue; 01077 } 01078 01079 /*---- -automask -----*/ 01080 if( strcmp(argv[nopt],"-automask") == 0 ){ /* 15 Apr 2005 */ 01081 if( option_data->mask_filename != NULL ) 01082 DC_error("can't use -automask AND -mask!") ; 01083 option_data->automask = 1 ; 01084 nopt++ ; continue ; 01085 } 01086 01087 01088 /*----- -input1D filename -----*/ 01089 if (strcmp(argv[nopt], "-input1D") == 0) 01090 { 01091 nopt++; 01092 if (nopt >= argc) DC_error ("need argument after -input1D "); 01093 option_data->input1D_filename = 01094 malloc (sizeof(char)*THD_MAX_NAME); 01095 MTEST (option_data->input1D_filename); 01096 strcpy (option_data->input1D_filename, argv[nopt]); 01097 nopt++; 01098 continue; 01099 } 01100 01101 01102 /*----- -censor filename -----*/ 01103 if (strcmp(argv[nopt], "-censor") == 0) 01104 { 01105 nopt++; 01106 if (nopt >= argc) DC_error ("need argument after -censor "); 01107 option_data->censor_filename = 01108 malloc (sizeof(char)*THD_MAX_NAME); 01109 MTEST (option_data->censor_filename); 01110 strcpy (option_data->censor_filename, argv[nopt]); 01111 nopt++; 01112 continue; 01113 } 01114 01115 01116 /*----- -concat filename -----*/ 01117 if (strcmp(argv[nopt], "-concat") == 0) 01118 { 01119 nopt++; 01120 if (nopt >= argc) DC_error ("need argument after -concat "); 01121 option_data->concat_filename = 01122 malloc (sizeof(char)*THD_MAX_NAME); 01123 MTEST (option_data->concat_filename); 01124 strcpy (option_data->concat_filename, argv[nopt]); 01125 nopt++; 01126 continue; 01127 } 01128 01129 01130 /*----- -nodata -----*/ 01131 if (strcmp(argv[nopt], "-nodata") == 0) 01132 { 01133 option_data->nodata = 1; 01134 nopt++; 01135 01136 /* 27 Apr 2005: check for additional numeric values */ 01137 01138 if( isdigit(argv[nopt][0]) ){ /* get NT */ 01139 option_data->nodata_NT = (int)strtol(argv[nopt++],NULL,10) ; 01140 if( isdigit(argv[nopt][0]) ){ /* get TR */ 01141 option_data->nodata_TR = (float)strtod(argv[nopt++],NULL) ; 01142 } 01143 } 01144 continue; 01145 } 01146 01147 01148 /*----- -nfirst num -----*/ 01149 if (strcmp(argv[nopt], "-nfirst") == 0) 01150 { 01151 nopt++; 01152 if (nopt >= argc) DC_error ("need argument after -nfirst "); 01153 sscanf (argv[nopt], "%d", &ival); 01154 if (ival < 0) 01155 DC_error ("illegal argument after -nfirst "); 01156 option_data->NFirst = ival; 01157 nopt++; 01158 continue; 01159 } 01160 01161 01162 /*----- -nlast num -----*/ 01163 if (strcmp(argv[nopt], "-nlast") == 0) 01164 { 01165 nopt++; 01166 if (nopt >= argc) DC_error ("need argument after -nlast "); 01167 sscanf (argv[nopt], "%d", &ival); 01168 if (ival < 0) 01169 DC_error ("illegal argument after -nlast "); 01170 option_data->NLast = ival; 01171 nopt++; 01172 continue; 01173 } 01174 01175 01176 /*----- -polort num -----*/ 01177 if (strcmp(argv[nopt], "-polort") == 0) 01178 { 01179 nopt++; 01180 if (nopt >= argc) DC_error ("need argument after -polort "); 01181 sscanf (argv[nopt], "%d", &ival); 01182 if (ival < -1) 01183 DC_error ("illegal argument after -polort "); 01184 option_data->polort = ival; 01185 nopt++; 01186 continue; 01187 } 01188 01189 /*----- -legendre AND -nolegendre [15 Jul 2004] -----*/ 01190 01191 if( strstr(argv[nopt],"legendre") != NULL ){ 01192 legendre_polort = (strncmp(argv[nopt],"-leg",4) == 0) ; 01193 nopt++ ; continue ; 01194 } 01195 01196 /*----- -nosvd [20 Jul 2004] -----*/ 01197 01198 if( strstr(argv[nopt],"svd") != NULL ){ 01199 use_psinv = (strncmp(argv[nopt],"-svd",4) == 0) ; 01200 nopt++ ; continue ; 01201 } 01202 01203 /*----- -nodmbase [12 Aug 2004] -----*/ 01204 01205 if( strstr(argv[nopt],"dmbase") != NULL ){ 01206 demean_base = (strncmp(argv[nopt],"-dmb",4) == 0) ; 01207 nopt++ ; continue ; 01208 } 01209 01210 /*----- -noxsave [25 Jul 2004] -----*/ 01211 01212 if( strstr(argv[nopt],"xsave") != NULL ){ 01213 xsave = (strncmp(argv[nopt],"-xsave",5) == 0) ; 01214 nopt++ ; continue ; 01215 } 01216 01217 /*----- -xrestore [26 Jul 2004] -----*/ 01218 01219 if( strcmp(argv[nopt],"-xrestore") == 0 ){ 01220 nopt++; 01221 if( nopt >= argc) DC_error ("need argument after -xrestore "); 01222 xrestore_filename = strdup( argv[nopt] ) ; 01223 if( !THD_is_file(xrestore_filename) ) 01224 DC_error("file named after -xrestore doesn't exist") ; 01225 xrestore = 1 ; nopt++ ; continue ; 01226 } 01227 01228 /*----- -quiet -----*/ 01229 if (strcmp(argv[nopt], "-quiet") == 0) 01230 { 01231 option_data->quiet = 1; verb = 0 ; 01232 nopt++; 01233 continue; 01234 } 01235 01236 /*----- -progress n -----*/ 01237 if (strcmp(argv[nopt], "-progress") == 0) 01238 { 01239 nopt++; 01240 if (nopt >= argc) DC_error ("need argument after -progress "); 01241 sscanf (argv[nopt], "%d", &ival); 01242 if (ival < 0) 01243 DC_error ("illegal argument after -progress "); 01244 option_data->progress = ival; 01245 nopt++; 01246 continue; 01247 } 01248 01249 01250 /*----- -rmsmin r -----*/ 01251 if (strcmp(argv[nopt], "-rmsmin") == 0) 01252 { 01253 nopt++; 01254 if (nopt >= argc) DC_error ("need argument after -rmsmin "); 01255 sscanf (argv[nopt], "%f", &fval); 01256 if (fval < 0.0) 01257 DC_error ("illegal argument after -rmsmin "); 01258 option_data->rms_min = fval; 01259 nopt++; 01260 continue; 01261 } 01262 01263 01264 /*----- -fdisp fval -----*/ 01265 if (strcmp(argv[nopt], "-fdisp") == 0) 01266 { 01267 nopt++; 01268 if (nopt >= argc) DC_error ("need argument after -fdisp "); 01269 sscanf (argv[nopt], "%f", &fval); 01270 option_data->fdisp = fval; 01271 nopt++; 01272 continue; 01273 } 01274 01275 01276 /*----- -num_stimts num -----*/ 01277 if (strcmp(argv[nopt], "-num_stimts") == 0) 01278 { 01279 nopt++; 01280 if (nopt >= argc) DC_error ("need argument after -num_stimts "); 01281 sscanf (argv[nopt], "%d", &ival); 01282 if (ival < 0) 01283 { 01284 DC_error ("-num_stimts num Require: num >= 0 "); 01285 } 01286 01287 initialize_stim_options (option_data, ival); 01288 01289 nopt++; 01290 continue; 01291 } 01292 01293 /*----- -TR_times basis_dtout [16 Aug 2004] -----*/ 01294 if( strcmp(argv[nopt],"-TR_times") == 0 ){ 01295 nopt++ ; 01296 if( nopt >= argc ) DC_error("need argument after -TR_times") ; 01297 sscanf( argv[nopt] , "%f" , &basis_dtout ) ; 01298 if( basis_dtout <= 0.0f ){ 01299 fprintf(stderr,"** ERROR: -TR_times '%s' is illegal\n",argv[nopt]) ; 01300 exit(1) ; 01301 } 01302 nopt++ ; continue ; 01303 } 01304 01305 /*----- -TR_irc irc_dt [08 Sep 2004] -----*/ 01306 if( strcmp(argv[nopt],"-TR_irc") == 0 ){ 01307 nopt++ ; 01308 if( nopt >= argc ) DC_error("need argument after -TR_irc") ; 01309 sscanf( argv[nopt] , "%f" , &irc_dt ) ; 01310 if( irc_dt <= 0.0f ){ 01311 fprintf(stderr,"** ERROR: -TR_irc '%s' is illegal\n",argv[nopt]) ; 01312 exit(1) ; 01313 } 01314 nopt++ ; continue ; 01315 } 01316 01317 /*----- -basis_normall a [28 Apr 2005] -----*/ 01318 01319 if( strcmp(argv[nopt],"-basis_normall") == 0 ){ 01320 nopt++ ; 01321 if( nopt >= argc ) DC_error("need argument after -basis_normall") ; 01322 basis_normall = strtod( argv[nopt] , NULL ) ; 01323 if( basis_normall <= 0.0f ) 01324 DC_error("value after -basis_normall is illegal!") ; 01325 nopt++ ; continue ; 01326 } 01327 01328 /*----- -stim_times k sname rtype [10 Aug 2004] -----*/ 01329 if( strcmp(argv[nopt],"-stim_times") == 0 ){ 01330 nopt++ ; 01331 if( nopt+2 >= argc ) DC_error("need 3 arguments after -stim_times"); 01332 sscanf( argv[nopt] , "%d" , &ival ) ; 01333 if( (ival < 1) || (ival > option_data->num_stimts) ){ 01334 fprintf(stderr, 01335 "** ERROR: '-stim_times %d' value out of range 1..%d\n", 01336 ival , option_data->num_stimts ) ; 01337 exit(1) ; 01338 } 01339 k = ival-1 ; nopt++ ; 01340 if( option_data->stim_filename[k] != NULL ){ 01341 fprintf(stderr, 01342 "** ERROR: '-stim_times %d' trying to overwrite previous stimulus\n", 01343 ival ) ; 01344 exit(1) ; 01345 } 01346 option_data->stim_filename[k] = strdup( argv[nopt] ) ; 01347 basis_times[k] = mri_read_ascii_ragged( argv[nopt] , basis_filler ) ; 01348 if( basis_times[k] == NULL ){ 01349 fprintf(stderr, 01350 "** ERROR: '-stim_times %d' can't read file '%s'\n", 01351 ival , argv[nopt] ) ; 01352 exit(1) ; 01353 } 01354 nopt++ ; 01355 basis_stim[k] = basis_parser( argv[nopt] ) ; /* regression model */ 01356 if( basis_stim[k] == NULL ){ 01357 fprintf(stderr, 01358 "** ERROR: '-stim_times %d %s' can't parse '%s'\n", 01359 ival , argv[nopt-1] , argv[nopt] ) ; 01360 } 01361 basis_count++ ; 01362 nopt++ ; continue ; 01363 } 01364 01365 /*----- -stim_file k sname -----*/ 01366 if (strcmp(argv[nopt], "-stim_file") == 0) 01367 { 01368 nopt++; 01369 if (nopt+1 >= argc) DC_error ("need 2 arguments after -stim_file"); 01370 01371 sscanf (argv[nopt], "%d", &ival); 01372 if ((ival < 1) || (ival > option_data->num_stimts)) 01373 DC_error ("-stim_file k sname Require: 1 <= k <= num_stimts"); 01374 k = ival-1; 01375 nopt++; 01376 if( option_data->stim_filename[k] != NULL ){ 01377 fprintf(stderr, 01378 "** ERROR: '-stim_file %d' trying to overwrite previous stimulus\n", 01379 ival ) ; 01380 exit(1) ; 01381 } 01382 01383 option_data->stim_filename[k] = malloc (sizeof(char)*THD_MAX_NAME); 01384 MTEST (option_data->stim_filename[k]); 01385 strcpy (option_data->stim_filename[k], argv[nopt]); 01386 nopt++; 01387 continue; 01388 } 01389 01390 01391 /*----- -stim_label k slabel -----*/ 01392 if (strcmp(argv[nopt], "-stim_label") == 0) 01393 { 01394 nopt++; 01395 if (nopt+1 >= argc) DC_error ("need 2 arguments after -stim_label"); 01396 01397 sscanf (argv[nopt], "%d", &ival); 01398 if ((ival < 1) || (ival > option_data->num_stimts)) 01399 DC_error ("-stim_label k slabel Require: 1 <= k <= num_stimts"); 01400 k = ival-1; 01401 nopt++; 01402 01403 strcpy (option_data->stim_label[k], argv[nopt]); 01404 nopt++; 01405 continue; 01406 } 01407 01408 01409 /*----- -stim_base k -----*/ 01410 if (strcmp(argv[nopt], "-stim_base") == 0) 01411 { 01412 nopt++; 01413 if (nopt >= argc) 01414 DC_error ("need 1 argument after -stim_base"); 01415 01416 sscanf (argv[nopt], "%d", &ival); 01417 if ((ival < 1) || (ival > option_data->num_stimts)) 01418 DC_error ("-stim_base k Require: 1 <= k <= num_stimts"); 01419 k = ival-1; 01420 option_data->stim_base[k] = 1; 01421 nopt++; 01422 continue; 01423 } 01424 01425 01426 /*----- -stim_minlag k lag -----*/ 01427 if (strcmp(argv[nopt], "-stim_minlag") == 0) 01428 { 01429 nopt++; 01430 if (nopt+1 >= argc) 01431 DC_error ("need 2 arguments after -stim_minlag"); 01432 01433 sscanf (argv[nopt], "%d", &ival); 01434 if ((ival < 1) || (ival > option_data->num_stimts)) 01435 DC_error ("-stim_minlag k lag Require: 1 <= k <= num_stimts"); 01436 k = ival-1; 01437 nopt++; 01438 01439 sscanf (argv[nopt], "%d", &ival); 01440 if (ival < 0) 01441 DC_error ("-stim_minlag k lag Require: 0 <= lag"); 01442 option_data->stim_minlag[k] = ival; 01443 nopt++; 01444 continue; 01445 } 01446 01447 01448 /*----- -stim_maxlag k lag -----*/ 01449 if (strcmp(argv[nopt], "-stim_maxlag") == 0) 01450 { 01451 nopt++; 01452 if (nopt+1 >= argc) 01453 DC_error ("need 2 arguments after -stim_maxlag"); 01454 01455 sscanf (argv[nopt], "%d", &ival); 01456 if ((ival < 1) || (ival > option_data->num_stimts)) 01457 DC_error ("-stim_maxlag k lag Require: 1 <= k <= num_stimts"); 01458 k = ival-1; 01459 nopt++; 01460 01461 sscanf (argv[nopt], "%d", &ival); 01462 if (ival < 0) 01463 DC_error ("-stim_maxlag k lag Require: 0 <= lag"); 01464 option_data->stim_maxlag[k] = ival; 01465 nopt++; 01466 continue; 01467 } 01468 01469 01470 /*----- -stim_nptr k p -----*/ 01471 if (strcmp(argv[nopt], "-stim_nptr") == 0) 01472 { 01473 nopt++; 01474 if (nopt+1 >= argc) 01475 DC_error ("need 2 arguments after -stim_nptr"); 01476 01477 sscanf (argv[nopt], "%d", &ival); 01478 if ((ival < 1) || (ival > option_data->num_stimts)) 01479 DC_error ("-stim_nptr k p Require: 1 <= k <= num_stimts"); 01480 k = ival-1; 01481 nopt++; 01482 01483 sscanf (argv[nopt], "%d", &ival); 01484 if (ival < 1) 01485 DC_error ("-stim_nptr k p Require: 1 <= p"); 01486 option_data->stim_nptr[k] = ival; 01487 nopt++; 01488 continue; 01489 } 01490 01491 01492 /*----- -num_glt num -----*/ 01493 if (strcmp(argv[nopt], "-num_glt") == 0) 01494 { 01495 nopt++; 01496 if (nopt >= argc) DC_error ("need argument after -num_glt "); 01497 sscanf (argv[nopt], "%d", &ival); 01498 if (ival < 0) 01499 { 01500 DC_error ("-num_glt num Require: num >= 0 "); 01501 } 01502 01503 if (option_data->num_glt > 0) 01504 DC_error ("-num_glt option must precede any -glt options "); 01505 01506 initialize_glt_options (option_data, ival); 01507 01508 nopt++; 01509 continue; 01510 } 01511 01512 01513 /*----- -glt s gltname -----*/ 01514 if (strcmp(argv[nopt], "-glt") == 0) 01515 { 01516 nopt++; 01517 if (nopt+1 >= argc) DC_error ("need 2 arguments after -glt"); 01518 01519 sscanf (argv[nopt], "%d", &ival); 01520 if (ival < 1) 01521 { 01522 DC_error ("-glt s gltname Require: s >= 1 (s = #rows in GLT)"); 01523 } 01524 s = ival; 01525 01526 if (option_data->num_glt == 0) 01527 initialize_glt_options (option_data, 10); /* default limit on GLTs */ 01528 01529 if (iglt+1 > option_data->num_glt) 01530 DC_error ("Use -num_glt option to specify number of GLTs"); 01531 01532 option_data->glt_rows[iglt] = s; 01533 nopt++; 01534 01535 option_data->glt_filename[iglt] 01536 = malloc (sizeof(char)*THD_MAX_NAME); 01537 MTEST (option_data->glt_filename[iglt]); 01538 strcpy (option_data->glt_filename[iglt], 01539 argv[nopt]); 01540 iglt++; 01541 01542 nopt++; 01543 continue; 01544 } 01545 01546 /*---- -gltsym gltname [29 Jul 2004] -----*/ 01547 01548 if( strcmp(argv[nopt],"-gltsym") == 0 ){ 01549 nopt++ ; 01550 if( nopt >= argc ) DC_error("need 1 argument after -gltsym") ; 01551 01552 if( option_data->num_glt == 0 ) 01553 initialize_glt_options(option_data,10) ; /* default limit on GLTs */ 01554 01555 if( iglt+1 > option_data->num_glt ) 01556 DC_error("Use -num_glt option to specify number of GLTs when more than 10") ; 01557 01558 option_data->glt_rows[iglt] = -1 ; /* flag for symbolic read */ 01559 01560 option_data->glt_filename[iglt] = strdup( argv[nopt] ) ; 01561 iglt++ ; nopt++ ; continue ; 01562 } 01563 01564 01565 /*----- -glt_label k glabel -----*/ 01566 if (strcmp(argv[nopt], "-glt_label") == 0) 01567 { 01568 nopt++; 01569 if (nopt+1 >= argc) DC_error ("need 2 arguments after -glt_label"); 01570 01571 sscanf (argv[nopt], "%d", &ival); 01572 if ((ival < 1) || (ival > option_data->num_glt)) 01573 DC_error ("-stim_label k slabel Require: 1 <= k <= num_glt"); 01574 k = ival-1; 01575 nopt++; 01576 01577 strcpy (option_data->glt_label[k], argv[nopt]); 01578 nopt++; 01579 continue; 01580 } 01581 01582 01583 /*----- -iresp k iprefix -----*/ 01584 if (strcmp(argv[nopt], "-iresp") == 0) 01585 { 01586 nopt++; 01587 if (nopt+1 >= argc) DC_error ("need 2 arguments after -iresp"); 01588 01589 sscanf (argv[nopt], "%d", &ival); 01590 if ((ival < 1) || (ival > option_data->num_stimts)) 01591 DC_error ("-iresp k iprefix Require: 1 <= k <= num_stimts"); 01592 k = ival-1; 01593 nopt++; 01594 01595 option_data->iresp_filename[k] 01596 = malloc (sizeof(char)*THD_MAX_NAME); 01597 MTEST (option_data->iresp_filename[k]); 01598 strcpy (option_data->iresp_filename[k], argv[nopt]); 01599 nopt++; 01600 continue; 01601 } 01602 01603 01604 /*----- -tshift -----*/ 01605 if (strcmp(argv[nopt], "-tshift") == 0) 01606 { 01607 option_data->tshift = 1; 01608 nopt++; 01609 continue; 01610 } 01611 01612 01613 /*----- -sresp k sprefix -----*/ 01614 if (strcmp(argv[nopt], "-sresp") == 0) 01615 { 01616 nopt++; 01617 if (nopt+1 >= argc) DC_error ("need 2 arguments after -sresp"); 01618 01619 sscanf (argv[nopt], "%d", &ival); 01620 if ((ival < 1) || (ival > option_data->num_stimts)) 01621 DC_error ("-sresp k iprefix Require: 1 <= k <= num_stimts"); 01622 k = ival-1; 01623 nopt++; 01624 01625 option_data->sresp_filename[k] 01626 = malloc (sizeof(char)*THD_MAX_NAME); 01627 MTEST (option_data->sresp_filename[k]); 01628 strcpy (option_data->sresp_filename[k], argv[nopt]); 01629 nopt++; 01630 continue; 01631 } 01632 01633 01634 /*----- -fout -----*/ 01635 if (strcmp(argv[nopt], "-fout") == 0) 01636 { 01637 option_data->fout = 1; 01638 nopt++; 01639 continue; 01640 } 01641 01642 01643 /*----- -rout -----*/ 01644 if (strcmp(argv[nopt], "-rout") == 0) 01645 { 01646 option_data->rout = 1; 01647 nopt++; 01648 continue; 01649 } 01650 01651 01652 /*----- -tout -----*/ 01653 if (strcmp(argv[nopt], "-tout") == 0) 01654 { 01655 option_data->tout = 1; 01656 nopt++; 01657 continue; 01658 } 01659 01660 01661 /*----- -vout -----*/ 01662 if (strcmp(argv[nopt], "-vout") == 0) 01663 { 01664 option_data->vout = 1; 01665 nopt++; 01666 continue; 01667 } 01668 01669 01670 /*----- -xout -----*/ 01671 if (strcmp(argv[nopt], "-xout") == 0) 01672 { 01673 option_data->xout = 1; 01674 nopt++; 01675 continue; 01676 } 01677 01678 01679 /*----- -nobout -----*/ 01680 if (strcmp(argv[nopt], "-nobout") == 0) 01681 { 01682 option_data->nobout = 1; 01683 nopt++; 01684 continue; 01685 } 01686 01687 01688 /*----- -nocout -----*/ 01689 if (strcmp(argv[nopt], "-nocout") == 0) 01690 { 01691 option_data->nocout = 1; 01692 nopt++; 01693 continue; 01694 } 01695 01696 01697 /*----- -full_first -----*/ 01698 if (strcmp(argv[nopt], "-full_first") == 0) 01699 { 01700 option_data->full_first = 1; 01701 nopt++; 01702 continue; 01703 } 01704 01705 01706 /*----- -bucket filename -----*/ 01707 if (strcmp(argv[nopt], "-bucket") == 0 || strcmp(argv[nopt],"-prefix") == 0 ) 01708 { 01709 nopt++; 01710 if (nopt >= argc) DC_error ("need file prefixname after -bucket "); 01711 option_data->bucket_filename = malloc (sizeof(char)*THD_MAX_NAME); 01712 MTEST (option_data->bucket_filename); 01713 strcpy (option_data->bucket_filename, argv[nopt]); 01714 nopt++; 01715 continue; 01716 } 01717 01718 /*----- -cbucket filename -----*/ 01719 if (strcmp(argv[nopt], "-cbucket") == 0 || strcmp(argv[nopt],"-cprefix") == 0 ) 01720 { 01721 nopt++; 01722 if (nopt >= argc) DC_error ("need file prefixname after -cbucket "); 01723 CoefFilename = strdup( argv[nopt] ) ; 01724 nopt++; continue; 01725 } 01726 01727 01728 /*----- -fitts filename -----*/ 01729 if (strcmp(argv[nopt], "-fitts") == 0) 01730 { 01731 nopt++; 01732 if (nopt >= argc) DC_error ("need file prefixname after -fitts "); 01733 option_data->fitts_filename = malloc (sizeof(char)*THD_MAX_NAME); 01734 MTEST (option_data->fitts_filename); 01735 strcpy (option_data->fitts_filename, argv[nopt]); 01736 nopt++; 01737 continue; 01738 } 01739 01740 01741 /*----- -errts filename -----*/ 01742 if (strcmp(argv[nopt], "-errts") == 0) 01743 { 01744 nopt++; 01745 if (nopt >= argc) DC_error ("need file prefixname after -errts "); 01746 option_data->errts_filename = malloc (sizeof(char)*THD_MAX_NAME); 01747 MTEST (option_data->errts_filename); 01748 strcpy (option_data->errts_filename, argv[nopt]); 01749 nopt++; 01750 continue; 01751 } 01752 01753 /*----- -jobs J -----*/ 01754 if( strcmp(argv[nopt],"-jobs") == 0 ){ /* RWCox */ 01755 nopt++ ; 01756 if (nopt >= argc) DC_error ("need J parameter after -jobs "); 01757 #ifdef PROC_MAX 01758 proc_numjob = strtol(argv[nopt],NULL,10) ; 01759 if( proc_numjob < 1 ){ 01760 fprintf(stderr,"** NOTICE: setting number of processes to 1!\n") ; 01761 proc_numjob = 1 ; 01762 } else if( proc_numjob > PROC_MAX ){ 01763 fprintf(stderr,"** NOTICE: setting number of processes to %d!\n",PROC_MAX); 01764 proc_numjob = PROC_MAX ; 01765 } 01766 #else 01767 fprintf(stderr,"** WARNING: -jobs not supported in this version\n") ; 01768 #endif 01769 proc_use_jobs = 1 ; /* -jobs opt given 2003.08.15 [rickr] */ 01770 nopt++; continue; 01771 } 01772 01773 01774 /*----- unknown command -----*/ 01775 sprintf(message,"Unrecognized command line option: %s\n", argv[nopt]); 01776 DC_error (message); 01777 01778 } 01779 01780 01781 /*----- Set number of GLTs actually present -----*/ 01782 option_data->num_glt = iglt; 01783 01784 /*---- if -jobs is given, make sure are processing 3D data ----*/ 01785 01786 #ifdef PROC_MAX 01787 if( (xrestore || option_data->input1D_filename != NULL) && proc_numjob > 1 ){ 01788 proc_numjob = 1 ; 01789 if( verb ) fprintf(stderr,"** WARNING: -jobs reset to 1\n") ; 01790 } 01791 #endif 01792 01793 /**--- Test various combinations for legality [11 Aug 2004] ---**/ 01794 01795 if( option_data->polort < 0 ) demean_base = 0 ; /* 12 Aug 2004 */ 01796 01797 nerr = 0 ; 01798 for( k=0 ; k < option_data->num_stimts ; k++ ){ 01799 01800 if( basis_stim[k] != NULL ){ /* -stim_times input */ 01801 01802 basis_stim[k]->name = strdup( option_data->stim_label[k] ) ; 01803 01804 if( option_data->sresp_filename[k] != NULL ) basis_need_mse = 1 ; 01805 01806 if( option_data->stim_nptr[k] != 1 ){ 01807 fprintf(stderr, 01808 "** ERROR: '-stim_nptr %d %d' illegal with '-stim_times'\n", 01809 k+1 , option_data->stim_nptr[k] ) ; 01810 nerr++ ; 01811 } 01812 if( option_data->stim_base[k] != 0 ){ 01813 fprintf(stderr, 01814 "** ERROR: '-stim_base %d' illegal with '-stim_times'\n", 01815 k+1 ) ; 01816 nerr++ ; 01817 } 01818 if( option_data->stim_minlag[k] != 0 ){ 01819 fprintf(stderr, 01820 "** ERROR: '-stim_minlag %d %d' illegal with '-stim_times'\n", 01821 k+1 , option_data->stim_minlag[k] ) ; 01822 nerr++ ; 01823 } 01824 if( option_data->stim_maxlag[k] != 0 ){ 01825 fprintf(stderr, 01826 "** ERROR: '-stim_maxlag %d %d' illegal with '-stim_times'\n", 01827 k+1 , option_data->stim_maxlag[k] ) ; 01828 nerr++ ; 01829 } 01830 01831 } else { /* -stim_file type of input */ 01832 01833 if( option_data->stim_filename[k] == NULL ){ 01834 fprintf(stderr,"** ERROR: no stimulus #%d given\n",k+1) ; 01835 nerr++ ; 01836 } 01837 01838 } 01839 } /* end of loop over stimuli */ 01840 if( nerr > 0 ) exit(1) ; 01841 01842 } |
|
Definition at line 551 of file 3dDeconvolve.c. References INFO_message(), PRINT_VERSION, PROGRAM_AUTHOR, PROGRAM_INITIAL, PROGRAM_LATEST, and PROGRAM_NAME. Referenced by display_help_menu(), initialize_program(), and print_options().
00552 { 00553 00554 /*----- Identify software -----*/ 00555 #if 1 00556 PRINT_VERSION("3dDeconvolve") ; 00557 #else 00558 printf ("\n\n"); 00559 printf ("Program: %s \n", PROGRAM_NAME); 00560 printf ("Author: %s \n", PROGRAM_AUTHOR); 00561 printf ("Initial Release: %s \n", PROGRAM_INITIAL); 00562 printf ("Latest Revision: %s \n", PROGRAM_LATEST); 00563 #endif 00564 00565 #ifdef USE_ALTIVEC 00566 INFO_message ("Compiled with Altivec acceleration for Mac OS X\n") ; 00567 #elif defined(USE_SUNPERF) && !defined(FLOATIZE) 00568 INFO_message ("Compiled with BLAS-1 acceleration for Solaris\n") ; 00569 #elif defined(USE_SCSLBLAS) 00570 INFO_message ("Compiled with BLAS-1 acceleration for SGI Altix\n") ; 00571 #endif 00572 } |
|
Definition at line 918 of file 3dDeconvolve.c. References ENTRY, malloc, MTEST, and THD_MAX_NAME. Referenced by get_options().
00923 { 00924 int iglt; /* glt index */ 00925 00926 ENTRY("initialize_glt_options") ; 00927 00928 00929 /*----- Set number of general linear tests -----*/ 00930 if (num_glt <= 0) EXRETURN ; 00931 else option_data->num_glt = num_glt; 00932 00933 00934 /*----- Allocate memory for glt options -----*/ 00935 option_data->glt_filename = (char **) malloc (sizeof(char *) * num_glt); 00936 MTEST (option_data->glt_filename); 00937 option_data->glt_label = (char **) malloc (sizeof(char *) * num_glt); 00938 MTEST (option_data->glt_label); 00939 option_data->glt_rows = (int *) malloc (sizeof(int) * num_glt); 00940 MTEST (option_data->glt_rows); 00941 00942 00943 /*----- Initialize glt options -----*/ 00944 for (iglt = 0; iglt < num_glt; iglt++) 00945 { 00946 option_data->glt_filename[iglt] = NULL; 00947 option_data->glt_label[iglt] = malloc (sizeof(char)*THD_MAX_NAME); 00948 MTEST (option_data->glt_label[iglt]); 00949 sprintf (option_data->glt_label[iglt], "GLT #%d ", iglt+1); 00950 option_data->glt_rows[iglt] = 0; 00951 } 00952 00953 00954 EXRETURN ; 00955 } |
|
Definition at line 771 of file 3dDeconvolve.c.
00775 { 00776 int is; /* input stimulus time series index */ 00777 00778 /*----- Initialize default values -----*/ 00779 option_data->nxyz = -1; 00780 option_data->nt = -1; 00781 option_data->NFirst = -1; 00782 option_data->NLast = -1; 00783 option_data->N = 0; 00784 option_data->polort = 1; 00785 option_data->rms_min = 0.0; 00786 option_data->quiet = 0; 00787 option_data->progress = 0; 00788 option_data->fdisp = -1.0; 00789 option_data->nodata = 0; 00790 option_data->p = 0; 00791 option_data->q = 0; 00792 option_data->qp = 0; 00793 option_data->nbricks = 0; 00794 option_data->nocond = 0; /* 15 Jul 2004 */ 00795 option_data->nodata_NT= 0; /* 27 Apr 2005 */ 00796 option_data->nodata_TR= 0.0; 00797 00798 option_data->xjpeg_filename = NULL ; /* 21 Jul 2004 */ 00799 00800 /*----- Initialize stimulus options -----*/ 00801 option_data->num_stimts = 0; 00802 option_data->stim_filename = NULL; 00803 option_data->stim_label = NULL; 00804 option_data->stim_base = NULL; 00805 option_data->stim_minlag = NULL; 00806 option_data->stim_maxlag = NULL; 00807 option_data->stim_nptr = NULL; 00808 option_data->iresp_filename = NULL; 00809 option_data->sresp_filename = NULL; 00810 00811 /*----- Initialize glt options -----*/ 00812 option_data->num_glt = 0; 00813 option_data->glt_filename = NULL; 00814 option_data->glt_label = NULL; 00815 option_data->glt_rows = NULL; 00816 00817 /*----- Initialize output flags -----*/ 00818 option_data->tshift = 0; 00819 option_data->fout = 0; 00820 option_data->rout = 0; 00821 option_data->tout = 0; 00822 option_data->vout = 0; 00823 option_data->xout = 0; 00824 option_data->nobout = 0; 00825 option_data->nocout = 0; 00826 option_data->full_first = 0; 00827 00828 /*----- Initialize character strings -----*/ 00829 option_data->input_filename = NULL; 00830 option_data->mask_filename = NULL; 00831 option_data->input1D_filename = NULL; 00832 option_data->censor_filename = NULL; 00833 option_data->concat_filename = NULL; 00834 option_data->bucket_filename = NULL; 00835 option_data->fitts_filename = NULL; 00836 option_data->errts_filename = NULL; 00837 00838 option_data->automask = 0 ; /* 15 Apr 2005 */ 00839 } |
|
Definition at line 3278 of file 3dDeconvolve.c. References allocate_memory(), argc, check_for_valid_inputs(), ENTRY, get_options(), identify_software(), malloc, read_input_data(), and remove_zero_stimfns().
03313 { 03314 int iglt; /* general linear test index */ 03315 03316 ENTRY("initialize_program") ; 03317 03318 03319 /*----- Allocate memory -----*/ 03320 *option_data = (DC_options *) malloc (sizeof(DC_options)); 03321 03322 03323 /*----- Get command line inputs -----*/ 03324 get_options (argc, argv, *option_data); 03325 03326 03327 /*----- Identify software -----*/ 03328 if (!(*option_data)->quiet) identify_software(); 03329 03330 if( xrestore ) EXRETURN ; /* 26 Jul 2004 - special operations to do! */ 03331 03332 /*----- Tell the user if he is being foolish -----*/ 03333 if( !(*option_data)->quiet && 03334 !legendre_polort && 03335 (*option_data)->polort > 1 ){ /* 20 Jul 2004 */ 03336 fprintf(stderr,"** WARNING: you have polynomials of order %d for the baseline\n" 03337 "** but disabled use of the Legendre polynomials!\n" 03338 "** Check the matrix condition and accuracy of results!\n" , 03339 (*option_data)->polort ) ; 03340 (*option_data)->nocond = 0 ; 03341 } 03342 03343 /*----- Read input data -----*/ 03344 read_input_data (*option_data, dset_time, mask_vol, fmri_data, fmri_length, 03345 censor_array, censor_length, block_list, num_blocks, 03346 stimulus, stim_length, glt_cmat); 03347 03348 03349 /*----- Remove all-zero stimulus functions -----*/ 03350 if( !use_psinv ) 03351 remove_zero_stimfns (*option_data, *stimulus, *stim_length, *glt_cmat); 03352 03353 03354 /*----- Check for valid inputs -----*/ 03355 check_for_valid_inputs (*option_data, *dset_time, 03356 *fmri_length, *censor_array, *censor_length, 03357 *block_list, *num_blocks, *stim_length, *stimulus, good_list); 03358 03359 03360 /*----- Allocate memory for output volumes -----*/ 03361 if (!(*option_data)->nodata) 03362 allocate_memory (*option_data, coef_vol, scoef_vol, tcoef_vol, 03363 fpart_vol, rpart_vol, mse_vol, ffull_vol, rfull_vol, 03364 glt_coef_vol, glt_tcoef_vol, glt_fstat_vol, glt_rstat_vol, 03365 fitts_vol, errts_vol); 03366 03367 EXRETURN ; 03368 } |
|
Definition at line 848 of file 3dDeconvolve.c. References ENTRY, malloc, MTEST, and THD_MAX_NAME. Referenced by get_options().
00853 { 00854 int is; /* input stimulus time series index */ 00855 00856 ENTRY("initialize_stim_options") ; 00857 00858 /*----- Set number of input stimulus time series -----*/ 00859 if (num_stimts <= 0) EXRETURN ; 00860 else option_data->num_stimts = num_stimts; 00861 00862 00863 /*----- Allocate memory for stimulus options -----*/ 00864 option_data->stim_filename = (char **) malloc (sizeof(char *) * num_stimts); 00865 MTEST (option_data->stim_filename); 00866 option_data->stim_label = (char **) malloc (sizeof(char *) * num_stimts); 00867 MTEST (option_data->stim_label); 00868 option_data->stim_base = (int *) malloc (sizeof(int) * num_stimts); 00869 MTEST (option_data->stim_base); 00870 option_data->stim_minlag = (int *) malloc (sizeof(int) * num_stimts); 00871 MTEST (option_data->stim_minlag); 00872 option_data->stim_maxlag = (int *) malloc (sizeof(int) * num_stimts); 00873 MTEST (option_data->stim_maxlag); 00874 option_data->stim_nptr = (int *) malloc (sizeof(int) * num_stimts); 00875 MTEST (option_data->stim_nptr); 00876 option_data->iresp_filename = (char **) malloc (sizeof(char *) * num_stimts); 00877 MTEST (option_data->iresp_filename); 00878 option_data->sresp_filename = (char **) malloc (sizeof(char *) * num_stimts); 00879 MTEST (option_data->sresp_filename); 00880 00881 /* 10 Aug 2004: add space for basis function expansions */ 00882 00883 basis_stim = (basis_expansion **)malloc(sizeof(basis_expansion *)*num_stimts); 00884 basis_times = (MRI_IMAGE **) malloc(sizeof(MRI_IMAGE *) *num_stimts); 00885 basis_vect = (MRI_IMAGE **) malloc(sizeof(MRI_IMAGE *) *num_stimts); 00886 00887 /*----- Initialize stimulus options -----*/ 00888 for (is = 0; is < num_stimts; is++) 00889 { 00890 option_data->stim_filename[is] = NULL; 00891 option_data->stim_label[is] = malloc (sizeof(char)*THD_MAX_NAME); 00892 MTEST (option_data->stim_label[is]); 00893 sprintf (option_data->stim_label[is], "Stim#%d", is+1); 00894 00895 option_data->stim_base[is] = 0; 00896 option_data->stim_minlag[is] = 0; 00897 option_data->stim_maxlag[is] = 0; 00898 option_data->stim_nptr[is] = 1; 00899 00900 option_data->iresp_filename[is] = NULL; 00901 option_data->sresp_filename[is] = NULL; 00902 00903 basis_stim [is] = NULL ; /* 10 Aug 2004 */ 00904 basis_times[is] = NULL ; 00905 basis_vect [is] = NULL ; 00906 } 00907 00908 EXRETURN ; 00909 } |
|
Encode an integer list into a NIML element. NI_free_element() this when done with it. ename is the name of the NIML element to create. ------------------------------------------------------------------- Definition at line 5985 of file 3dDeconvolve.c. References NI_add_column(), NI_INT, NI_new_data_element(), and vec. Referenced by XSAVE_output().
05986 { 05987 NI_element *nel ; 05988 05989 if( nvec < 1 || vec == NULL ) return NULL ; /* bad user, bad */ 05990 05991 if( ename == NULL || *ename == '\0' ) ename = "intvec" ; 05992 05993 nel = NI_new_data_element( ename , nvec ) ; 05994 NI_add_column( nel , NI_INT , vec ) ; 05995 return nel ; 05996 } |
|
Definition at line 5843 of file 3dDeconvolve.c. References free, malloc, mri_free(), MRI_RGB_PTR, MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, pclose, PLOT_matrix_gray(), popen, and THD_find_executable(). Referenced by calculate_results().
05844 { 05845 char *pg , *jpfilt ; 05846 MRI_IMAGE *im ; 05847 FILE *fp ; 05848 05849 if( fname == NULL || *fname == '\0' ) return ; 05850 05851 pg = THD_find_executable( "cjpeg" ) ; 05852 if( pg == NULL ){ 05853 fprintf(stderr, 05854 "** WARNING: can't save %s because program 'cjpeg' not in path!\n", 05855 fname) ; 05856 return ; 05857 } 05858 05859 im = PLOT_matrix_gray( X ) ; 05860 if( im == NULL ){ 05861 fprintf(stderr, 05862 "** WARNING: can't save %s because of internal error!\n",fname) ; 05863 return ; 05864 } 05865 05866 jpfilt = (char *)malloc( sizeof(char)*(strlen(pg)+strlen(fname)+32) ) ; 05867 sprintf( jpfilt , "%s -quality 95 > %s" , pg , fname ) ; 05868 #ifndef CYGWIN 05869 signal( SIGPIPE , SIG_IGN ) ; errno = 0 ; 05870 #endif 05871 fp = popen( jpfilt , "w" ) ; 05872 if( fp == NULL ){ 05873 mri_free(im) ; free((void *)jpfilt) ; 05874 fprintf(stderr,"** WARNING: can't save %s because cjpeg filter fails!\n",fname) ; 05875 return ; 05876 } 05877 fprintf(fp,"P6\n%d %d\n255\n" , im->nx,im->ny ) ; 05878 fwrite( MRI_RGB_PTR(im), sizeof(byte), 3*im->nvox, fp ) ; 05879 (void) pclose(fp) ; 05880 if( verb ) fprintf(stderr,"++ Wrote matrix image to file %s\n",fname) ; 05881 05882 mri_free(im) ; free((void *)jpfilt) ; return ; 05883 } |
|
Definition at line 5568 of file 3dDeconvolve.c. References argc, calculate_results(), COX_clock_time(), do_xrestore_stuff(), enable_mcw_malloc(), fd, free, get_matrix_dotlen(), get_matrix_flops(), initialize_program(), mainENTRY, DC_options::nodata, output_results(), proc_numjob, proc_use_jobs, terminate_program(), THD_delete_3dim_dataset(), and verb.
05573 { 05574 DC_options * option_data; /* deconvolution algorithm options */ 05575 THD_3dim_dataset * dset_time = NULL; /* input 3d+time data set */ 05576 byte * mask_vol = NULL; /* mask volume */ 05577 float * fmri_data = NULL; /* input fMRI time series data */ 05578 int fmri_length; /* length of fMRI time series */ 05579 float * censor_array = NULL; /* input censor time series array */ 05580 int censor_length; /* length of censor time series */ 05581 int * good_list = NULL; /* list of usable time points */ 05582 int * block_list = NULL; /* list of block starting points */ 05583 int num_blocks; /* number of blocks (runs) */ 05584 float ** stimulus = NULL; /* stimulus time series arrays */ 05585 int * stim_length = NULL; /* length of stimulus time series */ 05586 matrix * glt_cmat = NULL; /* general linear test matrices */ 05587 05588 float ** coef_vol = NULL; /* array of volumes for model parameters */ 05589 float ** scoef_vol = NULL; /* array of volumes for parameter std. devs. */ 05590 float ** tcoef_vol = NULL; /* array of volumes for parameter t-statistics */ 05591 float ** fpart_vol = NULL; /* array of volumes of partial F-statistics */ 05592 float ** rpart_vol = NULL; /* array of volumes of partial R^2 stats. */ 05593 05594 float * mse_vol = NULL; /* volume of full model mean square error */ 05595 float * ffull_vol = NULL; /* volume of full model F-statistics */ 05596 float * rfull_vol = NULL; /* volume of full model R^2 stats. */ 05597 05598 float *** glt_coef_vol = NULL; /* volumes for GLT linear combinations */ 05599 float *** glt_tcoef_vol = NULL; /* volumes for GLT t-statistics */ 05600 float ** glt_fstat_vol = NULL; /* volumes for GLT F-statistics */ 05601 float ** glt_rstat_vol = NULL; /* volumes for GLT R^2 stats. */ 05602 05603 float ** fitts_vol = NULL; /* volumes for full model fit to input data */ 05604 float ** errts_vol = NULL; /* volumes for residual errors */ 05605 05606 05607 #ifdef FLOATIZE 05608 /*----- force the user to acknowledge the riskiness of his behavior -----*/ 05609 if( argc < 2 || strcmp(argv[1],"-OK") != 0 ){ 05610 fprintf(stderr,"**\n" 05611 "** 3dDeconvolve_f is now disabled by default.\n" 05612 "** It is dangerous, due to roundoff problems.\n" 05613 "** Please use 3dDeconvolve from now on!\n" 05614 "**\n" 05615 "** HOWEVER, if you insist on using 3dDeconvolve_f, then:\n" 05616 "** + Use '-OK' as the first command line option.\n" 05617 "** + Check the matrix condition number;\n" 05618 "** if it is greater than 100, BEWARE!\n" 05619 "**\n" 05620 "** RWCox - July 2004\n" 05621 "**\n" 05622 ) ; 05623 exit(0) ; 05624 } 05625 #endif 05626 05627 #ifdef USING_MCW_MALLOC 05628 enable_mcw_malloc() ; 05629 #endif 05630 mainENTRY("3dDeconvolve main") ; 05631 05632 /*----- start the elapsed time counter -----*/ 05633 (void) COX_clock_time() ; 05634 05635 /*----- Program initialization -----*/ 05636 initialize_program (argc, argv, &option_data, &dset_time, &mask_vol, 05637 &fmri_data, &fmri_length, &censor_array, &censor_length, &good_list, 05638 &block_list, &num_blocks, &stimulus, &stim_length, &glt_cmat, 05639 &coef_vol, &scoef_vol, &tcoef_vol, &fpart_vol, &rpart_vol, 05640 &mse_vol, &ffull_vol, &rfull_vol, &glt_coef_vol, &glt_tcoef_vol, 05641 &glt_fstat_vol, &glt_rstat_vol, &fitts_vol, &errts_vol); 05642 05643 if( xrestore ){ /* 26 Jul 2004 - very special operations */ 05644 do_xrestore_stuff( argc,argv , option_data ) ; 05645 exit(0) ; 05646 } 05647 05648 05649 /*----- Perform deconvolution -----*/ 05650 calculate_results (option_data, dset_time, mask_vol, fmri_data, fmri_length, 05651 good_list, block_list, num_blocks, stimulus, stim_length, 05652 glt_cmat, coef_vol, scoef_vol, tcoef_vol, fpart_vol, 05653 rpart_vol, mse_vol, ffull_vol, rfull_vol, glt_coef_vol, glt_tcoef_vol, 05654 glt_fstat_vol, glt_rstat_vol, fitts_vol, errts_vol); 05655 05656 05657 /*----- Deallocate memory for input datasets -----*/ 05658 if (dset_time != NULL) 05659 { THD_delete_3dim_dataset (dset_time, False); dset_time = NULL; } 05660 if (mask_vol != NULL) 05661 { free (mask_vol); mask_vol = NULL; } 05662 05663 05664 /*----- Write requested output files -----*/ 05665 if (!option_data->nodata) 05666 output_results (argc, argv, option_data, coef_vol, scoef_vol, tcoef_vol, 05667 fpart_vol, rpart_vol, mse_vol, ffull_vol, rfull_vol, 05668 glt_coef_vol, glt_tcoef_vol, glt_fstat_vol, glt_rstat_vol, 05669 fitts_vol, errts_vol); 05670 05671 05672 #if 0 05673 /*----- Terminate program -----*/ 05674 terminate_program (&option_data, &stimulus, &glt_cmat, &coef_vol, &scoef_vol, 05675 &tcoef_vol, &fpart_vol, &rpart_vol, & mse_vol, &ffull_vol, 05676 &rfull_vol, &glt_coef_vol, &glt_tcoef_vol, &glt_fstat_vol, 05677 &glt_rstat_vol, &fitts_vol, &errts_vol); 05678 #endif 05679 05680 if( proc_use_jobs == 1 && verb ){ /* output requested - 2003.08.15 [rickr] */ 05681 fprintf(stderr,"++ Program finished; elapsed time=%.3f\n",COX_clock_time()); 05682 } 05683 #ifndef FLOATIZE 05684 if( proc_numjob == 1 && verb ){ /* 16 Jan 2004: print operation count */ 05685 double fv=get_matrix_flops() , fd=get_matrix_dotlen() ; 05686 if( fv > 0.0 && fd > 0.0 ) 05687 fprintf(stderr,"++ #Flops=%g Average Dot Product=%g\n",fv,fd) ; 05688 } 05689 #endif 05690 05691 exit(0); 05692 } |
|
Encode a matrix into a NIML element, which is returned; NI_free_element() this when done with it. ename is the name of the NIML element to create. ------------------------------------------------------------------- Definition at line 5925 of file 3dDeconvolve.c. References a, matrix::cols, matrix::elts, free, malloc, MTYPE, NI_add_column(), NI_DOUBLE, NI_new_data_element(), and matrix::rows. Referenced by XSAVE_output().
05926 { 05927 int m=a.rows , n=a.cols , ii,jj ; 05928 MTYPE **aar = a.elts ; 05929 NI_element *nel ; 05930 double *ecol ; 05931 05932 if( m < 1 || n < 1 || aar == NULL ) return NULL ; /* bad user, bad */ 05933 05934 if( ename == NULL || *ename == '\0' ) ename = "matrix" ; 05935 05936 nel = NI_new_data_element( ename , m ) ; 05937 ecol = (double *) malloc(sizeof(double)*m) ; 05938 05939 for( jj=0 ; jj < n ; jj++ ){ 05940 for( ii=0 ; ii < m ; ii++ ) ecol[ii] = aar[ii][jj] ; 05941 NI_add_column( nel , NI_DOUBLE , ecol ) ; 05942 } 05943 05944 free((void *)ecol) ; 05945 return nel ; 05946 } |
|
Definition at line 6000 of file 3dDeconvolve.c. References malloc, NI_INT, NI_element::vec, vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by XSAVE_input().
06001 { 06002 if( nel == NULL || nvec == NULL || vec == NULL ) return ; 06003 06004 if( nel->vec_len < 1 || nel->vec_num < 1 ) return ; 06005 if( nel->vec_typ[0] != NI_INT ) return ; 06006 06007 *nvec = nel->vec_len ; 06008 *vec = (int *)malloc(*nvec*sizeof(int)) ; 06009 memcpy(*vec,nel->vec[0],*nvec*sizeof(int)) ; 06010 return ; 06011 } |
|
Decode an NIML element into a matrix. --------------------------------------------------------------------- Definition at line 5952 of file 3dDeconvolve.c. References a, matrix::elts, matrix_create(), MTYPE, NI_DOUBLE, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by XSAVE_input().
05953 { 05954 int m , n , ii , jj ; 05955 double *ecol ; 05956 MTYPE **aar ; 05957 char *ename ; 05958 05959 if( nel == NULL || a == NULL ) return ; 05960 05961 m = nel->vec_len ; /* number of rows */ 05962 n = nel->vec_num ; /* number of cols */ 05963 05964 if( m < 1 || n < 1 ) return ; 05965 for( jj=0 ; jj < n ; jj++ ) 05966 if( nel->vec_typ[jj] != NI_DOUBLE ) return ; 05967 05968 matrix_create( m , n , a ) ; 05969 aar = a->elts ; 05970 05971 for( jj=0 ; jj < n ; jj++ ){ 05972 ecol = (double *)nel->vec[jj] ; 05973 for( ii=0 ; ii < m ; ii++ ) aar[ii][jj] = (MTYPE)ecol[ii] ;; 05974 } 05975 05976 return ; 05977 } |
|
Definition at line 6030 of file 3dDeconvolve.c. References calloc, NI_STRING, NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by XSAVE_input().
06031 { 06032 int ii ; 06033 char **sv ; 06034 06035 if( nel == NULL || nstr == NULL || str == NULL ) return ; 06036 06037 if( nel->vec_len < 1 || nel->vec_num < 1 ) return ; 06038 if( nel->vec_typ[0] != NI_STRING ) return ; 06039 sv = (char **) nel->vec[0] ; 06040 06041 *nstr = nel->vec_len ; 06042 *str = (char **)calloc(sizeof(char *),*nstr) ; 06043 for( ii=0 ; ii < *nstr ; ii++ ) (*str)[ii] = strdup(sv[ii]) ; 06044 return ; 06045 } |
|
Definition at line 6080 of file 3dDeconvolve.c. References calloc, name, NI_INT, NI_STRING, NI_strncpy(), NI_element::vec, NI_element::vec_len, NI_element::vec_num, and NI_element::vec_typ. Referenced by XSAVE_input().
06081 { 06082 int ii , *bc,*tc,*gc ; char **sc ; 06083 06084 if( nel == NULL || ns == NULL || sv == NULL ) return ; 06085 06086 if( nel->vec_len < 1 || nel->vec_num < 4 ) return ; 06087 if( nel->vec_typ[0] != NI_INT ) return ; bc = (int *) nel->vec[0] ; 06088 if( nel->vec_typ[1] != NI_INT ) return ; tc = (int *) nel->vec[1] ; 06089 if( nel->vec_typ[2] != NI_INT ) return ; gc = (int *) nel->vec[2] ; 06090 if( nel->vec_typ[3] != NI_STRING ) return ; sc = (char **)nel->vec[3] ; 06091 06092 *ns = nel->vec_len ; 06093 *sv = (SYM_irange *)calloc(sizeof(SYM_irange),*ns) ; 06094 for( ii=0 ; ii < *ns ; ii++ ){ 06095 (*sv)[ii].nbot = bc[ii] ; 06096 (*sv)[ii].ntop = tc[ii] ; 06097 (*sv)[ii].gbot = gc[ii] ; 06098 NI_strncpy( (*sv)[ii].name , sc[ii] , 64 ) ; 06099 } 06100 return ; 06101 } |
|
Definition at line 5220 of file 3dDeconvolve.c. References argc, basis_dtout, basis_write_iresp(), basis_write_sresp(), cubic_spline(), basis_expansion::nfunc, p, q, write_bucket_data(), write_one_ts(), and write_ts_array().
05241 { 05242 int qp; /* number of poly. trend baseline parameters */ 05243 int q; /* number of baseline model parameters */ 05244 int p; /* number of full model parameters */ 05245 int polort; /* degree of polynomial for baseline model */ 05246 int num_stimts; /* number of stimulus time series */ 05247 int * min_lag; /* minimum time delay for impulse response */ 05248 int * max_lag; /* maximum time delay for impulse response */ 05249 int * nptr; /* number of stim fn. time points per TR */ 05250 int ib; /* sub-brick index */ 05251 int is; /* stimulus index */ 05252 int ts_length; /* length of impulse reponse function */ 05253 int nt; /* number of images in input 3d+time dataset */ 05254 int nxyz; /* number of voxels */ 05255 05256 05257 /*----- Initialize local variables -----*/ 05258 polort = option_data->polort; 05259 qp = option_data->qp; 05260 q = option_data->q; 05261 p = option_data->p; 05262 num_stimts = option_data->num_stimts; 05263 min_lag = option_data->stim_minlag; 05264 max_lag = option_data->stim_maxlag; 05265 nptr = option_data->stim_nptr; 05266 nt = option_data->nt; 05267 nxyz = option_data->nxyz; 05268 05269 05270 /*----- Write the bucket dataset -----*/ 05271 if (option_data->bucket_filename != NULL) 05272 if (nxyz > 1) 05273 write_bucket_data (argc, argv, option_data, coef_vol, tcoef_vol, 05274 fpart_vol, rpart_vol, mse_vol, ffull_vol, rfull_vol, 05275 glt_coef_vol, glt_tcoef_vol, glt_fstat_vol, glt_rstat_vol); 05276 else 05277 write_one_ts (option_data->bucket_filename, p, coef_vol); 05278 05279 05280 /*----- Write the impulse response function 3d+time dataset -----*/ 05281 ib = qp; 05282 for (is = 0; is < num_stimts; is++) 05283 { 05284 if( basis_stim[is] != NULL ){ /* until later */ 05285 if( option_data->iresp_filename[is] != NULL ) 05286 #if 0 05287 fprintf(stderr, 05288 "** WARNING: Ignoring -iresp %d '%s'\n", 05289 is+1,option_data->iresp_filename[is]) ; 05290 #else 05291 basis_write_iresp( argc , argv , option_data , 05292 basis_stim[is] , basis_dtout , 05293 coef_vol+ib , 05294 option_data->iresp_filename[is] ) ; 05295 ib += basis_stim[is]->nfunc ; 05296 #endif 05297 continue ; 05298 } 05299 05300 /* old style iresp: each coefficent is a response */ 05301 05302 ts_length = max_lag[is] - min_lag[is] + 1; 05303 if (option_data->iresp_filename[is] != NULL) 05304 { 05305 /*----- If requested, time shift the impulse response -----*/ 05306 if ((option_data->tshift) && (nptr[is] == 1) && (nxyz > 1)) 05307 cubic_spline (option_data, ts_length, coef_vol+ib); 05308 05309 if (nxyz > 1) 05310 write_ts_array (argc, argv, option_data, ts_length, 05311 nptr[is], option_data->tshift, coef_vol+ib, 05312 option_data->iresp_filename[is]); 05313 else 05314 write_one_ts (option_data->iresp_filename[is], 05315 ts_length, coef_vol+ib); 05316 } 05317 ib += ts_length; 05318 } 05319 05320 05321 /*----- Write the standard deviation 3d+time dataset -----*/ 05322 ib = qp; 05323 for (is = 0; is < num_stimts; is++) 05324 { 05325 if( basis_stim[is] != NULL ){ /* until later */ 05326 if( option_data->sresp_filename[is] != NULL ) 05327 #if 0 05328 fprintf(stderr, 05329 "** WARNING: Ignoring -sresp %d '%s'\n", 05330 is+1 , option_data->sresp_filename[is]) ; 05331 #else 05332 basis_write_sresp( argc , argv , option_data , 05333 basis_stim[is] , basis_dtout , 05334 mse_vol , ib , XtXinv , 05335 option_data->sresp_filename[is] ) ; 05336 ib += basis_stim[is]->nfunc ; 05337 #endif 05338 continue ; 05339 } 05340 05341 /* old style iresp: each coef is a response, so coef var is what we want */ 05342 05343 ts_length = max_lag[is] - min_lag[is] + 1; 05344 if (option_data->sresp_filename[is] != NULL) 05345 if (nxyz > 1) 05346 write_ts_array (argc, argv, option_data, ts_length, 05347 nptr[is], 0, scoef_vol+ib, 05348 option_data->sresp_filename[is]); 05349 else 05350 write_one_ts (option_data->sresp_filename[is], 05351 ts_length, scoef_vol+ib); 05352 05353 ib += ts_length; 05354 } 05355 05356 05357 /*----- Write the fitted (full model) 3d+time dataset -----*/ 05358 if (option_data->fitts_filename != NULL) 05359 if (nxyz > 1) 05360 write_ts_array (argc, argv, option_data, nt, 1, 0, fitts_vol, 05361 option_data->fitts_filename); 05362 else 05363 write_one_ts (option_data->fitts_filename, nt, fitts_vol); 05364 05365 05366 05367 /*----- Write the residual errors 3d+time dataset -----*/ 05368 if (option_data->errts_filename != NULL) 05369 if (nxyz > 1) 05370 write_ts_array (argc, argv, option_data, nt, 1, 0, errts_vol, 05371 option_data->errts_filename); 05372 else 05373 write_one_ts (option_data->errts_filename, nt, errts_vol); 05374 05375 } |
|
Definition at line 5802 of file 3dDeconvolve.c. References a, matrix::cols, delete_memplot(), matrix::elts, free, malloc, memplot_to_RGB_sef(), mp, mri_new(), MRI_RGB_PTR, my_getenv(), MRI_IMAGE::nvox, nxim, nyim, PLOT_tsgray(), matrix::rows, and TSGRAY_SEPARATE_YSCALE. Referenced by JPEG_matrix_gray().
05803 { 05804 int nts=X.cols , npt=X.rows , ii,jj , nxim=768 , nyim=1024 ; 05805 MEM_plotdata *mp ; 05806 float **xar ; 05807 MRI_IMAGE *im ; 05808 char *eee ; 05809 05810 if( nts < 1 || npt < 2 ) return NULL ; 05811 05812 xar = (float **)malloc( sizeof(float *)*nts ) ; 05813 for( jj=0 ; jj < nts ; jj++ ){ 05814 xar[jj] = (float *)malloc( sizeof(float *)*npt ) ; 05815 for( ii=0 ; ii < npt ; ii++ ) xar[jj][ii] = X.elts[ii][jj] ; 05816 } 05817 05818 mp = PLOT_tsgray( npt , nts , TSGRAY_SEPARATE_YSCALE , xar ) ; 05819 05820 for( jj=0 ; jj < nts ; jj++ ) free((void *)xar[jj]) ; 05821 free((void *)xar) ; 05822 05823 if( mp == NULL ) return NULL ; 05824 05825 eee = my_getenv( "AFNI_XJPEG_IMXY") ; 05826 if( eee != NULL ){ 05827 int a=-1, b=-1 ; 05828 sscanf( eee , "%dx%d" , &a,&b ) ; 05829 if( a > 99 && b > 99 ){ nxim = a ; nyim = b ; } 05830 if( a < -1 ) nxim = -a*nts ; 05831 if( b < 0 ) nyim = -b*npt ; 05832 } 05833 05834 im = mri_new( nxim , nyim , MRI_rgb ) ; 05835 memset( MRI_RGB_PTR(im) , 255 , 3*im->nvox ) ; /* whiten it */ 05836 memplot_to_RGB_sef( im , mp , 0,0,1 ) ; 05837 delete_memplot( mp ) ; 05838 return im ; 05839 } |
|
Definition at line 5713 of file 3dDeconvolve.c. References create_memplot_surely(), get_active_memplot(), mp, my_getenv(), NOISH, plotline_memplot(), plotrect_memplot(), set_color_memplot(), set_opacity_memplot(), set_thick_memplot(), TSGRAY_FLIP_XY, and TSGRAY_SEPARATE_YSCALE. Referenced by main(), PLOT_matrix_gray(), and startup_timeout_CB().
05714 { 05715 MEM_plotdata *mp ; 05716 float ybot,ytop , yfac , dx,dy , val ; 05717 int ii,jj , flipxy ; 05718 char str[32] ; 05719 int sepscl ; 05720 float boxr=1.0,boxg=0.9,boxb=0.0 ; 05721 char *eee ; 05722 int dobox=1 ; 05723 05724 if( npt < 2 || nts < 1 || y == NULL ) return NULL ; 05725 05726 eee = my_getenv( "AFNI_XJPEG_COLOR" ) ; 05727 if( eee != NULL ){ 05728 float rf=-1.0, gf=-1.0 , bf=-1.0 ; 05729 sscanf( eee , "rgbi:%f/%f/%f" , &rf,&gf,&bf ) ; 05730 if( rf >= 0.0 && rf <= 1.0 && gf >= 0.0 && gf <= 1.0 && bf >= 0.0 && bf <= 1.0 ){ 05731 boxr = rf ; boxg = gf ; boxb = bf ; 05732 } 05733 if( NOISH(eee) ) dobox = 0 ; /* don't do boxes */ 05734 } 05735 05736 /* find range of all the data */ 05737 05738 ybot = ytop = y[0][0] ; 05739 for( jj=0 ; jj < nts ; jj++ ){ 05740 for( ii=0 ; ii < npt ; ii++ ){ 05741 val = y[jj][ii] ; 05742 if( ybot > val ) ybot = val ; 05743 else if( ytop < val ) ytop = val ; 05744 } 05745 } 05746 if( ybot >= ytop ) return NULL ; /* data is all the same? */ 05747 yfac = 1.0/(ytop-ybot) ; 05748 dx = 0.9999/npt ; 05749 dy = 0.9999/nts ; 05750 05751 create_memplot_surely( "Gplot" , 1.0 ) ; 05752 set_color_memplot( 0.0 , 0.0 , 0.0 ) ; 05753 set_thick_memplot( 0.0 ) ; 05754 set_opacity_memplot( 1.0 ) ; 05755 05756 flipxy = (ymask & TSGRAY_FLIP_XY) != 0 ; 05757 sepscl = (ymask & TSGRAY_SEPARATE_YSCALE) != 0 ; 05758 05759 for( jj=0 ; jj < nts ; jj++ ){ 05760 05761 if( sepscl ){ 05762 ybot = ytop = y[jj][0] ; /* find range of data */ 05763 for( ii=1 ; ii < npt ; ii++ ){ 05764 val = y[jj][ii] ; 05765 if( ybot > val ) ybot = val ; 05766 else if( ytop < val ) ytop = val ; 05767 } 05768 if( ybot >= ytop ) yfac = 1.0 ; 05769 else yfac = 1.0/(ytop-ybot) ; 05770 } 05771 05772 for( ii=0 ; ii < npt ; ii++ ){ 05773 val = yfac*(ytop-y[jj][ii]) ; 05774 set_color_memplot( val,val,val ) ; 05775 if( flipxy ) 05776 plotrect_memplot( ii*dx,jj*dy , (ii+1)*dx,(jj+1)*dy ) ; 05777 else 05778 plotrect_memplot( jj*dy,1.0-ii*dx , (jj+1)*dy,1.0-(ii+1)*dy ) ; 05779 } 05780 } 05781 05782 if( dobox ){ 05783 set_color_memplot( boxr, boxg, boxb ) ; /* lines between each column */ 05784 set_opacity_memplot( 0.789 ) ; 05785 for( jj=0 ; jj <= nts ; jj++ ){ 05786 if( flipxy ){ 05787 plotline_memplot( 1.0,jj*dy , 0.0,jj*dy ) ; 05788 } else { 05789 plotline_memplot( jj*dy,1.0 , jj*dy,0.0 ) ; 05790 } 05791 } 05792 } 05793 05794 set_opacity_memplot( 1.0 ) ; 05795 set_color_memplot( 0.0 , 0.0 , 0.0 ) ; 05796 mp = get_active_memplot() ; 05797 return mp ; 05798 } |
|
Definition at line 2925 of file 3dDeconvolve.c. References proc_shmid. Referenced by proc_finalize_shm_volumes().
02926 { 02927 if( proc_shmid > 0 ) 02928 shmctl( proc_shmid , IPC_RMID , NULL ) ; 02929 } |
|
Definition at line 2935 of file 3dDeconvolve.c. References atexit(), pclose, popen, proc_atexit(), proc_shm_ar, proc_shm_arnum, proc_shm_arsiz, proc_shmid, proc_shmptr, proc_shmsize, proc_sigfunc(), shm_attach(), shm_create(), SIGHUP, and UNIQ_idcode_fill(). Referenced by allocate_memory(), and initialize_program().
02936 { 02937 char kstr[32] ; int ii ; 02938 02939 if( proc_shm_arnum == 0 ) return ; /* should never happen */ 02940 02941 proc_shmsize = 0 ; /* add up sizes of */ 02942 for( ii=0 ; ii < proc_shm_arnum ; ii++ ) /* all arrays for */ 02943 proc_shmsize += proc_shm_arsiz[ii] ; /* shared memory */ 02944 02945 proc_shmsize *= sizeof(float) ; /* convert to byte count */ 02946 02947 /* create shared memory segment */ 02948 02949 UNIQ_idcode_fill( kstr ) ; /* unique string "key" */ 02950 proc_shmid = shm_create( kstr , proc_shmsize ) ; /* thd_iochan.c */ 02951 if( proc_shmid < 0 ){ 02952 fprintf(stderr,"\n** Can't create shared memory of size %d!\n" 02953 "** Try re-running without -jobs option!\n" , 02954 proc_shmsize ) ; 02955 02956 /** if failed, print out some advice on how to tune SHMMAX **/ 02957 02958 { char *cmd=NULL ; 02959 #if defined(LINUX) 02960 cmd = "cat /proc/sys/kernel/shmmax" ; 02961 #elif defined(SOLARIS) 02962 cmd = "/usr/sbin/sysdef | grep SHMMAX" ; 02963 #elif defined(DARWIN) 02964 cmd = "sysctl -n kern.sysv.shmmax" ; 02965 #endif 02966 if( cmd != NULL ){ 02967 FILE *fp = popen( cmd , "r" ) ; 02968 if( fp != NULL ){ 02969 unsigned int smax=0 ; 02970 fscanf(fp,"%u",&smax) ; pclose(fp) ; 02971 if( smax > 0 ) 02972 fprintf(stderr , 02973 "\n" 02974 "** POSSIBLY USEFUL ADVICE:\n" 02975 "** Current max shared memory size = %u bytes.\n" 02976 "** For information on how to change this, see\n" 02977 "** http://afni.nimh.nih.gov/afni/doc/misc/parallize.html \n" 02978 "** and also contact your system administrator.\n" 02979 , smax ) ; 02980 } 02981 } 02982 } 02983 exit(1) ; 02984 } 02985 02986 /* set a signal handler to catch most fatal errors and 02987 delete the shared memory segment if program crashes */ 02988 02989 signal(SIGPIPE,proc_sigfunc) ; signal(SIGSEGV,proc_sigfunc) ; 02990 signal(SIGINT ,proc_sigfunc) ; signal(SIGFPE ,proc_sigfunc) ; 02991 signal(SIGBUS ,proc_sigfunc) ; signal(SIGHUP ,proc_sigfunc) ; 02992 signal(SIGTERM,proc_sigfunc) ; signal(SIGILL ,proc_sigfunc) ; 02993 signal(SIGKILL,proc_sigfunc) ; signal(SIGPIPE,proc_sigfunc) ; 02994 atexit(proc_atexit) ; /* or when the program exits */ 02995 02996 fprintf(stderr , "++ Shared memory: %d bytes at id=%d\n" , 02997 proc_shmsize , proc_shmid ) ; 02998 02999 /* get pointer to shared memory segment we just created */ 03000 03001 proc_shmptr = shm_attach( proc_shmid ) ; /* thd_iochan.c */ 03002 if( proc_shmptr == NULL ){ 03003 fprintf(stderr,"\n** Can't attach to shared memory!?\n" 03004 "** This is bizarre.\n" ) ; 03005 shmctl( proc_shmid , IPC_RMID , NULL ) ; 03006 exit(1) ; 03007 } 03008 03009 /* clear all shared memory */ 03010 03011 memset( proc_shmptr , 0 , proc_shmsize ) ; 03012 03013 /* fix the local pointers to arrays in shared memory */ 03014 03015 *proc_shm_ar[0] = (float *) proc_shmptr ; 03016 for( ii=1 ; ii < proc_shm_arnum ; ii++ ) 03017 *proc_shm_ar[ii] = *proc_shm_ar[ii-1] + proc_shm_arsiz[ii] ; 03018 } |
|
if failed, print out some advice on how to tune SHMMAX * Definition at line 3024 of file 3dDeconvolve.c. References free, proc_shm_ar, proc_shm_arnum, and proc_shmid.
03025 { 03026 int ii ; 03027 03028 if( ptr == NULL ) return ; 03029 if( proc_shmid == 0 ){ free(ptr); return; } /* no shm */ 03030 for( ii=0 ; ii < proc_shm_arnum ; ii++ ) 03031 if( ((float *)ptr) == *proc_shm_ar[ii] ) return; 03032 free(ptr); return; 03033 } |
|
Definition at line 2900 of file 3dDeconvolve.c. References proc_ind, proc_shmid, and SIGHUP. Referenced by proc_finalize_shm_volumes().
02901 { 02902 char * sname ; int ii ; 02903 static volatile int fff=0 ; 02904 if( fff ) _exit(1); else fff=1 ; 02905 switch(sig){ 02906 default: sname = "unknown" ; break ; 02907 case SIGHUP: sname = "SIGHUP" ; break ; 02908 case SIGTERM: sname = "SIGTERM" ; break ; 02909 case SIGILL: sname = "SIGILL" ; break ; 02910 case SIGKILL: sname = "SIGKILL" ; break ; 02911 case SIGPIPE: sname = "SIGPIPE" ; break ; 02912 case SIGSEGV: sname = "SIGSEGV" ; break ; 02913 case SIGBUS: sname = "SIGBUS" ; break ; 02914 case SIGINT: sname = "SIGINT" ; break ; 02915 case SIGFPE: sname = "SIGFPE" ; break ; 02916 } 02917 if( proc_shmid > 0 ){ 02918 shmctl( proc_shmid , IPC_RMID , NULL ) ; proc_shmid = 0 ; 02919 } 02920 fprintf(stderr,"Fatal Signal %d (%s) received in job #%d\n", 02921 sig,sname,proc_ind) ; 02922 exit(1) ; 02923 } |
|
Definition at line 6818 of file 3dDeconvolve.c. References AFNI_noenv(), floatvec::ar, array_to_matrix(), matrix::elts, ENTRY, far, free, floatvecvec::fvar, GLT_ERR, matrix_file_read(), matrix_print(), ncol, nr, nSymStim, floatvecvec::nvec, realloc, and SYM_expand_ranges(). Referenced by do_xrestore_stuff(), and read_input_data().
06819 { 06820 int ii,jj ; 06821 06822 ENTRY("read_glt_matrix") ; 06823 06824 if( *nrows > 0 ){ /* standard read of numbers from a file*/ 06825 06826 matrix_file_read( fname , *nrows , ncol , cmat , 1 ) ; /* mri_read_1D */ 06827 if( cmat->elts == NULL ) GLT_ERR ; 06828 06829 } else { /* symbolic read of stim_labels */ 06830 floatvecvec *fvv ; 06831 float **far=NULL ; 06832 int nr=0 , iv ; 06833 06834 if( nSymStim < 1 ){ 06835 fprintf(stderr,"** ERROR: use of -gltsym without SymStim being defined\n"); 06836 exit(1) ; 06837 } 06838 06839 if( strncmp(fname,"SYM:",4) == 0 ){ /* read directly from fname string */ 06840 char *fdup=strdup(fname+4) , *fpt , *buf ; 06841 int ss , ns ; 06842 06843 buf = fdup ; 06844 while(1){ 06845 fpt = strchr(buf,'\\') ; /* end of 'line' */ 06846 if( fpt != NULL ) *fpt = '\0' ; 06847 fvv = SYM_expand_ranges( ncol-1 , nSymStim,SymStim , buf ) ; 06848 if( fvv == NULL || fvv->nvec < 1 ) continue ; 06849 far = (float **)realloc((void *)far , sizeof(float *)*(nr+fvv->nvec)) ; 06850 for( iv=0 ; iv < fvv->nvec ; iv++ ) far[nr++] = fvv->fvar[iv].ar ; 06851 free((void *)fvv->fvar) ; free((void *)fvv) ; 06852 if( fpt == NULL ) break ; /* reached end of string? */ 06853 buf = fpt+1 ; /* no, so loop back for next 'line' */ 06854 } 06855 free((void *)fdup) ; 06856 06857 } else { /* read from file */ 06858 char buf[8192] , *cpt ; 06859 FILE *fp = fopen( fname , "r" ) ; 06860 if( fp == NULL ) GLT_ERR ; 06861 while(1){ 06862 cpt = fgets( buf , 8192 , fp ) ; /* read next line */ 06863 if( cpt == NULL ) break ; /* end of input? */ 06864 fvv = SYM_expand_ranges( ncol-1 , nSymStim,SymStim , buf ) ; 06865 if( fvv == NULL || fvv->nvec < 1 ) continue ; 06866 far = (float **)realloc((void *)far , sizeof(float *)*(nr+fvv->nvec)) ; 06867 for( iv=0 ; iv < fvv->nvec ; iv++ ) far[nr++] = fvv->fvar[iv].ar ; 06868 free((void *)fvv->fvar) ; free((void *)fvv) ; 06869 } 06870 fclose(fp) ; 06871 } 06872 if( nr == 0 ) GLT_ERR ; 06873 *nrows = nr ; 06874 array_to_matrix( nr , ncol , far , cmat ) ; 06875 06876 for( ii=0 ; ii < nr ; ii++ ) free((void *)far[ii]) ; 06877 free((void *)far) ; 06878 06879 if( !AFNI_noenv("AFNI_GLTSYM_PRINT") ){ 06880 printf("GLT matrix from '%s':\n",fname) ; 06881 matrix_print( *cmat ) ; 06882 } 06883 } 06884 06885 /** check for all zero rows, which will cause trouble later **/ 06886 06887 for( ii=0 ; ii < *nrows ; ii++ ){ 06888 for( jj=0 ; jj < ncol && cmat->elts[ii][jj] == 0.0 ; jj++ ) ; /* nada */ 06889 if( jj == ncol ) 06890 fprintf(stderr,"** ERROR: row #%d of matrix '%s' is all zero!\n", 06891 ii+1 , fname ) ; 06892 } 06893 06894 EXRETURN ; 06895 } |
|
Definition at line 1914 of file 3dDeconvolve.c. References AFNI_yesenv(), basis_count, basis_dtout, basis_funceval, basis_TR, basis_expansion::bfunc, calloc, DC_error(), DSET_delete, DSET_IS_TCAT, DSET_LOADED, DSET_NUM_TIMES, DSET_NVALS, DSET_NVOX, DSET_NX, DSET_NY, DSET_NZ, DSET_TIMEUNITS, DSET_TR, ENTRY, free, SYM_irange::gbot, ISVALID_3DIM_DATASET, malloc, matrix_file_read(), matrix_initialize(), mc, MCW_strncpy, mri_automask_image(), mri_fix_data_pointer(), MRI_FLOAT_PTR, mri_free(), mri_new(), mri_new_vol_empty(), MTEST, name, SYM_irange::nbot, basis_expansion::nfunc, nSymStim, SYM_irange::ntop, MRI_IMAGE::nx, MRI_IMAGE::ny, p, basis_expansion::pbot, q, read_glt_matrix(), read_time_series(), realloc, basis_expansion::tbot, THD_countmask(), THD_load_datablock(), THD_makemask(), THD_MAX_NAME, THD_open_dataset(), THD_rms_brick(), tt, basis_expansion::ttop, UNITS_MSEC_TYPE, and voxel_num.
01929 { 01930 char message[THD_MAX_NAME]; /* error message */ 01931 int it; /* time point index */ 01932 int nt; /* number of input data time points */ 01933 int nxyz; /* number of voxels */ 01934 int num_stimts; /* number of stimulus time series arrays */ 01935 int * baseline; /* flag for baseline stimulus function */ 01936 int * min_lag; /* minimum time delay for impulse response */ 01937 int * max_lag; /* maximum time delay for impulse response */ 01938 int qp; /* number of polynomial trend baseline parameters */ 01939 int q; /* number of baseline model parameters */ 01940 int p; /* number of full model parameters */ 01941 int is; /* stimulus time series index */ 01942 int num_glt; /* number of general linear tests */ 01943 int iglt; /* general linear test index */ 01944 01945 01946 ENTRY("read_input_data") ; 01947 01948 /*----- Initialize local variables -----*/ 01949 num_stimts = option_data->num_stimts; 01950 num_glt = option_data->num_glt; 01951 baseline = option_data->stim_base; 01952 min_lag = option_data->stim_minlag; 01953 max_lag = option_data->stim_maxlag; 01954 01955 01956 /*----- Read the input stimulus time series -----*/ 01957 if (num_stimts > 0) 01958 { 01959 int nerr=0 ; 01960 01961 *stimulus = (float **) calloc (sizeof(float *) , num_stimts); 01962 MTEST (*stimulus); 01963 *stim_length = (int *) calloc (sizeof(int) , num_stimts); 01964 MTEST (*stim_length); 01965 01966 /** 14 Jul 2004: check for duplicate filename - RWCox **/ 01967 01968 { int js ; 01969 for( is=0 ; is < num_stimts ; is++ ){ 01970 for( js=is+1 ; js < num_stimts ; js++ ){ 01971 if( strcmp( option_data->stim_filename[is] , 01972 option_data->stim_filename[js] ) == 0 ) 01973 fprintf(stderr,"** WARNING: stimulus filename " 01974 "#%d:'%s' same as #%d:'%s'\n" , 01975 is+1,option_data->stim_filename[is] , 01976 js+1,option_data->stim_filename[js] ) ; nerr++ ; 01977 } 01978 } 01979 } 01980 01981 if( nerr > 0 && AFNI_yesenv("AFNI_3dDeconvolve_nodup") ){ 01982 fprintf(stderr,"** ERROR: can't continue after above warnings!\n"); 01983 exit(1) ; 01984 } 01985 01986 for (is = 0; is < num_stimts; is++) 01987 { 01988 if( basis_stim[is] != NULL ) continue ; /* 11 Aug 2004: skip thisn */ 01989 01990 (*stimulus)[is] = read_time_series (option_data->stim_filename[is], 01991 &((*stim_length)[is])); 01992 01993 if ((*stimulus)[is] == NULL) 01994 { 01995 sprintf (message, "Unable to read stimulus time series: %s", 01996 option_data->stim_filename[is]); 01997 DC_error (message); 01998 } 01999 02000 } 02001 } 02002 02003 02004 *num_blocks = 0 ; /* 04 Aug 2004 */ 02005 02006 /*----- Read the input fMRI measurement data -----*/ 02007 if (option_data->nodata) 02008 { 02009 /*----- No input data -----*/ 02010 if (num_stimts <= 0) 02011 DC_error ("Must have num_stimts > 0 for -nodata option"); 02012 02013 if( basis_count > 0 ){ 02014 if( option_data->nodata_TR > 0.0 ) basis_TR = option_data->nodata_TR ; 02015 else if( basis_dtout > 0.0 ) basis_TR = basis_dtout ; 02016 fprintf(stderr, 02017 "** NOTICE: using TR=%.3f for -stim_times and -nodata\n",basis_TR); 02018 } 02019 02020 *dset_time = NULL; 02021 if( option_data->nodata_NT > 0 ) /* special case */ 02022 nt = option_data->nodata_NT ; 02023 else 02024 nt = (*stim_length)[0] / option_data->stim_nptr[0]; 02025 02026 nxyz = 0; 02027 } 02028 02029 else if (option_data->input1D_filename != NULL) 02030 { 02031 /*----- Read the input fMRI 1D time series -----*/ 02032 *fmri_data = read_time_series (option_data->input1D_filename, 02033 fmri_length); 02034 if (*fmri_data == NULL) 02035 { 02036 sprintf (message, "Unable to read time series file: %s", 02037 option_data->input1D_filename); 02038 DC_error (message); 02039 } 02040 *dset_time = NULL; 02041 nt = *fmri_length; 02042 nxyz = 1; 02043 } 02044 02045 else if (option_data->input_filename != NULL) 02046 { 02047 /*----- Read the input 3d+time dataset -----*/ 02048 *dset_time = THD_open_dataset (option_data->input_filename); 02049 if (!ISVALID_3DIM_DATASET(*dset_time)) 02050 { 02051 sprintf (message, "Unable to open dataset '%s'", 02052 option_data->input_filename); 02053 DC_error (message); 02054 } 02055 THD_load_datablock ((*dset_time)->dblk); 02056 if( !DSET_LOADED(*dset_time) ){ 02057 sprintf (message, "Unable to load dataset '%s'", 02058 option_data->input_filename); 02059 DC_error (message); 02060 } 02061 if( (*dset_time)->taxis == NULL ){ 02062 fprintf(stderr,"** WARNING: dataset '%s' has no time axis!!\n", 02063 option_data->input_filename) ; 02064 } 02065 nt = DSET_NUM_TIMES (*dset_time); 02066 nxyz = DSET_NVOX (*dset_time); 02067 02068 basis_TR = DSET_TR(*dset_time) ; /* 11 Aug 2004 */ 02069 if( basis_TR <= 0.0f ) basis_TR = 1.0f ; 02070 if( DSET_TIMEUNITS(*dset_time) == UNITS_MSEC_TYPE ) basis_TR *= 0.001 ; 02071 02072 if( DSET_IS_TCAT(*dset_time) ){ /** 04 Aug 2004: manufacture block list **/ 02073 if( option_data->concat_filename != NULL ){ 02074 fprintf(stderr, 02075 "** WARNING: '-concat %s' ignored: input dataset is auto-catenated\n" , 02076 option_data->concat_filename ) ; 02077 option_data->concat_filename = NULL ; 02078 } 02079 *num_blocks = (*dset_time)->tcat_num ; 02080 *block_list = (int *) malloc (sizeof(int) * (*num_blocks)); 02081 (*block_list)[0] = 0; 02082 for( it=0 ; it < (*num_blocks)-1 ; it++ ) 02083 (*block_list)[it+1] = (*block_list)[it] + (*dset_time)->tcat_len[it] ; 02084 if( verb ){ 02085 fprintf(stderr,"++ Auto-catenated datasets start at:") ; 02086 for( it=0 ; it < (*num_blocks) ; it++ ) 02087 fprintf(stderr," %d",(*block_list)[it]) ; 02088 fprintf(stderr,"\n") ; 02089 } 02090 } 02091 02092 if( option_data->automask ){ /* 15 Apr 2005: automasking */ 02093 MRI_IMAGE *qim ; int mc ; 02094 qim = THD_rms_brick( *dset_time ) ; 02095 *mask_vol = mri_automask_image( qim ) ; 02096 mri_free( qim ) ; 02097 if( *mask_vol == NULL ){ 02098 fprintf(stderr,"** WARNING: unable to generate automask?!\n") ; 02099 } else { 02100 mc = THD_countmask( DSET_NVOX(*dset_time) , *mask_vol ) ; 02101 if( mc <= 1 ){ 02102 fprintf(stderr,"** WARNING: automask is empty!?\n") ; 02103 free(*mask_vol) ; *mask_vol = NULL ; 02104 } else { 02105 fprintf(stderr,"++ %d voxels in automask (out of %d)\n", 02106 mc,DSET_NVOX(*dset_time)) ; 02107 } 02108 } 02109 } 02110 02111 if (option_data->mask_filename != NULL) /* read mask from file */ 02112 { 02113 THD_3dim_dataset * mask_dset = NULL; 02114 02115 /*----- Read the input mask dataset -----*/ 02116 mask_dset = THD_open_dataset (option_data->mask_filename); 02117 if (!ISVALID_3DIM_DATASET(mask_dset)) 02118 { 02119 sprintf (message, "Unable to open mask file: %s", 02120 option_data->mask_filename); 02121 DC_error (message); 02122 } 02123 02124 /*----- If mask is used, check for compatible dimensions -----*/ 02125 if ( (DSET_NX(*dset_time) != DSET_NX(mask_dset)) 02126 || (DSET_NY(*dset_time) != DSET_NY(mask_dset)) 02127 || (DSET_NZ(*dset_time) != DSET_NZ(mask_dset)) ) 02128 { 02129 sprintf (message, "datasets '%s' and '%s' have incompatible dimensions", 02130 option_data->input_filename, option_data->mask_filename); 02131 DC_error (message); 02132 } 02133 02134 if (DSET_NVALS(mask_dset) != 1 ) 02135 DC_error ("Must specify exactly 1 sub-brick from mask dataset"); 02136 02137 *mask_vol = THD_makemask( mask_dset , 0 , 1.0,0.0 ) ; 02138 if (*mask_vol == NULL) DC_error ("Unable to read mask dataset"); 02139 02140 DSET_delete(mask_dset) ; 02141 } 02142 02143 } else { /* no input data? */ 02144 DC_error ("Must specify input data"); 02145 } 02146 02147 02148 /*----- Check number of data points -----*/ 02149 if (nt <= 0) DC_error ("No time points?"); 02150 option_data->nt = nt; 02151 if (nxyz < 0) DC_error ("Program initialization error: nxyz < 0"); 02152 option_data->nxyz = nxyz; 02153 02154 voxel_num = nxyz ; /* 31 Aug 2004 */ 02155 02156 02157 /*----- Read the block list -----*/ 02158 if (option_data->concat_filename == NULL) 02159 { 02160 if( *num_blocks <= 0 ){ /* make one big block, if not already set */ 02161 *num_blocks = 1; 02162 *block_list = (int *) malloc (sizeof(int) * 1); 02163 (*block_list)[0] = 0; 02164 } 02165 } 02166 else 02167 { 02168 float * f = NULL; 02169 02170 f = read_time_series (option_data->concat_filename, num_blocks); 02171 if (*num_blocks < 1) 02172 { 02173 sprintf (message, "Problem reading concat file: %s ", 02174 option_data->concat_filename); 02175 DC_error (message); 02176 } 02177 else 02178 { 02179 *block_list = (int *) malloc (sizeof(int) * (*num_blocks)); 02180 for (it = 0; it < *num_blocks; it++) 02181 (*block_list)[it] = floor (f[it]+0.5); 02182 } 02183 } 02184 02185 /*-- Create timing for each -stim_times input [11 Aug 2004] --*/ 02186 02187 if( basis_count > 0 ){ /* if there are any, that is */ 02188 MRI_IMAGE *tim , *qim ; 02189 float *tar , *qar , toff , tmax,tt,ss ; 02190 int ii,jj , kk , ngood , nx,ny , nf,dd ; 02191 int nbl=*num_blocks , *bst=*block_list ; 02192 basis_expansion *be ; 02193 02194 if( basis_TR <= 0.0f ) basis_TR = 1.0f ; 02195 if( basis_dtout <= 0.0f ) basis_dtout = basis_TR ; 02196 02197 for( is=0 ; is < num_stimts ; is++ ){ 02198 be = basis_stim[is] ; 02199 if( be == NULL ) continue ; /* old style -stim_file */ 02200 02201 /* convert entries to global time indexes */ 02202 02203 tim = basis_times[is] ; nx = tim->nx ; ny = tim->ny ; 02204 ngood = 0 ; tar = MRI_FLOAT_PTR(tim) ; 02205 qar = (float *)calloc(sizeof(float),nx*ny) ; 02206 02207 if( nx == 1 ){ /* 1 column = global times */ 02208 tmax = (nt-1)*basis_TR ; /* max allowed time offset */ 02209 for( ii=0 ; ii < nx*ny ; ii++ ){ 02210 tt = tar[ii] ; 02211 if( tt >= 0.0f && tt <= tmax ) qar[ngood++] = tt/basis_TR ; 02212 } 02213 } else { /* multicol => 1 row per block */ 02214 if( ny != nbl ){ /* times are relative to block */ 02215 fprintf(stderr, 02216 "** WARNING: '-stim_times %d' file '%s' has %d rows," 02217 " but data has %d time blocks\n" , 02218 is+1 , option_data->stim_filename[is] , ny,nbl ) ; 02219 if( ny > nbl ) ny = nbl ; 02220 } 02221 for( jj=0 ; jj < ny ; jj++ ){ /* jj=row index=block index */ 02222 if( jj < nbl-1 ) tmax = (bst[jj+1]-1-bst[jj])*basis_TR ; 02223 else tmax = (nt -1-bst[jj])*basis_TR ; 02224 for( ii=0 ; ii < nx ; ii++ ){ 02225 tt = tar[ii+jj*nx] ; 02226 if( tt >= 0.0f && tt <= tmax ) qar[ngood++] = tt/basis_TR+bst[jj] ; 02227 } 02228 } 02229 } 02230 02231 if( ngood == 0 ){ 02232 fprintf(stderr, 02233 "** WARNING: '-stim_times %d' file '%s' has no good entries\n", 02234 is+1 , option_data->stim_filename[is] ) ; 02235 free((void *)qar) ; qim = NULL ; 02236 } else { 02237 qim = mri_new_vol_empty(ngood,1,1,MRI_float) ; 02238 qar = (float *)realloc((void *)qar,sizeof(float)*ngood) ; 02239 mri_fix_data_pointer( qar , qim ) ; 02240 } 02241 02242 mri_free(tim) ; basis_times[is] = qim ; 02243 02244 /* create basis vectors for this model now */ 02245 02246 nf = basis_stim[is]->nfunc ; 02247 basis_vect[is] = mri_new( nt , nf , MRI_float ) ; /* all zeros */ 02248 if( qim != NULL ){ 02249 int imin,imax , ibot,itop ; 02250 float *bv = MRI_FLOAT_PTR(basis_vect[is]) , dbot,dtop ; 02251 02252 #if 0 02253 fprintf(stderr,"-stim_times %d: adjusted time indexes follow:\n",is+1) ; 02254 for( kk=0 ; kk < ngood ; kk++ ) fprintf(stderr," %g",qar[kk]) ; 02255 fprintf(stderr,"\n") ; 02256 #endif 02257 02258 dbot = be->tbot / basis_TR ; /* range of indexes about each stim time */ 02259 dtop = be->ttop / basis_TR ; 02260 imin = 0 ; imax = nt-1 ; /* for the case of nbl=1 */ 02261 02262 for( kk=0 ; kk < ngood ; kk++ ){ /* for the kk-th stim time */ 02263 tt = qar[kk] ; if( tt < 0.0f || tt >= (float)nt ) continue ; 02264 02265 if( nbl > 1 ){ 02266 for( jj=1 ; jj < nbl ; jj++ ) if( tt < bst[jj] ) break ; 02267 jj-- ; /* time index tt is in block #jj */ 02268 imin = bst[jj] ; /* first index in block */ 02269 if( jj < nbl-1 ) imax = bst[jj+1] - 1 ; /* last index in block */ 02270 else imax = nt - 1 ; 02271 } 02272 02273 /* range of indexes to load with the response model */ 02274 02275 ibot = (int)ceil ( tt + dbot ) ; if( ibot < imin ) ibot = imin ; 02276 itop = (int)floor( tt + dtop ) ; if( itop > imax ) itop = imax ; 02277 02278 for( ii=ibot ; ii <= itop ; ii++ ){ /* loop over active interval */ 02279 ss = basis_TR*(ii-tt) ; 02280 if( ss < be->tbot || ss > be->ttop ) continue ; 02281 for( jj=0 ; jj < nf ; jj++ ) 02282 bv[ii+jj*nt] += basis_funceval( be->bfunc[jj] , basis_TR*(ii-tt) ); 02283 } 02284 } 02285 #if 0 02286 fprintf(stderr,"-stim_times %d: basis vectors follow:\n",is+1) ; 02287 for( ii=0 ; ii < nt ; ii++ ){ 02288 fprintf(stderr,"%d:",ii) ; 02289 for( jj=0 ; jj < nf ; jj++ ) fprintf(stderr," %g",bv[ii+jj*nt]) ; 02290 fprintf(stderr,"\n") ; 02291 } 02292 #endif 02293 } 02294 02295 } /* end of loop over stim functions */ 02296 } /* end of if we have any -stim_times inputs */ 02297 02298 02299 /*----- Determine total number of parameters in the model -----*/ 02300 qp = (option_data->polort + 1) * (*num_blocks); 02301 q = qp; /* number of baseline parameters */ 02302 p = qp; /* number of total parameters */ 02303 for (is = 0; is < num_stimts; is++){ 02304 if( basis_stim[is] != NULL ){ /* 11 Aug 2004 */ 02305 basis_stim[is]->pbot = p ; /* 1st parameter for this model */ 02306 p += basis_stim[is]->nfunc ; /* number of parameters in model */ 02307 } else { 02308 if (max_lag[is] < min_lag[is]) 02309 DC_error ("Require min lag <= max lag for all stimuli"); 02310 p += max_lag[is] - min_lag[is] + 1; 02311 if (baseline[is]) q += max_lag[is] - min_lag[is] + 1; 02312 } 02313 } 02314 option_data->p = p; /* total number of parameters */ 02315 option_data->q = q; /* number of baseline parameters (polort+stim_base) */ 02316 option_data->qp = qp; /* number of polort baseline parameters */ 02317 02318 /*----- Read the censorship file -----*/ 02319 if (option_data->censor_filename != NULL) 02320 { 02321 /*----- Read the input censor time series array -----*/ 02322 *censor_array = read_time_series (option_data->censor_filename, 02323 censor_length); 02324 if (*censor_array == NULL) 02325 { 02326 sprintf (message, "Unable to read censor time series file: %s", 02327 option_data->censor_filename); 02328 DC_error (message); 02329 } 02330 } 02331 else 02332 { 02333 /*----- Create non-censoring censor time series array -----*/ 02334 *censor_array = (float *) malloc (sizeof(float) * nt); 02335 MTEST (*censor_array); 02336 *censor_length = nt; 02337 for (it = 0; it < nt; it++) 02338 (*censor_array)[it] = 1.0; 02339 } 02340 02341 02342 /*----- Build symbolic list of stim names and index ranges [29 Jul 2004] -----*/ 02343 02344 nSymStim = num_stimts+1 ; 02345 SymStim = (SYM_irange *)calloc(sizeof(SYM_irange),nSymStim) ; 02346 02347 strcpy( SymStim[num_stimts].name , "Ort" ) ; 02348 SymStim[num_stimts].nbot = 0 ; 02349 SymStim[num_stimts].ntop = qp-1 ; 02350 SymStim[num_stimts].gbot = 0 ; 02351 it = qp ; 02352 for( is=0 ; is < num_stimts ; is++ ){ 02353 MCW_strncpy( SymStim[is].name , option_data->stim_label[is] , 64 ) ; 02354 if( basis_stim[is] != NULL ){ 02355 SymStim[is].nbot = 0 ; 02356 SymStim[is].ntop = basis_stim[is]->nfunc-1 ; 02357 } else { 02358 SymStim[is].nbot = min_lag[is] ; 02359 SymStim[is].ntop = max_lag[is] ; 02360 } 02361 SymStim[is].gbot = it ; 02362 it += SymStim[is].ntop - SymStim[is].nbot + 1 ; 02363 if( strchr(SymStim[is].name,' ') != NULL || 02364 strchr(SymStim[is].name,'*') != NULL || 02365 strchr(SymStim[is].name,';') != NULL ){ 02366 fprintf(stderr, 02367 "** WARNING: -stim_label #%d '%s' has characters bad for -gltsym\n", 02368 is+1 , SymStim[is].name ) ; 02369 } 02370 } 02371 02372 /*----- Read the general linear test matrices -----*/ 02373 if (num_glt > 0) 02374 { 02375 *glt_cmat = (matrix *) malloc (sizeof(matrix) * num_glt); 02376 02377 /*----- Initialize general linear test matrices -----*/ 02378 for (iglt = 0; iglt < num_glt; iglt++) 02379 matrix_initialize (&((*glt_cmat)[iglt])); 02380 02381 02382 for (iglt = 0; iglt < num_glt; iglt++) 02383 { 02384 #if 1 02385 read_glt_matrix( option_data->glt_filename[iglt] , 02386 option_data->glt_rows + iglt , 02387 p , *glt_cmat + iglt ) ; 02388 #else 02389 matrix_file_read (option_data->glt_filename[iglt], /* uses MRI_read_1D() */ 02390 option_data->glt_rows[iglt], 02391 p, &((*glt_cmat)[iglt]), 1); 02392 if ((*glt_cmat)[iglt].elts == NULL) 02393 { 02394 sprintf (message, "Unable to read GLT matrix from file: %s", 02395 option_data->glt_filename[iglt]); 02396 DC_error (message); 02397 } 02398 #endif 02399 } 02400 } 02401 02402 EXRETURN ; 02403 } |
|
--- Test various combinations for legality [11 Aug 2004] ---* Definition at line 1852 of file 3dDeconvolve.c. References DC_error(), ENTRY, far, malloc, MRI_FLOAT_PTR, mri_free(), mri_read_1D(), MTEST, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and THD_MAX_NAME.
01857 { 01858 char message[THD_MAX_NAME]; /* error message */ 01859 char * cpt; /* pointer to column suffix */ 01860 char filename[THD_MAX_NAME]; /* time series file name w/o column index */ 01861 char subv[THD_MAX_NAME]; /* string containing column index */ 01862 MRI_IMAGE * im, * flim; /* pointers to image structures 01863 -- used to read 1D ASCII */ 01864 float * far; /* pointer to MRI_IMAGE floating point data */ 01865 int nx; /* number of time points in time series */ 01866 int ny; /* number of columns in time series file */ 01867 int iy; /* time series file column index */ 01868 int ipt; /* time point index */ 01869 float * ts_data = NULL; /* input time series data */ 01870 01871 01872 ENTRY("read_time_series") ; 01873 01874 /*----- First, check for empty filename -----*/ 01875 if (ts_filename == NULL) 01876 DC_error ("Missing input time series file name"); 01877 01878 01879 /*----- Read the time series file -----*/ 01880 flim = mri_read_1D( ts_filename ) ; 01881 if (flim == NULL) 01882 { 01883 sprintf (message, "Unable to read time series file: %s", ts_filename); 01884 DC_error (message); 01885 } 01886 far = MRI_FLOAT_PTR(flim); 01887 nx = flim->nx; 01888 ny = flim->ny; iy = 0 ; 01889 if( ny > 1 ){ 01890 fprintf(stderr,"** WARNING: time series %s has %d columns\n",ts_filename,ny); 01891 } 01892 01893 01894 /*----- Save the time series data -----*/ 01895 *ts_length = nx; 01896 ts_data = (float *) malloc (sizeof(float) * nx); 01897 MTEST (ts_data); 01898 for (ipt = 0; ipt < nx; ipt++) 01899 ts_data[ipt] = far[ipt + iy*nx]; 01900 01901 01902 mri_free (flim); flim = NULL; 01903 01904 RETURN (ts_data); 01905 } |
|
04 Aug 2004: manufacture block list * Definition at line 2413 of file 3dDeconvolve.c. References basis_count, DC_error(), and ENTRY. Referenced by initialize_program().
02420 { 02421 int num_stimts; /* number of stimulus time series arrays */ 02422 int is, isp; /* stimulus time series index */ 02423 int it; /* time point index */ 02424 int num_glt; /* number of general linear tests */ 02425 int iglt; /* general linear test index */ 02426 int all_zero; /* boolean for stim function contains all zeros */ 02427 02428 02429 ENTRY("remove_zero_stimfns") ; 02430 02431 /*----- Initialize local variables -----*/ 02432 num_stimts = option_data->num_stimts; 02433 num_glt = option_data->num_glt; 02434 02435 02436 /*----- Loop over all stimulus funcitons -----*/ 02437 is = 0; 02438 while (is < num_stimts) 02439 { 02440 if( basis_stim[is] != NULL ){ is++ ; continue ; } /* 12 Aug 2004 */ 02441 02442 /*----- Check whether stim function consists of all zeros -----*/ 02443 all_zero = TRUE; 02444 for (it = 0; it < stim_length[is]; it++) 02445 { 02446 if (stimulus[is][it] != 0.0) 02447 { 02448 all_zero = FALSE; 02449 break; 02450 } 02451 } 02452 02453 if (all_zero) /*----- Remove this stimulus function -----*/ 02454 { 02455 printf("** WARNING! -stim_file function %s comprises all zeros!\n", 02456 option_data->stim_filename[is]); fflush(stdout); 02457 if (option_data->num_glt > 0) 02458 DC_error 02459 ("Cannot process -glt option(s) when -stim_file function is all zero"); 02460 if( basis_count > 0 ) 02461 DC_error 02462 ("Cannot process -basis_stim option(s) when -stim_file function is all zero"); 02463 02464 option_data->p -= 02465 option_data->stim_maxlag[is] - option_data->stim_minlag[is] + 1; 02466 if (option_data->stim_base[is]) 02467 option_data->q -= 02468 option_data->stim_maxlag[is] - option_data->stim_minlag[is] + 1; 02469 for (isp = is; isp < num_stimts-1; isp++) 02470 { 02471 stimulus[isp] = stimulus[isp+1]; 02472 stim_length[isp] = stim_length[isp+1]; 02473 option_data->stim_filename[isp] 02474 = option_data->stim_filename[isp+1]; 02475 option_data->stim_label[isp] = option_data->stim_label[isp+1]; 02476 option_data->stim_base[isp] 02477 = option_data->stim_base[isp+1]; 02478 option_data->stim_minlag[isp] = option_data->stim_minlag[isp+1]; 02479 option_data->stim_maxlag[isp] = option_data->stim_maxlag[isp+1]; 02480 option_data->iresp_filename[isp] 02481 = option_data->iresp_filename[isp+1]; 02482 option_data->sresp_filename[isp] 02483 = option_data->sresp_filename[isp+1]; 02484 } 02485 02486 num_stimts--; 02487 option_data->num_stimts = num_stimts; 02488 } 02489 else 02490 is++; 02491 } 02492 02493 EXRETURN ; 02494 } |
|
Definition at line 3581 of file 3dDeconvolve.c. References AFNI_yesenv(), basis_expansion::nfunc, and SQR. Referenced by calculate_results().
03587 : X for full model */ 03588 matrix xtxinv_full, /* matrix: 1/(X'X) for full model */ 03589 int num_glt, /* number of general linear tests */ 03590 char ** glt_label, /* label for general linear test */ 03591 int * glt_rows, /* number of linear constraints in glt */ 03592 matrix * cxtxinvct /* array of matrices: C(1/(X'X))C' for glt */ 03593 ) 03594 03595 { 03596 int m; /* parameter index */ 03597 int is; /* stimulus index */ 03598 int ilag; /* time lag index */ 03599 int iglt; /* general linear test index */ 03600 int ilc; /* linear combination index */ 03601 float stddev; /* normalized parameter standard deviation */ 03602 int ibot,itop ; 03603 int j , do_extras ; float jnorm ; 03604 03605 03606 /*----- Print the normalized parameter standard deviations -----*/ 03607 do_extras = AFNI_yesenv("AFNI_3dDeconvolve_nodata_extras") ; 03608 if( do_extras ){ 03609 printf("\nBaseline -polort parameters:\n") ; 03610 for( m=0 ; m < qp ; m++ ){ 03611 jnorm = 0.0 ; 03612 for( j=0 ; j < x_full.rows ; j++ ) jnorm += SQR(x_full.elts[j][m]) ; 03613 jnorm = sqrt(jnorm) ; 03614 stddev = sqrt ( xtxinv_full.elts[m][m] ); 03615 printf (" h[%2d] norm. std. dev. = %8.4f X col. norm = %8.4f\n", 03616 ilag, stddev, jnorm ); 03617 } 03618 } 03619 03620 /*----- Print the normalized parameter standard deviations -----*/ 03621 m = qp; 03622 for (is = 0; is < num_stimts; is++) 03623 { 03624 printf ("\nStimulus: %s \n", stim_label[is]); 03625 if( basis_stim[is] != NULL ){ ibot = 0 ; itop = basis_stim[is]->nfunc-1 ; } 03626 else { ibot = min_lag[is] ; itop = max_lag[is] ; } 03627 for (ilag = ibot; ilag <= itop; ilag++) 03628 { 03629 jnorm = 0.0 ; 03630 for( j=0 ; j < x_full.rows ; j++ ) jnorm += SQR(x_full.elts[j][m]) ; 03631 jnorm = sqrt(jnorm) ; 03632 stddev = sqrt ( xtxinv_full.elts[m][m] ); 03633 if( do_extras ) 03634 printf (" h[%2d] norm. std. dev. = %8.4f X col. norm = %8.4f\n", 03635 ilag, stddev, jnorm ); 03636 else 03637 printf (" h[%2d] norm. std. dev. = %8.4f\n", 03638 ilag, stddev ); 03639 m++; 03640 } 03641 } 03642 03643 /*----- Print normalized standard deviations for GLTs -----*/ 03644 if (num_glt > 0) 03645 { 03646 for (iglt = 0; iglt < num_glt; iglt++) 03647 { 03648 printf ("\nGeneral Linear Test: %s \n", glt_label[iglt]); 03649 03650 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 03651 { 03652 stddev = sqrt ( 1.0 * cxtxinvct[iglt].elts[ilc][ilc] ); 03653 printf (" LC[%d] norm. std. dev. = %8.4f \n", 03654 ilc, stddev); 03655 } 03656 } 03657 } 03658 03659 fflush(stdout); 03660 } |
|
Definition at line 3425 of file 3dDeconvolve.c. References p.
03463 { 03464 int ip; /* parameter index */ 03465 int p; /* total number of parameters */ 03466 int is; /* stimulus time series index */ 03467 int num_stimts; /* number of stimulus time series */ 03468 int num_glt; /* number of general linear tests */ 03469 int * glt_rows; /* number of linear constraints in glt */ 03470 int iglt; /* general linear test index */ 03471 int ilc; /* linear combination index */ 03472 int it; /* time point index */ 03473 int N; /* number of usable data points */ 03474 03475 03476 /*----- Initialize local variables -----*/ 03477 num_stimts = option_data->num_stimts; 03478 p = option_data->p; 03479 num_glt = option_data->num_glt; 03480 glt_rows = option_data->glt_rows; 03481 N = option_data->N; 03482 03483 03484 /*----- Saved regression coefficients, std.dev.'s, and t-statistics -----*/ 03485 if (coef_vol != NULL) 03486 for (ip = 0; ip < p; ip++) 03487 if (coef_vol[ip] != NULL) 03488 coef_vol[ip][iv] = coef.elts[ip]; 03489 if (scoef_vol != NULL) 03490 for (ip = 0; ip < p; ip++) 03491 if (scoef_vol[ip] != NULL) 03492 scoef_vol[ip][iv] = scoef.elts[ip]; 03493 if (tcoef_vol != NULL) 03494 for (ip = 0; ip < p; ip++) 03495 if (tcoef_vol[ip] != NULL) 03496 tcoef_vol[ip][iv] = tcoef.elts[ip]; 03497 03498 03499 /*----- Save partial F-statistics and R^2 statistics -----*/ 03500 if (fpart_vol != NULL) 03501 for (is = 0; is < num_stimts; is++) 03502 if (fpart_vol[is] != NULL) 03503 fpart_vol[is][iv] = fpart[is]; 03504 if (rpart_vol != NULL) 03505 for (is = 0; is < num_stimts; is++) 03506 if (rpart_vol[is] != NULL) 03507 rpart_vol[is][iv] = rpart[is]; 03508 03509 03510 /*----- Save full model mean square error -----*/ 03511 if (mse_vol != NULL) mse_vol[iv] = mse; 03512 03513 03514 /*----- Save regression F-statistic -----*/ 03515 if (ffull_vol != NULL) ffull_vol[iv] = ffull; 03516 03517 03518 /*----- Save R^2 values -----*/ 03519 if (rfull_vol != NULL) rfull_vol[iv] = rfull; 03520 03521 03522 /*----- If general linear test -----*/ 03523 if (num_glt > 0) 03524 { 03525 /*----- Save linear combinations -----*/ 03526 if (glt_coef_vol != NULL) 03527 for (iglt = 0; iglt < num_glt; iglt++) 03528 if (glt_coef_vol[iglt] != NULL) 03529 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 03530 glt_coef_vol[iglt][ilc][iv] = glt_coef[iglt].elts[ilc]; 03531 03532 /*----- Save GLT t-statistics -----*/ 03533 if (glt_tcoef_vol != NULL) 03534 for (iglt = 0; iglt < num_glt; iglt++) 03535 if (glt_tcoef_vol[iglt] != NULL) 03536 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 03537 glt_tcoef_vol[iglt][ilc][iv] = glt_tcoef[iglt].elts[ilc]; 03538 03539 /*----- Save GLT F-statistics -----*/ 03540 if (glt_fstat_vol != NULL) 03541 for (iglt = 0; iglt < num_glt; iglt++) 03542 if (glt_fstat_vol[iglt] != NULL) 03543 glt_fstat_vol[iglt][iv] = fglt[iglt]; 03544 03545 /*----- Save GLT R^2 statistics -----*/ 03546 if (glt_rstat_vol != NULL) 03547 for (iglt = 0; iglt < num_glt; iglt++) 03548 if (glt_rstat_vol[iglt] != NULL) 03549 glt_rstat_vol[iglt][iv] = rglt[iglt]; 03550 } 03551 03552 03553 /*----- Save the fitted time series and residual errors -----*/ 03554 if (fitts_vol != NULL) 03555 { 03556 for (it = 0; it < nt; it++) /* for bad points */ 03557 fitts_vol[it][iv] = ts_array[it]; 03558 03559 for (it = 0; it < N; it++) /* for good points */ 03560 fitts_vol[good_list[it]][iv] = fitts[it]; 03561 } 03562 03563 if (errts_vol != NULL) 03564 { 03565 for (it = 0; it < nt; it++) /* for bad points */ 03566 errts_vol[it][iv] = 0.0; 03567 03568 for (it = 0; it < N; it++) /* for good points */ 03569 errts_vol[good_list[it]][iv] = errts[it]; 03570 } 03571 03572 } |
|
Definition at line 6015 of file 3dDeconvolve.c. References NI_add_column(), NI_new_data_element(), and NI_STRING. Referenced by XSAVE_output().
06016 { 06017 NI_element *nel ; 06018 06019 if( nstr < 1 || str == NULL ) return NULL ; /* bad user, bad */ 06020 06021 if( ename == NULL || *ename == '\0' ) ename = "stringvec" ; 06022 06023 nel = NI_new_data_element( ename , nstr ) ; 06024 NI_add_column( nel , NI_STRING , str ) ; 06025 return nel ; 06026 } |
|
Definition at line 6049 of file 3dDeconvolve.c. References free, SYM_irange::gbot, malloc, SYM_irange::name, SYM_irange::nbot, NI_add_column(), NI_INT, NI_new_data_element(), NI_STRING, and SYM_irange::ntop. Referenced by XSAVE_output().
06050 { 06051 NI_element *nel ; 06052 int ii , *bc,*tc,*gc ; char **sc ; 06053 06054 if( ns < 1 || sv == NULL ) return NULL ; /* bad user, bad */ 06055 06056 if( ename == NULL || *ename == '\0' ) ename = "symvec" ; 06057 06058 nel = NI_new_data_element( ename , ns ) ; 06059 06060 bc = (int *) malloc(sizeof(int) *ns) ; 06061 tc = (int *) malloc(sizeof(int) *ns) ; 06062 gc = (int *) malloc(sizeof(int) *ns) ; 06063 sc = (char **)malloc(sizeof(char *)*ns) ; 06064 06065 for( ii=0 ; ii < ns ; ii++ ){ 06066 bc[ii] = sv[ii].nbot ; tc[ii] = sv[ii].ntop ; 06067 gc[ii] = sv[ii].gbot ; sc[ii] = sv[ii].name ; 06068 } 06069 06070 NI_add_column( nel , NI_INT , bc ); free((void *)bc) ; 06071 NI_add_column( nel , NI_INT , tc ); free((void *)tc) ; 06072 NI_add_column( nel , NI_INT , gc ); free((void *)gc) ; 06073 NI_add_column( nel , NI_STRING , sc ); free((void *)sc) ; 06074 06075 return nel ; 06076 } |
|
check for all zero rows, which will cause trouble later * Definition at line 6899 of file 3dDeconvolve.c. Referenced by calculate_results(), and do_xrestore_stuff().
06900 { 06901 static int nn=0 ; 06902 static char xx[10] = "0123456789" ; 06903 fprintf(stderr , "%c" , xx[nn%10] ) ; 06904 if( nn%10 == 9) fprintf(stderr,".") ; 06905 nn++ ; 06906 } |
|
Definition at line 4723 of file 3dDeconvolve.c. References ADN_datum_all, ADN_directory_name, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_type, argc, attach_sub_brick(), BucketFilename, calloc, CoefFilename, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, DSET_BRIKNAME, DSET_delete, DSET_HEADNAME, DSET_IS_TCAT, DSET_NUM_TIMES, DSET_PREFIX, DSET_write, EDIT_dset_items(), EDIT_empty_copy(), FUNC_BUCK_TYPE, FUNC_FIM_TYPE, FUNC_THR_TYPE, HEAD_FUNC_TYPE, InputFilename, malloc, MTEST, basis_expansion::nfunc, nParam, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, p, ParamIndex, ParamLabel, ParamStim, PROGRAM_NAME, q, THD_3dim_dataset::tcat_list, THD_delete_3dim_dataset(), THD_is_file(), THD_load_statistics(), THD_MAX_NAME, THD_open_dataset(), THD_trailname(), THD_write_3dim_dataset(), tross_Append_History(), tross_Copy_History(), tross_Make_History(), and XSAVE_output().
04741 { 04742 THD_3dim_dataset * old_dset = NULL; /* prototype dataset */ 04743 THD_3dim_dataset * new_dset = NULL; /* output bucket dataset */ 04744 char output_prefix[THD_MAX_NAME]; /* prefix name for bucket dataset */ 04745 char output_session[THD_MAX_NAME]; /* directory for bucket dataset */ 04746 int nbricks; /* number of sub-bricks in bucket dataset */ 04747 short ** bar = NULL; /* bar[ib] points to data for sub-brick #ib */ 04748 04749 int brick_type; /* indicates statistical type of sub-brick */ 04750 int brick_coef; /* regression coefficient index for sub-brick */ 04751 char brick_label[THD_MAX_NAME]; /* character string label for sub-brick */ 04752 04753 int ierror; /* number of errors in editing data */ 04754 float * volume; /* volume of floating point data */ 04755 04756 int N; /* number of usable data points */ 04757 int qp; /* number of poly. trend baseline parameters */ 04758 int q; /* number of baseline model parameters */ 04759 int p; /* number of full model parameters */ 04760 int polort; /* degree of polynomial for baseline model */ 04761 int num_stimts; /* number of stimulus time series */ 04762 int istim; /* stimulus index */ 04763 int nxyz; /* total number of voxels */ 04764 int nt; /* number of images in input 3d+time dataset */ 04765 int ilag; /* lag index */ 04766 int icoef; /* coefficient index */ 04767 int ibrick; /* sub-brick index */ 04768 int dof, ndof, ddof; /* degrees of freedom */ 04769 char label[THD_MAX_NAME]; /* general label for sub-bricks */ 04770 char blab[THD_MAX_NAME] ; /* label for baseline funcs */ 04771 int num_glt; /* number of general linear tests */ 04772 int * glt_rows; /* number of linear constraints in glt */ 04773 int iglt; /* general linear test index */ 04774 int ilc; /* linear combination index */ 04775 04776 THD_3dim_dataset *coef_dset = NULL ; /* coefficient bucket? */ 04777 int cbuck , bout,cout , ibot,itop ; 04778 04779 /*----- read prototype dataset -----*/ 04780 old_dset = THD_open_dataset (option_data->input_filename); 04781 04782 bout = !option_data->nobout ; 04783 cout = !option_data->nocout ; 04784 04785 /*----- Initialize local variables -----*/ 04786 nxyz = old_dset->daxes->nxx * old_dset->daxes->nyy * old_dset->daxes->nzz; 04787 num_stimts = option_data->num_stimts; 04788 nt = DSET_NUM_TIMES (old_dset); 04789 num_glt = option_data->num_glt; 04790 glt_rows = option_data->glt_rows; 04791 04792 polort = option_data->polort; 04793 qp = option_data->qp; 04794 q = option_data->q; 04795 p = option_data->p; 04796 N = option_data->N; 04797 nbricks = option_data->nbricks; 04798 04799 04800 /*----- Prepare output file name -----*/ 04801 strcpy (output_prefix, option_data->bucket_filename); 04802 strcpy (output_session, "./"); 04803 04804 04805 /*----- allocate memory -----*/ 04806 bar = (short **) malloc (sizeof(short *) * nbricks); 04807 MTEST (bar); 04808 04809 04810 /*-- make an empty copy of prototype dataset, for eventual output --*/ 04811 new_dset = EDIT_empty_copy (old_dset); 04812 04813 04814 /*----- Record history of dataset -----*/ 04815 tross_Copy_History( old_dset , new_dset ) ; 04816 tross_Make_History( PROGRAM_NAME , argc , argv , new_dset ) ; 04817 sprintf (label, "Output prefix: %s", output_prefix); 04818 tross_Append_History ( new_dset, label); 04819 04820 /*----- Modify some structural properties. Note that the nbricks 04821 just make empty sub-bricks, without any data attached. -----*/ 04822 ierror = EDIT_dset_items (new_dset, 04823 ADN_prefix, output_prefix, 04824 ADN_type, HEAD_FUNC_TYPE, 04825 ADN_func_type, FUNC_BUCK_TYPE, 04826 ADN_datum_all, MRI_short , 04827 ADN_ntt, 0, /* no time */ 04828 ADN_nvals, nbricks, 04829 ADN_malloc_type, DATABLOCK_MEM_MALLOC , 04830 ADN_none ) ; 04831 04832 if( ierror > 0 ) 04833 { 04834 fprintf(stderr, 04835 "** %d errors in attempting to create bucket dataset!\n", 04836 ierror); 04837 exit(1); 04838 } 04839 04840 if( strstr(output_prefix,"/") == NULL ) 04841 (void) EDIT_dset_items (new_dset, 04842 ADN_directory_name, output_session, 04843 ADN_none ) ; 04844 04845 if (THD_is_file(DSET_HEADNAME(new_dset))) 04846 { 04847 fprintf(stderr, 04848 "** Bucket dataset file %s already exists--cannot continue!\n", 04849 DSET_HEADNAME(new_dset)); 04850 exit(1); 04851 } 04852 04853 if( CoefFilename != NULL ){ 04854 coef_dset = EDIT_empty_copy( new_dset ) ; 04855 tross_Copy_History( old_dset , coef_dset ) ; 04856 tross_Make_History( PROGRAM_NAME , argc , argv , coef_dset ) ; 04857 (void) EDIT_dset_items( coef_dset, 04858 ADN_prefix, CoefFilename , 04859 ADN_type, HEAD_FUNC_TYPE, 04860 ADN_func_type, FUNC_BUCK_TYPE, 04861 ADN_datum_all, MRI_short , 04862 ADN_ntt, 0, /* no time */ 04863 ADN_nvals, p , 04864 ADN_malloc_type, DATABLOCK_MEM_MALLOC , 04865 ADN_none ) ; 04866 if( strstr(CoefFilename,"/") == NULL ) 04867 (void) EDIT_dset_items( coef_dset , 04868 ADN_directory_name, output_session, 04869 ADN_none ) ; 04870 if( THD_is_file(DSET_HEADNAME(coef_dset)) ){ 04871 fprintf(stderr, 04872 "** Coefficient dataset file %s already exists--cannot continue!\n", 04873 DSET_HEADNAME(coef_dset)); 04874 exit(1); 04875 } 04876 } 04877 04878 /*----- save names for future xsave-ing -----*/ 04879 if( DSET_IS_TCAT(old_dset) ) 04880 InputFilename = strdup(old_dset->tcat_list) ; 04881 else 04882 InputFilename = strdup(THD_trailname(DSET_HEADNAME(old_dset),0)) ; 04883 04884 BucketFilename = strdup(THD_trailname(DSET_HEADNAME(new_dset),0)) ; 04885 04886 if( coef_dset != NULL ) 04887 CoefFilename = strdup(THD_trailname(DSET_HEADNAME(coef_dset),0)) ; 04888 04889 /*----- delete prototype dataset -----*/ 04890 THD_delete_3dim_dataset( old_dset , False ); old_dset = NULL ; 04891 04892 04893 /*----- Attach individual sub-bricks to the bucket dataset -----*/ 04894 04895 04896 /*----- User can choose to place full model stats first -----*/ 04897 ibrick = -1; 04898 if (option_data->full_first) 04899 ibrick += option_data->vout + option_data->rout + option_data->fout; 04900 04901 cbuck = -1 ; 04902 04903 04904 /*----- Include fit coefficients and associated statistics? -----*/ 04905 if( cout || coef_dset != NULL ) 04906 { 04907 04908 { int ii ; 04909 ParamStim = (int *) calloc(sizeof(int) ,nParam) ; 04910 ParamLabel = (char **)calloc(sizeof(char *),nParam) ; 04911 for( ii=0 ; ii < qp ; ii++ ) ParamLabel[ii] = strdup("ort") ; 04912 for( ; ii < nParam ; ii++ ) ParamLabel[ii] = strdup("coef") ; 04913 if( cout && bout ) 04914 ParamIndex = (int *)calloc(sizeof(int) ,nParam) ; 04915 else 04916 ParamIndex = NULL ; 04917 } 04918 04919 /*----- Baseline statistics -----*/ 04920 if( bout || coef_dset != NULL ) 04921 { 04922 strcpy (label, "Base"); 04923 04924 if( legendre_polort ) strcpy(blab,"P_") ; /* 25 Jul 2004: */ 04925 else strcpy(blab,"t^") ; /* label for polynomials */ 04926 04927 for (icoef = 0; icoef < qp; icoef++) 04928 { 04929 if (qp == polort+1) 04930 strcpy (label, "Base"); /* only 1 run */ 04931 else 04932 sprintf (label, "Run#%d", icoef/(polort+1) + 1); /* multiple runs */ 04933 04934 /*----- Baseline coefficient -----*/ 04935 brick_type = FUNC_FIM_TYPE; 04936 sprintf (brick_label, "%s %s%d Coef", label,blab, icoef % (polort+1)); 04937 volume = coef_vol[icoef]; 04938 04939 if( cout && bout ) 04940 attach_sub_brick (new_dset, ++ibrick, volume, nxyz, 04941 brick_type, brick_label, 0, 0, 0, bar); 04942 04943 sprintf(brick_label,"%s:%s%d" , label,blab,icoef%(polort+1)) ; 04944 04945 if( ParamIndex != NULL ) ParamIndex[icoef] = ibrick ; 04946 ParamStim [icoef] = 0 ; 04947 ParamLabel[icoef] = strdup(brick_label) ; 04948 04949 if( coef_dset != NULL ){ 04950 cbuck++ ; 04951 attach_sub_brick( coef_dset , cbuck , volume , nxyz , 04952 brick_type, brick_label, 0, 0, 0, NULL); 04953 } 04954 04955 /*----- Baseline t-stat -----*/ 04956 if ( cout && bout && option_data->tout) 04957 { 04958 ibrick++; 04959 brick_type = FUNC_TT_TYPE; 04960 dof = N - p; 04961 sprintf (brick_label, "%s %s%d t-st", 04962 label,blab, icoef % (polort+1)); 04963 volume = tcoef_vol[icoef]; 04964 attach_sub_brick (new_dset, ibrick, volume, nxyz, 04965 brick_type, brick_label, dof, 0, 0, bar); 04966 } 04967 } 04968 } 04969 04970 04971 /*----- Stimulus statistics -----*/ 04972 icoef = qp; 04973 for (istim = 0; istim < num_stimts; istim++) 04974 { 04975 strcpy (label, option_data->stim_label[istim]); 04976 04977 if( basis_stim[istim] != NULL ){ 04978 ibot = 0 ; itop = basis_stim[istim]->nfunc-1 ; 04979 } else { 04980 ibot = option_data->stim_minlag[istim] ; 04981 itop = option_data->stim_maxlag[istim] ; 04982 } 04983 04984 /*----- Loop over stimulus time lags -----*/ 04985 for( ilag=ibot ; ilag <= itop ; ilag++ ) 04986 { 04987 if( !option_data->stim_base[istim] || 04988 bout || 04989 coef_dset != NULL ) 04990 { 04991 /*----- Stimulus coefficient -----*/ 04992 brick_type = FUNC_FIM_TYPE; 04993 sprintf (brick_label, "%s[%d] Coef", label, ilag); 04994 volume = coef_vol[icoef]; 04995 if( cout && (!option_data->stim_base[istim] || bout) ) 04996 attach_sub_brick (new_dset, ++ibrick, volume, nxyz, 04997 brick_type, brick_label, 0, 0, 0, bar); 04998 04999 sprintf(brick_label,"%s:%d",label,ilag) ; 05000 05001 if( ParamIndex != NULL ) ParamIndex[icoef] = ibrick ; 05002 ParamStim [icoef] = option_data->stim_base[istim] ? 0 05003 : istim+1 ; 05004 ParamLabel[icoef] = strdup(brick_label) ; 05005 05006 if( coef_dset != NULL ){ 05007 cbuck++ ; 05008 attach_sub_brick( coef_dset , cbuck , volume , nxyz , 05009 brick_type, brick_label, 0, 0, 0, NULL); 05010 } 05011 05012 /*----- Stimulus t-stat -----*/ 05013 if (cout && option_data->tout && (!option_data->stim_base[istim] || bout) ) 05014 { 05015 ibrick++; 05016 brick_type = FUNC_TT_TYPE; 05017 dof = N - p; 05018 sprintf (brick_label, "%s[%d] t-st", label, ilag); 05019 volume = tcoef_vol[icoef]; 05020 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05021 brick_type, brick_label, dof, 0, 0, bar); 05022 } 05023 } 05024 05025 icoef++; 05026 } 05027 05028 /*----- Stimulus R^2 stat -----*/ 05029 if( cout && option_data->rout 05030 && (!option_data->stim_base[istim] || bout) ) 05031 { 05032 ibrick++; 05033 brick_type = FUNC_THR_TYPE; 05034 sprintf (brick_label, "%s R^2", label); 05035 volume = rpart_vol[istim]; 05036 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05037 brick_type, brick_label, 0, 0, 0, bar); 05038 } 05039 05040 /*----- Stimulus F-stat -----*/ 05041 if( cout && option_data->fout 05042 && (!option_data->stim_base[istim] || bout) ) 05043 { 05044 ibrick++; 05045 brick_type = FUNC_FT_TYPE; 05046 ndof = itop - ibot + 1 ; 05047 ddof = N - p; 05048 sprintf (brick_label, "%s F-stat", label); 05049 volume = fpart_vol[istim]; 05050 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05051 brick_type, brick_label, 0, ndof, ddof, bar); 05052 } 05053 05054 } /* End loop over stim functions */ 05055 05056 } /* if (! option_data->nocout) */ 05057 05058 if( coef_dset != NULL ){ 05059 DSET_write(coef_dset) ; 05060 if( !option_data->quiet ) 05061 fprintf(stderr,"++ Wrote cbucket to %s\n",DSET_BRIKNAME(coef_dset)) ; 05062 DSET_delete(coef_dset) ; coef_dset = NULL ; 05063 } 05064 05065 05066 /*----- 25 Jul 2004: save matrix info (etc.) to dataset header -----*/ 05067 05068 if( xsave ) XSAVE_output( DSET_PREFIX(new_dset) ) ; 05069 05070 /*----- General linear test statistics -----*/ 05071 for (iglt = 0; iglt < num_glt; iglt++) 05072 { 05073 strcpy (label, option_data->glt_label[iglt]); 05074 05075 /*----- Loop over rows of GLT matrix -----*/ 05076 for (ilc = 0; ilc < glt_rows[iglt]; ilc++) 05077 { 05078 /*----- GLT coefficient -----*/ 05079 ibrick++; 05080 brick_type = FUNC_FIM_TYPE; 05081 sprintf (brick_label, "%s LC[%d] coef", label, ilc); 05082 volume = glt_coef_vol[iglt][ilc]; 05083 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05084 brick_type, brick_label, 0, 0, 0, bar); 05085 05086 /*----- GLT t-stat -----*/ 05087 if (option_data->tout) 05088 { 05089 ibrick++; 05090 brick_type = FUNC_TT_TYPE; 05091 dof = N - p; 05092 sprintf (brick_label, "%s LC[%d] t-st", label, ilc); 05093 volume = glt_tcoef_vol[iglt][ilc]; 05094 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05095 brick_type, brick_label, dof, 0, 0, bar); 05096 } 05097 } 05098 05099 /*----- GLT R^2 stat -----*/ 05100 if (option_data->rout) 05101 { 05102 ibrick++; 05103 brick_type = FUNC_THR_TYPE; 05104 sprintf (brick_label, "%s R^2", label); 05105 volume = glt_rstat_vol[iglt]; 05106 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05107 brick_type, brick_label, 0, 0, 0, bar); 05108 } 05109 05110 /*----- GLT F-stat -----*/ 05111 if (option_data->fout) 05112 { 05113 ibrick++; 05114 brick_type = FUNC_FT_TYPE; 05115 ndof = glt_rows[iglt]; 05116 ddof = N - p; 05117 sprintf (brick_label, "%s F-stat", label); 05118 volume = glt_fstat_vol[iglt]; 05119 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05120 brick_type, brick_label, 0, ndof, ddof, bar); 05121 } 05122 05123 } /* End loop over general linear tests */ 05124 05125 05126 /*----- Statistics for full model -----*/ 05127 if (option_data->full_first) ibrick = -1; 05128 05129 /*----- Full model MSE -----*/ 05130 if (option_data->vout) 05131 { 05132 ibrick++; 05133 brick_type = FUNC_FIM_TYPE; 05134 sprintf (brick_label, "Full MSE"); 05135 volume = mse_vol; 05136 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05137 brick_type, brick_label, 0, 0, 0, bar); 05138 } 05139 05140 /*----- Full model R^2 -----*/ 05141 if (option_data->rout) 05142 { 05143 ibrick++; 05144 brick_type = FUNC_THR_TYPE; 05145 sprintf (brick_label, "Full R^2"); 05146 volume = rfull_vol; 05147 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05148 brick_type, brick_label, 0, 0, 0, bar); 05149 } 05150 05151 /*----- Full model F-stat -----*/ 05152 if (option_data->fout) 05153 { 05154 ibrick++; 05155 brick_type = FUNC_FT_TYPE; 05156 ndof = p - q; 05157 ddof = N - p; 05158 sprintf (brick_label, "Full F-stat"); 05159 volume = ffull_vol; 05160 attach_sub_brick (new_dset, ibrick, volume, nxyz, 05161 brick_type, brick_label, 0, ndof, ddof, bar); 05162 } 05163 05164 05165 /*----- write bucket data set -----*/ 05166 05167 THD_load_statistics (new_dset); 05168 THD_write_3dim_dataset( NULL,NULL , new_dset , True ) ; 05169 if (! option_data->quiet) 05170 printf("++ Wrote bucket dataset into %s\n", DSET_BRIKNAME(new_dset)); 05171 05172 05173 /*----- deallocate memory -----*/ 05174 THD_delete_3dim_dataset( new_dset , False ) ; new_dset = NULL ; 05175 05176 } |
|
Definition at line 5185 of file 3dDeconvolve.c.
05191 { 05192 char filename[80]; /* output time series file name */ 05193 int it; /* time index */ 05194 FILE * outfile = NULL; /* file pointer */ 05195 05196 05197 /*----- Create output filename by appending ".1D" -----*/ 05198 sprintf (filename, "%s.1D", prefix); 05199 outfile = fopen (filename, "w"); 05200 05201 05202 /*----- 'Volume' data consists of just one voxel -----*/ 05203 for (it = 0; it < ts_length; it++) 05204 { 05205 fprintf (outfile, "%f", vol_array[it][0]); 05206 fprintf (outfile, " \n"); 05207 } 05208 05209 05210 fclose (outfile); 05211 } |
|
Definition at line 4534 of file 3dDeconvolve.c. References ADN_brick_fac, ADN_datum_all, ADN_label1, ADN_malloc_type, ADN_none, ADN_nsl, ADN_ntt, ADN_nvals, ADN_prefix, ADN_self_name, ADN_ttdel, ADN_ttdur, ADN_ttorg, argc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_BRICK, DSET_BRIKNAME, DSET_TIMESTEP, EDIT_coerce_autoscale_new(), EDIT_dset_items(), EDIT_empty_copy(), free, THD_diskptr::header_name, malloc, mri_fix_data_pointer(), MTEST, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, PROGRAM_NAME, THD_delete_3dim_dataset(), THD_is_file(), THD_load_statistics(), THD_MAX_NAME, THD_open_dataset(), THD_write_3dim_dataset(), tross_Append_History(), tross_commandline(), tross_Copy_History(), and tross_multi_Append_History().
04545 { 04546 const float EPSILON = 1.0e-10; 04547 04548 THD_3dim_dataset * dset = NULL; /* input afni data set pointer */ 04549 THD_3dim_dataset * new_dset = NULL; /* output afni data set pointer */ 04550 int ib; /* sub-brick index */ 04551 int ierror; /* number of errors in editing data */ 04552 int nxyz; /* total number of voxels */ 04553 float factor; /* factor is new scale factor for sub-brick #ib */ 04554 char * input_filename; /* input afni data set file name */ 04555 short ** bar = NULL; /* bar[ib] points to data for sub-brick #ib */ 04556 float * fbuf = NULL; /* float buffer */ 04557 float * volume; /* pointer to volume of data */ 04558 char label[THD_MAX_NAME]; /* label for output file */ 04559 float newtr; /* new time step = TR/nptr */ 04560 04561 04562 /*----- Initialize local variables -----*/ 04563 input_filename = option_data->input_filename; 04564 dset = THD_open_dataset (input_filename); 04565 nxyz = dset->daxes->nxx * dset->daxes->nyy * dset->daxes->nzz; 04566 newtr = DSET_TIMESTEP(dset) / nptr; 04567 04568 /*----- allocate memory -----*/ 04569 bar = (short **) malloc (sizeof(short *) * ts_length); MTEST (bar); 04570 fbuf = (float *) malloc (sizeof(float) * ts_length); MTEST (fbuf); 04571 04572 /*-- make an empty copy of the prototype dataset, for eventual output --*/ 04573 new_dset = EDIT_empty_copy (dset); 04574 04575 /*----- Record history of dataset -----*/ 04576 tross_Copy_History( dset , new_dset ) ; 04577 04578 { char * commandline = tross_commandline( PROGRAM_NAME , argc , argv ) ; 04579 sprintf (label, "Output prefix: %s", output_filename); 04580 if( commandline != NULL ) 04581 tross_multi_Append_History( new_dset , commandline,label,NULL ) ; 04582 else 04583 tross_Append_History ( new_dset, label); 04584 free(commandline) ; 04585 } 04586 04587 /*----- Delete prototype dataset -----*/ 04588 THD_delete_3dim_dataset (dset, False); dset = NULL ; 04589 04590 04591 ierror = EDIT_dset_items (new_dset, 04592 ADN_prefix, output_filename, 04593 ADN_label1, output_filename, 04594 ADN_self_name, output_filename, 04595 ADN_malloc_type, DATABLOCK_MEM_MALLOC, 04596 ADN_datum_all, MRI_short, 04597 ADN_nvals, ts_length, 04598 ADN_ntt, ts_length, 04599 ADN_ttdel, newtr, 04600 ADN_none); 04601 04602 if( ierror > 0 ){ 04603 fprintf(stderr, 04604 "** %d errors in attempting to create output dataset!\n", ierror ) ; 04605 exit(1) ; 04606 } 04607 04608 if( THD_is_file(new_dset->dblk->diskptr->header_name) ){ 04609 fprintf(stderr, 04610 "** Output dataset file %s already exists--cannot continue!\a\n", 04611 new_dset->dblk->diskptr->header_name ) ; 04612 exit(1) ; 04613 } 04614 04615 04616 /*----- Reset slice offset times to zero -----*/ 04617 if (tshift) 04618 EDIT_dset_items (new_dset, 04619 ADN_nsl, 0, /* will have no offsets when done */ 04620 ADN_ttorg, 0.0, /* in case not already set */ 04621 ADN_ttdur, 0.0, /* in case not already set */ 04622 ADN_none); 04623 04624 04625 /*----- attach bricks to new data set -----*/ 04626 for (ib = 0; ib < ts_length; ib++) 04627 { 04628 04629 /*----- Set pointer to appropriate volume -----*/ 04630 volume = vol_array[ib]; 04631 04632 /*----- Allocate memory for output sub-brick -----*/ 04633 bar[ib] = (short *) malloc (sizeof(short) * nxyz); 04634 MTEST (bar[ib]); 04635 04636 /*----- Convert data type to short for this sub-brick -----*/ 04637 factor = EDIT_coerce_autoscale_new (nxyz, MRI_float, volume, 04638 MRI_short, bar[ib]); 04639 if (factor < EPSILON) factor = 0.0; 04640 else factor = 1.0 / factor; 04641 fbuf[ib] = factor; 04642 04643 /*----- attach bar[ib] to be sub-brick #ib -----*/ 04644 mri_fix_data_pointer (bar[ib], DSET_BRICK(new_dset,ib)); 04645 } 04646 04647 04648 /*----- write afni data set -----*/ 04649 04650 (void) EDIT_dset_items( new_dset , ADN_brick_fac , fbuf , ADN_none ) ; 04651 04652 THD_load_statistics (new_dset); 04653 THD_write_3dim_dataset (NULL, NULL, new_dset, True); 04654 if (! option_data->quiet) 04655 fprintf(stderr,"++ Wrote 3D+time dataset into %s\n",DSET_BRIKNAME(new_dset)) ; 04656 04657 04658 /*----- deallocate memory -----*/ 04659 THD_delete_3dim_dataset (new_dset, False); new_dset = NULL ; 04660 free (fbuf); fbuf = NULL; 04661 04662 } |
|
Definition at line 6228 of file 3dDeconvolve.c. References BucketFilename, CoefFilename, free, GoodList, InputFilename, malloc, NI_element::name, nGoodList, NI_free_element(), NI_get_attribute(), NI_read_element(), NI_stream_close(), NI_stream_open(), niml_to_intvec(), niml_to_matrix(), niml_to_stringvec(), niml_to_symvec(), nParam, nSymStim, NumRegressors, NumTimePoints, ParamIndex, ParamLabel, and ParamStim. Referenced by do_xrestore_stuff().
06229 { 06230 char *fname , *cpt ; 06231 NI_stream ns ; 06232 NI_element *nel ; 06233 06234 if( xname == NULL || *xname == '\0' ) return ; 06235 06236 /*-- open input file --*/ 06237 06238 fname = malloc( sizeof(char) * (strlen(xname)+32) ) ; 06239 strcpy(fname,"file:") ; strcat(fname,xname) ; 06240 ns = NI_stream_open( fname , "r" ) ; 06241 free((void *)fname) ; 06242 if( ns == (NI_stream)NULL ){ 06243 fprintf(stderr,"** ERROR: can't open file %s for -xrestore!\n",xname) ; 06244 return ; 06245 } 06246 06247 /*-- read and decode header element --*/ 06248 06249 nel = NI_read_element( ns , 1 ) ; 06250 if( nel == NULL ){ 06251 fprintf(stderr,"** ERROR: can't read header in file %s for -xrestore!\n",xname) ; 06252 NI_stream_close( ns ) ; return ; 06253 } 06254 06255 /* extract filenames */ 06256 06257 cpt = NI_get_attribute( nel , "InputFilename" ) ; 06258 if( cpt != NULL ) InputFilename = strdup(cpt) ; 06259 cpt = NI_get_attribute( nel , "BucketFilename" ) ; 06260 if( cpt != NULL ) BucketFilename = strdup(cpt) ; 06261 cpt = NI_get_attribute( nel , "CoefFilename" ) ; 06262 if( cpt != NULL ) CoefFilename = strdup(cpt) ; 06263 06264 /* extract other stuff (not used, yet) */ 06265 06266 cpt = NI_get_attribute( nel , "NumTimePoints" ) ; 06267 if( cpt != NULL ) NumTimePoints = strtol(cpt,NULL,10) ; 06268 cpt = NI_get_attribute( nel , "NumRegressors" ) ; 06269 if( cpt != NULL ) NumRegressors = strtol(cpt,NULL,10) ; 06270 06271 NI_free_element( nel ) ; 06272 06273 /*-- read succeeding elements, decode and store them --*/ 06274 06275 while(1){ 06276 06277 nel = NI_read_element( ns , 1 ) ; 06278 if( nel == NULL ) break ; /* end of input */ 06279 06280 cpt = NI_get_attribute( nel , "Xname" ) ; /*- name of variable to save -*/ 06281 if( cpt == NULL ){ 06282 NI_free_element( nel ) ; continue ; /*- unnamed ==> skip this! -*/ 06283 } 06284 06285 if( strcmp(nel->name,"matrix") == 0 ){ /*- matrix elements -*/ 06286 06287 if( strcmp(cpt,"X" )==0 ) niml_to_matrix( nel , &X ); 06288 else if( strcmp(cpt,"XtXinv" )==0 ) niml_to_matrix( nel , &XtXinv ); 06289 else if( strcmp(cpt,"XtXinvXt")==0 ) niml_to_matrix( nel , &XtXinvXt ); 06290 06291 } else if( strcmp(nel->name,"intvec") == 0 ){ /*- intvec elements -*/ 06292 06293 if( strcmp(cpt,"GoodList") == 0 ) 06294 niml_to_intvec( nel , &nGoodList, &GoodList ); 06295 else if( strcmp(cpt,"ParamIndex") == 0 ) 06296 niml_to_intvec( nel , &nParam , &ParamIndex ); 06297 else if( strcmp(cpt,"ParamStim" ) == 0 ) 06298 niml_to_intvec( nel , &nParam , &ParamStim ); 06299 06300 } else if( strcmp(nel->name,"stringvec") == 0 ){ /*- stringvec elements -*/ 06301 06302 if( strcmp(cpt,"ParamLabel") == 0 ) 06303 niml_to_stringvec( nel , &nParam , &ParamLabel ); 06304 06305 } else if( strcmp(nel->name,"symvec") == 0 ){ /*- symvec elements -*/ 06306 06307 if( strcmp(cpt,"SymStim") == 0 ) 06308 niml_to_symvec( nel , &nSymStim , &SymStim ); 06309 06310 } else { /*- other elements? -*/ 06311 /*- silently skip them -*/ 06312 } 06313 06314 NI_free_element( nel ) ; /* toss the trash (or recycle it) */ 06315 06316 } /*-- end of loop over elements in file --*/ 06317 06318 NI_stream_close( ns ) ; return ; 06319 } |
|
Definition at line 6105 of file 3dDeconvolve.c. References AFNI_yesenv(), BucketFilename, CoefFilename, matrix::cols, free, GoodList, InputFilename, intvec_to_niml(), malloc, matrix_to_niml(), nGoodList, NI_BINARY_MODE, NI_free_element(), NI_new_data_element(), NI_set_attribute(), NI_stream_close(), NI_stream_open(), NI_TEXT_MODE, NI_write_element(), nParam, nSymStim, ParamIndex, ParamLabel, ParamStim, matrix::rows, stringvec_to_niml(), symvec_to_niml(), THD_is_ondisk(), tross_datetime(), tross_hostname(), tross_username(), verb, xsave, and XSAVE_version. Referenced by write_bucket_data().
06106 { 06107 char *fname , *cpt ; 06108 NI_stream ns ; 06109 NI_element *nel ; 06110 int nimode = NI_BINARY_MODE ; 06111 06112 if( !xsave ) return ; 06113 06114 if( AFNI_yesenv("AFNI_XSAVE_TEXT") ) nimode = NI_TEXT_MODE ; 06115 06116 /*-- open output stream --*/ 06117 06118 if( prefix == NULL || *prefix == '\0' ) prefix = "X" ; 06119 06120 fname = malloc( sizeof(char) * (strlen(prefix)+32) ) ; 06121 strcpy(fname,"file:") ; strcat(fname,prefix) ; strcat(fname,".xsave") ; 06122 if( THD_is_ondisk(fname+5) && verb ) 06123 fprintf(stderr, 06124 "** WARNING: -xsave output file %s will be overwritten!\n",fname+5) ; 06125 ns = NI_stream_open( fname , "w" ) ; 06126 if( ns == (NI_stream)NULL ){ 06127 fprintf(stderr, 06128 "** ERROR: -xsave output file %s can't be opened!\n",fname+5) ; 06129 free((void *)fname) ; 06130 return ; 06131 } 06132 06133 /*-- write a header element --*/ 06134 06135 nel = NI_new_data_element( "XSAVE", 0 ) ; 06136 if( InputFilename != NULL ) 06137 NI_set_attribute( nel , "InputFilename" , InputFilename ) ; 06138 if( BucketFilename != NULL ) 06139 NI_set_attribute( nel , "BucketFilename" , BucketFilename ) ; 06140 if( CoefFilename != NULL ) 06141 NI_set_attribute( nel , "CoefFilename" , CoefFilename ) ; 06142 06143 sprintf(fname,"%d",X.rows) ; 06144 NI_set_attribute( nel , "NumTimePoints" , fname ) ; 06145 sprintf(fname,"%d",X.cols) ; 06146 NI_set_attribute( nel , "NumRegressors" , fname ) ; 06147 06148 NI_set_attribute( nel , "Deconvolveries" , XSAVE_version ) ; 06149 06150 cpt = tross_datetime() ; 06151 NI_set_attribute( nel , "DateTime" , cpt ) ; 06152 free((void *)cpt) ; 06153 cpt = tross_hostname() ; 06154 NI_set_attribute( nel , "Hostname" , cpt ) ; 06155 free((void *)cpt) ; 06156 cpt = tross_username() ; 06157 NI_set_attribute( nel , "Username" , cpt ) ; 06158 free((void *)cpt) ; 06159 06160 (void) NI_write_element( ns , nel , nimode ) ; 06161 NI_free_element( nel ) ; 06162 06163 /*-- write the matrices --*/ 06164 06165 nel = matrix_to_niml( X , "matrix" ) ; 06166 NI_set_attribute( nel , "Xname" , "X" ) ; 06167 (void) NI_write_element( ns , nel , nimode ) ; 06168 NI_free_element( nel ) ; 06169 06170 nel = matrix_to_niml( XtXinv , "matrix" ) ; 06171 NI_set_attribute( nel , "Xname" , "XtXinv" ) ; 06172 (void) NI_write_element( ns , nel , nimode ) ; 06173 NI_free_element( nel ) ; 06174 06175 nel = matrix_to_niml( XtXinvXt , "matrix" ) ; 06176 NI_set_attribute( nel , "Xname" , "XtXinvXt" ) ; 06177 (void) NI_write_element( ns , nel , nimode ) ; 06178 NI_free_element( nel ) ; 06179 06180 /*-- list of good time points --*/ 06181 06182 nel = intvec_to_niml( nGoodList , GoodList , "intvec" ) ; 06183 NI_set_attribute( nel , "Xname" , "GoodList" ) ; 06184 (void) NI_write_element( ns , nel , nimode ) ; 06185 NI_free_element( nel ) ; 06186 06187 /*-- list of bucket indices with estimated parameters --*/ 06188 06189 if( ParamIndex != NULL ){ 06190 nel = intvec_to_niml( nParam, ParamIndex , "intvec" ) ; 06191 NI_set_attribute( nel , "Xname" , "ParamIndex" ) ; 06192 (void) NI_write_element( ns , nel , nimode ) ; 06193 NI_free_element( nel ) ; 06194 } 06195 06196 /*-- which stimlus input file, for each parameter --*/ 06197 06198 nel = intvec_to_niml( nParam, ParamStim , "intvec" ) ; 06199 NI_set_attribute( nel , "Xname" , "ParamStim" ) ; 06200 (void) NI_write_element( ns , nel , nimode ) ; 06201 NI_free_element( nel ) ; 06202 06203 /*-- stimulus label, for each parameter --*/ 06204 06205 nel = stringvec_to_niml( nParam , ParamLabel , "stringvec" ) ; 06206 NI_set_attribute( nel , "Xname" , "ParamLabel" ) ; 06207 (void) NI_write_element( ns , nel , nimode ) ; 06208 NI_free_element( nel ) ; 06209 06210 /*-- stimulus symbols [29 Jul 2004] --*/ 06211 06212 if( nSymStim > 0 ){ 06213 nel = symvec_to_niml( nSymStim , SymStim , "symvec" ) ; 06214 NI_set_attribute( nel , "Xname" , "SymStim" ) ; 06215 (void) NI_write_element( ns , nel , nimode ) ; 06216 NI_free_element( nel ) ; 06217 } 06218 06219 /*-- done, finito, ciao babee --*/ 06220 06221 NI_stream_close(ns) ; free((void *)fname) ; return ; 06222 } |
|
Definition at line 2863 of file 3dDeconvolve.c. References malloc, MTEST, proc_numjob, proc_shm_ar, proc_shm_arnum, proc_shm_arsiz, and realloc.
02864 { 02865 int ixyz; 02866 02867 if( proc_numjob == 1 ){ /* 1 process ==> allocate locally */ 02868 02869 *fvol = (float *) malloc (sizeof(float) * nxyz); MTEST(*fvol); 02870 for (ixyz = 0; ixyz < nxyz; ixyz++) 02871 (*fvol)[ixyz] = 0.0; 02872 02873 } 02874 #ifdef PROC_MAX 02875 else { /* multiple processes ==> prepare for shared memory */ 02876 /* by remembering what to do */ 02877 02878 proc_shm_arnum++ ; 02879 proc_shm_arsiz = (int *) realloc( proc_shm_arsiz , 02880 sizeof(int) *proc_shm_arnum ) ; 02881 proc_shm_ar = (float ***) realloc( proc_shm_ar , 02882 sizeof(float **)*proc_shm_arnum ) ; 02883 proc_shm_arsiz[proc_shm_arnum-1] = nxyz ; 02884 proc_shm_ar[proc_shm_arnum-1] = fvol ; 02885 02886 /* actual allocation and pointer assignment (to *fvol) 02887 will take place in function proc_finalize_shm_volumes() */ 02888 } 02889 #endif 02890 } |
Variable Documentation
|
Definition at line 437 of file 3dDeconvolve.c. Referenced by get_options(), read_input_data(), and remove_zero_stimfns(). |
|
Definition at line 438 of file 3dDeconvolve.c. Referenced by get_options(), output_results(), and read_input_data(). |
|
Definition at line 441 of file 3dDeconvolve.c. Referenced by allocate_memory(), and get_options(). |
|
Definition at line 443 of file 3dDeconvolve.c. Referenced by basis_parser(), and get_options(). |
|
global variables for stimulus basis expansions * Definition at line 433 of file 3dDeconvolve.c. |
|
Definition at line 434 of file 3dDeconvolve.c. |
|
Definition at line 436 of file 3dDeconvolve.c. Referenced by read_input_data(). |
|
Definition at line 435 of file 3dDeconvolve.c. |
|
Definition at line 356 of file 3dDeconvolve.c. Referenced by do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 356 of file 3dDeconvolve.c. Referenced by allocate_memory(), do_xrestore_stuff(), get_options(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 353 of file 3dDeconvolve.c. Referenced by check_for_valid_inputs(), check_xrestore_data(), do_xrestore_stuff(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 356 of file 3dDeconvolve.c. Referenced by check_xrestore_data(), do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 462 of file 3dDeconvolve.c. |
|
Definition at line 439 of file 3dDeconvolve.c. Referenced by get_options(). |
|
Definition at line 353 of file 3dDeconvolve.c. Referenced by check_for_valid_inputs(), check_xrestore_data(), do_xrestore_stuff(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 354 of file 3dDeconvolve.c. Referenced by baseline_mean(), check_for_valid_inputs(), check_xrestore_data(), do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 379 of file 3dDeconvolve.c. Referenced by read_glt_matrix(), read_input_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 461 of file 3dDeconvolve.c. |
|
Definition at line 369 of file 3dDeconvolve.c. Referenced by XSAVE_input(). |
|
Definition at line 369 of file 3dDeconvolve.c. Referenced by XSAVE_input(). |
|
Definition at line 354 of file 3dDeconvolve.c. Referenced by do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 355 of file 3dDeconvolve.c. Referenced by check_xrestore_data(), do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 354 of file 3dDeconvolve.c. Referenced by check_xrestore_data(), do_xrestore_stuff(), write_bucket_data(), XSAVE_input(), and XSAVE_output(). |
|
Definition at line 325 of file 3dDeconvolve.c. Referenced by calculate_results(), and proc_sigfunc(). |
|
Definition at line 312 of file 3dDeconvolve.c. Referenced by allocate_memory(), calculate_results(), get_options(), main(), and zero_fill_volume(). |
|
Definition at line 313 of file 3dDeconvolve.c. Referenced by calculate_results(). |
|
Definition at line 319 of file 3dDeconvolve.c. Referenced by proc_finalize_shm_volumes(), proc_free(), and zero_fill_volume(). |
|
Definition at line 318 of file 3dDeconvolve.c. Referenced by proc_finalize_shm_volumes(), proc_free(), and zero_fill_volume(). |
|
Definition at line 320 of file 3dDeconvolve.c. Referenced by proc_finalize_shm_volumes(), and zero_fill_volume(). |
|
Definition at line 314 of file 3dDeconvolve.c. Referenced by proc_atexit(), proc_finalize_shm_volumes(), proc_free(), and proc_sigfunc(). |
|
Definition at line 315 of file 3dDeconvolve.c. Referenced by proc_finalize_shm_volumes(). |
|
Definition at line 316 of file 3dDeconvolve.c. Referenced by proc_finalize_shm_volumes(). |
|
Definition at line 334 of file 3dDeconvolve.c. Referenced by get_options(), and main(). |
|
Definition at line 322 of file 3dDeconvolve.c. Referenced by calculate_results(). |
|
Definition at line 323 of file 3dDeconvolve.c. Referenced by calculate_results(). |
|
Definition at line 385 of file 3dDeconvolve.c. Referenced by calculate_results(), and get_options(). |
|
Definition at line 380 of file 3dDeconvolve.c. |
|
Definition at line 371 of file 3dDeconvolve.c. Referenced by do_xrestore_stuff(), get_options(), main(), and XSAVE_output(). |
|
Definition at line 363 of file 3dDeconvolve.c. Referenced by calculate_results(). |
|
Definition at line 362 of file 3dDeconvolve.c. Referenced by read_input_data(). |
|
Definition at line 358 of file 3dDeconvolve.c. |
|
Definition at line 360 of file 3dDeconvolve.c. Referenced by baseline_mean(), and calculate_results(). |
|
Definition at line 361 of file 3dDeconvolve.c. Referenced by baseline_mean(), and calculate_results(). |
|
Definition at line 367 of file 3dDeconvolve.c. Referenced by get_options(). |
|
Definition at line 368 of file 3dDeconvolve.c. Referenced by check_xrestore_data(), do_xrestore_stuff(), and get_options(). |
|
Definition at line 352 of file 3dDeconvolve.c. Referenced by check_for_valid_inputs(), get_options(), and XSAVE_output(). |
|
Definition at line 358 of file 3dDeconvolve.c. |
|
Definition at line 358 of file 3dDeconvolve.c. |