#!/bin/csh -f #+ # lasttvimage -- return full disk name of the most recent TV image # # Purpose: # Seeks the newest image in the current nightly # directory, and returns its full disk name. # # Usage: # lastimage [-tail] # # Arguments: # -tail = print only the tail of the filename # # Output: # The full or tail of the disk name is echoed to stdout # # Exit values: # 0 = normal exit # 1 = no images found # -1 = output directory not found # # Example: # 1) Return the full name of the latest image: # lasttvimage # returns: # /s/nightly2/10/09/09/deimos_195121_935.fits # # 2) Return the tail of the latest image: # lastimage -tail # returns # deimos_195121_935.fits #- # Modification history: # 2002-Jun-24 GDW Original version # 2010-Sep-11 GDW Updated to work with MAGIQ output images # 2012-May-29 GDW Removed trailing underscore so that it also # returns images acquired via keyword request #----------------------------------------------------------------------- # define usage... set buf = $0 set cmd = $buf:t set usage = "Usage: $cmd [-tail]" set tail = 0 # check flags... if ( $1 == "-tail" ) then set tail = 1 shift endif # check args... if ( $#argv > 0 ) then printf "$usage\n" exit 1 endif # get the current outdir... set outdir = `/home/deimos/bin/nightpath` if ( $status ) exit $status # abort if output directory not existing... if (! -e $outdir) exit -1 # get the current outfile... set outfile = deimos # check whether files exist... \ls -1t $outdir$outfile*.fits >& /dev/null if ( $status ) exit $status # get disk name of latest file... set buf = `\ls -1t $outdir$outfile*.fits | head -1` if ( $tail ) then echo $buf | sed "s|^.*\/||" else echo $buf endif