~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.li/r.li.pielou/pielou.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <math.h>
21
21
 
22
22
#include <grass/gis.h>
 
23
#include <grass/raster.h>
23
24
#include <grass/glocale.h>
24
25
 
25
26
#include "../r.li.daemon/daemon.h"
42
43
    module = G_define_module();
43
44
    module->description =
44
45
        _("Calculates Pielou's diversity index on a raster map");
45
 
    module->keywords =
46
 
        _("raster, landscape structure analysis, diversity index");
 
46
    G_add_keyword(_("raster"));
 
47
    G_add_keyword(_("landscape structure analysis"));
 
48
    G_add_keyword(_("diversity index"));
47
49
 
48
50
    /* define options */
49
51
 
50
 
    raster = G_define_standard_option(G_OPT_R_MAP);
 
52
    raster = G_define_standard_option(G_OPT_R_INPUT);
51
53
 
52
54
    conf = G_define_standard_option(G_OPT_F_INPUT);
53
 
    conf->key = "conf";
 
55
    conf->key = "config";
54
56
    conf->description = _("Configuration file");
55
57
    conf->required = YES;
56
58
 
121
123
    long area = 0;
122
124
 
123
125
    avl_tree albero = NULL;
124
 
    AVL_table *array;
 
126
    AVL_table array;
125
127
    generic_cell uc;
126
128
 
127
129
    uc.t = CELL_TYPE;
138
140
        masked = TRUE;
139
141
    }
140
142
 
141
 
    G_set_c_null_value(&precCell, 1);
 
143
    Rast_set_c_null_value(&precCell, 1);
