#! /bin/csh -f

# Convert between nTITLE and SoftImage cell numbering style.
# Feb 7 1992    Keith Gordon
#

# Get args and do a little error catching
if ( $#argv != 7 ) then
	goto usage
endif

set self	= $0
set self	= self:t
@ start		= ( $1 )
@ end		= ( $2 )
set from_name	= $3
set from_suffix	= $4
set to_name	= $5
set to_suffix	= $6
set direction	= $7
@ remaining	= ( $end - $start )
@ remaining	= ( $remaining + 1 )
@ done		= ( 0 )
@ frame		= ( $start )

if ( $direction != "ntitle" && $direction != "soft" ) then
	goto usage
endif

if( $direction == "ntitle" ) then
	goto to_ntitle
else
	goto to_softimage
endif
exit -1

# Convert from nTITLE format to SoftImage format.
to_ntitle:
while ( $remaining )
	set from_file = $from_name.$frame.$from_suffix
	if( $frame < 10 ) then
		set to_file = "00"$frame"_"$to_name.$to_suffix
	else if ( $frame < 100 ) then
		set to_file = "0"$frame"_"$to_name.$to_suffix
	else
		set to_file = $frame"_"$to_name.$to_suffix
	endif

	# Move the file.
	echo "mv $from_file $to_file"
	mv $from_file $to_file
	
	@ remaining	= ( $remaining  - 1 )
	@ frame		= ( $frame + 1 )
	@ done		= ( $done + 1 )
end
exit 0

# Convert from SoftImage to nTITLE format.
to_softimage:
while ( $remaining )
	if( $frame < 10 ) then
		set from_file = "00"$frame"_"$from_name.$from_suffix
	else if ( $frame < 100 ) then
		set from_file = "0"$frame"_"$from_name.$from_suffix
	else
		set from_file = $frame"_"$from_name.$from_suffix
	endif
	set to_file = $to_name.$frame.$to_suffix

	# Move the file.
	echo "mv $from_file $to_file"
	mv $from_file $to_file

	@ remaining	= ( $remaining  - 1 )
	@ frame		= ( $frame + 1 )
	@ done		= ( $done + 1 )
end
exit 0


# Print usage info...
usage:
	echo "Convert animation from nTITLE to SoftImage numbering style"
	echo "usage: $0 start end fromname fromsuffix toname tosuffix ntitle|soft"
	echo "eg: $0 0 30 test sgi fred pic soft"
	echo "        'ntitle' -> Softimage to nTITLE"
	echo "        'soft'   -> nTITLE to Softimage"
	exit 0
