#!/usr/bin/perl
# Nelson Hu
# EE464H
# 08/06/03

#######################################################
# This Program "MoveSiInp.pl" does the following:
#  1)copies Spectre netlist (si.inp) to appropriate folder specified by the @file list and link below 
#  2)run TransientHspice.pl (create Hspice code for Transient Analysis) to all the si.inp copied
#  3)run the Hspice code created for Transient Analysis and stored in the appropriate folder
#  4)run CapaFinder.pl 

#######################################################
# how to use this program:
# at prompt, type
#    perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/MoveSiInp.pl

#######################################################
# Input:
#  none

#######################################################
# Output:
#  TRANS_%CELLNAME%.sp -- Hspice code for Transient Analysis
#  TRANS_%CELLNAME%.ic  -\
#  TRANS_%CELLNAME%.pa0 --\
#  TRANS_%CELLNAME%.st0 ---> file for graphing by awaves, generated by Hspice
#  TRANS_%CELLNAME%.sw0 --/
#  TRANS_%CELLNAME%.tr0 -/
#
#  All of the above files will be stored under the link
#  "/home/projects/abraham/vlsi464/spicetest/%CELLNAME%/"
#  as provided below


#######################################################
# "@files" contains all the cell name to be processed
#######################################################
@files = qw $ inv1 inv2 inv4 
	      buf1 buf2 buf4
	      nand2x1 nand2x2 nand2x4
	      nand3x1 nand3x2 nand3x4
	      nand4x1 nand4x2 nand4x4
	      nand5x1 nand5x2 nand5x4
	      nor2x1 nor2x2 nor2x4
	      nor3x1 nor3x2 nor3x4
	      nor4x1 nor4x2 nor4x4
	      nor5x1 nor5x2 nor5x4
	      and2x1 and2x2 and2x4
	      and3x1 and3x2 and3x4
	      and4x1 and4x2 and4x4
	      and5x1 and5x2 and5x4
	      or2x1 or2x2 or2x4
	      or3x1 or3x2 or3x4
	      or4x1 or4x2 or4x4
	      or5x1 or5x2 or5x4 
	      mux2
	      xor2x1 xor2x2 xor2x4 $;

#######################################################
# remove all the directories that "si.inp" 
# will be placed under
#######################################################

foreach (@files){
    system "rm -r /home/projects/abraham/vlsi464/spicetest/$_";}

#######################################################
# make all the directories named by "@files"
# and copy si.inp into it
#
# NOTE: 1) Make sure the link where "si.inp" can be found is correct.
#       2) Make sure your folders containing "si.inp" is distinguishable
#          and able to link with "@files" names
#          In this program all of our si.inp is containes in
#          "spectre_CELLNAME.run1"
#######################################################
foreach (@files){
    system "mkdir /home/projects/abraham/vlsi464/spicetest/$_";
    system "cp /home/projects/abraham/vlsi464/seniorlab/spectre_$_.run1/si.inp /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# run TransientHspice.pl in the folders created.
# TransientHspice.pl creates Hspice code for Transient Analysis
#
# NOTE: Make sure the link to TransientHspice.pl is correct
#######################################################
foreach (@files){
    system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/TransientHspice.pl /home/projects/abraham/vlsi464/spicetest/$_/si.inp";
    system "mv TRANS_$_.sp /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# run all the Transient tests
#######################################################
foreach (@files){
    system "hspice /home/projects/abraham/vlsi464/spicetest/$_/TRANS_$_.sp";
    system "mv TRANS_$_.* /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# run CapaFinder.pl in the folders created.
# CapaFinder.pl creates Hspice code for calculating Input Capacitance
#
# NOTE: Make sure the link to CapaFinder.pl is correct
#######################################################
foreach (@files){
    system "perl /home/projects/abraham/vlsi464/spicetest/FinalTOOLS/CapaFinder.pl /home/projects/abraham/vlsi464/spicetest/$_/si.inp";
    system "mv $_"."cap.sp /home/projects/abraham/vlsi464/spicetest/$_/";}

#######################################################
# run all the Transient tests
#######################################################
open CAPA, ">CellCapacitance.list";
foreach (@files){
    system "hspice /home/projects/abraham/vlsi464/spicetest/$_/$_"."cap.sp";
    $cellname = $_;
    print CAPA "$cellname     ";
    for ($n = 0; $n <= 4; $n++){
	open TEMP, "$cellname"."cap.mt$n";
	@lines = <TEMP>;
	close TEMP;
	@numbers = split /  /,$lines[3];
	if ($numbers[2] == ""){
	    $finalcapa = $numbers[2];}
	    else {
		$finalcapa = $numbers[2] * 1e15;}
	print CAPA "$finalcapa ";}
    print CAPA "\n";
    system "mv $_"."cap.* /home/projects/abraham/vlsi464/spicetest/$_/";
}
close CAPA;
