#!/bin/sh
#
# USAGE
#        nspice [-x] cellname [cmdfile]
# OPTIONS
#        -x : only extract spicefile, do not run spice3
# ARGUMENTS
#        Cellname is the name of the circuit to be simulated.
#        Cmdfile is the file containing sls commands. The default name of
#        cmdfile is cellname.cmd
# DESCRIPTION
#        Nspice3 extracts a spice listing from the nelsis database. It then
#        calls the preprocessor nspice_pp to replace symbolic net/terminal
#        names with numerical node names as required by spice. If no -x option
#        is given it then calls spice3 in batch mode, redirecting the results
#        to the file cellname.ana. Finally, the numerical node names are
#        replaced by their symbolic equivalents by nspice3_bs.
#
#
# xsls: always use options -Shlmbf;
#       the use of options -xy [ -z name ] is recommended 
#

# exit immediately on error
set -e

# spice3 in batch mode crashes on hp400 if DISPLAY is set...:
# unset DISPLAY

extractonly=0
if [ "X$1" = "X-x" ] ; then
   extractonly=1 ; shift
fi
if [ $# -eq 1 ] ; then
   cmd="$1.cmd"
else 
   cmd=$2
fi
xspice -hilmbf -xy $1
nspice_pp $1 $cmd >> $1.spc
if [ $extractonly = 1 ] ; then
   exit 0
fi

# execute spice3 in batch mode:
spice3 < $1.spc > $1.ana

# perform back substitution:
if nspice_bs $1
then
   exit 0
else
   exit 1
fi
