GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <math.h> 00004 #include "local_proto.h" 00005 00006 00007 double *dagostino_d(double *x, int n) 00008 { 00009 int i; 00010 static double y[2]; 00011 double d, s, t = 0., *xcopy, m2, s1 = 0., s2, mn = 0.0; 00012 00013 if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) { 00014 fprintf(stderr, "Memory allocation error\n"); 00015 exit(EXIT_FAILURE); 00016 } 00017 00018 for (i = 0; i < n; ++i) 00019 xcopy[i] = x[i]; 00020 00021 qsort(xcopy, n, sizeof(double), dcmp); 00022 00023 for (i = 0; i < n; ++i) { 00024 t += xcopy[i] * ((i + 1) - 0.5 * (n + 1)); 00025 mn += xcopy[i]; 00026 } 00027 00028 m2 = mn / n; 00029 for (i = 0; i < n; ++i) 00030 s1 += (xcopy[i] - m2) * (xcopy[i] - m2); 00031 00032 s2 = s1 / n; 00033 s = sqrt(s2); 00034 d = t / (n * n * s); 00035 00036 /* y[0] = (d - 1. / (2*sqrt (M_PI))) * sqrt ((double)n) / 0.02998598; */ 00037 y[0] = d; 00038 y[1] = sqrt((double)n) * (y[0] - 0.28209479) / 0.02998598; 00039 00040 #ifdef NOISY 00041 fprintf(stdout, " TEST4 DAGN =%10.4f\n", y[0]); 00042 #endif /* NOISY */ 00043 00044 return y; 00045 }