aboutsummaryrefslogtreecommitdiff
path: root/vo/votools/t_votget.x
blob: c189638fa1706e36fcc96abf30c6e5f7f3ffc07d (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
#
# VOTGET -- Download Access References from a VOTable

include <ctype.h>
include <votParse_spp.h>


define DEF_BASE   	"file"
define DEF_EXTN   	"fits"


#    input	input list of VOTables
#
#    base	base output filename
#    extn	output filename extension
#    sequential	use sequential file numbers
#
#    list	list, rather than download, access references
#    nthreads	Number of simultaneous downloads
#
#    col	column number to use for acred (0-indexed)
#    acref	ucd to identify the access reference column
#    format	format to download (e.g. 'fits' or 'jpeg')


procedure t_votget ()

pointer	sp, in, base, extn, efname, acref, format, in_osfn, line
char    nth[SZ_FNAME], cnum[SZ_FNAME], seq[SZ_FNAME]
int	efd, inlist, nthreads, col
bool	sequential, list

int	open(), getline(), clgeti(), clpopni(), clgfil()
bool	clgetb()

begin
	call smark (sp)
	call salloc (in, SZ_FNAME, TY_CHAR)
	call salloc (base, SZ_FNAME, TY_CHAR)
	call salloc (extn, SZ_FNAME, TY_CHAR)
	call salloc (efname, SZ_FNAME, TY_CHAR)
	call salloc (acref, SZ_FNAME, TY_CHAR)
	call salloc (format, SZ_FNAME, TY_CHAR)
	call salloc (line, SZ_LINE, TY_CHAR)

	call strcpy ("", Memc[base], SZ_LINE)

	# Get the task parameters.
	inlist = clpopni ("input")

	list       = clgetb ("list")
	if (!list)
	    call clgstr ("base", Memc[base], SZ_LINE)
	call clgstr ("extn", Memc[extn], SZ_LINE)
	call clgstr ("format", Memc[format], SZ_FNAME)
	call clgstr ("acref", Memc[acref], SZ_FNAME)

	nthreads   = clgeti ("nthreads")
	col        = clgeti ("col")
	list       = clgetb ("list")
	sequential = clgetb ("sequential")


	# Convert integer args to strings for passing to the task.
	call sprintf (nth, SZ_FNAME, "%d")
	    call pargi (nthreads)
	if (!IS_INDEFI(col)) {
	    call sprintf (cnum, SZ_FNAME, "%d")
	        call pargi (col)
	}

	if (list)
	    call mktemp ("/tmp/ex", Memc[efname], SZ_FNAME)

	if (sequential)
	    call strcpy ("-s", seq, SZ_FNAME)
	else
	    call strcpy ("+n", seq, SZ_FNAME)


	# Loop over the files,
	while (clgfil (inlist, Memc[in], SZ_LINE) != EOF) {

            call fmapfn (Memc[in], Memc[in_osfn], SZ_PATHNAME)
            call strupk (Memc[in_osfn], Memc[in_osfn], SZ_PATHNAME)

	    # Call the application part of the task.
	    if (IS_INDEFI(col)) {
		if (list) {
                    call vx_voget (7, "-o", Memc[efname], "-f", Memc[format], 
			"-u", Memc[acref], Memc[in_osfn])
		} else {
                    call vx_voget (12, "-b", Memc[base], "-N", nth, seq, 
		        "-e", Memc[extn], "-f", Memc[format], 
			"-u", Memc[acref], Memc[in_osfn])
		}
	    } else {
		if (list) {
                    call vx_voget (7, "-o", Memc[efname], "-f", Memc[format], 
			"-F", cnum, Memc[in_osfn])
		} else {
                    call vx_voget (12, "-b", Memc[base], "-N", nth, seq,
		        "-e", Memc[extn], "-f", Memc[format], 
			"-F", cnum, Memc[in_osfn])
		}
	    }
	}

	# Print the extracted access references from the concatenated file.
	if (list) {
            efd = open (Memc[efname], READ_ONLY, TEXT_FILE)
            while (getline (efd, Memc[line]) != EOF) {
		call printf ("%s")
		    call pargstr (Memc[line])
	    }
	    call close (efd)
	    call delete (Memc[efname])
	}

	call clpcls (inlist)
	call sfree (sp)
end