GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
eigen_tools.c
Go to the documentation of this file.
1
#include <stdlib.h>
2
#include <math.h>
3
#include <grass/gis.h>
4
#include <grass/gmath.h>
5
6
static
int
egcmp(
const
void
*pa,
const
void
*pb);
7
8
int
G_math_egvorder
(
double
*d,
double
**z,
long
bands)
9
{
10
double
*buff;
11
double
**tmp;
12
int
i, j;
13
14
/* allocate temporary matrix */
15
buff = (
double
*)G_malloc(bands * (bands + 1) *
sizeof
(
double
));
16
tmp = (
double
**)G_malloc(bands *
sizeof
(
double
*));
17
for
(i = 0; i < bands; i++)
18
tmp[i] = &buff[i * (bands + 1)];
19
20
/* concatenate (vertically) z and d into tmp */
21
for
(i = 0; i < bands; i++) {
22
for
(j = 0; j < bands; j++)
23
tmp[i][j + 1] = z[j][i];
24
tmp[i][0] = d[i];
25
}
26
27
/* sort the combined matrix */
28
qsort(tmp, bands,
sizeof
(
double
*), egcmp);
29
30
/* split tmp into z and d */
31
for
(i = 0; i < bands; i++) {
32
for
(j = 0; j < bands; j++)
33
z[j][i] = tmp[i][j + 1];
34
d[i] = tmp[i][0];
35
}
36
37
/* free temporary matrix */
38
G_free
(tmp);
39
G_free
(buff);
40
41
return
0;
42
}
43
44
/***************************************************************************/
45
46
static
int
egcmp(
const
void
*pa,
const
void
*pb)
47
{
48
const
double
*a = *(
const
double
*
const
*)pa;
49
const
double
*
b
= *(
const
double
*
const
*)pb;
50
51
if
(*a > *
b
)
52
return
-1;
53
if
(*a < *
b
)
54
return
1;
55
56
return
0;
57
}
58
59
/***************************************************************************/
G_free
void G_free(void *buf)
Free allocated memory.
Definition
alloc.c:147
b
double b
Definition
driver/set_window.c:5
G_math_egvorder
int G_math_egvorder(double *d, double **z, long bands)
Definition
eigen_tools.c:8
gmath
eigen_tools.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0