summaryrefslogtreecommitdiffstats
path: root/ds9/library/external.tcl
blob: 01342801f2d556d7bbbe62be909905c96a877e80 (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
#  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 InitExternalFile {} {
    global ds9

    if {[file exists "./$ds9(ext,file)"]} {
	ProcessExternalFile "./$ds9(ext,file)"
    } elseif {[file exists "./$ds9(ext,alt)"]} {
	ProcessExternalFile "./$ds9(ext,alt)"
    } elseif {[file exists "~/$ds9(ext,file)"]} {
	ProcessExternalFile "~/$ds9(ext,file)"
    } elseif {[file exists "~/$ds9(ext,alt)"]} {
	ProcessExternalFile "~/$ds9(ext,alt)"
    }
}

proc ProcessExternalFile {fn} {
    global extFits

    set status 1
    if {[file exists "$fn"]} {
	set id [open $fn r]
	while {[gets $id line] >= 0} {
	    # empty line
	    if {[string length $line] == 0} continue
	    # comments	    
	    if {[string range $line 0 0] == "\#"} continue
	    # else
	    switch -- $status {
		1 {
		    # eat the line
		    set template {}
		    set status 2
		}
		2 {
		    set template "$line"
		    set status 3
		}
		3 {
		    # eat the line
		    set status 4
		}
		4 {
		    if {"$template" != {} && "$line" != {}} {
			foreach t $template {
			    set extFits($t) "$line"
			}
		    }

		    set status 1
		}
	    }
	}
	close $id
    }
}