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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
#{ REGISTRY -- Do a Registry query.
procedure registry (query)
string query { prompt = "Query terms" }
string type = "" { prompt = "Sevice type constraint" }
string bandpass = "" { prompt = "Bandpass constraint" }
string content = "" { prompt = "ContentLevel constraint" }
string sql = "" { prompt = "SQL Query terms" }
string fields="Title,Subject,CoverageSpectral" \
{ prompt = "Verbose output fields" }
bool header = yes { prompt = "Header output?" }
bool verbose = no { prompt = "Verbose output?" }
bool interactive = no { prompt = "Interactive processing?" }
int record = -1 { prompt = "Record number to list?" }
bool metadata = no { prompt = "List resource metadata?" }
int nlines = 5 { prompt = "Number lines in Vizier preview" }
int qres = 0 { prompt = "Saved resource record pointer" }
int qcount = 0 { prompt = "Saved record count" }
string qstring = "" { prompt = "Saved query string" }
string qbandpass = "" { prompt = "Saved bandpass constraint" }
string qcontent = "" { prompt = "Saved ContentLevel constraint" }
string qsvc = "" { prompt = "Saved service type constraint" }
string qsql = "" { prompt = "Saved SQL constraint" }
int status = 0 { prompt = "Service status code" }
begin
string qterm, fstr, ffile, qstr, id, typ, str
string bpass, clevel, sqlstr, stype, ch
bool verb, meta, interact, summary
int res, count, istart, iend, n, vnlines, rec
verb = verbose
fstr = fields
meta = metadata
stype = type
bpass = bandpass
clevel = content
sqlstr = sql
interact = interactive
vnlines = nlines
# Set the environment.
reset clobber = yes
summary = no
# Print the resource alias list
if (query == "aliases") {
if (access ("home$registry.dat") == yes)
type ("home$registry.dat")
return
} else if (query == "alias") {
return
}
# See if all we want is a list of the available metadata.
if (meta) {
regmetalist(all-)
return
}
submit:
# Build a sql predicate string from the contraints (if any).
qstr = ""
if (stype != "") {
str = strlwr (stype)
if (str == "sia" || substr (str,1,2) == "im")
qstr = "(Tag like '%images%')"
else
qstr = "(xml like '%" // stype // "%')"
}
if (bpass != "") {
str = "([coverage/waveband] like '%" // bpass // "%')"
if (qstr != "")
qstr = qstr // " AND " // str
else
qstr = str
}
if (clevel != "") {
str = "([content/contentLevel] like '%" // clevel // "%')"
if (qstr != "")
qstr = qstr // " AND " // str
else
qstr = str
}
if (sqlstr != "") {
str = "(" // sqlstr // ")"
if (qstr != "")
qstr = qstr // " AND " // str
else
qstr = str
}
# Get a temp file so we can loop over the fields. Dump the fields
# string to the file for easy reading.
ffile = mktemp ("tmp$reg")
again:
if (record > 0 || fstr == "all") {
regmetalist (all+, > ffile)
} else {
print (fstr) | translit ("STDIN",",","\n",del-, > ffile)
}
# Do the query
if (record >= 0) {
res = qres
count = qcount
if (record == 0) {
istart = 0
iend = qcount
} else {
istart = record - 1
iend = record
verb = yes # reset verbose flag for single full record
}
qterm = qstring
stype = qsvc
bpass = qbandpass
clevel = qcontent
sqlstr = qsql
if (header)
printf ("#\n# Record: %d\n#\n", record)
} else {
qterm = query
if (qstr != "")
res = regSearch (qstr, qterm, 0)
else
res = regSearch (qterm, 0)
count = regResCount (res)
istart = 0
iend = count
if (header)
printf ("#\n# Found %d records\n#\n", count)
}
# Dump the query constraints we used in the search.
if (header) {
printf ("# Registry Query Constraints:\n")
if (qterm != "") printf ("#\t Query Term: '%s'\n", qterm)
if (stype != "") printf ("#\t ServiceType: %s\n", stype)
if (bpass != "") printf ("#\t Bandpass: %s\n", bpass)
if (clevel != "") printf ("#\tContentLevel: %s\n", clevel)
if (sqlstr != "") printf ("#\tSQL: %s\n", sqlstr)
printf ("#\n")
}
if (record <= 0 && header) {
printf ("#No ShortName ServiceType Identifier\n")
printf ("#-- --------- ----------- ----------\n#\n")
}
for (i=istart; i < iend; i=i+1) {
if (record <= 0 && fstr != "all") {
printf ("%3d %-18.18s %-10.10s %s\n",
(i+1),
trim (regValue (res, "ShortName", i)),
trim (regValue (res, "ServiceType", i)),
trim (regValue (res, "Identifier", i)))
} else if (fstr == "all")
printf ("Record: %d\n", i)
if (!summary && verb) {
list = ffile
while (fscan (list, str) != EOF) {
printf (" %12.12s: ", str)
line = regValue (res, str, i)
prettystr (trim(line))
}
list = ""
printf ("\n")
}
}
# Save the resource pointer and record count in case we come back.
if (record < 0) {
qres = res
qcount = count
qstring = qterm
qbandpass = bpass
qcontent = clevel
qsvc = stype
qsql = sqlstr
}
if (interact) {
nextcmd:
printf ("\nCommand? ")
summary = no
ch = cl.ukey
if (substr(ch,1,4) == "\\015") {
goto nextcmd
}
switch (ch) {
case "?": # print help
{ print ("\n\n REGISTRY Command Summary:")
print (" t constrain by service Type")
print (" b constrain by Bandpass")
print (" r view details of individual Record")
print (" s print Summary table of results")
print (" p Preview a vizier table")
print (" v set Verbose flag")
print (" q Quit")
goto nextcmd
}
case "t": # Record
{ printf ("\nService Type? ")
n = scan (stype)
record = -1
summary = yes
goto submit
}
case "b": # Record
{ printf ("\nBandpass? ")
n = scan (bpass)
record = -1
summary = yes
goto submit
}
case "r": # Record
{ printf ("\nRecord number? ")
n = scan (record)
goto again
}
case "s": # Summary list
{ record = 0
summary = yes
goto again
}
case "p": # Preview a VizieR table
{ printf ("\nRecord number? ")
n = scan (rec)
id = trim (regValue (res, "Identifier", rec-1))
typ = strlwr (trim (regValue (res, "ServiceType", rec-1)))
if (substr(typ,1,7) != "tabular") {
printf ("\nError: Record %d is not a VizieR table\n", n)
goto nextcmd
} else {
vizier (id, output="STDOUT", otype="ascii", all-) | \
head ("STDIN", nlines=vnlines)
}
goto nextcmd
}
case "v": # Set verbose
{ verb = yes
goto again
}
case "q": # Quit
{ record = -1
print ("")
}
}
}
# Clean up.
delete (ffile, verify-, >& "dev$null")
end
|