#!/bin/csh -f
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This is a csh script that can be used to record chunks of image
#  while those very images are being rendered in the background.
#  Only five (marked) lines in this script need to be edited (see below).
#
#
#  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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  Setup environment for record
#
setenv WF_DSPL_EXIT 0
setenv WF_BUFFER ntsc
setenv WF_RECDEV diaq
setenv WF_NO_HEAD 1 
#
#  Prepare to record these frames...
#
@ nframe     = 1                                      # edit
@ last_frame = 300                                    # only
@ step_size  =  40                                    # these
set base_name = 'im'                                  # five
set extension = '.rla'                                # lines
#
#  Lay down a hold (maybe).
#
if ($nframe == 1) then
   echo "Record a hold with frame 1" | tee smart_log
   setenv WF_SHOOT 'record -s 61'
   setmon -n
   imf_dspl -fs $nframe -x $base_name
   setmon -6
endif
#
#  Record these frames when they become available.
#
setenv WF_SHOOT record
while ($nframe <= $last_frame)
   @ eochunk = $nframe + $step_size - 1
   @ test = $eochunk + 1
   if ($test > $last_frame) then
      @ test = $last_frame
      @ eochunk = $last_frame - 1
   endif
   if ($test < 10) then
      set file_name = "$base_name.000$test$extension"
   else if ($test < 100) then
      set file_name = "$base_name.00$test$extension"
   else
      set file_name = "$base_name.0$test$extension"
   endif
   if (-e $file_name) then
      echo " " | tee -a smart_log
      echo -n "$file_name exists -- " | tee -a smart_log
      date | tee -a smart_log
      echo "Recording frames $nframe through $eochunk" | tee -a smart_log
#
#  Pause for a bit.
#
      sleep 10
      blanktime 0
      setmon -n
      imf_dspl -fs $nframe -fe $eochunk -x $base_name
      setmon -6
      blanktime 36000
#      echo "Deleting  frames $nframe through $eochunk"
#      @ id = $nframe
#      while ($id <= $eochunk)
#         rm $base_name.0$id$extension
#         @ id++
#      end
      @ nframe += $step_size
   else
      echo -n "waiting..."
      sleep 600
   endif
end
#
#  Lay down a hold.
#
setenv WF_SHOOT 'record -s 61'
setmon -n
imf_dspl -fs $last_frame -x $base_name
setmon -6
setenv WF_BUFFER full
setenv WF_DSPL_EXIT 1
