GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
secpar2d.c
Go to the documentation of this file.
1/*!
2 * \file secpar2d.c
3 *
4 * \author H. Mitasova, L. Mitas, I. Kosinovsky, D. Gerdes Fall 1994 (original
5 * authors) \author modified by McCauley in August 1995 \author modified by
6 * Mitasova in August 1995 \author H. Mitasova (University of Illinois) \author
7 * L. Mitas (University of Illinois) \author I. Kosinovsky, (USA-CERL) \author
8 * D.Gerdes (USA-CERL)
9 *
10 * SPDX-FileCopyrightText: 1994-1995 Helena Mitasova
11 * SPDX-FileCopyrightText: GRASS Development Team
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 */
15
16#include <stdio.h>
17#include <math.h>
18#include <unistd.h>
19#include <grass/gis.h>
20#include <grass/bitmap.h>
21#include <grass/interpf.h>
22
23/*!
24 * Compute slope aspect and curvatures
25 *
26 * Computes slope, aspect and curvatures (depending on cond1, cond2) for
27 * derivative arrays adx,...,adxy between columns ngstc and nszc.
28 */
30 struct interp_params *params, int ngstc, /*!< starting column */
31 int nszc, /*!< ending column */
32 int k, /*!< current row */
33 struct BM *bitmask, double *gmin, double *gmax, double *c1min,
34 double *c1max, double *c2min, double *c2max, /*!< min,max interp. values */
35 int cond1,
36 int cond2 /*!< determine if particular values need to be computed */
37)
38{
39 double dnorm1, ro, /* rad to deg conv */
40 dx2 = 0, dy2 = 0, grad2 = 0, /* gradient squared */
41 slp = 0, grad, /* gradient */
42 oor = 0, /* aspect (orientation) */
43 curn = 0, /* profile curvature */
44 curh = 0, /* tangential curvature */
45 curm = 0, /* mean curvature */
46 temp, /* temp variable */
47 dxy2; /* temp variable square of part diriv. */
48
49 double gradmin;
50 int i, got, bmask = 1;
51 static int first_time_g = 1;
52
53 ro = M_R2D;
54 gradmin = 0.001;
55
56 for (i = ngstc; i <= nszc; i++) {
57 if (bitmask != NULL) {
58 bmask = BM_get(bitmask, i, k);
59 }
60 got = 0;
61 if (bmask == 1) {
62 while ((got == 0) && (cond1)) {
63 dx2 = (double)(params->adx[i] * params->adx[i]);
64 dy2 = (double)(params->ady[i] * params->ady[i]);
65 grad2 = dx2 + dy2;
66 grad = sqrt(grad2);
67 /* slope in % slp = 100. * grad; */
68 /* slope in degrees */
69 slp = ro * atan(grad);
70 if (grad <= gradmin) {
71 oor = 0.;
72 got = 3;
73 if (cond2) {
74 curn = 0.;
75 curh = 0.;
76 got = 3;
77 break;
78 }
79 }
80 if (got == 3)
81 break;
82
83 /***********aspect from r.slope.aspect, with adx, ady computed
84 from interpol. function RST
85 **************************/
86
87 if (params->adx[i] == 0.) {
88 if (params->ady[i] > 0.)
89 oor = 90;
90 else
91 oor = 270;
92 }
93 else {
94 oor = ro * atan2(params->ady[i], params->adx[i]);
95 if (oor <= 0.)
96 oor = 360. + oor;
97 }
98
99 got = 1;
100 } /* while */
101 if ((got != 3) && (cond2)) {
102
103 dnorm1 = sqrt(grad2 + 1.);
104 dxy2 = 2. * (double)(params->adxy[i] * params->adx[i] *
105 params->ady[i]);
106
107 curn = (double)(params->adxx[i] * dx2 + dxy2 +
108 params->adyy[i] * dy2) /
109 (grad2 * dnorm1 * dnorm1 * dnorm1);
110
111 curh = (double)(params->adxx[i] * dy2 - dxy2 +
112 params->adyy[i] * dx2) /
113 (grad2 * dnorm1);
114
115 temp = grad2 + 1.;
116 curm = .5 *
117 ((1. + dy2) * params->adxx[i] - dxy2 +
118 (1. + dx2) * params->adyy[i]) /
119 (temp * dnorm1);
120 }
121 if (first_time_g) {
122 first_time_g = 0;
123 *gmin = *gmax = slp;
124 *c1min = *c1max = curn;
125 *c2min = *c2max = curh;
126 }
127 *gmin = amin1(*gmin, slp);
128 *gmax = amax1(*gmax, slp);
129 *c1min = amin1(*c1min, curn);
130 *c1max = amax1(*c1max, curn);
131 *c2min = amin1(*c2min, curh);
132 *c2max = amax1(*c2max, curh);
133 if (cond1) {
134 params->adx[i] = (FCELL)slp;
135 params->ady[i] = (FCELL)oor;
136 if (cond2) {
137 params->adxx[i] = (FCELL)curn;
138 params->adyy[i] = (FCELL)curh;
139 params->adxy[i] = (FCELL)curm;
140 }
141 }
142 } /* bmask == 1 */
143 }
144 return 1;
145}
#define NULL
Definition ccmath.h:32
int BM_get(struct BM *, int, int)
Gets 'val' from the bitmap.
Definition bitmap.c:213
float FCELL
Definition gis.h:633
#define M_R2D
Definition gis.h:169
double amin1(double, double)
Definition minmax.c:68
double amax1(double, double)
Definition minmax.c:55
int IL_secpar_loop_2d(struct interp_params *params, int ngstc, int nszc, int k, struct BM *bitmask, double *gmin, double *gmax, double *c1min, double *c1max, double *c2min, double *c2max, int cond1, int cond2)
Definition secpar2d.c:29
Definition bitmap.h:17
DCELL * adxy
Definition interpf.h:94
DCELL * adyy
Definition interpf.h:94
DCELL * adx
Definition interpf.h:94
DCELL * ady
Definition interpf.h:94
DCELL * adxx
Definition interpf.h:94