#!/bin/bash
Tmax=3000
Tmin=100
Tcur=1500
Tdiv=16
num=0
bench=1;
echo "/*========="$bench"-test==========*/"
echo "Parameter:"
echo "Tmax:" $Tmax 
echo "Tmin:" $Tmin 
echo "Tcur:" $Tcur 
echo "Tdiv:" $Tdiv 
echo "Pass:" $num
while [ $(($Tmax-$Tmin)) -gt 1 ]
do
#check 16
    sed -i '8c.param period=nnnp C0=0 C1=0' testbench.sp 
    sed -i "s/nnn/$Tcur/g" testbench.sp
    hspice -i testbench.sp -o testbench.lis
    gcc getvalue.c
    ./a.out $Tmax $Tmin $Tcur $Tdiv $num
    Tmax=$(sed -n '1p' "check.txt")
    Tmin=$(sed -n '2p' "check.txt")
    Tcur=$(sed -n '3p' "check.txt")
    Tdiv=18
    num=$(sed -n '4p' "check.txt")
    bench=$(($bench+1))
    echo "/*========="$bench"-test==========*/"
    echo "Parameter:"
    echo "Tmax:" $Tmax 
    echo "Tmin:" $Tmin 
    echo "Tcur:" $Tcur 
    echo "Tdiv:" $Tdiv 
    echo "Pass:" $num
#cheeck 18
    sed -i '8c.param period=nnnp C0=1.8 C1=0' testbench.sp 
    sed -i "s/nnn/$Tcur/g" testbench.sp
    hspice -i testbench.sp -o testbench.lis
    gcc getvalue.c
    ./a.out $Tmax $Tmin $Tcur $Tdiv $num
    Tmax=$(sed -n '1p' "check.txt")
    Tmin=$(sed -n '2p' "check.txt")
    Tcur=$(sed -n '3p' "check.txt")
    Tdiv=20
    num=$(sed -n '4p' "check.txt")
    bench=$(($bench+1))
    echo "/*========="$bench"-test==========*/"
    echo "Parameter:"
    echo "Tmax:" $Tmax 
    echo "Tmin:" $Tmin 
    echo "Tcur:" $Tcur 
    echo "Tdiv:" $Tdiv 
    echo "Pass:" $num
#cheeck 20
    sed -i '8c.param period=nnnp C0=0 C1=1.8' testbench.sp 
    sed -i "s/nnn/$Tcur/g" testbench.sp
    hspice -i testbench.sp -o testbench.lis
    gcc getvalue.c
    ./a.out $Tmax $Tmin $Tcur $Tdiv $num
    Tmax=$(sed -n '1p' "check.txt")
    Tmin=$(sed -n '2p' "check.txt")
    Tcur=$(sed -n '3p' "check.txt")
    Tdiv=22
    num=$(sed -n '4p' "check.txt")
    bench=$(($bench+1))
    echo "/*========="$bench"-test==========*/"
    echo "Parameter:"
    echo "Tmax:" $Tmax 
    echo "Tmin:" $Tmin 
    echo "Tcur:" $Tcur 
    echo "Tdiv:" $Tdiv 
    echo "Pass:" $num
#cheeck 22
    sed -i '8c.param period=nnnp C0=1.8 C1=1.8' testbench.sp 
    sed -i "s/nnn/$Tcur/g" testbench.sp
    hspice -i testbench.sp -o testbench.lis
    gcc getvalue.c
    ./a.out $Tmax $Tmin $Tcur $Tdiv $num
    Tmax=$(sed -n '1p' "check.txt")
    Tmin=$(sed -n '2p' "check.txt")
    Tcur=$(sed -n '3p' "check.txt")
    Tdiv=16
    num=$(sed -n '4p' "check.txt")
    bench=$(($bench+1))
    echo "/*========="$bench"-test==========*/"
    echo "Parameter:"
    echo "Tmax:" $Tmax 
    echo "Tmin:" $Tmin 
    echo "Tcur:" $Tcur 
    echo "Tdiv:" $Tdiv 
    echo "Pass:" $num
done
echo "/*===========end============*/"
sed -i '8c.param period=nnnp' final.sp
sed -i "s/nnn/$Tcur/g" final.sp
hspice -i final.sp -o final.lis

