GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
dagstndn.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "local_proto.h"
5 
6 
7 double *Cdhc_dagostino_d(double *x, int n)
8 {
9  int i;
10  static double y[2];
11  double d, s, t = 0., *xcopy, m2, s1 = 0., s2, mn = 0.0;
12 
13  if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
14  fprintf(stderr, "Memory allocation error\n");
15  exit(EXIT_FAILURE);
16  }
17 
18  for (i = 0; i < n; ++i)
19  xcopy[i] = x[i];
20 
21  qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
22 
23  for (i = 0; i < n; ++i) {
24  t += xcopy[i] * ((i + 1) - 0.5 * (n + 1));
25  mn += xcopy[i];
26  }
27 
28  m2 = mn / n;
29  for (i = 0; i < n; ++i)
30  s1 += (xcopy[i] - m2) * (xcopy[i] - m2);
31 
32  s2 = s1 / n;
33  s = sqrt(s2);
34  d = t / (n * n * s);
35 
36  /* y[0] = (d - 1. / (2*sqrt (M_PI))) * sqrt ((double)n) / 0.02998598; */
37  y[0] = d;
38  y[1] = sqrt((double)n) * (y[0] - 0.28209479) / 0.02998598;
39 
40 #ifdef NOISY
41  fprintf(stdout, " TEST4 DAGN =%10.4f\n", y[0]);
42 #endif /* NOISY */
43 
44  return y;
45 }
#define NULL
Definition: ccmath.h:32
#define x
void * malloc(YYSIZE_T)
double t
Definition: r_raster.c:39
double * Cdhc_dagostino_d(double *x, int n)
Definition: dagstndn.c:7
int Cdhc_dcmp(const void *i, const void *j)
Definition: dcmp.c:1