forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumn_shift.c
96 lines (82 loc) · 1.78 KB
/
column_shift.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include "expression.h"
#include "globals.h"
void column_shift(void *buf, int res_type, int col)
{
CELL *ibuf = buf;
FCELL *fbuf = buf;
DCELL *dbuf = buf;
int i;
/* if column offset, copy cell to itself shifting by col */
if (col > 0) {
switch (res_type) {
case CELL_TYPE:
for (i = 0; i < columns - col; i++) {
if (IS_NULL_C(&ibuf[i + col]))
SET_NULL_C(&ibuf[i]);
else
ibuf[i] = ibuf[i + col];
}
for (; i < columns; i++)
SET_NULL_C(&ibuf[i]);
break;
case FCELL_TYPE:
for (i = 0; i < columns - col; i++) {
if (IS_NULL_F(&fbuf[i + col]))
SET_NULL_F(&fbuf[i]);
else
fbuf[i] = fbuf[i + col];
}
for (; i < columns; i++)
SET_NULL_F(&fbuf[i]);
break;
case DCELL_TYPE:
for (i = 0; i < columns - col; i++) {
if (IS_NULL_D(&dbuf[i + col]))
SET_NULL_D(&dbuf[i]);
else
dbuf[i] = dbuf[i + col];
}
for (; i < columns; i++)
SET_NULL_D(&dbuf[i]);
break;
}
}
else if (col < 0) {
col = -col;
switch (res_type) {
case CELL_TYPE:
for (i = columns - 1; i >= col; i--) {
if (IS_NULL_C(&ibuf[i - col]))
SET_NULL_C(&ibuf[i]);
else
ibuf[i] = ibuf[i - col];
}
for (; i >= 0; i--)
SET_NULL_C(&ibuf[i]);
break;
case FCELL_TYPE:
for (i = columns - 1; i >= col; i--) {
if (IS_NULL_F(&fbuf[i - col]))
SET_NULL_F(&fbuf[i]);
else
fbuf[i] = fbuf[i - col];
}
for (; i >= 0; i--)
SET_NULL_F(&fbuf[i]);
break;
case DCELL_TYPE:
for (i = columns - 1; i >= col; i--) {
if (IS_NULL_D(&dbuf[i - col]))
SET_NULL_D(&dbuf[i]);
else
dbuf[i] = dbuf[i - col];
}
for (; i >= 0; i--)
SET_NULL_D(&dbuf[i]);
break;
}
}
}