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

« back to all changes in this revision

Viewing changes to raster/r.mapcalc/xadd.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:
1
1
 
2
2
#include <grass/gis.h>
 
3
#include <grass/raster.h>
3
4
#include "globals.h"
4
5
#include "expression.h"
5
6
#include "func_proto.h"
6
7
 
7
8
/****************************************************************
8
 
add(a,b) = a + b
 
9
add(a,b,c,...) = a + b + c + ...
9
10
****************************************************************/
10
11
 
11
12
int f_add(int argc, const int *argt, void **args)
12
13
{
13
 
    int i;
 
14
    int i, j;
14
15
 
15
 
    if (argc < 2)
 
16
    if (argc < 1)
16
17
        return E_ARG_LO;
17
 
    if (argc > 2)
18
 
        return E_ARG_HI;
19
18
 
20
 
    if (argt[1] != argt[0] || argt[2] != argt[0])
21
 
        return E_ARG_TYPE;
 
19
    for (i = 1; i <= argc; i++)
 
20
        if (argt[i] != argt[0])
 
21
            return E_ARG_TYPE;
22
22
 
23
23
    switch (argt[0]) {
24
24
    case CELL_TYPE:
25
25
        {
26
26
            CELL *res = args[0];
27
 
            CELL *arg1 = args[1];
28
 
            CELL *arg2 = args[2];
 
27
            CELL **argz = (CELL **) args;
29
28
 
30
29
            for (i = 0; i < columns; i++) {
31
 
                if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
32
 
                    SET_NULL_C(&res[i]);
33
 
                else
34
 
                    res[i] = arg1[i] + arg2[i];
 
30
                res[i] = 0;
 
31
                for (j = 1; j <= argc; j++) {
 
32
                    if (IS_NULL_C(&argz[j][i])) {
 
33
                        SET_NULL_C(&res[i]);
 
34
                        break;
 
35
                    }
 
36
                    res[i] += argz[j][i];
 
37
                }
35
38
            }
36
39
            return 0;
37
40
        }
38
41
    case FCELL_TYPE:
39
42
        {
40
43
            FCELL *res = args[0];
41
 
            FCELL *arg1 = args[1];
42
 
            FCELL *arg2 = args[2];
 
44
            FCELL **argz = (FCELL **) args;
43
45
 
44
46
            for (i = 0; i < columns; i++) {
45
 
                if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
46
 
                    SET_NULL_F(&res[i]);
47
 
                else
48
 
                    res[i] = arg1[i] + arg2[i];
 
47
                res[i] = 0;
 
48
                for (j = 1; j <= argc; j++) {
 
49
                    if (IS_NULL_F(&argz[j][i])) {
 
50
                        SET_NULL_F(&res[i]);
 
51
                        break;
 
52
                    }
 
53
                    res[i] += argz[j][i];
 
54
                }
49
55
            }
50
56
            return 0;
51
57
        }
52
58
    case DCELL_TYPE:
53
59
        {
54
60
            DCELL *res = args[0];
55
 
            DCELL *arg1 = args[1];
56
 
            DCELL *arg2 = args[2];
 
61
            DCELL **argz = (DCELL **) args;
57
62
 
58
63
            for (i = 0; i < columns; i++) {
59
 
                if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
60
 
                    SET_NULL_D(&res[i]);
61
 
                else
62
 
                    res[i] = arg1[i] + arg2[i];
 
64
                res[i] = 0;
 
65
                for (j = 1; j <= argc; j++) {
 
66
                    if (IS_NULL_D(&argz[j][i])) {
 
67
                        SET_NULL_D(&res[i]);
 
68
                        break;
 
69
                    }
 
70
                    res[i] += argz[j][i];
 
71
                }
63
72
            }
64
73
            return 0;
65
74
        }