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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
#
# SPPTEST -- SPP test programs for the VOClient interface.
#
# M. Fitzpatrick, NOAO, Jul 2006
task simple = t_simple,
cone = t_cone,
siap = t_siap,
sesame = t_sesame,
skybot = t_skybot,
registry1 = t_registry1,
registry2 = t_registry2,
registry3 = t_registry3
define DEF_RA 12.0; # default search values
define DEF_DEC 12.0;
define DEF_SIZE 0.1;
define DEF_SR 0.5;
define CONE_SVC "http://www.nofs.navy.mil/cgi-bin/vo_cone.cgi?CAT=USNO-B1&"
define SIAP_SVC "http://skyview.gsfc.nasa.gov/cgi-bin/vo/sia.pl?"
define MAX_IMAGES 5
define SZ_URL 512
define SZ_RESULT 128000 # allow up to 128K of results
# SIMPLE -- Trivial SPP task to call the high-level interface functions.
# Here we test the all-in-one caller procedures and get the result as a
# string. We'll simply write out the string, a real app could just as
# easily open the string as a file and parse it as needed.
procedure t_simple ()
char fname[SZ_FNAME], otype[SZ_FNAME], svctype[SZ_FNAME]
char result[SZ_RESULT]
double ra, dec, size
int reslen
double clgetd()
bool streq()
int vx_conecaller() # returns the length of the result
int vx_siapcaller() # returns the length of the result
begin
call aclrs (fname, SZ_FNAME) # clear string arrays
call aclrs (otype, SZ_FNAME)
call aclrs (svctype, SZ_FNAME)
call aclrs (result, SZ_RESULT)
call clgstr ("dal", svctype, SZ_FNAME) # get task parameters
ra = clgetd ("ra")
dec = clgetd ("dec")
size = clgetd ("size")
call clgstr ("type", otype, SZ_FNAME)
# Now call the service requested.
if (streq ("cone", svctype)) {
reslen = vx_coneCaller (CONE_SVC, ra, dec, size, otype,
result, SZ_RESULT)
} else if (streq ("siap", svctype)) {
reslen = vx_siapCaller (SIAP_SVC, ra, dec, size, size,
"image/fits", otype, result, SZ_RESULT)
} else {
call eprintf ("Invalid service type '%s'\n")
call pargstr (svctype)
return
}
# Print the results to the screen.
if (reslen > 0) {
call write (STDOUT, result, reslen)
if (reslen >= SZ_RESULT)
call eprintf ("\n\nResults possibly truncated....\n\n")
} else
call eprintf ("No results from service\n")
end
# CONE -- Simple test program to call a Cone search service and summarize
# the results to the screen.
procedure t_cone ()
char qstring[SZ_URL]
char sid[SZ_FNAME], sra[SZ_FNAME], sdec[SZ_FNAME]
double ra, dec, size
int cone, query, qr, rec
int i, nrec, nattr, len
double clgetd()
int vx_initVOClient(), vx_coneConnection()
int vx_executeQuery(), vx_coneQuery(), vx_stringAttr()
int vx_record(), vx_recordCount(), vx_atCount()
begin
ra = clgetd ("ra") # get task parameters
dec = clgetd ("dec")
size = clgetd ("size")
# Make the Cone call and summarize the table.
if (vx_initVOClient("") == ERR) # Initialize
return
# Open a connection and form the query.
cone = vx_coneConnection (CONE_SVC)
query = vx_coneQuery (cone, ra, dec, size)
call vx_queryString (query, "cone", 0, qstring, SZ_PATHNAME)
call printf ("\nExecuting query:\n %s\n\n")
call pargstr (qstring)
# Execute the query.
qr = vx_executeQuery (query)
# Summarize the response.
nrec = vx_recordCount (qr)
if (nrec <= 0) {
call eprintf ("No records matched.")
return
} else {
rec = vx_record (qr, 0)
nattr = 0
if (rec != ERR)
nattr = vx_atCount (rec)
call printf ("# return %d records containing %d attrs each\n#\n")
call pargi (nrec)
call pargi (nattr)
call printf ("#\n# --- Summary output ---\n#\n")
}
# Download a few images.
for (i = 0; i < nrec; i=i+1) {
rec = vx_record (qr, i)
if (rec > 0) {
len = vx_stringAttr (rec, "ID_MAIN", sid, SZ_FNAME)
len = vx_stringAttr (rec, "POS_EQ_RA_MAIN", sra, SZ_FNAME)
len = vx_stringAttr (rec, "POS_EQ_DEC_MAIN", sdec, SZ_FNAME)
call printf ("%4d id=%s ra=%s dec=%s\n")
call pargi (i)
call pargstr (sid)
call pargstr (sra)
call pargstr (sdec)
} else {
call eprintf ("\nError getting record number %d\n")
call pargi (i)
}
}
call vx_closeConnection (cone)
call vx_closeVOClient (0)
end
# SIAP -- Simple test procedure to call a SIAP service and download several
# test images.
procedure t_siap ()
char fname[SZ_FNAME], qstring[SZ_URL], acref[SZ_URL]
double ra, dec, size
int siap, query, qr, rec, v
int i, nrec, nattr, len
double clgetd()
int vx_initVOClient(), vx_siapConnection()
int vx_executeQuery(), vx_siapQuery()
int vx_record(), vx_recordCount(), vx_atCount()
int vx_getAttribute(), vx_getDataset(), vx_stringValue()
begin
ra = clgetd ("ra") # get task parameters
dec = clgetd ("dec")
size = clgetd ("size")
# Make the SIAP call and download a few images.
if (vx_initVOClient("") == ERR) # Initialize
return
# Open a connection and form the query.
siap = vx_siapConnection (SIAP_SVC)
query = vx_siapQuery (siap, ra, dec, size, size, "image/fits")
call vx_queryString (query, "siap", 0, qstring, SZ_PATHNAME)
call printf ("\nExecuting query:\n %s\n\n")
call pargstr (qstring)
# Execute the query.
qr = vx_executeQuery (query)
# Summarize the response.
nrec = vx_recordCount (qr)
if (nrec <= 0) {
call eprintf ("No records matched.")
return
} else {
rec = vx_record (qr, 0)
nattr = 0
if (rec != ERR)
nattr = vx_atCount (rec)
call printf ("# return %d records containing %d attrs each\n#\n")
call pargi (nrec)
call pargi (nattr)
}
# Download a few images.
for (i = 0; i < nrec && i < MAX_IMAGES; i=i+1) {
rec = vx_record (qr, i)
v = vx_getAttribute (rec, "AccessReference")
if (v <= 0)
next
call aclrs (fname, SZ_FNAME) # clear string arrays
call sprintf (fname, SZ_FNAME, "dataset%04d.fits")
call pargi (i)
len = vx_stringValue (v, acref, SZ_URL)
call printf ("Downloading: %s\n")
call pargstr (acref)
if (vx_getDataset (rec, acref, fname) == OK) {
call printf ("\n Saved to file: %s\n\n")
call pargstr (fname)
} else
call eprintf ("\n Downloaded failed\n")
}
call vx_closeConnection (siap)
call vx_closeVOClient (0)
end
# SESAME -- Simple test procedure of the Sesame service.
procedure t_sesame ()
char target[SZ_FNAME], pos[SZ_LINE]
double ra, dec
int sr, len
int vx_initVOClient()
int vx_nameresolver(), vx_resolverpos()
double vx_resolverra(), vx_resolverdec()
begin
call clgstr ("target", target, SZ_FNAME)
if (vx_initVOClient("") == ERR) # Initialize
return
sr = vx_nameresolver (target)
ra = vx_resolverra (sr)
dec = vx_resolverdec (sr)
len = vx_resolverpos (sr, pos, SZ_LINE)
call printf ("target=%s ra=%.6f dec=%.6f (%s)\n\n")
call pargstr (target)
call pargd (ra)
call pargd (dec)
call pargstr (pos)
call vx_closeVOClient (0)
end
# SKYBOT -- Simple test procedure of the SkyBoT service.
procedure t_skybot ()
char name[SZ_FNAME]
double ra, dec, sr, epoch, vmag
int sb, nobjs, len, i
real clgetr()
int vx_initVOClient()
int vx_skybot(), vx_skybotnobjs(), vx_skybotstr()
double vx_skybotdbl()
begin
ra = clgetr ("ra") # Get the parameters
dec = clgetr ("dec")
sr = clgetr ("sr")
epoch = clgetr ("epoch")
if (vx_initVOClient("") == ERR) # Initialize
return
call printf ("#\n# Search Terms: ra=%.6f dec=%.6f sr=%.1f epoch=%.3f\n")
call pargd (ra)
call pargd (dec)
call pargd (sr)
call pargd (epoch)
# Call the service
sb = vx_skybot (ra, dec, sr, sr, epoch)
nobjs = vx_skybotnobjs (sb)
call printf ("#\n# Found %d objects\n#\n")
call pargi (nobjs)
for (i=0; i < nobjs; i=i+1) {
len = vx_skybotstr (sb, "name", i, name, SZ_FNAME)
ra = vx_skybotdbl (sb, "ra", i)
dec = vx_skybotdbl (sb, "dec", i)
vmag = vx_skybotdbl (sb, "vmag", i)
call printf ("%d: obj=%12s ra=%.6f dec=%.6f Mv=%s\n")
call pargi (i)
call pargstr (name)
call pargd (ra)
call pargd (dec)
call pargd (vmag)
}
call vx_closeVOClient (0)
end
# REGISTRY -- Simple tests of the Registry search procedures.
procedure t_registry1 ()
char sql[SZ_LINE], keywords[SZ_LINE]
int orValues, res, count
int vx_initVOClient(), vx_regsearch(), vx_rscount(), btoi()
bool clgetb()
begin
call clgstr ("sql", sql, SZ_LINE)
call clgstr ("keywords", keywords, SZ_LINE)
orValues = btoi (clgetb ("orValues"))
if (vx_initVOClient("") == ERR) # Initialize
return
# Do the Registry search, get back a result object. Remember that
# the 'orValues' is an integer in the interface, we converted from
# the boolean parameter above.
res = vx_regsearch (sql, keywords, orValues)
count = vx_rscount (res)
call printf ("#\n# Found %d matching records\n#\n\n")
call pargi (count)
call reg_printRecords (res, count)
call vx_closeVOClient (0)
end
procedure t_registry2 ()
char sql[SZ_LINE], keywords[SZ_LINE], qstring[1024]
int orValues, res, query, count, len
int vx_initVOClient(), vx_rscount(), vx_regquery()
int btoi(), vx_rgetquerystring(), vx_rexecute()
bool clgetb()
begin
call clgstr ("sql", sql, SZ_LINE)
call clgstr ("keywords", keywords, SZ_LINE)
orValues = btoi (clgetb ("orValues"))
if (vx_initVOClient("") == ERR) # Initialize
return
# Do the Registry search, get back a result object. Remember that
# the 'orValues' is an integer in the interface, we converted from
# the boolean parameter above.
query = vx_regquery (sql, 0);
call vx_raddsearchterm (query, keywords, orValues)
len = vx_rgetquerystring (query, qstring, 1024)
call printf ("#\n# Query;\n %s\n#\n\n")
call pargstr (qstring)
res = vx_rexecute (query)
count = vx_rscount (res)
call printf ("#\n# Found %d matching records\n#\n\n")
call pargi (count)
call reg_printRecords (res, count)
call vx_closeVOClient (0)
end
procedure t_registry3 ()
char svc[SZ_LINE], term[SZ_LINE]
int orValues, res, count
int vx_initVOClient(), vx_regsearchbysvc(), vx_rscount(), btoi()
bool clgetb()
begin
call clgstr ("svc", svc, SZ_LINE)
call clgstr ("term", term, SZ_LINE)
orValues = btoi (clgetb ("orValues"))
if (vx_initVOClient("") == ERR) # Initialize
return
# Do the Registry search given the particular service type. The
# search term may be either a keyword list or another SQL predicate.
res = vx_regsearchbysvc (svc, term, orValues)
count = vx_rscount (res)
call printf ("#\n# Found %d matching records\n#\n\n")
call pargi (count)
call reg_printRecords (res, count)
call vx_closeVOClient (0)
end
procedure reg_printRecords (res, count)
int res, count, i
char title[SZ_LINE], url[SZ_LINE], svctype[SZ_LINE], type[SZ_LINE]
begin
for (i = 0; i < count; i=i+1) {
call vx_rsstr (res, "Title", i, title, SZ_LINE)
call vx_rsstr (res, "ServiceUrl", i, url, SZ_LINE)
call vx_rsstr (res, "ResourceType", i, svctype, SZ_LINE)
call vx_rsstr (res, "Type", i, type, SZ_LINE)
call printf ("\n----------------------------------------------------\n")
call printf ("(%d of %d) %s\n")
call pargi (i+1)
call pargi (count)
call pargstr (title)
call printf ("ServiceURL: %s\n")
call pargstr (url)
call printf ("ResourceType: %s\t\tType: %s\n")
call pargstr (svctype)
call pargstr (type)
}
end
|