#!/bin/csh -f
#
# SccsId = "@(#)getldm_nelsis3 1.2 03/05/93 "
#
# getldm   : get a flat ldm description from your design 
#            in which the library cells are NOT flattened
#
# usage: getldm -o <outcellname> <cellname>
#
# the result is a cell called <outcellname> and the file <outcellname>.ldm
# 
# Patrick Groeneveld 9-1992
#
#
#

set PROGRAM=$0

# command line checking...
if ($#argv < 3) then
   echo "Error: no cell names specified"
   goto help
   exit 1
endif

top:

if ($#argv >= 2) then
  switch ($argv[1])

  case -o:		# specify output cell name
      shift argv
      set OUTPUTCELLNAME = $argv[1]
      shift argv
      goto top

  case -h:		# help
help:
      echo "usage: getldm -o <outcellname> <cellname>"
      echo
      echo "getldm: Get a flat ldm description from your design "
      echo "         in which the library cells are NOT flattened."
      echo "         The result is a cell called <outcellname> and the file"
      echo "         <outcellname>.ldm."
      echo "         The cell <outcellname> contains only the SoG masks and no"
      echo "         library cells."
      echo "         Patrick Groeneveld 9-1992"
      exit 0
  default:
      echo "WARNING: argument ignored: '$argv[1]'"
      shift argv
      goto top     
  endsw
endif

set CELLNAME=$argv[1]

# echo "Cellname : $CELLNAME en OUTCellname : $OUTPUTCELLNAME"


if( ! -f ".dmrc") then
   echo "Error: You are not in a project directory."
   echo "$PROGRAM : program aborted"
   exit 1
endif

if( ! -d "layout/$CELLNAME") then
   echo "Error: Cell $CELLNAME does not seem to exist."
   echo "$PROGRAM : program aborted"
   exit 1
endif

if( $CELLNAME == $OUTPUTCELLNAME ) then
  echo "Error: input cell name and output cell name are the same"
  echo "       It is not so wise to overwrite your cell"  
  echo "$PROGRAM : program aborted"
  exit 1
endif

if( $CELLNAME == $OUTPUTCELLNAME ) then
  echo "Error: input cell name and output cell name are the same"
  echo "       It is not so wise to overwrite your cell"  
  echo "$PROGRAM : program aborted"
  exit 1
endif

if( -d "layout/$OUTPUTCELLNAME") then
   echo "Warning: existing cell '$OUTPUTCELLNAME' will be overwritten."
   echo "         (if you're scared: Hit ^C to prevent this)"
   sleep 2
endif

if( -f "${OUTPUTCELLNAME}.ldm") then
   echo "Warning: existing file '${OUTPUTCELLNAME}.ldm' will be overwritten."
   echo "         (if you're scared: Hit ^C to prevent this)"
   sleep 2
   /bin/rm -f ${OUTPUTCELLNAME}.ldm
endif

echo "-- Calling the layout flattener --"
layflat -L /celllibs/ -i in -i ins -i con -i cop -i cps -i cos -i bb -o $OUTPUTCELLNAME $CELLNAME || exit 1

echo "-- Creating the ldm file $OUTPUTCELLNAME.ldm --"
xldm $OUTPUTCELLNAME || exit 1

echo "-- ${PROGRAM}: I'm ready\! --"
