[GRASS-SVN] r58994 - grass/branches/develbranch_6/raster/r.li/r.li.dominance
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 11 06:04:11 PST 2014
Author: neteler
Date: 2014-02-11 06:04:10 -0800 (Tue, 11 Feb 2014)
New Revision: 58994
Modified:
grass/branches/develbranch_6/raster/r.li/r.li.dominance/dominance.c
Log:
r.li.dominance: code style updated to that of r.li.simpson
Modified: grass/branches/develbranch_6/raster/r.li/r.li.dominance/dominance.c
===================================================================
--- grass/branches/develbranch_6/raster/r.li/r.li.dominance/dominance.c 2014-02-11 14:04:03 UTC (rev 58993)
+++ grass/branches/develbranch_6/raster/r.li/r.li.dominance/dominance.c 2014-02-11 14:04:10 UTC (rev 58994)
@@ -6,7 +6,7 @@
*
* This program is free software under the GPL (>=v2)
* Read the COPYING file that comes with GRASS for details.
- *
+ *
*/
#include <grass/gis.h>
@@ -44,8 +44,8 @@
conf = G_define_option();
conf->key = "conf";
conf->description = _("Configuration file");
- conf->gisprompt = "old_file,file,input";
conf->type = TYPE_STRING;
+ conf->gisprompt = "old_file,file,input";
conf->required = YES;
output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -61,35 +61,29 @@
int dominance(int fd, char **par, struct area_entry *ad, double *result)
{
-
char *mapset;
-
int ris = RLI_OK;
-
double indice = 0;
-
struct Cell_head hd;
-
mapset = G_find_cell(ad->raster, "");
if (G_get_cellhd(ad->raster, mapset, &hd) == -1)
return RLI_ERRORE;
-
switch (ad->data_type) {
case CELL_TYPE:
{
- calculate(fd, ad, &indice);
+ ris = calculate(fd, ad, &indice);
break;
}
case DCELL_TYPE:
{
- calculateD(fd, ad, &indice);
+ ris = calculateD(fd, ad, &indice);
break;
}
case FCELL_TYPE:
{
- calculateF(fd, ad, &indice);
+ ris = calculateF(fd, ad, &indice);
break;
}
default:
@@ -97,12 +91,12 @@
G_fatal_error("data type unknown");
return RLI_ERRORE;
}
- }
- if (ris != RLI_OK) {
- return RLI_ERRORE;
}
+ if (ris != RLI_OK)
+ return RLI_ERRORE;
+
*result = indice;
return RLI_OK;
@@ -135,12 +129,10 @@
double t;
double logaritmo;
- generic_cell cc;
-
avl_tree albero = NULL;
-
AVL_table *array;
+ generic_cell cc;
cc.t = CELL_TYPE;
@@ -156,15 +148,9 @@
masked = TRUE;
}
-
G_set_c_null_value(&precCell, 1);
-
- /*for each row */
- for (j = 0; j < ad->rl; j++) {
- buf = RLI_get_cell_raster_row(fd, j + ad->y, ad);
-
-
+ for (j = 0; j < ad->rl; j++) { /* for each row */
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
@@ -172,12 +158,12 @@
}
}
-
+ buf = RLI_get_cell_raster_row(fd, j + ad->y, ad);
for (i = 0; i < ad->cl; i++) { /* for each cell in the row */
area++;
corrCell = buf[i + ad->x];
- if (masked && mask_buf[i + ad->x] == 0) {
+ if ((masked) && (mask_buf[i + ad->x] == 0)) {
G_set_c_null_value(&corrCell, 1);
area--;
}
@@ -187,7 +173,6 @@
if (G_is_null_value(&precCell, cc.t)) {
precCell = corrCell;
}
-
if (corrCell != precCell) {
if (albero == NULL) {
cc.val.c = precCell;
@@ -197,6 +182,7 @@
G_fatal_error("avl_make error");
return RLI_ERRORE;
}
+ /* TODO missing?: else - see r.li.simpson/simpson.c */
m++;
}
else {
@@ -235,10 +221,8 @@
} /* end for */
} /* end for */
-
-
+ /*last closing */
if (a != 0) {
- /*last closing */
if (albero == NULL) {
cc.val.c = precCell;
albero = avl_make(cc, totCorr);
@@ -306,25 +290,18 @@
else /*if a is 0, that is all cell are null, i put index=-1 */
indice = (double)(-1);
- *result = indice;
-
- if (masked) {
+ if (masked)
G_free(mask_buf);
- }
+ *result = indice;
+
return RLI_OK;
}
-
-
-
-
-
int calculateD(int fd, struct area_entry *ad, double *result)
{
-
DCELL *buf;
DCELL corrCell;
DCELL precCell;
@@ -367,14 +344,9 @@
masked = TRUE;
}
-
G_set_d_null_value(&precCell, 1);
- /*for each row */
- for (j = 0; j < ad->rl; j++) {
- buf = RLI_get_dcell_raster_row(fd, j + ad->y, ad);
-
-
+ for (j = 0; j < ad->rl; j++) { /* for each row */
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
@@ -382,6 +354,7 @@
}
}
+ buf = RLI_get_dcell_raster_row(fd, j + ad->y, ad);
for (i = 0; i < ad->cl; i++) { /* for each dcell in the row */
area++;
@@ -447,9 +420,8 @@
G_free(mask_buf);
}
-
- if (a != 0) {
/*last closing */
+ if (a != 0) {
if (albero == NULL) {
cc.val.dc = precCell;
albero = avl_make(cc, totCorr);
@@ -528,7 +500,6 @@
int calculateF(int fd, struct area_entry *ad, double *result)
{
-
FCELL *buf;
FCELL corrCell;
FCELL precCell;
@@ -571,15 +542,10 @@
masked = TRUE;
}
-
G_set_f_null_value(&precCell, 1);
- /*for each row */
- for (j = 0; j < ad->rl; j++) {
- buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
-
-
+ for (j = 0; j < ad->rl; j++) { /* for each row */
if (masked) {
if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
G_fatal_error("mask read failed");
@@ -587,10 +553,13 @@
}
}
+ buf = RLI_get_fcell_raster_row(fd, j + ad->y, ad);
for (i = 0; i < ad->cl; i++) { /* for each fcell in the row */
+
area++;
corrCell = buf[i + ad->x];
+
if (masked && mask_buf[i + ad->x] == 0) {
G_set_f_null_value(&corrCell, 1);
area--;
@@ -648,7 +617,6 @@
}
}
-
/*last closing */
if (a != 0) {
if (albero == NULL) {
@@ -715,18 +683,15 @@
G_free(array);
}
-
-
else /*if a is 0, that is all cell are null, i put index=-1 */
- indice = (double)(-1);
+ indice = (double)(-1);
- *result = indice;
-
-
-
if (masked) {
G_free(mask_buf);
}
+
+ *result = indice;
+
return RLI_OK;
}
More information about the grass-commit
mailing list