aboutsummaryrefslogtreecommitdiff
path: root/vo/src/OLD/datascope.cl
blob: 6eb1cdec4bf4b92cef567d985ca8325c72a3ac6a (plain) (blame)
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
#{  DATASCOPE --  Toy DataScope task that returns a table of data services
#   and the number of results that can be expected for each given either an
#   input image or object name.  For image input, the WCS footprint is computed
#   and used as the search parameters;  For an object name the coordinates are
#   resolved and the search radius specified by the user is used.
#
#   Example:  Query a specific set of services, finding how many hits would
#		be returned against the dev$wpix test image
#
#	cl> datascope dev$wpix service="GSC2.2,USNO-B1,DSS2"
#	#Num  ShortName         Count   IVO Identifier
#	#---  ---------         -----   --------------
#	   1   GSC2.2              50   ivo://archive.stsci.edu/gsc/gsc2.2
#	   2   USNO-B1            344   ivo://fs.usno/cat/usnob
#	   3   DSS2                 1   ivo://archive.stsci.edu/dss/dss2
#
#   REQUIRES:  NVO package and VO-CL builtin functions.
# 
#   M. Fitzpatrick, Aug 2006


procedure datascope (what)

string	what			{ prompt = "Object Name or Image"	   }
string	service = "cone"	{ prompt = "Service Type or list"	   }
string	bandpass = "optical"	{ prompt = "Bandpass of search"		   }
real	sr = 0.25		{ prompt = "search radius"		   }

bool	filter = yes		{ prompt = "Filter results?"		   }
bool	verbose = yes		{ prompt = "Verbose output?"		   }
int	status = 0		{ prompt = "Service status code"	   }

begin
	string  url, tname, stype, this, bpass
	string  sname, ivorn, regResults, junk, svctyp
	string  zresp, eresp
	real	ra, dec, size
	bool    verb, filt
	int	dal, index, count, lnum

	this  = what
	bpass = bandpass
	verb  = verbose
	stype = service
	filt  = filter

	if (stype == "catalog") {
	    stype = "cone"
	} else if (stype == "image") {
	    stype = "siap"
	}
	;

	if (imaccess (this)) {
	    iferr { wcsinfo (this) } then {
		error (0, "Cannot determine image coords for `"//this//"'")
	    } else {
	        ra  = wcsinfo.midx
	        dec = wcsinfo.midy
	        size = max (wcsinfo.width, wcsinfo.height) / 60.0
	    }

	} else { 
	    # Assume it's an object name, resolve to coords.
	    sesame (this)
	    if (sesame.status < 0)
		error (0, "Cannot resolve object `"//this//"'")
	    ra   = sesame.ra
	    dec  = sesame.dec
	    size = sr
	}

	# Initialize
	zresp = ""
	eresp = ""

	# Now do a Registry query for the given service type and bandpass.
	regResults = mktemp ("tmp$reg")
	if (stype == "all") {
	    s1 = mktemp ("tmp$reg")
	    print (stype) | translit ("STDIN",",","\n",del-, > s1)
	    list = s1
	    i = 1

	    # Convert the list of specific services to a table we use below to
	    # query each.
	    while (fscan (list, s2) != EOF) {
		printf ("%4d  %s\n", i, 
		    regResolver (s2,"","ShortName,ServiceType,Identifier"), 
			>> regResults)
		i = i + 1
	    }
	    delete (s1, verify-)

	} else {
	    registry ("", svc=stype, bandpass=bpass, verb-, header-, 
		>& regResults)
	}


	if (verbose) {
	    count (regResults) | scan (i)
	    printf ("#\n")
	    printf ("#  Search Terms:  RA=%H  Dec=%h  SR=%.3f\n", ra, dec, size)
	    printf ("#  Service Type:  %s\n", stype)
	    printf ("#  Total Querys:  %d\n", i)
	    printf ("#\n#\n")
	    printf ("#Num  ShortName         Count   IVO Identifier\n")
	    printf ("#---  ---------         -----   --------------\n")
	}

	# Loop over the registry and query by service type.
	list = regResults
	lnum = 1
	while (fscan (list, index, sname, svctyp, ivorn) != EOF) {

	    count = 0
	    if (substr (svctyp,1,4) == "CONE")
	        count = dalRecordCount (\
			    dalConeSvc(\
				regResolver(ivorn,"cone"), ra, dec, size))
	    else if (substr (svctyp,1,4) == "SIAP")
	        count = dalRecordCount (\
			    dalSiapSvc(\
				regResolver(ivorn,"siap"), ra, dec, size, size))

	    if (count == 0)
		zresp = zresp // sname // ","
	    if (!filter) {
	        printf ("%4d   %-14.14s  ", lnum, sname)
                if (count < 0) {
                    printf (" ERROR   %s\n", ivorn)
		    eresp = eresp // sname // ","
                } else
                    printf ("%6d   %s\n", count, ivorn)
		lnum = lnum + 1
	    } else if (filter && count > 0) {
	        printf ("%4d   %-14.14s  %6d   %s\n", lnum,sname,count,ivorn)
		lnum = lnum + 1
	    } else if (count < 0)
		eresp = eresp // sname // ","
	}

	if (verbose) {
	    printf ("#\n")
	    printf ("#  Zero Values: ") ; prettystr(zresp,start=15,comment+)
	    printf ("#  Err Returns: ") ; prettystr(eresp,start=15,comment+)
	}

	# Clean up.
	delete (regResults, verify-)
end