1# JStrack:  copyright 1997/2010 by Jim Graham, N5IAL, all rights reserved.
2#
3
4# Global (well, static, actually, but Tcl doesn't have static vars)
5# array variable to be used in this file ONLY!
6
7array set last_st_access {}
8
9# Globals here must mirror test_st_files below
10proc test_progs {cmd} {
11   global st_names st_times last_st_access storms auto_update
12   global full_update update_prog pos_est_prog last_full_update
13   global ok_for_full_test new_pos_est auto_load_new
14
15   if {[catch { eval exec $cmd } msg]} {
16      tk_messageBox -type ok -message $msg
17   }
18}
19
20# Globals here must be mirrored in test_progs above
21proc test_st_files {{init 0}} {
22   global st_names st_times last_st_access storms auto_update
23   global full_update update_prog pos_est_prog last_full_update
24   global ok_for_full_test new_pos_est auto_load_new
25
26   if {[catch {glob $storms/*.trk}]} { return }
27   foreach i [glob $storms/*.trk] {
28      file stat $i f_stats
29      set f_mtime $f_stats(mtime)
30      set name [string toupper [file tail [file rootname $i]]]
31
32      if {[string compare [array get st_times $name] ""]} {
33         set full_update 0
34         set new_pos_est 0
35         set ok_for_full_test 0
36         set tmplist [split "$st_times($name)"]
37         set last_full_update [lindex $tmplist end]
38      }
39
40      if {$init} {
41         set last_st_access($i) $f_mtime
42      } elseif {[array get last_st_access $i] == ""} {
43         if {[info exists auto_load_new] && $auto_load_new} {
44            set load "yes"
45         } else {
46            set load [tk_messageBox -message "New storm ($name):  Load data?" \
47               -type yesno]
48         }
49
50         if {$load == "yes"} {
51            reload $name ; update
52            if {[info exists update_prog] && $update_prog != ""} {
53               catch { eval exec $update_prog }
54            }
55         }
56         set last_st_access($i) $f_mtime
57      } elseif {$st_names == ""} {
58         set last_st_access($i) $f_mtime
59      } else {
60         set f_atime $last_st_access($i)
61         if {$f_atime < $f_mtime} {
62            if {[array get st_times $name] != ""} {
63               toplevel .file$name
64               wm geometry .file$name +150+150
65               wm attributes .file$name -topmost true
66               label .file$name.lbl -text "Reloading storm data for $name"
67               pack .file$name.lbl
68               update
69               after 2500
70               destroy .file$name ; reload $name ; update
71               set last_st_access($i) $f_mtime
72               set nm [string tolower $name]
73               if {[info exists update_prog] && $update_prog != "" && $full_update} {
74                  catch { eval exec $update_prog }
75               } elseif {[info exists pos_est_prog] && $pos_est_prog != "" && $new_pos_est} {
76                  catch { eval exec $pos_est_prog }
77               }
78            }
79         }
80      }
81   }
82   if {$auto_update} { after 60000 test_st_files }
83}
84
85
86