
# JStrack:  copyright 1997/2010 by Jim Graham, N5IAL, all rights reserved.

# Wipe the chart clean, and create empty copies of variables.

proc wipeclean {{name ""}} {
   global stinfo forecasts st_names st_times watchwarn
   global fc_tm_idx advisory_list

   catch { .c delete withtag WATCHWARN.[string toupper $name] }
   array unset watchwarn [string toupper $name]*

   if {$name == ""} {
      all_wipeclean
      return
   }

   set name [string toupper [file tail $name]]
   set idx "STORM_$name*"
   foreach i [array names stinfo        "$idx"]  { unset stinfo($i) }
   foreach i [array names stfile        "$idx"]  { unset stfile($i) }
   foreach i [array names advisory_list "$idx"]  { unset advisory_list($i) }
   foreach i [array names stradii       "$idx"]  { unset stradii($i) }
   foreach i [array names fc_stradii    "$idx"]  { unset fc_stradii($i) }

   set idx "$name*"
   foreach i [array names st_times  "$idx"]  { unset st_times($i) }
   foreach i [array names forecasts "$idx"]  { unset forecasts($i) }
   foreach i [array names fc_tm_idx "$idx"]  { unset fc_tm_idx($i) }

   set old_st_names $st_names
   set st_names [list]
   foreach nm $old_st_names {
      if {[string compare $nm $name]} { lappend st_names $nm }
   }
   tk_wipe $name
}


proc all_wipeclean {} {
   global stinfo forecasts st_names st_times watchwarn
   global fc_tm_idx advisory_list

   catch { .c delete withtag WATCHWARN }
   array unset watchwarn
   set watchwarn() [list]

   catch { unset stinfo }         ;  array set stinfo {}
   catch { unset advisory_list }  ;  array set advisory_list {}
   catch { unset forecasts }      ;  array set forecasts {}
   catch { unset st_times }       ;  array set st_times {}
   catch { unset fc_tm_idx }      ;  array set fc_tm_idx {}
   catch { unset stradii }        ;  array set stradii {}
   catch { unset fc_stradii }     ;  array set fc_stradii {}
   catch { unset stfile }         ;  array set stfile {}
   set st_names [list]
   tk_wipe
}


# reload multiple storms

proc mreload {args} {
   global st_names
   if {[llength $args] > 0} {
      foreach i $args { reload $i }
   } else {
      if {[llength $st_names] > 0} {
         foreach i $st_names { reload $i }
      }
   }
}


# reload the data for a given storm

proc reload {{name ""}} {
   global advisory_list current_storm_name storms stfile
   if {$name == ""} {
      wipeclean
   } else {
      wipeclean $name
   }
   if {$name == ""} {
      foreach filename [glob $storms/*.trk] {
         source $filename
         newtrk_curr
         plot_last $current_storm_name
      }
   } else {
      set filename "$storms/[string tolower $name].trk"
      if {[file exists $filename]} {
         set stfile([file tail $name]) "[string tolower $name]"
         source $filename
         newtrk_curr
         plot_last $current_storm_name
      } else {
         puts "Can't find $filename ... $name not loaded."
      }
   }
   set fakeset ""  ;# prevents the last result from being displayed
}




