#!/bin/csh

foreach i (\
	1100:physical \
	1120:physical \
	1130:physical \
	1140:physical \
	1220:physical \
	1230:physical \
	1240:physical \
	1310:physical \
	1320:physical \
	1340:physical \
	1350:physical \
	1370:physical \
	1410:physical \
	1420:physical \
	1430:physical \
	1440:physical \
	1480:physical \
	1520:physical \
	1530:physical \
	1540:physical \
	1550:physical \
	1560:physical \
	1570:physical \
	1580:physical \
	1610:physical \
	1620:physical \
	1660:physical \
	1670:physical \
	1680:physical \
	1740:physical \
	1760:physical \
	1770:physical \
	1810:physical \
	1830:physical \
	1850:physical \
	1860:physical \
	1870:physical \
	1880:physical \
	1890:physical \
	1910:physical \
	1930:physical \
	1970:physical \
	2310:physical \
	2350:physical \
	)
set BANNER = "CRYSTAL.FACET.GENERATOR >> "

set SAVE = 0

set CVF = `echo $i | sed 's/\:/ /'`

set CELL = $CVF[1]
set VIEW = $CVF[2]
set ROOT = ${CELL}_${VIEW}
set STRIPPED_CELL_NAME = $CELL:t
set MAGIC_CELL = ${STRIPPED_CELL_NAME}_${VIEW}
set CIF_FILE = ${ROOT}.cif
set MAGIC_EXT_FILE = ${STRIPPED_CELL_NAME}.ext
set MAGIC_SIM_FILE = ${STRIPPED_CELL_NAME}.sim
set SIM_FILE = ${ROOT}.sim

set AUX_DIR = oct2crystal.tmp.dir

set OCT_TO_CIF_SCRIPT = /cad/lib/technology/scmos/to-mosis-pwell

###################################
#  HERE BEGINS THE PATH TO CRYSTAL ( THIS IS A BIT HARD TO UNDERSTAND)
###################################
echo $BANNER Operating on ${CELL}:${VIEW}
echo $BANNER "OCT -> CIF"
octtocif -f $OCT_TO_CIF_SCRIPT ${CELL}:${VIEW} | sed -e 's:^9.*/\(.*\);:9 \1;:'  > $CIF_FILE

echo $BANNER "CIF -> MAGIC -> EXT"

mkdir $AUX_DIR
\mv -f $CIF_FILE $AUX_DIR
cd $AUX_DIR

magic -d NULL > /dev/null << ++
:cif read ${MAGIC_CELL}
:extract all
:quit
yes
++


echo $BANNER "EXT -> SIM"

# no Resistances, no Alias file , no Label file
ext2sim -R -A -L  $MAGIC_EXT_FILE

cd ..

\mv -f ${AUX_DIR}/$MAGIC_SIM_FILE $SIM_FILE

if (! ${SAVE} ) then
	\rm -fr $AUX_DIR
else 
	echo $BANNER "preserving temporary files in $AUX_DIR"
endif

echo $BANNER "The simulatable file is" $SIM_FILE

## Patch for MAGIC cells
cat $SIM_FILE | sed -e s/Vdd/Vdd\!/  -e s/GND/GND\!/ > tmp ; mv tmp $SIM_FILE
sim2facet -s $SIM_FILE -T scmos -f crystal ${CELL}:${VIEW}

\rm $SIM_FILE
end
