aboutsummaryrefslogtreecommitdiff
path: root/vo/handlers/tblhandler.cl
blob: 7d1d0e9a5a64e8e3b2d6738473f38331bfd4f09f (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
#{ TBLHANDLER -- Utility VOTable SAMP message handler

procedure tblhandler (url)

string	url 			{ prompt = "VOTable URL"		}

string	task1 = "imexam %s 1"   { prompt = "Single-row task to execute"	}
string	taskn = "" 		{ prompt = "Multi--row task to execute"	}

begin
	string  inurl, sname, tname, tab, tsk, t1, tn, root
	int     sia

	inurl   = url
	t1      = task1
	tn      = taskn


	iferr {
	    tab = mktemp ("tmp$tbl")
	    # copy (inurl, tab)		FIXME
	    urlget (inurl, tab, use_cache-, extn="", verb-)
	    unlearn ("tinfo")
	    tinfo (inurl, >& "dev$null")

	    # Check for an SIA result table.
	    match ("Image_AccessReference", tab) | count ("STDIN") | scan (sia)

	    if (tinfo.nrows == 1 && sia == 1)		# get task to execute
		tsk = t1
	    else
		tsk = tn

	    # Execute the command depending on the number of rows in the table.

	    sections ("@" // osfn (tab)) | scan (tname)
	    root = tname
	    if (imaccess (tname // "[1]") == yes) {
	        if (imaccess (tname // "[SCI]") == yes)
		    tname = tname // "[SCI]"
	        else
		    tname = tname // "[1]"
	    }

	    # Execute the command.
	    printf (tsk // "\n", tname) | clbye()

	    printf ("Save As (or <cr> to quit)? ")	# Save displayed image?
	    scan (sname)
	    if (nscan () == 1) {
		print (root // " --> " // sname)
		copy (root, sname)
	    }

	} then {
	    delete (tab, ver-, >& "dev$null")
	    logout
	}

	delete (tab, ver-, >& "dev$null")
end