#!/bin/csh -f
#+
# nextframe -- reset FRAMENO to the specified value, or 1+last frame
#
# Purpose:
#	If an argument is given, resets FRAMENO to this value,
#	causing the next image taken to have this number.  Without an
#	argument, checks for the highest-numbered image in the current
#	output directory, and set FRAMENO keyword to 1 above that value.
#
# Usage:
#	nextframe [n]
# 
# Arguments:
#	n = value for next image's index number (FRAMENO)
# 
# Output:
#	none
#
# Exit values:
#	 0 = normal completion
#	 1 = wrong number of arguments
#	-1 = output directory not found or invalid frameno
# 
# Example:
#	1) Set next frame number to 123:
#		nextframe 123
#
#	2) Set next frame number to 1 above the last frame number:
#		nextframe
#
#-
# Modification history:
#	2000-Jul-03	GDW	Original version
#-----------------------------------------------------------------------

set buf = $0
set cmd = $buf:t
set usage = "Usage: $cmd [n]"

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

# case of 1 argument...
if ( $#argv == 1) then
  modify -s deiccd frameno = $1
  exit $status
endif

# default case: no argument ==> reset to last + 1
@ n = `nextfile`
if ( $status ) exit $status
modify -s deiccd frameno = $n