#!/bin/bash
#
# !!!! NOT CURRENTLY USED !!!!
#
# script to create all cell views. Using Alliance version 20060218 and
# Magic version 7.4.8 with Magic compiled with the TCL option
#
if test $# -eq 0
then
  echo "# Usage ./makeallviews cell_name (without AP extension). Please supply cell_name."
  exit 1
fi
if test -f "$1.ap"
then
dir=$PWD

echo "#"
echo "# MAKING ALL VIEWS FOR CELL $1" 1>&2
echo "#"
echo "# Write vtxlib013 CIF from Alliance"

source /usr/share/pharosc/alliance/bin/env_vtx013
/usr/share/pharosc/alliance/bin/make_al $1
RDS_IN=cif
RDS_OUT=cif
rm -f $1.cif
frds_vtx013 $1 >/dev/null
s2r -p $1 >/dev/null
/usr/share/pharosc/alliance/bin/touch_alliance_cif $1
cp $1.cif /usr/share/pharosc/alliance/cif/vtxlib013
/usr/share/pharosc/alliance/bin/grep_ref_boxes $1 ../../../magic/etc/vtxlib/$1_vtx013.ref
grep '^4A' $1.cif > /usr/share/pharosc/magic/etc/vtxlib/$1_vtx013.ab

echo "# Write vtxlib013 GDS from Alliance"

RDS_IN=gds
RDS_OUT=gds
rm -f $1.gds
frds_vtx013 $1 >/dev/null
cp $1.gds /usr/share/pharosc/alliance/gds/vtxlib013

echo "# Write spice deck using vtx013 values"

/usr/share/pharosc/alliance/bin/vtx013_make_spice $1
grep subckt $1.spi > /usr/share/pharosc/magic/etc/vtxlib/$1.subckt
cp $1.spi /usr/share/pharosc/alliance/subckt/vtxlib013

echo "# Write vtxlib100 CIF from Alliance"

source /usr/share/pharosc/alliance/bin/env_vtx100
/usr/share/pharosc/alliance/bin/make_al $1
RDS_IN=cif
RDS_OUT=cif
rm -f $1.cif
s2r_vtx100 $1 >/dev/null
s2r -p $1 >/dev/null
/usr/share/pharosc/alliance/bin/touch_alliance_cif $1
cp $1.cif /usr/share/pharosc/alliance/cif/vtxlib100
/usr/share/pharosc/alliance/bin/grep_ref_boxes $1 ../../../magic/etc/vtxlib/$1_vtx100.ref
grep '^4A' $1.cif > /usr/share/pharosc/magic/etc/vtxlib/$1_vtx100.ab

echo "# Write vtxlib200 CIF from Alliance for Magic"

source /usr/share/pharosc/alliance/bin/env_vtx200
RDS_IN=cif
RDS_OUT=cif
rm -f $1.cif
s2r_vtx200 $1 >/dev/null
s2r -p $1 >/dev/null
/usr/share/pharosc/alliance/bin/touch_alliance_cif $1
cp $1.cif /usr/share/pharosc/alliance/cif/vtxlib200
/usr/share/pharosc/alliance/bin/grep_ref_boxes $1 ../../../magic/etc/vtxlib/$1_vtx200.ref
grep '^4A' $1.cif > /usr/share/pharosc/magic/etc/vtxlib/$1_vtx200.ab

/usr/share/pharosc/alliance/bin/make_magic_cif $1
cp $1.cif /usr/share/pharosc/magic/cells/vtxlib

rm -f $1.al
rm -f $1.spi
rm -f $1.cif
rm -f $1.gds

cd /usr/share/pharosc/magic/cells/vtxlib

#
# Script update 23-JUN-06 to run with Magic compiled with TCL. The
# actual version of Magic being used is the 7.4.8 release.
#
# xhost + command needed for -noconsole option to be accepted
#
xhost + 1>/dev/null

echo
echo "# Read vtxlib200 CIF into Magic"
magic -Tvsc200 -dnull -noconsole <<EOF  >/dev/null 2>&1
;cif read $1.cif
;load $1
;drc count total
;save
exit
EOF

echo
echo "# Extract 0.13um SPI file from Magic"
magic -Tvsc013 -dnull -noconsole <<EOF >/dev/null 2>&1
;load $1
;box 0 0 1 1
;select more box pwell
;delete
;box 0 99 1 100
;select more box nwell
;delete
;select
;extract do capacitance
;extract do coupling
;extract do adjust
;extract do resistance
;extract all
;ext2spice -f spice3 -c 0.001 -r 1 -y 3 -d
;quit
EOF

echo "# Write vtxlib200 CIF file from Magic"
magic -Tvsc200 -dnull -noconsole <<EOF >/dev/null 2>&1
;load $1
;cif write $1
;gds labels
;gds write $1
;quit
EOF

/usr/share/pharosc/alliance/bin/make_alliance_cif $1 ../../../alliance/cif/vtxlib200/$1 ../../../magic/etc/vtxlib/$1_vtx200.ref
cp $1.cif /usr/share/pharosc/magic/cif/vtxlib200
cp $1.gds /usr/share/pharosc/magic/gds/vtxlib200

echo "# Write vtxlib013 CIF and GDS files from Magic"
magic -Tvsc013 -dnull -noconsole <<EOF >/dev/null 2>&1
;load $1
;cif ostyle lambda=0.055um(vsclib)
;cif write $1
;gds labels
;gds write $1
;quit
EOF

/usr/share/pharosc/alliance/bin/make_alliance_cif $1 ../../../alliance/cif/vtxlib013/$1 ../../../magic/etc/vtxlib/$1_vtx013.ref
mv $1.cif /usr/share/pharosc/magic/cif/vtxlib013
mv $1.gds /usr/share/pharosc/magic/gds/vtxlib013

echo
echo "# Convert Magic SPICE output to SPI subckt"
/usr/share/pharosc/alliance/bin/spice2spi_013 $1 vtxlib
cp $1.spi /usr/share/pharosc/magic/subckt/vtxlib013
cd $dir
else
  echo "# Usage ./makeallviews cell_name (without AP extension). cell_name supplied does not exist."
  exit 1
fi
