#! /bin/csh

# Set shell variable with name of labeled stack file.
set STACK=modelstack
# Use the get commands to inquire on the size of the stack file from its labels.
set NT=`getnt <$STACK `
set NX=`getnx <$STACK `

# Make a temporary file of binary traces without labels for input to viewmat.
strip if=$STACK asciihd=1
# Remove the ascii file of label information output by strip.
rm ahd$STACK

# Scan the unlabeled stack traces for their overall RMS amplitude to help
# scale the plot amplitude.
set CLIP=`rms $NT <st${STACK}.$NT `
# Set the plot saturation at 2 times the RMS amplitude of the stack,
# usually a good guess.
# The product program is used since the shell will only do integer math.
set CLIP=`product 2 $CLIP `

# Plot the temporary file with viewmat, using the parameters in the appropriate
# par file, but only to a PostScript file and not to the screen.
viewmat par=plstkpar if=st${STACK}.$NT ny=$NX nx=$NT clip=$CLIP plot=ps

# Remove the stripped temporary file.
rm st${STACK}.$NT

# Spool the PostScript file to the printer in 320 LME.
lpr -h -PPostScript st${STACK}.${NT}.0.ps

# Remove the PostScript file.
rm st${STACK}.${NT}.0.ps
