blob: 443ad0637a9635564b38d706219a7f5db36799e7 (
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
|
# 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 DisplayHeaderMenu {} {
global current
# possible cases
# image primary
# image xtension
# compressed primary
# compressed xtension
# bin table xtension
# hpx xtension
# cube primary
# cube xtension
# multiple xtension cube
# multiple file cube
# mosaic extension
# mosaic image xtension
# mosaic cube xtension
# mosaic image cube xtension
set cnt [$current(frame) get fits count]
if {$cnt > 0} {
set slb(count) 0
# check for primary
set fn [$current(frame) get fits file name 1]
set xten \
[string trim [$current(frame) get fits header 1 keyword {XTENSION}]]
if {$xten != {}} {
set bb [string first {[} $fn]
if {$bb>0} {
set pn [string range $fn 0 [expr $bb-1]]
} else {
set pn "primary"
}
incr slb(count)
set slb($slb(count),item) $pn
set slb($slb(count),value) -1
}
set last {}
for {set ii 1} {$ii <= $cnt} {incr ii} {
set fn [$current(frame) get fits file name $ii]
set bb [string first {[} $fn]
if {$bb<0} {
set nn [$current(frame) get fits ext $ii]
if {$nn > 0} {
set fn "$fn\[\]"
}
}
if {$fn != $last} {
incr slb(count)
set slb($slb(count),item) $fn
set slb($slb(count),value) $ii
set last $fn
}
}
if {$slb(count) <= 1} {
DisplayHeader $current(frame) 1 $fn
} else {
if {[SLBDialog slb {Select Header} 40]} {
DisplayHeader $current(frame) $slb(value) $slb(item)
}
}
}
}
proc DisplayHeader {frame id title} {
global current
set varname "hd-$frame-$id"
global $varname
SimpleTextDialog $varname $title 80 40 insert top \
[$current(frame) get fits header $id]
# create a special text tag for keywords
upvar #0 $varname var
$var(text) tag configure keyword -foreground blue
# color tag keywords
set stop [$var(text) index end]
for {set ii 1.0} {$ii<$stop} {set ii [expr $ii+1]} {
$var(text) tag add keyword $ii "$ii +8 chars"
}
}
proc UpdateHeaderDialog {} {
global current
set frame $current(frame)
set cnt 1
if {[$frame has fits mosaic]} {
set cnt [$frame get fits count]
}
for {set id 1} {$id <= $cnt} {incr id} {
set varname "hd-$frame-$id"
global $varname
if {![info exists $varname]} {
continue
}
upvar #0 $varname var
$var(text) delete 1.0 end
$var(text) insert end [$frame get fits header $id]
# color tag keywords
set stop [$var(text) index end]
for {set ii 1.0} {$ii<$stop} {set ii [expr $ii+1]} {
$var(text) tag add keyword $ii "$ii +8 chars"
}
}
}
proc DestroyHeader {frame} {
set cnt 1
if {[$frame has fits mosaic]} {
set cnt [$frame get fits count]
}
for {set id 1} {$id <= $cnt} {incr id} {
DestroyHeaderOne $frame $id
}
}
proc DestroyHeaderOne {frame id} {
set varname "hd-$frame-$id"
global $varname
if {[info exists $varname]} {
SimpleTextDestroy $varname
}
}
proc ProcessHeaderCmd {varname iname} {
upvar $varname var
upvar $iname i
global debug
if {$debug(tcl,parser)} {
header::YY_FLUSH_BUFFER
header::yy_scan_string [lrange $var $i end]
header::yyparse
incr i [expr $header::yycnt-1]
} else {
set item [string tolower [lindex $var $i]]
switch -- $item {
close -
save {incr i}
}
if {[lindex $var $i] != {} && [string is integer [lindex $var $i]]} {
set jj [lindex $var $i]
incr i
} else {
set jj 1
}
global current
if {$current(frame) != {}} {
switch -- $item {
close {
CloseHeaderCmd $jj
incr i -1
}
save {
SaveHeaderCmd $jj [lindex $var $i]
}
default {
DisplayHeaderCmd $jj
incr i -1
}
}
}
}
}
proc DisplayHeaderCmd {id} {
global current
DisplayHeader $current(frame) $id [$current(frame) get fits file name $id]
}
proc CloseHeaderCmd {id} {
global current
DestroyHeaderOne $current(frame) $id
}
proc SaveHeaderCmd {id fn} {
global current
if {$fn != {}} {
if {[catch {set ch [open "| cat > \"$fn\"" w]}]} {
Error [msgcat::mc {An error has occurred while saving}]
return
}
puts -nonewline $ch [$current(frame) get fits header $id]
close $ch
}
}
|