#!/bin/sh  
# \
exec oagwish "$0" "$@"

# $Log: not supported by cvs2svn $
# Revision 1.10  2003/05/27 19:42:30  soliday
# The PAR RF PVs no longer exist. The values are now hard coded.
#
# Revision 1.9  1999/10/16 19:10:30  borland
# Replaced SY:Hp8657RefFreq with RFS:Hp8657RefFreqC.
#
# Revision 1.8  1997/07/25 19:12:45  borland
# Added update statement inside RefreshValues.  RefreshValues now calls
# itself after 0.5s no matter what the state of the frequencies.
#
# Revision 1.7  1996/03/04  20:14:17  saunders
# Added revision/author to Version menu.
#
# Revision 1.6  1996/01/17  16:59:28  saunders
# Added /usr/local/oag/lib_patch to front to auto_path.
#
# Revision 1.5  1996/01/16  21:12:00  saunders
# Fixed log entry problem, so now comments and version numbers
# appear properly. Also, renames X.tcl files to just X.
#
# Revision 1.4  1996/01/12 22:36:41  saunders
# Removing dependence on ~borland/tcl/rel auto_path entry. There are still
# references to personal directories. Also fixed minor bugs as encountered.
#
# Revision 1.3  1995/12/15  20:12:30  saunders
# Added proper installation Makefile and Log
#

set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]
set CVSRevisionAuthor "\$Revision: 1.11 $ \$Author: soliday $"

APSApplication . -name checkFrequency -version $CVSRevisionAuthor \
  -overview {This application monitors the RF frequencies for the PAR fundamental and harmonic systems, and for the booster/storage-ring systems.  It evaluates and displays the mismatch between these frequencies. Note that this is probably irrelevant, because the independent oscillators are no longer used.}

frame .userFrame.outputs 
pack .userFrame.outputs -side top

frame .userFrame.outputs.freq
APSMakeLabeledOutputs .userFrame.outputs.freq.rf1  "PAR Fundamental (Hz):" \
  -ewidth 16 RF1Freq -lanchor w -eside right  -lwidth 20
APSMakeLabeledOutputs .userFrame.outputs.freq.rf12 "PAR Harmonic (Hz):" \
  -ewidth 16 RF12Freq  -lanchor w -eside right  -lwidth 20
APSMakeLabeledOutputs .userFrame.outputs.freq.rf36 "Booster/Ring (Hz):" \
  -ewidth 16 RF36Freq  -lanchor w -eside right  -lwidth 20
pack .userFrame.outputs.freq -side left

frame .userFrame.outputs.error 
APSMakeLabeledOutputs .userFrame.outputs.error.rf36 "Error (Hz):" \
  -ewidth 16 RF36Error -lanchor w -fside bottom -lwidth 20
APSMakeLabeledOutputs .userFrame.outputs.error.rf12 "Error (Hz):" \
  -ewidth 16 RF12Error -lanchor w -eside left -fside bottom  -lwidth 20
pack .userFrame.outputs.error -side left -fill y

frame .userFrame.ops
pack .userFrame.ops -side top
button .userFrame.ops.exit  -text EXIT -command exit
pack .userFrame.ops.exit

if 0 {
    if {[pv linkw {RF1Freq RF12Freq RF36Freq} \
	{PAR:RF1:PTSFreq PAR:RF12:hp8657RefFreq BRF:S:Hp8657RefFreqAO}] != 0} {
	APSAlertBox .errmsg001 -errorMessage "Error: $errorCode"
	exit
    }
    
    if {[pv mon {RF1Freq RF12Freq RF36Freq} RefreshValues] != 0} {
	APSAlertBox .errmsg002 -errorMessage "Error: $errorCode"
	exit
    }
}
    if {[pv linkw {RF36Freq} \
	{BRF:S:Hp8657RefFreqAO}] != 0} {
	APSAlertBox .errmsg001 -errorMessage "Error: $errorCode"
	exit
    }
    
    if {[pv mon {RF36Freq} RefreshValues] != 0} {
	APSAlertBox .errmsg002 -errorMessage "Error: $errorCode"
	exit
    }
set RF1Freq [expr {351.93 / 36.0}]
set RF12Freq [expr {351.93 / 3.0}]
proc RefreshValues {} {
    global RF1Freq RF12Freq RF36Freq RF12Error RF36Error
    set RF1Freq  $RF1Freq
    set RF12Freq $RF12Freq
    set RF36Freq $RF36Freq
    set RF12Error [format %f [expr $RF12Freq/$RF1Freq-12]]
    set RF36Error [format %f [expr $RF36Freq/$RF1Freq-36]]
    update
    after 500 
    RefreshValues
}

RefreshValues
