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

« back to all changes in this revision

Viewing changes to raster/r.li/r.li.cwed/cwed.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:
19
19
#include <fcntl.h>              /* for O_RDONLY usage */
20
20
 
21
21
#include <grass/gis.h>
 
22
#include <grass/raster.h>
22
23
#include <grass/glocale.h>
23
24
 
24
25
#include "../r.li.daemon/defs.h"
50
51
    module = G_define_module();
51
52
    module->description =
52
53
        _("Calculates contrast weighted edge density index on a raster map");
53
 
    module->keywords = _("raster, landscape structure analysis, patch index");
 
54
    G_add_keyword(_("raster"));
 
55
    G_add_keyword(_("landscape structure analysis"));
 
56
    G_add_keyword(_("patch index"));
54
57
 
55
58
    /* define options */
56
59
 
57
 
    raster = G_define_standard_option(G_OPT_R_MAP);
 
60
    raster = G_define_standard_option(G_OPT_R_INPUT);
58
61
 
59
62
    conf = G_define_standard_option(G_OPT_F_INPUT);
60
 
    conf->key = "conf";
 
63
    conf->key = "config";
61
64
    conf->description = _("Configuration file");
62
65
    conf->required = YES;
63
66
 
325
328
        masked = TRUE;
326
329
    }
327
330
 
328
 
    buf_null = G_allocate_cell_buf();
 
331
    buf_null = Rast_allocate_c_buf();
329
332
    if (buf_null == NULL) {
330
333
        G_fatal_error("malloc buf_null failed");
331
334
        return RLI_ERRORE;
335
338
    c2.t = CELL_TYPE;
336
339
 
337
340
    /*the first time buf_sup is all null */
338
 
    G_set_c_null_value(buf_null + ad->x, ad->cl);
 
341
    Rast_set_c_null_value(buf_null + ad->x, ad->cl);
339
342
    buf_sup = buf_null;
340
343
 
341
344
    for (j = 0; j < ad->rl; j++) {      /* for each row */
355
358
            }
356
359
        }
357
360
 
358
 
        G_set_c_null_value(&prevCell, 1);
359
 
        G_set_c_null_value(&corrCell, 1);
 
361
        Rast_set_c_null_value(&prevCell, 1);
 
362
        Rast_set_c_null_value(&corrCell, 1);
