#!/bin/csh -f
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This is a csh script which is used to create a new preview file.
#  The file name, number of frames, and number of objects may be
#  specified.
#
#
#  Author:     Wesley C. Barris
#              AHPCRC
#              Minnesota Supercomputer Center, Inc.
#  Date:       Sept. 10, 1990
#
#  Copyright @ 1990, Minnesota Supercomputer Center, Inc.
#
#  RESTRICTED RIGHTS LEGEND
#
#  Use, duplication, or disclosure of this software and its documentation
#  by the Government is subject to restrictions as set forth in subdivision
#  { (b) (3) (ii) } of the Rights in Technical Data and Computer Software
#  clause at 52.227-7013.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  Assign some defaults.
#
set name = "new.pv"
@ nobjs = 10
@ nframes = 100
#
#  Get the args
#
@ n = 1
while ($n <= $#argv)
   switch ($argv[$n])
   case -n*:                              # file name
      @ n++
      set name = $argv[$n]
      @ n++
      breaksw
   case -o*:                              # number of objects
      @ n++
      @ nobjs = $argv[$n]
      @ n++
      breaksw
   case -f*:                              # number of frames
      @ n++
      @ nframes = $argv[$n]
      @ n++
      breaksw
   case -h:                               # help
   case -help:                            # help
      echo "Usage: new_pv -n file_name.pv -o nobjs -f nframes"
      echo " "
      echo "If fewer arguments are specified, the following defaults are used:"
      echo "file_name = new.pv"
      echo "nobjs     = 10"
      echo "nframes   = 100"
      exit
      breaksw
   default:
      echo "Unknown switch"
      exit
   endsw
end
#
#  First make sure we don't clobber an existing preview file.
#
if (-e $WF_SCMP_DIR/$name.pv) then
   echo "Woah\!  $WF_SCMP_DIR/$name.pv already exists\! -- aborting..."
   exit
else if (-e $WF_SCMP_DIR/$name) then
   echo "Woah\!  $WF_SCMP_DIR/$name already exists\! -- aborting..."
   exit
endif
#
#  Use the "safe.hdr" template to create a specific safe.hdr for this file.
#
echo "Creating local .set and .hdr files..."
cp $WF_CMD_DIR/PV/safe.set $name.set
cp $WF_CMD_DIR/PV/safe.hdr $name.hdr
if ($nobjs > 7) then
   @ n = 8
   while ($n <= $nobjs)
      @ m = $n - 6
      echo "# Code    Name    Focal   Aperture  Aspect"		>>$name.set
#     echo "  O       obj$m     1.000   1.000      1.00"	>>$name.set
      echo "  O       Geometry  1.000   1.000      1.00"	>>$name.set
      echo "# Type    Units   PPU     Minimum   Maximum"	>>$name.set
      echo "  1       1        1.000   -10000.00    10000.00"	>>$name.set
      echo "  2       1        1.000   -10000.00    10000.00"	>>$name.set
      echo "  3       1        1.000   -10000.00    10000.00"	>>$name.set
      echo "  4       4        1.000   -360.00    360.00"	>>$name.set
      echo "  5       4        1.000   -360.00    360.00"	>>$name.set
      echo "  6       4        1.000   -360.00    360.00"	>>$name.set
      echo " 10      11        1.000   -10000.00    10000.00"	>>$name.set
#     echo "o $n;seto -n obj$m"		>>$name.hdr
      echo "o $n;seto -n Geometry"	>>$name.hdr
      echo "seto -f default;seto -p 0"	>>$name.hdr
#      echo "seto -c $n;seto -t O"	>>$name.hdr
      echo "seto -t O"	>>$name.hdr
      echo "seto -rp xyz;seto -tp trs"	>>$name.hdr
      @ n++
   end
endif
#
#  Put object 7 in the edit list.
#  Put the camera, a light, and object 7 in the playback list.
#
echo "o 7"	>>$name.hdr
echo "po 1 4 7"	>>$name.hdr
#
#  Create the new preview file.
#
pv <<!
init $name $name.set $nframes
< $name.hdr
< $WF_CMD_DIR/PV/safe.mth
exit
!
rm $name.set $name.hdr
echo "A preview file named $name was created."
echo "It has $nframes animation frames."
if ($nobjs <= 7) then
   echo "It will accomodate the minimum of 7 objects."
else
   echo "It will accomodate $nobjs objects."
endif
rm $WF_SCMP_DIR/,$name
