#!/bin/csh -f
#+
# nextfile -- return one plus the FRAMENO of the last saved image
#
# Purpose:
#	Check the OUTDIR directory for the highest numbered
#	*.fits* file, and return that value PLUS ONE.  If no images
#	matching the template are found in the directory, return 1.
#
# Usage:
#	nextfile
# 
# Arguments:
#	none
# 
# Output:
#	1+index number of the last image (leading zeros removed), or
#	-1 if output directory was not found
#
# Exit values:
#	 0 = normal exit
#	-1 = output directory not found
#
# Example:
#	To get the index number one above the last saved image, type
#		nextfile
#-
# Modification history:
#	2000-Jul-03	GDW	Original version
#       2002-Jun-06     GDW     DEIMOS
#-----------------------------------------------------------------------

set buf = $0
set cmd = $buf:t
set usage = "Usage: $cmd"

# verify args...
if ( $#argv > 0 ) then
  printf "$usage\n"
  exit 1
endif

# check for last image...
@ lastfile = `lastfile`
if ( $status ) exit $status

# return one greater...
@ lastfile++
echo $lastfile
