#!/usr/local/bin/tclsh8.4

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

# CONFIGURATION ITEMS:

cd [file dirname $argv0]
source ../paths.tcl

# On Unix, check path in first line (#! ...) and make sure it points to
# Tclsh

# END OF CONFIGURATION ITEMS (much easier!)

set dlist [split [read stdin] \n]

set stname ""
set inadv 0
set la1 -1 ; set la2 -1 ; set lo1 -1 ; set lo2 -1

foreach line $dlist {
   # a little house cleaning
   regsub {^  *} $line {} l2
   set line $l2


   if {[regexp {^([A-Z]*) WATCH/WARNING BREAKPOINTS} $line a name]} {
      set stname $name
puts "NAME:  $name"
   } elseif {[string compare $line  {$$}] == 0} {
      set lcname [string tolower $stname]
      set f [open $storms/$lcname.trk a]
puts "About to save data to $storms/$lcname.trk"
      puts $f "plot_ww $stname $str $lo1 $la1 $lo2 $la2"
      close $f
      set inadv 0
      set la1 0 ; set la2 0 ; set lo1 0 ; set lo2 0

   } elseif {[regexp {^/O.CAN.*Z/$} $line]} {
      set str $line ; 
      set lcname [string tolower $stname]
      set f [open $storms/$lcname.trk a]
puts "About to save data to $storms/$lcname.trk"
      puts $f "plot_ww $stname $str 0 0 0 0"
      close $f
      set inadv 1
   } elseif {[regexp {^/O.*Z/$} $line]} {
      set inadv 1
      set str $line
   } elseif {[regexp {.* ([0-9][0-9].[0-9][0-9])N ([0-9][0-9].[0-9][0-9])W} $line a la lo]} {
      if {$inadv == 1} {
         set la1 $la ; set lo1 $lo ; set inadv 2
      } elseif {$inadv == 2} {
         set la2 $la ; set lo2 $lo
      }
   }
}

