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