Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
plug_stats.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "afni.h"
00008
00009 #ifndef ALLOW_PLUGINS
00010 # error "Plugins not properly set up -- see machdep.h"
00011 #endif
00012
00013
00014
00015
00016
00017
00018
00019 static char helpstring[] =
00020 "Purpose: Compute mean, slope, or sigma of a 3D+time dataset.\n"
00021 "Input items are:\n"
00022 " 3d+time = 3D+time dataset to analyze\n"
00023 " Method = Mean, Slope, or Sigma = type of analysis to do\n"
00024 " Ignore = How many points to ignore at start\n"
00025 "\n"
00026 "Output: Prefix = Filename prefix for new dataset"
00027 ;
00028
00029
00030
00031 static char * method_strings[] = { "Mean" , "Slope" , "Sigma" , "CVar" } ;
00032
00033 #define NUM_METHOD_STRINGS (sizeof(method_strings)/sizeof(char *))
00034
00035 #define METH_MEAN 0
00036 #define METH_SLOPE 1
00037 #define METH_SIGMA 2
00038 #define METH_CVAR 3
00039
00040
00041
00042 char * STATS_main( PLUGIN_interface * ) ;
00043
00044 void STATS_tsfunc( double tzero , double tdelta ,
00045 int npts , float ts[] , double ts_mean , double ts_slope ,
00046 void * ud , float * val ) ;
00047
00048
00049
00050 static PLUGIN_interface * global_plint = NULL ;
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 DEFINE_PLUGIN_PROTOTYPE
00067
00068 PLUGIN_interface * PLUGIN_init( int ncall )
00069 {
00070 PLUGIN_interface * plint ;
00071
00072 if( ncall > 0 ) return NULL ;
00073
00074
00075
00076 plint = PLUTO_new_interface( "3D+t Statistic" ,
00077 "Voxel Statistics of 3D+time Dataset" ,
00078 helpstring ,
00079 PLUGIN_CALL_VIA_MENU , STATS_main ) ;
00080
00081 PLUTO_add_hint( plint , "Voxel Statistics of 3D+time Dataset" ) ;
00082
00083 PLUTO_set_sequence( plint , "A:newdset:statistics" ) ;
00084
00085 global_plint = plint ;
00086
00087
00088
00089 PLUTO_add_option( plint ,
00090 "Input" ,
00091 "Input" ,
00092 TRUE
00093 ) ;
00094
00095 PLUTO_add_dataset( plint ,
00096 "3D+time" ,
00097 ANAT_ALL_MASK ,
00098 FUNC_FIM_MASK ,
00099 DIMEN_4D_MASK |
00100 BRICK_ALLREAL_MASK
00101 ) ;
00102
00103 PLUTO_add_hint( plint , "Choose input dataset" ) ;
00104
00105
00106
00107 PLUTO_add_option( plint ,
00108 "Input" ,
00109 "Input" ,
00110 TRUE
00111 ) ;
00112
00113 PLUTO_add_hint( plint , "Control parameters" ) ;
00114
00115 PLUTO_add_string( plint ,
00116 "Method" ,
00117 NUM_METHOD_STRINGS ,
00118 method_strings ,
00119 0
00120 ) ;
00121
00122 PLUTO_add_hint( plint , "Choose statistic to compute" ) ;
00123
00124 PLUTO_add_number( plint ,
00125 "Ignore" ,
00126 0 ,
00127 20 ,
00128 0 ,
00129 3 ,
00130 FALSE
00131 ) ;
00132
00133 PLUTO_add_hint( plint , "Number of points to ignore at start of time series" ) ;
00134
00135
00136
00137 PLUTO_add_option( plint ,
00138 "Output" ,
00139 "Output" ,
00140 TRUE
00141 ) ;
00142
00143 PLUTO_add_string( plint ,
00144 "Prefix" ,
00145 0,NULL ,
00146 19
00147 ) ;
00148
00149 PLUTO_add_hint( plint , "Name of output dataset" ) ;
00150
00151
00152
00153 return plint ;
00154 }
00155
00156
00157
00158
00159
00160
00161
00162 char * STATS_main( PLUGIN_interface * plint )
00163 {
00164 MCW_idcode * idc ;
00165 THD_3dim_dataset * old_dset , * new_dset ;
00166 char * new_prefix , * str ;
00167 int meth , ignore ;
00168
00169
00170
00171
00172
00173
00174 PLUTO_next_option(plint) ;
00175
00176 idc = PLUTO_get_idcode(plint) ;
00177 old_dset = PLUTO_find_dset(idc) ;
00178 if( old_dset == NULL )
00179 return "*************************\n"
00180 "Cannot find Input Dataset\n"
00181 "*************************" ;
00182
00183
00184
00185 PLUTO_next_option(plint) ;
00186
00187 str = PLUTO_get_string(plint) ;
00188 meth = PLUTO_string_index( str ,
00189 NUM_METHOD_STRINGS ,
00190 method_strings ) ;
00191
00192 ignore = PLUTO_get_number(plint) ;
00193
00194
00195
00196 PLUTO_next_option(plint) ;
00197
00198 new_prefix = PLUTO_get_string(plint) ;
00199 if( ! PLUTO_prefix_ok(new_prefix) )
00200 return "************************\n"
00201 "Output Prefix is illegal\n"
00202 "************************" ;
00203
00204
00205
00206 new_dset = PLUTO_4D_to_fim( old_dset ,
00207 new_prefix ,
00208 ignore ,
00209 1 ,
00210 STATS_tsfunc ,
00211 (void *) meth
00212 ) ;
00213
00214 PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ;
00215
00216 return NULL ;
00217 }
00218
00219
00220
00221
00222
00223 void STATS_tsfunc( double tzero , double tdelta ,
00224 int npts , float ts[] , double ts_mean , double ts_slope ,
00225 void * ud , float * val )
00226 {
00227 int meth = (int) ud ;
00228 static int nvox , ncall ;
00229
00230
00231
00232 if( val == NULL ){
00233
00234 if( npts > 0 ){
00235
00236 PLUTO_popup_meter( global_plint ) ;
00237 nvox = npts ;
00238 ncall = 0 ;
00239
00240 } else {
00241
00242 PLUTO_set_meter( global_plint , 100 ) ;
00243
00244 }
00245 return ;
00246 }
00247
00248
00249
00250 switch( meth ){
00251
00252 default:
00253 case METH_MEAN: *val = ts_mean ; break ;
00254
00255 case METH_SLOPE: *val = ts_slope ; break ;
00256
00257 case METH_CVAR:
00258 case METH_SIGMA:{
00259 register int ii ;
00260 register double sum ;
00261
00262 sum = 0.0 ;
00263 for( ii=0 ; ii < npts ; ii++ ) sum += ts[ii] * ts[ii] ;
00264
00265 sum = sqrt( sum/(npts-1) ) ;
00266
00267 if( meth == METH_SIGMA ) *val = sum ;
00268 else if( ts_mean != 0.0 ) *val = sum / fabs(ts_mean) ;
00269 else *val = 0.0 ;
00270 }
00271 }
00272
00273
00274
00275 ncall++ ;
00276 PLUTO_set_meter( global_plint , (100*ncall)/nvox ) ;
00277 return ;
00278 }