summaryrefslogtreecommitdiffstats
path: root/ds9/library/catskybot.tcl
blob: 61e5578be96fe8e4ffe11fabc466b0dc3cb77754 (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
#  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 CATSkyBot {varname} {
    upvar #0 $varname var
    global $varname

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

    CATSkyBotVOT $varname
}

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

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

    set var(proc,parser) VOTParse
    
    # coord (degrees)
    switch $var(skyformat) {
	degrees {
	    set xx $var(x)
	    set yy $var(y)
	}
	sexagesimal {
	    switch -- $var(sky) {
		fk4 -
		fk5 -
		icrs {set xx [h2d [Sex2H $var(x)]]}
		galactic -
		ecliptic {set xx [Sex2D $var(x)]}
	    }
	    set yy [Sex2D $var(y)]
	}
    }

    # size (arcmin)
    switch $var(rformat) {
	degrees {
	    set ww $var(width)
	    set hh $var(height)
	}
	arcmin {
	    set ww [expr $var(width)/60.]
	    set hh [expr $var(height)/60.]
	}
	arcsec {
	    set ww [expr $var(width)/60./60.]
	    set hh [expr $var(height)/60./60.]
	}
    }

    # now to radius
    set rr [expr sqrt($ww*$ww+$hh*$hh)/2.]

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

    # figure out a epoch (DATE-OBS, then DATE)
    global current
    set epoch [string trim [$current(frame) get fits header keyword DATE-OBS]]
    if {$epoch == {}} {
	set epoch [string trim [$current(frame) get fits header keyword DATE_OBS]]
    }
    if {$epoch == {}} {
	set epoch [string trim [$current(frame) get fits header keyword DATE]]
    }
    if {$epoch == {}} {
	ARError $varname [msgcat::mc {Unable to determine date of observation}]
	return
    }

    # do we have a time? else check UT, UTC-OBS, UTIME, TIME-OBS
    set ut {}
    if {[string first {T} $epoch] == -1} {
	set ut [string trim [$current(frame) get fits header keyword UT]]
	if {$ut == {}} {
	    set ut [string trim [$current(frame) get fits header keyword UTC-OBS]]
	}
	if {$ut == {}} {
	    set ut [string trim [$current(frame) get fits header keyword UTIME]]
	}
	if {$ut == {}} {
	    set ut [string trim [$current(frame) get fits header keyword TIME-OBS]]
	}
	if {$ut == {}} {
	    set ut [string trim [$current(frame) get fits header keyword TIME_OBS]]
	}

	if {$ut != {}} {
	    append epoch "T$ut"
	}
    }

    # do we finally have a date with time?
    set dt [split $epoch {T}]
    set dd [lindex $dt 0]
    set tt [lindex $dt 1]
    if {$tt != {}} {
	# do we have EXPTIME or EXP_TIME?
	set exp [string trim [$current(frame) get fits header keyword EXPTIME]]
	if {$exp == {}} {
	    set exp [string trim [$current(frame) get fits header keyword EXP_TIME]]
	}

	if {$exp != {} && [string is double $exp]} {
	    # ok, rebuild epoch
	    set ttt [split $tt {:}]
	    set total [expr [lindex $ttt 0]*60.*60. + [lindex $ttt 1]*60. + [lindex $ttt 2] + [expr $exp/2.]]
	    set hh [format "%02d" [expr int($total/60./60.)]]
	    set total [expr $total - $hh*60.*60.]
	    set mm [format "%02d" [expr int($total/60.)]]
	    set ss [format "%02.1f" [expr $total - $mm*60.]]
	    set epoch "${dd}T${hh}:${mm}:${ss}"
	}
    }

    # query
    set var(query) [http::formatQuery EPOCH $epoch RA $xx DEC $yy SR $rr VERB $type -mime votable -loc $var(loc) -filter 0 -objFilter $var(asteroids)$var(planets)$var(comets)]
    set var(url) "http://vo.imcce.fr/webservices/skybot/skybotconesearch_query.php"
    CATLoad $varname
}

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

    set msg {Acknowledgments for SkyBot

Request for Acknowledgment of Use of SkyBot

If SkyBoT was helpful for your research work, the following acknowledgment
would be appreciated: "This research has made use of IMCCE's SkyBoT VO tool",
or cite the following article 2006ASPC..351..367B.
    }

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