Archive for the ‘scripts’ Category
spice mosfet parameter annotator perl script
This is a very crude perl script (perl experts might have a heart-attack if they read this) but it works (I am just starting to learn perl).
What does it do?
Input: Spice code in which mosfets have only L and W specified — ether in nm,um or lambda units. Does not work if you have already specified AD,AS,PD,PS for some mosfet’s but that is a trivial expansion – do if you want to.
Output: Fully annotated code with AD,AS,PD,PS parameters and lambda to units conversion done for mosfet lines.
The Script: spice_fet.pl
#!/usr/bin/perl
use warnings;
use strict;
# spice_fet.pl (v0.9)
# functionality: To automatically annotate spice file with the AS,AD,PS,PD parameters
# Input spice file L and W could be in
# 1) no units -- implying lambda based line
# 2) n or u -- nm or um units
# Note: 1) please set the technology node variable $x in the first line of code
# 2) equations used are as follows if different change it in code
# AS=AD=(5*$x*width)
# PS=PD=((10*$x) + (2*width))
# Author: deepak
# Timestamp: Wed 14 Jan 2009 08:08 AM
#######################################################
my $x=120e-9; #my technology node
my $lambda_flag=0;
sub strip #convert l,w to floating point numbers
{ #and see if the line is lambda based
my $a=$_[0];
my $a_int=$a;
if($a =~ m/(d+)n/i) #l/w in units of n(m)
{ $a_int = $1*(1e-9); }
elsif($a =~ m/(d+)u/i) #l/w in units of u(m)
{ $a_int = $1*(1e-9); }
else #lamda based design
{
$a_int *= $x;
$a *= $x;
$lambda_flag=1; #flags the design as lambda based
}
return $a_int;
}
if(($ARGV[0] eq "-h")|($ARGV[0] eq "--help")) # if help requested
{ #print usage and exit;
print "usage-- n spice_fet n";
exit 0;
}
open FILE_IN,"","annotated.sp" or die $!; #open output file -- annotated.sp
while()
{
# ex line1: M1 1 2 0 0 N_50n L=120n W=120n
# ex line2: Mnmos1 net1 net2 net3 net4 model_nmos_120 L=240n W=240n
# ex line3: M1 1 2 0 0 N_120n L=2 W=6 -- lambda based line
$lambda_flag=0;
my $line;
if($_ =~ m/M([w s]+)L=(w+)(s+)W=(w+)/i)
{
my $l_int = strip($2); #pass L parameter
my $w_int = strip($4); #pass W parameter
my $ad = (5*$x*$w_int);
my $as = $ad;
my $ps = ((10*$x)+(2*$w_int));
my $pd = $ps;
if($lambda_flag==1) #if the line looks like lambda based make it normal
{
s/(L)=(d+(.d+)?)/$1=$l_int/i;
s/(W)=(d+(.d+)?)/$1=$w_int/i;
}
chomp $_;
$_ = $_." AD=$ad AS=$as PD=$pd PS=$ps *annotated by spice_fet.pln";
}
print FILE_OUT $_;
}
It can definitely be optimised but I did not much care about optimization (point of diminishing return).
sam2p bulk conversion script
I have lots of .jpg files to convert to .eps in a folder, not sure if there is a batch convert option in sam2p — did not see one in quick glance, hence wrote the following. The following was a bulk conversion bash script that worked for me…
#!/bin/bash
# makeeps.sh
# convert jpg files to eps
match=".jpg"
replace=".eps"
for i in $( ls *.jpg* );
do
src=$i
tgt=$(echo $i | sed -e "s/$match/$replace/")
sam2p $src $tgt
done
adding your shell-scripts dir to path
This is what my ~/.bashrc file looks like — pretty simple
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi# User specific aliases and function
PATH=$PATH:$HOME/bin
~/bin is where I put my scripts. Addidng that to the path is what “PATH=$PATH:$HOME/bin” line does. Then all that you need to do is to make the script executable with….
chmod 755 your_script