aboutsummaryrefslogtreecommitdiff
path: root/vo/src/OLD/vizier.cl
blob: bf9209bad5bc808b48bf2c1a074e9fb020d153c6 (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
#{  VIZIER -- Call a service Vizier TABULARSKY service.

procedure vizier (tab_id)

string	tab_id			{ prompt = "Table reference"		}

string	output  = "STDOUT"	{ prompt = "Output filename"		}
string	otype   = "ascii"	{ prompt = "Output format",
				    min="ascii|csv|votable|fits"	} 
bool	all     = yes		{ prompt = "Get all matching tables?"   }
bool	verbose = no		{ prompt = "Verbose output?"   }

int	status  = 0		{ prompt = "Service status code"	}

begin
	string  id, url, oname, tname, ctype, oroot
	string  sfile, fields, catid, svc_type
	bool	verb, do_all
	int	fnum, nrecords


	id     = tab_id
	ctype  = otype
	oroot  = output
	do_all = all
	verb   = verbose

	svc_type = "tabularskyservice"
	fields   = "ServiceURL,Identifier"
	fnum     = 1


	# Create a temporary url file and output name.
	sfile = mktemp ("tmp$vizier")
	tname = mktemp ("tmp$vizier") // ".xml"

	if (do_all)
	    print (regResolver (id, svc_type, fields, -1), > sfile)
	else
	    print (regResolver (id, svc_type, fields), > sfile)

	nrecords = nresolved()

	list = sfile 
	while (fscan (list, url, catid) != EOF) {

	    if (nrecords > 1)
	        oname = oroot // "." // fnum
	    else
	        oname = oroot

	    if (verb)
		printf ("Downloading %s ... to %s\n", catid, oname)

	    # Call the Vizier service url
	    rawcaller (url, otype="votable", output=tname)

	    # Output the table.
	    tabout (tname, oname, ctype)

	    delete (tname, verify-)
	    fnum = fnum + 1
	}

end