142
144
    for (j = 0; j < ad->rl; j++) {      /* for each row */
143
145
        if (masked) {
144
146
            if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
153
155
            corrCell = buf[i + ad->x];
154
156
 
155
157
            if ((masked) && (mask_buf[i] == 0)) {
156
 
                G_set_c_null_value(&corrCell, 1);
 
158
                Rast_set_c_null_value(&corrCell, 1);
157
159
            }
158
160
 
159
 
            if (!(G_is_null_value(&corrCell, uc.t))) {
 
161
            if (!(Rast_is_null_value(&corrCell, uc.t))) {
160
162
                /* total patch area */
161
163
                area++;
162
164
            }
163
165
 
164
 
            if (!(G_is_null_value(&precCell, uc.t)) &&
 
166
            if (!(Rast_is_null_value(&precCell, uc.t)) &&
165
167
                corrCell == precCell) {
166
168
 
167
169
                totCorr++;
168
170
            }
169
 
            else if (!(G_is_null_value(&precCell, uc.t)) &&
 
171
            else if (!(Rast_is_null_value(&precCell, uc.t)) &&
170
172
                     corrCell != precCell) {
171
173
                
172
174
                /* add precCell to search tree */
211
213
    }
212
214
 
213
215
    /* last closing */
214
 
    if (area > 0 && !(G_is_null_value(&precCell, uc.t))) {
 
216
    if (area > 0 && !(Rast_is_null_value(&precCell, uc.t))) {
215
217
        if (albero == NULL) {
216
218
            uc.val.c = precCell;
217
219
            albero = avl_make(uc, totCorr);
267
269
        /* calculate shannon */
268
270
        shannon = 0;
269
271
        for (i = 0; i < m; i++) {
270
 
            t = array[i]->tot;
 
272
            t = array[i].tot;
271
273
            perc = t / area;
272
274
            logarithm = log(perc);
273
275
            shannon += perc * logarithm;
277
279
        *result = -shannon / log(m);
278
280
    }
279
281
    else
280
 
        G_set_d_null_value(result, 1);
 
282
        Rast_set_d_null_value(result, 1);
281
283
 
282
284
    avl_destroy(albero);
283
285
    if (masked) {
308
310
    long area = 0;
309
311
 
310
312
    avl_tree albero = NULL;
311
 
    AVL_table *array;
 
313
    AVL_table array;
312
314
    generic_cell uc;
313
315
 
314
316
    uc.t = DCELL_TYPE;
325
327
        masked = TRUE;
326
328
    }
327
329
 
328
 
    G_set_d_null_value(&precCell, 1);
 
330
    Rast_set_d_null_value(&precCell, 1);
329
331
    for (j = 0; j < ad->rl; j++) {      /* for each row */
330
332
        if (masked) {
331
333
            if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
340
342
            corrCell = buf[i + ad->x];
341
343
 
342
344
            if ((masked) && (mask_buf[i] == 0)) {
343
 
                G_set_d_null_value(&corrCell, 1);
 
345
                Rast_set_d_null_value(&corrCell, 1);
344
346
            }
345
347
 
346
 
            if (!(G_is_null_value(&corrCell, uc.t))) {
 
348
            if (!(Rast_is_null_value(&corrCell, uc.t))) {
347
349
                /* total patch area */
348
350
                area++;
349
351
            }
350
352
 
351
 
            if (!(G_is_null_value(&precCell, uc.t)) &&
 
353
            if (!(Rast_is_null_value(&precCell, uc.t)) &&
352
354
                corrCell == precCell) {
353
355
 
354
356
                totCorr++;
355
357
            }
356
 
            else if (!(G_is_null_value(&precCell, uc.t)) &&
 
358
            else if (!(Rast_is_null_value(&precCell, uc.t)) &&
357
359
                     corrCell != precCell) {
358
360
                
359
361
                /* add precCell to search tree */
398
400
    }
399
401
 
400
402
    /* last closing */
401
 
    if (area > 0 && !(G_is_null_value(&precCell, uc.t))) {
 
403
    if (area > 0 && !(Rast_is_null_value(&precCell, uc.t))) {
402
404
        if (albero == NULL) {
403
405
            uc.val.dc = precCell;
404
406
            albero = avl_make(uc, totCorr);
454
456
        /* calculate shannon */
455
457
        shannon = 0;
456
458
        for (i = 0; i < m; i++) {
457
 
            t = array[i]->tot;
 
459
            t = array[i].tot;
458
460
            perc = t / area;
459
461
            logarithm = log(perc);
460
462
            shannon += perc * logarithm;
464
466
        *result = -shannon / log(m);
465
467
    }
466
468
    else
467
 
        G_set_d_null_value(result, 1);
 
469
        Rast_set_d_null_value(result, 1);
468
470
 
469
471
    avl_destroy(albero);
470
472
    if (masked) {
495
497
    long area = 0;
496
498
 
497
499
    avl_tree albero = NULL;
498
 
    AVL_table *array;
 
500
    AVL_table array;
499
501
    generic_cell uc;
500
502
 
501
503
    uc.t = FCELL_TYPE;
512
514
        masked = TRUE;
513
515
    }
514
516
 
515
 
    G_set_f_null_value(&precCell, 1);
 
517
    Rast_set_f_null_value(&precCell, 1);
516
518
    for (j = 0; j < ad->rl; j++) {      /* for each row */
517
519
        if (masked) {
518
520
            if (read(mask_fd, mask_buf, (ad->cl * sizeof(int))) < 0) {
527
529
            corrCell = buf[i + ad->x];
528
530
 
529
531
            if ((masked) && (mask_buf[i] == 0)) {
530
 
                G_set_f_null_value(&corrCell, 1);
 
532
                Rast_set_f_null_value(&corrCell, 1);
531
533
            }
532
534
 
533
 
            if (!(G_is_null_value(&corrCell, uc.t))) {
 
535
            if (!(Rast_is_null_value(&corrCell, uc.t))) {
534
536
                /* total patch area */
535
537
                area++;
536
538
            }
537
539
 
538
 
            if (!(G_is_null_value(&precCell, uc.t)) &&
 
540
            if (!(Rast_is_null_value(&precCell, uc.t)) &&
539
541
                corrCell == precCell) {
540
542
 
541
543
                totCorr++;
542
544
            }
543
 
            else if (!(G_is_null_value(&precCell, uc.t)) &&
 
545
            else if (!(Rast_is_null_value(&precCell, uc.t)) &&
544
546
                     corrCell != precCell) {
545
547
                
546
548
                /* add precCell to search tree */
585
587
    }
586
588
 
587
589
    /* last closing */
588
 
    if (area > 0 && !(G_is_null_value(&precCell, uc.t))) {
 
590
    if (area > 0 && !(Rast_is_null_value(&precCell, uc.t))) {
589
591
        if (albero == NULL) {
590
592
            uc.val.fc = precCell;
591
593
            albero = avl_make(uc, totCorr);
641
643
        /* calculate shannon */
642
644
        shannon = 0;
643
645
        for (i = 0; i < m; i++) {
644
 
            t = array[i]->tot;
 
646
            t = array[i].tot;
645
647
            perc = t / area;
646
648
            logarithm = log(perc);
647
649
            shannon += perc * logarithm;
651
653
        *result = -shannon / log(m);
652
654
    }
653
655
    else
654
 
        G_set_d_null_value(result, 1);
 
656
        Rast_set_d_null_value(result, 1);
655
657
 
656
658
    avl_destroy(albero);
657
659
    if (masked) {