#!/usr/local/ucolick/tcl831/bin/wishx ##!/usr/local/ucolick/tcl831/bin/tclsh ##!/usr/local/bin/tclsh8.3 #+ # fcsview -- view FCS reference image in ds9 # # Purpose: # Launch a ds9 image display window showing the current FCS # reference image. # # Usage: # fcsview [-diff] [-blink] # # Flags: # -diff = show current image and difference between ref and current # -blink = blink images (default mode is column tile) # # Arguments: # image = name of FCS image to compare against reference image # # Output: # ds9 window to current display # # Restrictions: # FCSIMGFI keyword must be defined # # Exit values: # 0 = normal completion # 1 = wrong number of arguments # # Example: # 1) display the current FCS reference image: # fcsview #- # Modification history: # 2007-Jun-14 GDW Original version # 2013-Jul-7 MK Added flag -view image to ensure # cursor positions are displayed. #----------------------------------------------------------------------- proc abort { {message "ABORT!"} {status 1} } { puts stderr "\a\[[info script]\] $message" exit $status } # truncate last element from arg list (appears to be a bug in wishx)... set n [expr [llength $argv] - 1] set argv [lreplace $argv $n $n] # parse command-line args... foreach arg $argv { switch -glob -- $arg { -d* {set diff 1} -b* {set blink 1} default {set fcslast $arg} } } # verify DISPLAY... if { [info exists env(DISPLAY)] == 0 } { abort "ERROR: DISPLAY is not defined -- abort!" } # refuse to mess up the existing ds9 window... if {[catch {send ds9 ""}] == 0 } { abort "ERROR: operation would affect existing ds9 window -- please run this command\non another display!" } # get reference image name... set fcsref [exec show -s deifcs -terse fcsimgfi] # check for blank name... if { [string equal $fcsref ""]} { ## set file /sdata1002/deimos3/2007jun15/fcs/fcs0615_0353.fits abort "ERROR: FCS reference image is undefined -- abort!" } # check for non-existent image... if { [file exists $fcsref] == 0 } { abort "ERROR: FCS reference file $fcsref not found -- abort!" } # launch ds9 window... set cmd {ds9 -geometry 1280x512 -scale mode zscale -zoom 8 -view image &} ## set cmd {ds9 -geometry 1280x512 -scale mode zscale &} eval exec $cmd # display image... set ntries 0 set maxtries 30 set keepgoing 1 while { 1 } { # check for okay... if {[catch {send ds9 ""}] == 0 } { puts stdout "ds9 now ready!" break } # check for max tries exceeded... if { $ntries > $maxtries } { abort "ds9 not available after $maxtries tries -- abort!" } # increment, wait, try again... puts stdout "waiting for ds9 ($ntries)..." incr ntries after 1000 } # load reference file... puts "displaying reference frame ($fcsref)..." send ds9 "LoadFits $fcsref" send ds9 "FinishLoad" # load last image and differenced image... if { [info exists diff] } { # locate last frame... set fcslast [exec lastfcsimage] puts "displaying latest frame ($fcslast)..." # check for non-existent image... if { [file exists $fcslast] == 0 } { abort "ERROR: current FCS file $fcslast not found -- abort!" } # load last frame... send ds9 "CreateFrame" send ds9 "LoadFits $fcslast" # compute and load difference frame... set pid [pid] set fcsdiff "fcsview${pid}.fits" set cmd {imarith $fcsref $fcslast $fcsdiff SUB datatype=long} eval exec $cmd # check for file... if { [file exists $fcsdiff] == 0 } { abort "ERROR: FCS difference image $fcsdiff not created -- abort!" } # load last frame... puts "displaying difference frame ($fcsdiff)..." send ds9 "CreateFrame" send ds9 "LoadFits $fcsdiff" # complete loading process... send ds9 "FinishLoad" # put the display into the proper mode... if { [info exists blink] } { puts stdout "blinking..." send ds9 "set ds9(display,user) blink" send ds9 "DisplayMode" } else { puts stdout "tiling..." send ds9 "set ds9(display,user) tile" send ds9 "set tile(mode) row" send ds9 "DisplayMode" } } exit