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
97
98
99
100
101
102
103
104
105
|
include <ctype.h>
# IR_DECODE_SECTION -- Procedure to decode the reference section.
int procedure ir_decode_section (section, ncols, nrows, c1ref, c2ref, l1ref,
l2ref)
char section[ARB] # reference subraster section
int ncols # number of columns in the image
int nrows # number of rows in the image
int c1ref # initial column
int c2ref # final reference column
int l1ref # initial reference line
int l2ref # final reference line
char leftbkt
int index, ip, step
int ir_decode_subscript(), stridx()
begin
leftbkt = '['
index = stridx (leftbkt, section)
if (index == 0)
return (ERR)
ip = index + 1
if (ir_decode_subscript (section, ip, ncols, c1ref, c2ref, step) == ERR)
return (ERR)
if (ir_decode_subscript (section, ip, nrows, l1ref, l2ref, step) == ERR)
return (ERR)
return (OK)
end
# IR_DECODE_SUBSCRIPT -- Decode a single subscript expression to produce the
# range of values for that subscript (X1:X2), and the sampling step size, STEP.
# Note that X1 may be less than, greater than, or equal to X2, and STEP may
# be a positive or negative nonzero integer. Various shorthand notations are
# permitted, as is embedded whitespace.
int procedure ir_decode_subscript (section, ip, maxnumber, x1, x2, step)
char section[ARB]
int ip
int maxnumber
long x1, x2, step, temp
int ctol()
begin
x1 = 1
x2 = maxnumber
step = 1
while (IS_WHITE(section[ip]))
ip = ip + 1
# Get X1, X2.
if (ctol (section, ip, temp) > 0) { # [x1
x1 = temp
if (section[ip] == ':') {
ip = ip + 1
if (ctol (section, ip, x2) == 0) # [x1:x2
return (ERR)
} else
x2 = x1
} else if (section[ip] == '-') {
x1 = maxnumber # [-*
x2 = 1
ip = ip + 1
if (section[ip] == '*')
ip = ip + 1
} else if (section[ip] == '*') # [*
ip = ip + 1
while (IS_WHITE(section[ip]))
ip = ip + 1
# Get sample step size, if give.
if (section[ip] == ':') { # ..:step
ip = ip + 1
if (ctol (section, ip, step) == 0)
return (ERR)
else if (step == 0)
return (ERR)
}
# Allow notation such as "-*:5", (or even "-:5") where the step
# is obviously supposed to be negative.
if (x1 > x2 && step > 0)
step = -step
while (IS_WHITE(section[ip]))
ip = ip + 1
if (section[ip] == ',') {
ip = ip + 1
return (OK)
} else if (section[ip] == ']')
return (OK)
else
return (ERR)
end
|