aboutsummaryrefslogtreecommitdiff
path: root/vo/votools/votpos.cl
blob: 75802abb07f20fc024427f5030c7ca384e8acfff (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
#{  VOTPOS -- Extract the main RA/Dec columns from a VOTable.

procedure votpos (input)

string	input			{ prompt = "Input VOTable"		}
string	output   = "STDOUT"	{ prompt = "Output filename"		}

int	ra_col   = INDEF	{ prompt = "RA column number"		}
int	dec_col  = INDEF	{ prompt = "RA column number"		}
string	rows     = "-"		{ prompt = "Rows to print"		}

bool    header   = no           { prompt = "Print output header?"       }
bool    number   = no           { prompt = "Number output rows?"        }
bool    plot     = no           { prompt = "Plot coordinate points?"    }
bool    overplot = yes          { prompt = "Overplot an existing plot?" }
int	color    = 1		{ prompt = "Plot marker color"		}
string  title	 = ""		{ prompt = "Plot title"			}

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

begin
    int     racol, deccol, lcolor
    string  lin, lout, ra_name, dec_name, tpos, pfields, ltitle
    bool    do_number, do_hdr, do_plot, do_overplot


    lin         = input
    lout        = output
    do_plot     = plot
    do_number   = number
    do_hdr      = header
    ltitle      = title

    do_overplot = overplot
    if (do_overplot)
        lcolor = color + 1
    else
	lcolor = 1


    # Get the RA column using either the old or new UCD.
    if (ra_col > 0) {
	racol = ra_col
	keypar (lin, "TTYPE" // racol)
	ra_name = keypar.value
    } else {
        colbyucd (lin, "POS_EQ_RA_MAIN")
        if (colbyucd.column < 0) {
            colbyucd (lin, "pos.eq.ra;meta.main")
            if (colbyucd.column < 0) {
	        error (0, "No RA column found in table")
	    } else {
	        racol = colbyucd.column
	        ra_name = colbyucd.name
	    }
        } else {
	    racol = colbyucd.column
	    ra_name = colbyucd.name
        }
    }

    # Get the Dec column using either the old or new UCD.
    if (dec_col > 0) {
	deccol = dec_col
	keypar (lin, "TTYPE" // deccol)
	dec_name = keypar.value
    } else {
        colbyucd (lin, "POS_EQ_DEC_MAIN")
        if (colbyucd.column < 0) {
            colbyucd (lin, "pos.eq.dec;meta.main")
            if (colbyucd.column < 0) {
	        error (0, "No DEC column found in table")
	    } else {
	        deccol = colbyucd.column
	        dec_name = colbyucd.name
	    }
        } else {
	    deccol = colbyucd.column
	    dec_name = colbyucd.name
        }
    }

    # Extract the position columnms
    tpos = mktemp ("tmp$pos")
    tprint (lin, prparam-, prdata+, showrow=do_number, showhdr=do_hdr,
	column=ra_name//","//dec_name, rows=rows, option="plain", > tpos)


    # Print the selected columns.
    if (lout == "STDOUT") {
	type (tpos)
    } else if (lout != "") {
	copy (tpos, lout, verbose-, >& "dev$null")
    }

    # Plot the positions?
    if (do_plot) {
	pfields = "1,2"
        if (do_number)
	    pfields = "2,3"

	fields (tpos, pfields) | graph ("STDIN", point+, 
		xformat="%H", yformat="%h", xlabel="RA", ylabel="Dec",
		title=ltitle, marker="box", szmarker=0.01, colors=lcolor,
		vx1=0.15, vx2=0.95, vy1=0.1, vy2=0.95, round-,
		append=do_overplot)
    }

    # Update and save the plot color.
    if (overplot && lcolor < 8)
	color = lcolor + 1
    else 
	color = 1
    overplot = no

    delete (tpos, verify-, >& "dev$null")
end