aboutsummaryrefslogtreecommitdiff
path: root/vo/votools/getspec.cl
blob: 12f02882cc1bb5a4fc5448536ea9d4f9e1b5679b (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
#{  GETSPEC -- Call an SSA service URL and return the raw result.

procedure getspec (resource, image)

string	resource		{ prompt = "Resource name"		}
string	image			{ prompt = "Query image"		}
string	pos   = ""		{ prompt = "POS string"			}
real	size  = 0.25		{ prompt = "SIZE value (degrees)"	}

bool    display  = no          { prompt = "Display field?"             }
bool    overlay  = no          { prompt = "Overlay display?"           }
string	output = "STDOUT"	{ prompt = "Output filename"		}
string	format = "ascii"		{ prompt = "Output format",
				    min="ascii|csv|votable|fits|raw"	} 
int	status = 0		{ prompt = "Service status code"	}

begin
	string  lname, lres, url, loname, tname, ltype, args
	bool	ldisp, lover
	real	ra, dec
	int     nread, len


	# Get params to local variables.
	lname  = image
	ltype  = format
	loname = output
	ldisp  = display
	lover  = overlay

	lres  = resource		# resolve resource name
	if (resource == "")
	    error (0, "No resource specified")
	    
        if (substr (lres, 1, 7) == "http://") {
            url  = lres
            len = strlen (url)
            if (substr(url,len,len) != '?' && substr(url,len,len) != '&') {
                if (strstr ("?", url) == 0)
                    url = url // "?"
                else
                    url = url // "&"
            }

        #} else if (access ("uparm$url") == yes) {
        #    list = "uparm$url" ; nread = fscan (list, url) ; list = ""
        } else {
            regdb ("resolve", lres, type="S")
            url   = regdb.url
            if (regdb.svctype != "S")
                error (0, "Resource '" // lres // "' is not a spectral service")
        }


	# Determine the query params from the image WCS.
	if (imaccess (lname) == no) {
	    #error (0, "Cannot open image '" // lname // "'")
            sesame (lname, verbose-)
            ra  = sesame.ra
            dec = sesame.dec

            if (ldisp)
                dss (lname, use_disp+)
            lname = "cache$" // lname // ".fits"
            args = "POS=" // ra // "," // dec  // "&SIZE=" // size

	} else {
	    wcsinfo (lname)
	    args = "POS=" // wcsinfo.pos // "&SIZE=" // wcsinfo.size
	}

        if (vo.runid != "")
            args = args // "&RUNID=" // vo.runid


	# Create a temporary output name.
	tname = mktemp ("tmp$raw") // ".xml"

	# Call the raw service via the URLGET generic task.
	urlget (url//args, tname, extn="", use_cache+, cache="cache$")

	# If we didn't want a VOTable, convert the file and rename to
	# desired output name
        votcopy (tname, loname, ltype, header+, verb-)

	delete (tname, verify-)
end