#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"

###################################################################
# This file is part of tk545, a control program for the
# Japan Radio Corp. NRD-545 receiver.
# 
#    Copyright (C) 2001, 2002, Bob Parnass
#					AJ9S
# 
# tk545 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
# 
# tk545 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with tk545; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307  USA
###################################################################


######################################################################
# Write error messages to stderr if linux/unix, stdout otherwise
######################################################################

proc Tattle { msg } \
{
	global tcl_platform

	 set platform $tcl_platform(os) 
	 switch -glob $platform \
		{
		{[Ll]inux} \
			{
			puts stderr $msg
			}
		{unix} \
			{
			puts stderr $msg
			}
		default \
			{
			puts $msg
			}
		}

	return
}
############################################################
set Version "1.4"

set AboutMsg  "tk545
version $Version

Copyright 2001, 2002, Bob Parnass
http://parnass.com

Released under the GNU General Public License.

tk545 is a control program for the
JRC NRD-545 receiver.
This is beta software. If you find a defect,
please report it."

############################################################

set Pgm [lindex [split $argv0 "/"] end]
set Libdir $env(tk545)


# Sanity check for the Libdir environment variable.
if {$Libdir == ""}\
	{
	Tattle "$Pgm: error: Environment variable tk545 must"
	Tattle "be set to the directory containing the library"
	Tattle "files for program $Pgm."
	exit 1
	}



source [ format "%s/%s" $Libdir "misclib.tcl" ]
source [ format "%s/%s" $Libdir "mylib.tcl" ]
source [ format "%s/%s" $Libdir "api545.tcl" ]
source [ format "%s/%s" $Libdir "gui545.tcl" ]
source [ format "%s/%s" $Libdir "presets.tcl" ]

SetUp

set lst [ InitStuff ]
set Rcfile [ lindex $lst 0 ]
set LabelFile [ lindex $lst 1 ]

FirstTimeCheck $Rcfile

# Set most global variable from a configuration file.
PresetGlobals
ReadSetup
OverrideGlobals

ReadLabel

#if {$GlobalParam(Font) != "" } \
#	{
#	# Designate a custom font for most widgets.
#
#	option add *font $GlobalParam(Font)
#	# puts stderr "font: $GlobalParam(Font)"
#	}
#
set CancelXfer 0

set FileTypes \
	{
	{"NRD-545 data files"           {.csv .txt}     }
	}


set msg [OpenDevice]

if { $msg != ""} \
	{
	tk_dialog .opnerror "tk545 error" \
		$msg error 0 OK
	exit
	}

# Create all the graphical widgets and make them appear on the screen.
MakeGui

# Add the current frequency and mode to the session history list.
Add2History

# Start polling the radio for S meter readings after a delay.
after 1000 PollSmeter

update idletasks
