12
12
#include <stdlib.h>
14
15
#include <unistd.h>
15
16
#include <grass/gis.h>
17
#include <grass/raster.h>
16
18
#include <grass/glocale.h>
18
20
#include "local_proto.h"
20
22
void eval_tcor(int method, Gfile * out, Gfile * cosi, Gfile * band,
23
double zenith, int do_scale)
23
25
int row, col, nrows, ncols;
26
double cos_z, cos_i, ref_i;
28
double cos_z, cos_i, ref_i, result;
27
29
double n, sx, sxx, sy, sxy, tx, ty;
28
30
double a, m, cka, ckb, kk;
32
double imin, imax, omin, omax, factor; /* for scaling to input */
31
nrows = G_window_rows();
32
ncols = G_window_cols();
34
nrows = Rast_window_rows();
35
ncols = Rast_window_cols();
34
37
cos_z = cos(D2R * zenith);
39
imin = omin = DBL_MAX;
40
imax = omax = -DBL_MAX;
36
43
/* Calculating regression */
37
44
if (method > NON_LAMBERTIAN) {
39
46
for (row = 0; row < nrows; row++) {
40
47
G_percent(row, nrows, 2);
42
G_get_raster_row(band->fd, band->rast, row, DCELL_TYPE);
43
G_get_raster_row(cosi->fd, cosi->rast, row, cosi->type);
49
Rast_get_row(band->fd, band->rast, row, band->type);
50
Rast_get_row(cosi->fd, cosi->rast, row, cosi->type);
45
55
for (col = 0; col < ncols; col++) {
48
pcos = (void *)((FCELL *) cosi->rast + col);
49
cos_i = (double)((FCELL *) cosi->rast)[col];
52
pcos = (void *)((DCELL *) cosi->rast + col);
53
cos_i = (double)((DCELL *) cosi->rast)[col];
60
pref = (void *)((DCELL *) band->rast + col);
57
cos_i = Rast_get_d_value(pcos, cosi->type);
62
if (!G_is_null_value(pref, DCELL_TYPE) &&
63
!G_is_null_value(pcos, cosi->type)) {
64
ref_i = (double)*((DCELL *) pref);
59
if (!Rast_is_null_value(pref, band->type) &&
60
!Rast_is_null_value(pcos, cosi->type)) {
61
ref_i = Rast_get_d_value(pref, band->type);
67
70
if (cos_i > 0. && cos_z > 0. && ref_i > 0.) {
123
/* Topographic correction, pass 1 */
124
for (row = 0; row < nrows; row++) {
125
G_percent(row, nrows, 2);
127
Rast_get_row(band->fd, band->rast, row, band->type);
128
Rast_get_row(cosi->fd, cosi->rast, row, cosi->type);
133
for (col = 0; col < ncols; col++) {
135
cos_i = Rast_get_d_value(pcos, cosi->type);
137
if (!Rast_is_null_value(pref, band->type) &&
138
!Rast_is_null_value(pcos, cosi->type)) {
140
ref_i = Rast_get_d_value(pref, band->type);
141
result = (DCELL) (ref_i * pow((cos_z + cka) /
144
"Old val: %f, cka: %f, cos_i: %f, ckb: %f, kk: %f, New val: %f",
145
ref_i, cka, cos_i, ckb, kk, result);
153
pref = G_incr_void_ptr(pref, Rast_cell_size(band->type));
154
pcos = G_incr_void_ptr(pcos, Rast_cell_size(cosi->type));
158
factor = (imax - imin) / (omax - omin);
116
160
/* Topographic correction */
117
161
for (row = 0; row < nrows; row++) {
118
162
G_percent(row, nrows, 2);
120
G_get_raster_row(band->fd, band->rast, row, band->type);
121
G_get_raster_row(cosi->fd, cosi->rast, row, cosi->type);
164
Rast_get_row(band->fd, band->rast, row, band->type);
165
Rast_get_row(cosi->fd, cosi->rast, row, cosi->type);
170
Rast_set_null_value(out->rast, ncols, DCELL_TYPE);
123
172
for (col = 0; col < ncols; col++) {
124
switch (cosi->type) {
126
pcos = (void *)((FCELL *) cosi->rast + col);
127
cos_i = (double)*((FCELL *) pcos);
130
pcos = (void *)((DCELL *) cosi->rast + col);
131
cos_i = (double)*((DCELL *) pcos);
138
pref = (void *)((DCELL *) band->rast + col);
141
G_is_null_value(pref, DCELL_TYPE) ||
142
G_is_null_value(pcos, cosi->type)) {
143
G_set_null_value((DCELL *) out->rast + col, 1, DCELL_TYPE);
146
ref_i = (double)*((DCELL *) pref);
147
((DCELL *) out->rast)[col] =
148
(DCELL) (ref_i * pow((cos_z + cka) / (cos_i + ckb), kk));
174
cos_i = Rast_get_d_value(pcos, cosi->type);
176
if (!Rast_is_null_value(pref, band->type) &&
177
!Rast_is_null_value(pcos, cosi->type)) {
179
ref_i = Rast_get_d_value(pref, band->type);
180
result = (DCELL) (ref_i * pow((cos_z + cka) /
184
result = (result - omin) * factor + imin;
186
((DCELL *) out->rast)[col] = result;
150
188
"Old val: %f, cka: %f, cos_i: %f, ckb: %f, kk: %f, New val: %f",
151
189
ref_i, cka, cos_i, ckb, kk,
152
190
((DCELL *) out->rast)[col]);
192
pref = G_incr_void_ptr(pref, Rast_cell_size(band->type));
193
pcos = G_incr_void_ptr(pcos, Rast_cell_size(cosi->type));
155
G_put_raster_row(out->fd, out->rast, out->type);
195
Rast_put_row(out->fd, out->rast, out->type);