[GRASS-SVN] r58995 - grass/trunk/raster/r.li/r.li.dominance

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 11 06:04:31 PST 2014


Author: neteler
Date: 2014-02-11 06:04:30 -0800 (Tue, 11 Feb 2014)
New Revision: 58995

Modified:
   grass/trunk/raster/r.li/r.li.dominance/dominance.c
Log:
r.li.dominance: code style updated to that of r.li.simpson (port of r58994)

Modified: grass/trunk/raster/r.li/r.li.dominance/dominance.c
===================================================================
--- grass/trunk/raster/r.li/r.li.dominance/dominance.c	2014-02-11 14:04:10 UTC (rev 58994)
+++ grass/trunk/raster/r.li/r.li.dominance/dominance.c	2014-02-11 14:04:30 UTC (rev 58995)
@@ -6,8 +6,6 @@
  *
  *   This program is free software under the GPL (>=v2)
  *   Read the COPYING file that comes with GRASS for details.
- *       
- *       \BUGS: please send bugs reports to pallecch at cli.di.unipi.it
  *
  */
 
@@ -24,7 +22,6 @@
 #include "../r.li.daemon/avl.h"
 #include "../r.li.daemon/daemon.h"
 
-
 int calculate(int fd, struct area_entry *ad, double *result);
 int calculateD(int fd, struct area_entry *ad, double *result);
 int calculateF(int fd, struct area_entry *ad, double *result);
@@ -75,17 +72,17 @@
     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:
@@ -93,12 +90,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;
@@ -131,12 +128,10 @@
     double t;
     double logaritmo;
 
-    generic_cell cc;
-
     avl_tree albero = NULL;
-
     AVL_table *array;
 
+    generic_cell cc;
 
     cc.t = CELL_TYPE;
 
@@ -152,15 +147,9 @@
 	masked = TRUE;
     }
 
-
     Rast_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");
@@ -168,7 +157,7 @@
 	    }
 	}
 
-
+	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];
@@ -183,7 +172,6 @@
 		if (Rast_is_null_value(&precCell, cc.t)) {
 		    precCell = corrCell;
 		}
-
 		if (corrCell != precCell) {
 		    if (albero == NULL) {
 			cc.val.c = precCell;
@@ -193,6 +181,7 @@
 			    G_fatal_error("avl_make error");
 			    return RLI_ERRORE;
 			}
+			/* TODO missing?: else  - see r.li.simpson/simpson.c */
 			m++;
 		    }
 		    else {
@@ -231,10 +220,8 @@
 	}			/* end for */
     }				/* end for */
 
-
-
+    /*last closing */
     if (a != 0) {
-	/*last closing */
 	if (albero == NULL) {
 	    cc.val.c = precCell;
 	    albero = avl_make(cc, totCorr);
@@ -302,25 +289,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;
@@ -363,14 +343,9 @@
 	masked = TRUE;
     }
 
-
     Rast_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");
@@ -378,6 +353,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++;
@@ -443,9 +419,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);
@@ -524,7 +499,6 @@
 
 int calculateF(int fd, struct area_entry *ad, double *result)
 {
-
     FCELL *buf;
     FCELL corrCell;
     FCELL precCell;
@@ -571,11 +545,7 @@
     Rast_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");
@@ -583,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) {
 		Rast_set_f_null_value(&corrCell, 1);
 		area--;
@@ -644,7 +617,6 @@
 	}
     }
 
-
     /*last closing */
     if (a != 0) {
 	if (albero == NULL) {
@@ -711,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