360
363
        for (i = 0; i < ad->cl; i++) {  /* for each cell in the row */
361
364
            corrCell = buf_corr[i + ad->x];
362
365
            if (masked && mask_corr[i] == 0) {
363
 
                G_set_c_null_value(&corrCell, 1);
364
 
            }
365
 
            else {
366
 
                /* total sample area */
367
 
                area++;
 
366
                Rast_set_c_null_value(&corrCell, 1);
368
367
            }
369
368
            
370
 
            if (!(G_is_null_value(&corrCell, CELL_TYPE))) {
 
369
            if (!(Rast_is_null_value(&corrCell, CELL_TYPE))) {
 
370
                /* total sample area */
 
371
                area += 1;
 
372
 
371
373
                supCell = buf_sup[i + ad->x];
372
374
                if (masked && (mask_sup[i] == 0)) {
373
 
                    G_set_c_null_value(&supCell, 1);
 
375
                    Rast_set_c_null_value(&supCell, 1);
374
376
                }
375
377
 
376
378
                /* calculate how many edges the cell has */
377
 
                if (((!G_is_null_value(&prevCell, CELL_TYPE))) &&
 
379
                if (((!Rast_is_null_value(&prevCell, CELL_TYPE))) &&
378
380
                    (corrCell != prevCell)) {
379
381
                    int r = 0;
380
382
 
387
389
 
388
390
                }
389
391
 
390
 
                if ((!(G_is_null_value(&supCell, CELL_TYPE))) &&
 
392
                if ((!(Rast_is_null_value(&supCell, CELL_TYPE))) &&
391
393
                    (corrCell != supCell)) {
392
394
                    int r = 0;
393
395
 
473
475
        masked = TRUE;
474
476
    }
475
477
 
476
 
    buf_null = G_allocate_d_raster_buf();
 
478
    buf_null = Rast_allocate_d_buf();
477
479
    if (buf_null == NULL) {
478
480
        G_fatal_error("malloc buf_null failed");
479
481
        return RLI_ERRORE;
483
485
    c2.t = DCELL_TYPE;
484
486
 
485
487
    /*the first time buf_sup is all null */
486
 
    G_set_d_null_value(buf_null + ad->x, ad->cl);
 
488
    Rast_set_d_null_value(buf_null + ad->x, ad->cl);
487
489
    buf_sup = buf_null;
488
490
 
489
491
    for (j = 0; j < ad->rl; j++) {      /* for each row */
502
504
                return RLI_ERRORE;
503
505
            }
504
506
        }
505
 
        G_set_d_null_value(&prevCell, 1);
506
 
        G_set_d_null_value(&corrCell, 1);
 
507
        Rast_set_d_null_value(&prevCell, 1);
 
508
        Rast_set_d_null_value(&corrCell, 1);
507
509
        for (i = 0; i < ad->cl; i++) {  /* for each cell in the row */
508
510
            corrCell = buf_corr[i + ad->x];
509
511
            if (masked && mask_corr[i] == 0) {
510
 
                G_set_d_null_value(&corrCell, 1);
 
512
                Rast_set_d_null_value(&corrCell, 1);
511
513
            }
512
 
            else {
 
514
 
 
515
            if (!(Rast_is_null_value(&corrCell, DCELL_TYPE))) {
513
516
                /* total sample area */
514
 
                area++;
515
 
            }
 
517
                area += 1;
516
518
 
517
 
            if (!(G_is_null_value(&corrCell, DCELL_TYPE))) {
518
519
                supCell = buf_sup[i + ad->x];
519
520
                if (masked && (mask_sup[i] == 0)) {
520
 
                    G_set_d_null_value(&supCell, 1);
 
521
                    Rast_set_d_null_value(&supCell, 1);
521
522
                }
522
523
 
523
524
                /* calculate how many edges the cell has */
524
 
                if (((!G_is_null_value(&prevCell, DCELL_TYPE))) &&
 
525
                if (((!Rast_is_null_value(&prevCell, DCELL_TYPE))) &&
525
526
                    (corrCell != prevCell)) {
526
527
                    int r = 0;
527
528
 
533
534
                }
534
535
 
535
536
 
536
 
                if ((!(G_is_null_value(&supCell, DCELL_TYPE))) &&
 
537
                if ((!(Rast_is_null_value(&supCell, DCELL_TYPE))) &&
537
538
                    (corrCell != supCell)) {
538
539
                    int r = 0;
539
540
 
621
622
    }
622
623
 
623
624
    /* allocate and inizialize buffers */
624
 
    buf_null = G_allocate_f_raster_buf();
 
625
    buf_null = Rast_allocate_f_buf();
625
626
    if (buf_null == NULL) {
626
627
        G_fatal_error("malloc buf_sup failed");
627
628
        return RLI_ERRORE;
628
629
    }
629
630
    /*the first time buf_sup is all null */
630
 
    G_set_f_null_value(buf_null + ad->x, ad->cl);
 
631
    Rast_set_f_null_value(buf_null + ad->x, ad->cl);
631
632
    buf_sup = buf_null;
632
633
 
633
634
    c1.t = FCELL_TYPE;
650
651
                return RLI_ERRORE;
651
652
            }
652
653
        }
653
 
        G_set_f_null_value(&prevCell, 1);
654
 
        G_set_f_null_value(&corrCell, 1);
 
654
        Rast_set_f_null_value(&prevCell, 1);
 
655
        Rast_set_f_null_value(&corrCell, 1);
655
656
        for (i = 0; i < ad->cl; i++) {  /* for each cell in the row */
656
657
            corrCell = buf_corr[i + ad->x];
657
658
            if (masked && mask_corr[i] == 0) {
658
 
                G_set_f_null_value(&corrCell, 1);
 
659
                Rast_set_f_null_value(&corrCell, 1);
659
660
            }
660
 
            else {
 
661
 
 
662
            if (!(Rast_is_null_value(&corrCell, FCELL_TYPE))) {
661
663
                /* total sample area */
662
 
                area++;
663
 
            }
 
664
                area += 1;
664
665
 
665
 
            if (!(G_is_null_value(&corrCell, FCELL_TYPE))) {
666
666
                supCell = buf_sup[i + ad->x];
667
667
                if (masked && (mask_sup[i] == 0)) {
668
 
                    G_set_f_null_value(&supCell, 1);
 
668
                    Rast_set_f_null_value(&supCell, 1);
669
669
                }
670
670
 
671
671
                /* calculate how many edges the cell has */
672
 
                if (((!G_is_null_value(&prevCell, FCELL_TYPE))) &&
 
672
                if (((!Rast_is_null_value(&prevCell, FCELL_TYPE))) &&
673
673
                    (corrCell != prevCell)) {
674
674
                    int r = 0;
675
675
 
680
680
                        return RLI_ERRORE;
681
681
                }
682
682
 
683
 
                if ((!(G_is_null_value(&supCell, FCELL_TYPE))) &&
 
683
                if ((!(Rast_is_null_value(&supCell, FCELL_TYPE))) &&
684
684
                    (corrCell != supCell)) {
685
685
                    int r = 0;
686
686
 
747
747
    switch (ce1.t) {
748
748
    case CELL_TYPE:
749
749
        {
750
 
            if ((G_is_null_value(&ce1.val.c, CELL_TYPE)) ||
751
 
                (G_is_null_value(&ce2.val.c, CELL_TYPE)))
 
750
            if ((Rast_is_null_value(&ce1.val.c, CELL_TYPE)) ||
 
751
                (Rast_is_null_value(&ce2.val.c, CELL_TYPE)))
752
752
                return _ERR;
753
753
            break;
754
754
        }
755
755
    case DCELL_TYPE:
756
756
        {
757
 
            if ((G_is_null_value(&ce1.val.dc, DCELL_TYPE)) ||
758
 
                (G_is_null_value(&ce2.val.dc, DCELL_TYPE)))
 
757
            if ((Rast_is_null_value(&ce1.val.dc, DCELL_TYPE)) ||
 
758
                (Rast_is_null_value(&ce2.val.dc, DCELL_TYPE)))
759
759
                return _ERR;
760
760
            break;
761
761
        }
762
762
    case FCELL_TYPE:
763
763
        {
764
 
            if ((G_is_null_value(&ce1.val.fc, FCELL_TYPE)) ||
765
 
                (G_is_null_value(&ce2.val.fc, FCELL_TYPE)))
 
764
            if ((Rast_is_null_value(&ce1.val.fc, FCELL_TYPE)) ||
 
765
                (Rast_is_null_value(&ce2.val.fc, FCELL_TYPE)))
766
766
                return _ERR;
767
767
            break;
768
768
        }
834
834
    switch (c1.t) {
835
835
    case CELL_TYPE:
836
836
        {
837
 
            if ((G_is_null_value(&(c1.val.c), CELL_TYPE)) ||
838
 
                (G_is_null_value(&(c2.val.c), CELL_TYPE)))
 
837
            if ((Rast_is_null_value(&(c1.val.c), CELL_TYPE)) ||
 
838
                (Rast_is_null_value(&(c2.val.c), CELL_TYPE)))
839
839
                return RLI_ERRORE;
840
840
            break;
841
841
        }
842
842
    case DCELL_TYPE:
843
843
        {
844
 
            if ((G_is_null_value(&(c1.val.dc), DCELL_TYPE)) ||
845
 
                (G_is_null_value(&(c2.val.dc), DCELL_TYPE)))
 
844
            if ((Rast_is_null_value(&(c1.val.dc), DCELL_TYPE)) ||
 
845
                (Rast_is_null_value(&(c2.val.dc), DCELL_TYPE)))
846
846
                return RLI_ERRORE;
847
847
            break;
848
848
        }
849
849
    case FCELL_TYPE:
850
850
        {
851
 
            if ((G_is_null_value(&(c1.val.fc), FCELL_TYPE)) ||
852
 
                (G_is_null_value(&(c2.val.fc), FCELL_TYPE)))
 
851
            if ((Rast_is_null_value(&(c1.val.fc), FCELL_TYPE)) ||
 
852
                (Rast_is_null_value(&(c2.val.fc), FCELL_TYPE)))
853
853
                return RLI_ERRORE;
854
854
            break;
855
855
        }