|
@@ -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@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 @@ int dominance(int fd, char **par, struct area_entry *ad, double *result)
|
|
|
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 @@ int dominance(int fd, char **par, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ 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 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
if (Rast_is_null_value(&precCell, cc.t)) {
|
|
|
precCell = corrCell;
|
|
|
}
|
|
|
-
|
|
|
if (corrCell != precCell) {
|
|
|
if (albero == NULL) {
|
|
|
cc.val.c = precCell;
|
|
@@ -193,6 +181,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
G_fatal_error("avl_make error");
|
|
|
return RLI_ERRORE;
|
|
|
}
|
|
|
+ /* TODO missing?: else - see r.li.simpson/simpson.c */
|
|
|
m++;
|
|
|
}
|
|
|
else {
|
|
@@ -231,10 +220,8 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
} /* 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 @@ int calculate(int fd, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculateD(int fd, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculateD(int fd, struct area_entry *ad, double *result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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 @@ int calculateD(int fd, struct area_entry *ad, double *result)
|
|
|
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 calculateD(int fd, struct area_entry *ad, double *result)
|
|
|
|
|
|
int calculateF(int fd, struct area_entry *ad, double *result)
|
|
|
{
|
|
|
-
|
|
|
FCELL *buf;
|
|
|
FCELL corrCell;
|
|
|
FCELL precCell;
|
|
@@ -571,11 +545,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
|
|
|
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 @@ int calculateF(int fd, struct area_entry *ad, double *result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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 @@ int calculateF(int fd, struct area_entry *ad, double *result)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/*last closing */
|
|
|
if (a != 0) {
|
|
|
if (albero == NULL) {
|
|
@@ -711,18 +683,15 @@ int calculateF(int fd, struct area_entry *ad, double *result)
|
|
|
|
|
|
G_free(array);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
else /*if a is 0, that is all cell are null, i put index=-1 */
|
|
|
- indice = (double)(-1);
|
|
|
-
|
|
|
-
|
|
|
- *result = indice;
|
|
|
-
|
|
|
+ indice = (double)(-1);
|
|
|
|
|
|
|
|
|
if (masked) {
|
|
|
G_free(mask_buf);
|
|
|
}
|
|
|
+
|
|
|
+ *result = indice;
|
|
|
+
|
|
|
return RLI_OK;
|
|
|
}
|