GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-77aab223bc
shapiro2.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 /* this is actually the Weisberg-Bingham stat. I need to
7  OCR the constants and implement this Cdhc_correctly */
8 
9 double *Cdhc_shapiro_francia(double *x, int n)
10 {
11  static double y[2];
12  double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
13  int i;
14 
15  if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
16  fprintf(stderr, "Memory error in Cdhc_shapiro_francia\n");
17  exit(EXIT_FAILURE);
18  }
19 
20  for (i = 0; i < n; ++i)
21  xcopy[i] = x[i];
22 
23  qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
24 
25  for (i = 0; i < n; ++i) {
26  z = Cdhc_xinormal((i + 1 - 0.375) / (n + 0.25));
27  suma += z * xcopy[i];
28  sumb += z * z;
29  sumc += xcopy[i];
30  sumd += xcopy[i] * xcopy[i];
31  }
32 
33  y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
34 
35 #ifdef NOISY
36  fprintf(stdout, " TEST14 SF(N) =%10.4f\n", y[0]);
37 #endif /* NOISY */
38 
39  free(xcopy);
40 
41  return y;
42 } /* test14_ */
#define NULL
Definition: ccmath.h:32
int Cdhc_dcmp(const void *i, const void *j)
Definition: dcmp.c:1
double Cdhc_xinormal(double)
Definition: xinormal.c:4
double * Cdhc_shapiro_francia(double *x, int n)
Definition: shapiro2.c:9
void * malloc(YYSIZE_T)
void free(void *)
#define x