Doxygen Source Code Documentation
niml_stat.c File Reference
#include "niml_private.h"
#include <math.h>
Go to the source code of this file.
Defines | |
#define | BSTRIP |
Functions | |
int | NI_stat_numparam (int scode) |
char * | NI_stat_distname (int scode) |
void | NI_fval_to_char (float qval, char *buf) |
char * | NI_stat_encode (int scode, float p1, float p2, float p3) |
void | NI_stat_decode (char *str, int *scode, float *p1, float *p2, float *p3) |
Variables | |
int | numparam [] |
char * | distname [] |
Define Documentation
|
Value: for( il=strlen(lbuf)-1 ; \ il>1 && (lbuf[il]=='0' || lbuf[il]==' ') ; \ il-- ) lbuf[il] = '\0' |
Function Documentation
|
Definition at line 37 of file niml_stat.c. References abs. Referenced by NI_stat_encode().
00038 { 00039 float aval = fabs(qval) ; 00040 int lv , il ; 00041 char lbuf[32] ; 00042 00043 /* special case if the value is an integer */ 00044 00045 if( qval == 0.0 ){ strcpy(buf,"0"); return; } 00046 00047 lv = (fabs(qval) < 99999999.0) ? (int)qval : 100000001 ; 00048 00049 if( qval == lv && abs(lv) < 100000000 ){ sprintf(buf,"%d",lv); return; } 00050 00051 /* macro to strip trailing zeros from output */ 00052 00053 #undef BSTRIP 00054 #define BSTRIP for( il=strlen(lbuf)-1 ; \ 00055 il>1 && (lbuf[il]=='0' || lbuf[il]==' ') ; \ 00056 il-- ) lbuf[il] = '\0' 00057 00058 /* noninteger: choose floating format based on magnitude */ 00059 00060 lv = (int) (10.0001 + log10(aval)) ; 00061 00062 switch( lv ){ 00063 00064 default: 00065 if( qval > 0.0 ) sprintf( lbuf , "%-12.6e" , qval ) ; 00066 else sprintf( lbuf , "%-12.5e" , qval ) ; 00067 break ; 00068 00069 case 6: /* 0.0001-0.001 */ 00070 case 7: /* 0.001 -0.01 */ 00071 case 8: /* 0.01 -0.1 */ 00072 case 9: /* 0.1 -1 */ 00073 case 10: /* 1 -9.99 */ 00074 sprintf( lbuf , "%-9.6f" , qval ) ; BSTRIP ; break ; 00075 00076 case 11: /* 10-99.9 */ 00077 sprintf( lbuf , "%-9.5f" , qval ) ; BSTRIP ; break ; 00078 00079 case 12: /* 100-999.9 */ 00080 sprintf( lbuf , "%-9.4f" , qval ) ; BSTRIP ; break ; 00081 00082 case 13: /* 1000-9999.9 */ 00083 sprintf( lbuf , "%-9.3f" , qval ) ; BSTRIP ; break ; 00084 00085 case 14: /* 10000-99999.9 */ 00086 sprintf( lbuf , "%-9.2f" , qval ) ; BSTRIP ; break ; 00087 00088 case 15: /* 100000-999999.9 */ 00089 sprintf( lbuf , "%-9.1f" , qval ) ; BSTRIP ; break ; 00090 00091 case 16: /* 1000000-9999999.9 */ 00092 sprintf( lbuf , "%-9.0f" , qval ) ; break ; 00093 } 00094 00095 strcpy(buf,lbuf) ; return ; 00096 } |
|
Definition at line 141 of file niml_stat.c. References NI_stat_distname(), NI_STAT_FIRSTCODE, NI_STAT_LASTCODE, and NI_stat_numparam(). Referenced by THD_datablock_from_atr().
00142 { 00143 int jj , ll ; 00144 char *dnam , qnam[64] ; 00145 00146 if( scode == NULL ) return ; /* bad input */ 00147 *scode = 0 ; 00148 if( str == NULL || *str == '\0' ) return ; /* bad input */ 00149 00150 /* scan for distribution name */ 00151 00152 for( jj=NI_STAT_FIRSTCODE ; jj <= NI_STAT_LASTCODE ; jj++ ){ 00153 dnam = NI_stat_distname(jj) ; 00154 strcpy(qnam,dnam); strcat(qnam,"("); ll = strlen(qnam); 00155 if( strncasecmp(str,qnam,ll) == 0 ) break ; 00156 } 00157 if( jj <= NI_STAT_LASTCODE ){ 00158 float parm[3]={1.0f,1.0f,1.0f} ; int np,kk,mm , sp ; 00159 np = NI_stat_numparam(jj) ; sp = ll ; 00160 for( kk=0 ; kk < np ; kk++ ){ 00161 mm = 0 ; sscanf(str+sp,"%f%n",parm+kk,&mm) ; sp += mm+1 ; 00162 } 00163 *scode = jj ; /* Save results */ 00164 if( p1 != NULL ) *p1 = parm[0] ; /* into output */ 00165 if( p2 != NULL ) *p2 = parm[1] ; /* variables. */ 00166 if( p3 != NULL ) *p3 = parm[2] ; 00167 } 00168 return ; 00169 } |
|
Definition at line 30 of file niml_stat.c. References distname, and NI_STAT_LASTCODE. Referenced by NI_stat_decode(), THD_open_3D(), and THD_write_1D().
00031 { 00032 return distname[(scode >=0 && scode <= NI_STAT_LASTCODE) ? scode : 0] ; 00033 } |
|
Definition at line 101 of file niml_stat.c. References distname, malloc, NI_fval_to_char(), NI_STAT_LASTCODE, and NI_stat_numparam(). Referenced by THD_set_dataset_attributes().
00102 { 00103 char *buf , *nam , b1[16] , b2[16] , b3[16] ; 00104 int np ; 00105 00106 if( scode < NI_STAT_FIRSTCODE || scode > NI_STAT_LASTCODE ){ 00107 buf = strdup("none") ; return buf ; 00108 } 00109 00110 np = NI_stat_numparam( scode ) ; /* # of parameters */ 00111 nam = distname[scode] ; /* distribution name */ 00112 buf = malloc( 20*(np+1) ) ; /* output buffer */ 00113 switch( np ){ 00114 case 0: 00115 sprintf(buf,"%s()",nam) ; break ; 00116 00117 case 1: 00118 NI_fval_to_char( p1 , b1 ) ; 00119 sprintf(buf,"%s(%s)",nam,b1) ; break ; 00120 00121 case 2: 00122 NI_fval_to_char( p1 , b1 ) ; 00123 NI_fval_to_char( p2 , b2 ) ; 00124 sprintf(buf,"%s(%s,%s)",nam,b1,b2) ; break ; 00125 00126 default: 00127 case 3: 00128 NI_fval_to_char( p1 , b1 ) ; 00129 NI_fval_to_char( p2 , b2 ) ; 00130 NI_fval_to_char( p3 , b3 ) ; 00131 sprintf(buf,"%s(%s,%s,%s)",nam,b1,b2,b3) ; break ; 00132 } 00133 00134 return buf ; 00135 } |
|
Definition at line 23 of file niml_stat.c. References NI_STAT_LASTCODE, and numparam. Referenced by NI_stat_decode(), NI_stat_encode(), THD_datablock_from_atr(), THD_open_3D(), and THD_write_1D().
00024 { 00025 return numparam[(scode >=0 && scode <= NI_STAT_LASTCODE) ? scode : 0] ; 00026 } |
Variable Documentation
|
Initial value: { "none" , "none" , "Correl" , "Ttest" , "Ftest" , "Zscore" , "Chisq" , "Beta" , "Binom" , "Gamma" , "Poisson" , "Normal" , "Ftest_nonc" , "Chisq_nonc" , "Logistic" , "Laplace" , "Uniform" , "Ttest_nonc" , "Weibull" , "Chi" , "Invgauss" , "Extval" , "Pval" , "LogPval" , "Log10Pval", NULL } Definition at line 13 of file niml_stat.c. Referenced by NI_stat_distname(), and NI_stat_encode(). |
|
Initial value: { 0,0,3,1,2,0,1,2,2,2, 1,2,3,2,2,2,2,2,3,1, 2,2,0,0,0, -1 } Definition at line 8 of file niml_stat.c. Referenced by NI_stat_numparam(). |