diff --git a/src/raster/r.accumulate/accumulate_iterative.c b/src/raster/r.accumulate/accumulate_iterative.c index 5348bfb947..2fbd7be198 100644 --- a/src/raster/r.accumulate/accumulate_iterative.c +++ b/src/raster/r.accumulate/accumulate_iterative.c @@ -135,7 +135,7 @@ static void trace_up(struct cell_map *dir_buf, struct raster_map *weight_buf, /* if a weight map is specified (no negative accumulation is * implied), use the weight value at the current cell; * otherwise use 1 */ - accum += weight_buf->map.v + accum += weight_buf->cells.v ? get(weight_buf, cur_up->row, cur_up->col) : 1.0; @@ -213,7 +213,7 @@ static void find_up(struct cell_map *dir_buf, struct raster_map *weight_buf, if (!*nup) { /* if a weight map is specified (no negative accumulation is implied), * use the weight value at the current cell; otherwise use 1 */ - double accum = weight_buf->map.v ? get(weight_buf, row, col) : 1.0; + double accum = weight_buf->cells.v ? get(weight_buf, row, col) : 1.0; /* if negative accumulation is desired and the current cell is * incomplete, use a negative cell count without weighting; otherwise diff --git a/src/raster/r.accumulate/accumulate_recursive.c b/src/raster/r.accumulate/accumulate_recursive.c index 781dd33dd7..06fb16726d 100644 --- a/src/raster/r.accumulate/accumulate_recursive.c +++ b/src/raster/r.accumulate/accumulate_recursive.c @@ -48,7 +48,7 @@ static double trace_up(struct cell_map *dir_buf, struct raster_map *weight_buf, /* if a weight map is specified (no negative accumulation is implied), use * the weight value at the current cell; otherwise use 1 */ - accum = weight_buf->map.v ? get(weight_buf, row, col) : 1.0; + accum = weight_buf->cells.v ? get(weight_buf, row, col) : 1.0; /* loop through all neighbor cells and see if any of them drains into the * current cell (are there upstream cells?) */ diff --git a/src/raster/r.accumulate/calculate_lfp_iterative.c b/src/raster/r.accumulate/calculate_lfp_iterative.c index d9cad2d49f..b094504c1f 100644 --- a/src/raster/r.accumulate/calculate_lfp_iterative.c +++ b/src/raster/r.accumulate/calculate_lfp_iterative.c @@ -314,9 +314,10 @@ static void find_up(struct cell_map *dir_buf, struct raster_map *accum_buf, /* diagonal if i * j == -1 or 1 * horizontal if i == 0 * vertical if j == 0 */ - double length = down_length + (i * j ? diag_length - : (i ? window.ns_res - : window.ew_res)); + double length = + down_length + + (i && j ? diag_length + : (i ? window.ns_res : window.ew_res)); up[*nup].row = row + i; up[*nup].col = col + j; diff --git a/src/raster/r.accumulate/calculate_lfp_recursive.c b/src/raster/r.accumulate/calculate_lfp_recursive.c index 930a30dbb7..9da5e32cf6 100644 --- a/src/raster/r.accumulate/calculate_lfp_recursive.c +++ b/src/raster/r.accumulate/calculate_lfp_recursive.c @@ -248,9 +248,10 @@ static int trace_up(struct cell_map *dir_buf, struct raster_map *accum_buf, /* diagonal if i * j == -1 or 1 * horizontal if i == 0 * vertical if j == 0 */ - double length = down_length + (i * j ? diag_length - : (i ? window.ns_res - : window.ew_res)); + double length = + down_length + + (i && j ? diag_length + : (i ? window.ns_res : window.ew_res)); up[nup].row = row + i; up[nup].col = col + j; diff --git a/src/raster/r.accumulate/global.h b/src/raster/r.accumulate/global.h index db01d1d26f..f86e665131 100644 --- a/src/raster/r.accumulate/global.h +++ b/src/raster/r.accumulate/global.h @@ -34,7 +34,7 @@ struct raster_map { CELL **c; FCELL **f; DCELL **d; - } map; + } cells; }; struct point_list { diff --git a/src/raster/r.accumulate/main.c b/src/raster/r.accumulate/main.c index 1dc0c08194..f234d99ad8 100644 --- a/src/raster/r.accumulate/main.c +++ b/src/raster/r.accumulate/main.c @@ -491,23 +491,23 @@ int main(int argc, char *argv[]) accum_buf.nrows = nrows; accum_buf.ncols = ncols; - accum_buf.map.v = (void **)G_malloc(nrows * sizeof(void *)); + accum_buf.cells.v = (void **)G_malloc(nrows * sizeof(void *)); /* optionally, read a weight map */ - weight_buf.map.v = NULL; + weight_buf.cells.v = NULL; if (weight_name) { int weight_fd = Rast_open_old(weight_name, ""); accum_buf.type = weight_buf.type = Rast_get_map_type(weight_fd); weight_buf.nrows = nrows; weight_buf.ncols = ncols; - weight_buf.map.v = (void **)G_malloc(nrows * sizeof(void *)); + weight_buf.cells.v = (void **)G_malloc(nrows * sizeof(void *)); G_message(_("Reading weight map...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 1); - weight_buf.map.v[row] = + weight_buf.cells.v[row] = (void *)Rast_allocate_buf(weight_buf.type); - Rast_get_row(weight_fd, weight_buf.map.v[row], row, + Rast_get_row(weight_fd, weight_buf.cells.v[row], row, weight_buf.type); } G_percent(1, 1, 1); @@ -528,9 +528,9 @@ int main(int argc, char *argv[]) : _("Reading subaccumulation map...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 1); - accum_buf.map.v[row] = + accum_buf.cells.v[row] = (void *)Rast_allocate_buf(accum_buf.type); - Rast_get_row(accum_fd, accum_buf.map.v[row], row, + Rast_get_row(accum_fd, accum_buf.cells.v[row], row, accum_buf.type); } G_percent(1, 1, 1); @@ -544,7 +544,7 @@ int main(int argc, char *argv[]) for (row = 0; row < nrows; row++) { G_percent(row, nrows, 1); done[row] = (char *)G_calloc(ncols, 1); - accum_buf.map.v[row] = + accum_buf.cells.v[row] = (void *)Rast_allocate_buf(accum_buf.type); } G_percent(1, 1, 1); @@ -562,10 +562,10 @@ int main(int argc, char *argv[]) } /* free buffer memory */ - if (weight_buf.map.v) { + if (weight_buf.cells.v) { for (row = 0; row < nrows; row++) - G_free(weight_buf.map.v[row]); - G_free(weight_buf.map.v); + G_free(weight_buf.cells.v[row]); + G_free(weight_buf.cells.v); } /* write out buffer to the accumulation map if requested */ @@ -576,7 +576,7 @@ int main(int argc, char *argv[]) G_message(_("Writing accumulation map...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 1); - Rast_put_row(accum_fd, accum_buf.map.v[row], accum_buf.type); + Rast_put_row(accum_fd, accum_buf.cells.v[row], accum_buf.type); } G_percent(1, 1, 1); Rast_close(accum_fd); @@ -595,7 +595,7 @@ int main(int argc, char *argv[]) } } else - accum_buf.map.v = NULL; + accum_buf.cells.v = NULL; /* delineate stream networks */ if (stream_name) { @@ -625,7 +625,8 @@ int main(int argc, char *argv[]) G_message(_("Writing subaccumulation map...")); for (row = 0; row < nrows; row++) { G_percent(row, nrows, 1); - Rast_put_row(subaccum_fd, accum_buf.map.v[row], accum_buf.type); + Rast_put_row(subaccum_fd, accum_buf.cells.v[row], + accum_buf.type); } G_percent(1, 1, 1); Rast_close(subaccum_fd); @@ -664,10 +665,10 @@ int main(int argc, char *argv[]) } /* free buffer memory */ - if (accum_buf.map.v) { + if (accum_buf.cells.v) { for (row = 0; row < nrows; row++) - G_free(accum_buf.map.v[row]); - G_free(accum_buf.map.v); + G_free(accum_buf.cells.v[row]); + G_free(accum_buf.cells.v); } /* delineate subwatersheds; this process overwrites dir_buf to save memory diff --git a/src/raster/r.accumulate/raster.c b/src/raster/r.accumulate/raster.c index 5db6e71e2c..167c9b310d 100644 --- a/src/raster/r.accumulate/raster.c +++ b/src/raster/r.accumulate/raster.c @@ -5,13 +5,13 @@ void set(struct raster_map *buf, int row, int col, double value) { switch (buf->type) { case CELL_TYPE: - buf->map.c[row][col] = (CELL)value; + buf->cells.c[row][col] = (CELL)value; break; case FCELL_TYPE: - buf->map.f[row][col] = (FCELL)value; + buf->cells.f[row][col] = (FCELL)value; break; case DCELL_TYPE: - buf->map.d[row][col] = (DCELL)value; + buf->cells.d[row][col] = (DCELL)value; break; } } @@ -22,13 +22,13 @@ double get(struct raster_map *buf, int row, int col) switch (buf->type) { case CELL_TYPE: - value = (double)buf->map.c[row][col]; + value = (double)buf->cells.c[row][col]; break; case FCELL_TYPE: - value = (double)buf->map.f[row][col]; + value = (double)buf->cells.f[row][col]; break; case DCELL_TYPE: - value = buf->map.d[row][col]; + value = buf->cells.d[row][col]; break; } @@ -41,13 +41,13 @@ int is_null(struct raster_map *buf, int row, int col) switch (buf->type) { case CELL_TYPE: - is_null_value = Rast_is_c_null_value(&buf->map.c[row][col]); + is_null_value = Rast_is_c_null_value(&buf->cells.c[row][col]); break; case FCELL_TYPE: - is_null_value = Rast_is_f_null_value(&buf->map.f[row][col]); + is_null_value = Rast_is_f_null_value(&buf->cells.f[row][col]); break; case DCELL_TYPE: - is_null_value = Rast_is_d_null_value(&buf->map.d[row][col]); + is_null_value = Rast_is_d_null_value(&buf->cells.d[row][col]); break; } @@ -58,13 +58,13 @@ void set_null(struct raster_map *buf, int row, int col) { switch (buf->type) { case CELL_TYPE: - Rast_set_c_null_value(&buf->map.c[row][col], 1); + Rast_set_c_null_value(&buf->cells.c[row][col], 1); break; case FCELL_TYPE: - Rast_set_f_null_value(&buf->map.f[row][col], 1); + Rast_set_f_null_value(&buf->cells.f[row][col], 1); break; case DCELL_TYPE: - Rast_set_d_null_value(&buf->map.d[row][col], 1); + Rast_set_d_null_value(&buf->cells.d[row][col], 1); break; } }