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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <ctype.h>
# IMX_BREAKOUT -- Break out the filename template from the filtering
# expression in the list item. Our input value is a single item in the
# template list, we'll logically separate image parameters, section strings
# and extension values from expressions that might be used in filtering.
int procedure imx_breakout (item, expand, fname, expr, sec, ikparams, maxch)
char item[ARB] #i template string ptr
int expand #i expanding contents?
char fname[ARB] #o list filename
char expr[ARB] #o filtering expression
char sec[ARB] #o section string
char ikparams[ARB] #o image kernel params
int maxch #i max chars in fname and expr
char ch, str[SZ_LINE], sifname[SZ_LINE]
int nchars, ip, op
bool is_sif
bool imx_issection(), imx_sifmatch()
int stridx()
define next_str_ 99
begin
call aclrc (fname, maxch)
call aclrc (expr, maxch)
call aclrc (sec, maxch)
# At the start the ip points to the '@' in the template string.
# Skip ahead to the start of the filename template string.
ip = 1
if (expand == YES)
ip = ip + 1
# Copy out the filename template up to the EOS, a '[' to indicate
# the start of a filter expression, or a comma indicating the next
# item in the list.
ch = item[ip]
for (op=1; ch != EOS; op=op+1) {
fname[op] = ch
ch = item[ip+1]
if (ch == ',' || ch == EOS)
return (ip-1) # next list item, no filter expr
else if (ch == '[')
break # break to get the filter expr
ip = ip + 1
}
# Get the string up to the closing ']' char.
next_str_
ip = ip + 2
ch = item[ip]
call aclrc (str, SZ_LINE)
for (op=1; ch != EOS; op=op+1) {
str[op] = ch
ip = ip + 1
ch = item[ip]
if (ch == ']')
break # break to get the filter expr
}
if (imx_issection (str)) {
call strcpy (str, sec, SZ_LINE)
} else {
if (expr[1] != EOS) {
call strcat (",", expr, SZ_LINE)
call strcat (str, expr, SZ_LINE)
} else
call strcpy (str, expr, SZ_LINE)
}
if (item[ip+1] != EOS)
goto next_str_
call imx_ikparams (expr, ikparams, SZ_LINE)
# If we've found both a section and an expression, check that the
# section isn't being confused with an index list.
#if (sec[1] != EOS && expr[1] != EOS) {
# if (!is_sif && stridx (':', sec) == 0) {
# call strcat (",", expr, SZ_LINE)
# call strcat (sec, expr, SZ_LINE)
# }
#}
if (sec[1] != EOS) {
call aclrc (sifname, SZ_LINE)
call sprintf (sifname, SZ_LINE, "%s[1][%s]")
if (fname[1] == '@')
call pargstr (fname[2])
else
call pargstr (fname)
call pargstr (sec)
} else {
call strcpy (fname, sifname, SZ_LINE)
}
is_sif = imx_sifmatch (sifname, "yes")
nchars = ip - 1
return (nchars)
end
# IMX_ISSECTION -- Determine if the string is an image section.
#
# Note: There is a possible ambiguity here where using an image section
# that represents a single pixel (e.g. foo.fits[100,100]) which might also
# be a list of image extensions.
bool procedure imx_issection (str)
char str[ARB] # string to be checked
int ip, stridxs()
begin
for (ip=1; str[ip] != EOS; ip=ip+1) {
if (IS_ALPHA(str[ip]) || stridxs ("x()<>?", str) > 0)
return (FALSE)
}
# Test for a range list, e.g. "[1-5]"
if (stridxs ("-,", str) > 0 && stridxs (":*", str) == 0)
return (FALSE);
# Test for a section that flips axes, e.g. "[-*,*]"
if (stridxs ("-*:,", str) > 0)
return (TRUE);
return (FALSE)
end
# IMX_IKPARMS -- Break out the image kernel params from the template list
# expression string.
procedure imx_ikparams (expr, ikparams, maxch)
char expr[ARB] # expression string to modify
char ikparams[ARB] # extracted image kernel params
int maxch # max size of output strings
int ip, op, nexpr, niki
char ch, in[SZ_LINE], sub[SZ_LINE]
bool imx_isikparam()
begin
call aclrc (in, SZ_LINE) # initialize
call strcpy (expr, in, SZ_LINE)
nexpr = 0
niki = 0
call aclrc (expr, maxch)
call aclrc (ikparams, maxch)
for (ip=1; in[ip] != EOS; ip=ip+1) {
# Copy out the sub expression, i.e. up to the comma or EOS.
call aclrc (sub, SZ_LINE)
op = 1
while (in[ip] != EOS && in[ip] != ',' && in[ip] != ';') {
sub[op] = in[ip]
ip = ip + 1
op = op + 1
}
ch = in[ip]
if (imx_isikparam (sub)) {
if (niki > 0)
call strcat (",", ikparams, maxch)
call strcat (sub, ikparams, maxch)
niki = niki + 1
} else {
if (nexpr > 0)
call strcat (",", expr, maxch)
call strcat (sub, expr, maxch)
nexpr = nexpr + 1
}
if (ch == EOS)
break
}
end
# IMX_ISIKPARAM -- See whether the substring refers to an image kernel param.
bool procedure imx_isikparam (str)
char str[ARB] # string to check
int strncmp()
begin
if (strncmp (str, "extname", 7) == 0 || strncmp (str, "extver", 6) == 0)
return (TRUE)
# Check for the "no" versions of selected keywords.
else if (strncmp (str, "no", 2) == 0) {
if ((strncmp (str[3], "append", 4) == 0) ||
(strncmp (str[3], "inherit", 4) == 0) ||
(strncmp (str[3], "overwrite", 4) == 0) ||
(strncmp (str[3], "dupname", 4) == 0) ||
(strncmp (str[3], "expand", 4) == 0))
return (TRUE)
}
# Other kernel keywords.
if (strncmp (str, "inherit", 4) == 0 ||
strncmp (str, "overwrite", 4) == 0 ||
strncmp (str, "dupname", 4) == 0 ||
strncmp (str, "append", 4) == 0 ||
strncmp (str, "noappend", 4) == 0 ||
strncmp (str, "type", 4) == 0 ||
strncmp (str, "expand", 4) == 0 ||
strncmp (str, "phulines", 4) == 0 ||
strncmp (str, "ehulines", 4) == 0 ||
strncmp (str, "padlines", 4) == 0 ||
strncmp (str, "cachesize", 4) == 0)
return (TRUE)
return (FALSE)
end
|