GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
atou1.c
Go to the documentation of this file.
1 /* atou1.c CCMATH mathematics library source code.
2  *
3  * Copyright (C) 2000 Daniel A. Atkinson All rights reserved.
4  * This code may be redistributed under the terms of the GNU library
5  * public license (LGPL). ( See the lgpl.license file for details.)
6  * ------------------------------------------------------------------------
7  */
8 #include <stdlib.h>
9 void atou1(double *a, int m, int n)
10 {
11  double *p0, *p, *q, *w;
12 
13  int i, j, k, mm;
14 
15  double s, h;
16 
17  w = (double *)calloc(m, sizeof(double));
18  p0 = a + n * n - 1;
19  i = n - 1;
20  mm = m - n;
21  if (mm == 0) {
22  *p0 = 1.;
23  p0 -= n + 1;
24  --i;
25  ++mm;
26  }
27  for (; i >= 0; --i, ++mm, p0 -= n + 1) {
28  if (*p0 != 0.) {
29  for (j = 0, p = p0 + n; j < mm; p += n)
30  w[j++] = *p;
31  h = *p0;
32  *p0 = 1. - h;
33  for (j = 0, p = p0 + n; j < mm; p += n)
34  *p = -h * w[j++];
35  for (k = i + 1, q = p0 + 1; k < n; ++k) {
36  for (j = 0, p = q + n, s = 0.; j < mm; p += n)
37  s += w[j++] * *p;
38  s *= h;
39  for (j = 0, p = q + n; j < mm; p += n)
40  *p -= s * w[j++];
41  *q++ = -s;
42  }
43  }
44  else {
45  *p0 = 1.;
46  for (j = 0, p = p0 + n, q = p0 + 1; j < mm; ++j, p += n)
47  *p = *q++ = 0.;
48  }
49  }
50  free(w);
51 }
void atou1(double *a, int m, int n)
Definition: atou1.c:9
void free(void *)