summaryrefslogtreecommitdiffstats
path: root/ds9/library/catcxc.tcl
blob: 311b25afb8b9887c449ffb911636d710ca72921d (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#  Copyright (C) 1999-2018
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

proc CATCXC {varname} {
    upvar #0 $varname var
    global $varname
    global pcat

    global debug
    if {$debug(tcl,cat)} {
	puts stderr "CATCXC $varname"
    }

    CATCXCVOT $varname
}

proc CATCXCVOT {varname} {
    upvar #0 $varname var
    global $varname

    global debug
    if {$debug(tcl,cat)} {
	puts stderr "CATCXCVOT $varname"
    }

    set var(proc,parser) VOTParse
    
    # coord (degrees)
    switch $var(skyformat) {
	degrees {
	    set xx $var(x)
	    set yy $var(y)
	}
	sexagesimal {
	    set xx [h2d [Sex2H $var(x)]]
	    set yy [Sex2D $var(y)]
	}
    }

    # size (degrees)
    switch $var(rformat) {
	degrees {
	    set rr $var(radius)
	}
	arcmin {
	    set rr [expr $var(radius)/60.]
	}
	arcsec {
	    set rr [expr $var(radius)/60./60.]
	}
    }

    # output
    if {$var(allcols)} {
	set type 3
    } else {
	set type 2
    }

    # query
    set var(query) [http::formatQuery RA $xx DEC $yy SR $rr VERB $type]
    set var(url) "http://cda.cfa.harvard.edu/cscvo/coneSearch"

    CATLoad $varname
}

proc CATCXCReader {t sock token} {
    upvar #0 $t T
    global $t

    set result 0

    if { ![info exists ${t}(state)]  } {
	set T(state) 0
    }

    switch -- $T(state) {
	0 {
	    # init db
	    fconfigure $sock -blocking 1
	    set T(Nrows) 0
	    set T(Ncols) 0
	    set T(Header) {}
	    set T(HLines) 0

	    set T(state) 1
	}

	1 {
	    # process header
	    if {[gets $sock line] == -1} {
		set T(Nrows) 0
		set T(Ncols) 0
		set T(Header) {}
		set T(HLines) 0

		set T(state) -1
		return $result
	    }

	    set result [string length "$line"]

	    incr ${t}(HLines)
	    set n $T(HLines)
	    set T(H_$n) $line

	    if {[regexp -- {^ *(-)+ *(\t *(-)+ *)*} $line]} {
		# clean up header column name
		set hh $T(H_[expr $n-1])
		regsub -all {\[} $hh {} hh
		regsub -all {\]} $hh {} hh
		set T(H_[expr $n-1]) $hh

		# cols
		set T(Header) [split $T(H_[expr $n-1]) "\t"]
		set T(Dashes) [split $T(H_$n) "\t"]
		set T(Ndshs) [llength $T(Dashes)]
		starbase_colmap $t
		set T(state) 2

		# these are hard coded
		set T(Id) $T(Header)
		set T(DataType) {}
		set T(ArraySize) {}
		set T(Unit) {}
		set T(Ucd) {}
		# name
		lappend T(DataType) {char}
		lappend T(ArraySize) {*}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# ra
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {deg}
		lappend T(Ucd) {pos.eq.ra;meta.main}
		# dec
		lappend T(DataType) {float} 
		lappend T(ArraySize) {}
		lappend T(Unit) {deg}
		lappend T(Ucd) {pos.eq.dec;meta.main}
		# err_ellipse_r0
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# err_ellipse_r1		
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# err_ellipse_ang
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {deg}
		lappend T(Ucd) {}
		# conf_flag
		lappend T(DataType) {boolean}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# extent_flag
		lappend T(DataType) {boolean}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# sat_src_flag
		lappend T(DataType) {boolean}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# flux_aper90_b
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# flux_aper90_hilim_b
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# flux_aper90_lolim_b
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# significance
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# hard_hm
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# hard_ms
		lappend T(DataType) {float}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}
		# var_intra_index_b
		lappend T(DataType) {int}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		# var_inter_index_b
		lappend T(DataType) {int}
		lappend T(ArraySize) {}
		lappend T(Unit) {}
		lappend T(Ucd) {}

		if {[llength $T(Header)] > 17} {
		    # obsid
		    lappend T(DataType) {int}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {}
		    lappend T(Ucd) {}
		    # ra_aper
		    lappend T(DataType) {float}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {deg}
		    lappend T(Ucd) {}
		    # dec_aper
		    lappend T(DataType) {float}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {deg}
		    lappend T(Ucd) {}
		    # mjr_axis_aper
		    lappend T(DataType) {float}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {}
		    lappend T(Ucd) {}
		    # mnr_axis_aper
		    lappend T(DataType) {float}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {}
		    lappend T(Ucd) {}
		    # pos_angle_aper
		    lappend T(DataType) {float}
		    lappend T(ArraySize) {}
		    lappend T(Unit) {deg}
		    lappend T(Ucd) {}
		}
	    }
	}

	2 { 
	    # process table
	    if {[gets $sock line] == -1} {
		set T(state) 0
	    } else {
		set result [string length "$line"]
		set line [string trim $line]

		if {$line != {}} {
		    # ok, save it
		    incr ${t}(Nrows)
		    set r $T(Nrows)

		    set NCols [starbase_ncols $t]
		    set c 1
		    foreach val [split $line "\t"] {
			set T($r,$c) $val
			incr c
		    }
		    for {} {$c <= $NCols} {incr c} {
			set T($r,$c) {}
		    }
		}
	    }
	}
    }

    return $result
}

proc CATCXCAck {varname} {
    upvar #0 $varname var
    global $varname

    set msg {Acknowledgments for CXC

Request for Acknowledgment of Use of the Chandra Source Catalog

Users are kindly requested to acknowledge in the acknowledgment
section of any resulting publications their use of the Chandra Source
Catalog.

This will help us greatly to keep track of catalog usage, information
that is essential for providing full accountability of our work and
services, as well as for planning future services.

The following language is suggested:

This research has made use of data obtained from the Chandra Source
Catalog, provided by the Chandra X-ray Center (CXC) as part of the
Chandra Data Archive.

We would like to remind you that it is also very helpful for us if you
could include Dataset Identifiers in the manuscript. The Dataset
Identifier for the Chandra Source Catalog is:

ADS/Sa.CXO#CSC
    }

    SimpleTextDialog ${varname}ack [msgcat::mc {Acknowledgment}] \
	80 10 insert top $msg
}