ohmkara 1.0

a technical blog.

Archive for January 2009

‘spice’ up linux

leave a comment »

To spice in linux I recommend ngspice (and post processor ngnutmeg).

# yum install ngspice

should install this (at-least on fedor10).

This page – link – tells what you need to know to get the tool-flow going — A ngspice / ngnutmeg basic how-to / tutorial.(explained in a simpler manner than in man pages)

Just a suggestion on top of link, entering stuff in nutmeg interactive session takes time, better type up a nutmeg command card file like

set hcopydevtype=postscript
hardcopy plot.ps i(vids)

Then you can call it up as

ngnutmeg raw_file.raw < nutmeg_command_card_file

It is faster going this way or so I feel.

Written by deepak

January 14, 2009 at 12:33 pm

Posted in links, my notes, tools

Tagged with

spice mosfet parameter annotator perl script

leave a comment »

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

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
	# 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
	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
		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).

Written by deepak

January 14, 2009 at 12:07 pm

Posted in my notes, scripts, tools

Tagged with ,

wordpress editor — posting tabs, spaces and code

leave a comment »

Posting Formatted Text

I may be posting lots of code / scripts in this blog. But when I posted a script yesterday, wordpress removed all the indentation tabs. Which is the last thing that I (or anybody who reads it) wants, a flattened script…. After about an hour of searching I found the solution for keeping the indentation tabs and leading white spaces here. (I must confess that prior to finding the solution I was thinking of going back to good old blogger — what is the use of an unintended script) This is how I posted the script (HTML of relevant section)

<pre style=”font:inherit;”>

Intended / Foratted Script



Posting Code

If in particular, you are interested in posting code, there is a better way as mentioned here…. a much better way (but the sad part is bash, perl etc. is not supported by default but you can choose any supported program type, it will display anyways)… this is how a script will look — pretty neat heeh…. but I wonder why others posting scripts are not using this (I tried to see how others are doing it on wordpress when my script was getting ‘de-spaced’).

This is what you do

Wrap your code in these tags:

[sourcecode language=’python’]

your script


And this is how it looks….

# a demo script
        echo "hello, world"     #see the tab / format maintained

Written by deepak

January 13, 2009 at 11:43 am

Posted in my notes

Tagged with

sam2p bulk conversion script

with one comment

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…

# makeeps.sh
# convert jpg files to eps
for i in $( ls *.jpg* );
    tgt=$(echo $i | sed -e "s/$match/$replace/")
    sam2p $src $tgt

Written by deepak

January 12, 2009 at 5:48 pm

Posted in my notes, scripts

Tagged with ,

adding your shell-scripts dir to path

leave a comment »

This is what my ~/.bashrc file looks like — pretty simple

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc

# User specific aliases and function

~/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

Written by deepak

January 12, 2009 at 3:39 pm

Posted in my notes, scripts

Tagged with

image converter tool — solution to eps / jpg latex woes

leave a comment »

pdflatex (as far as I know / am aware) does not support the inclusion of .eps figures. But it goes support formats like jpeg. latex does support eps figures. But the problem is latex only supports eps figures (not jpg etc.).

If, like me, you are planning to do a lot of jpg to eps (or any) image conversions, there is one tool that could make your life MUCH easier — sam2p.There are both linux and windows ports. I have have tried out only the linux port.

The ‘industry standard’ image conversion tool Imagemagick does pretty bad job at it (smudges up graphs / grayscale images and all). The image size that sam2p produces is considerably (orderS of magnitude)smaller than the image size produced by imagemagick and the clarity, detail etc. is orders of magnitude better (on default, no additional parameter run on * to eps conversions). Wicked!!!! — A tool that all (latex) users doing (eps) image conversion must have.

Installation is a breeze even if you are a linux noob (like me) please go ahead and try it out, even if this does not come as a pre-compiled package.

Installation in fedora / Red hat derivatives: There are just two minor differences from the installation instructions given in the site / downloaded package’s readme’s. The only difference from the steps mentioned at the site is that fedora equivalent of the Debian package libjpeg-progs is libjpeg so you have to do a

sudo yum install libjpeg

before following the rest of the instructions on the site and readme’s that come with the dowloaded packages(well there is another minor change in the installation script / commands — use the gcc versions that you have or delete the versions in the script if they are not yours). I installed this on a fedora10 x86_64 system. Works fine. The documentation is the readme itself, not much of it, but what I wanted was how to invoke — that was of course there.

Did I sound excited…. I am — I badly needed this for my M-Tech project reports. Thanks to google for pointing out this great tool.

P.S: I have just seen this and tried it out — this works, figures looks neat and gets included in the pdf made (That is all that you need right?). I have not used this extensively though, will update if there are some bugs / issues over prolonged use. Does not seem like it though…. Good night guys, got to sleep — had to post this hurriedly before I called it a day.

Written by deepak

January 11, 2009 at 11:40 pm

Posted in tools

Tagged with ,

gdm to kdm login in fedora

with 4 comments

Note: In the following I am talking about fedora in general and fedora 10 in particular.

I did not like the gdm(gnome display manager) login screen. As far as I am aware gdm has limited themability and hence customizability. kdm (KDE display manager) seemed better. The info given in the kdm documentation that about how to migrate to kdm was slightly off the mark (in the specific case of fedora 10, I am not sure about others) and hence this post. If you are looking for a quick way to fix this and move on, then stop reading this  post now and go read the fedora KDE wiki which details multiple ways to make the gdm to kdm transition. If you are not in so much of a hurry, do read on…..

The fedora KDE page says

….The default display manager on Fedora is GDM – The GNOME Display Manager. You can switch this to KDM – The KDE Display Manager….

The fedora KDE page details multiple ways to get the gdm to kdm switch done. One of the easiest and quickest ways (manual fix) is — add / edit lines in /etc/sysconfig/desktop  file to say…



This file is being loaded in the /etc/X11/prefdm (preferred display manager setting)which does the following (code in the prefdm file)

if [ -f /etc/sysconfig/desktop ]; then
        . /etc/sysconfig/desktop
        if [ "$DISPLAYMANAGER" = GNOME ]; then
        elif [ "$DISPLAYMANAGER" = KDE ]; then
        elif [ "$DISPLAYMANAGER" = WDM ]; then
        elif [ "$DISPLAYMANAGER" = XDM ]; then
        elif [ -n "$DISPLAYMANAGER" ]; then

But in my case (I am not sure if it is specific to my installation or more general) there was no /etc/sysconfig/desktop file and sice I was not sure if that file was supposed to do something else too i.e if I add these two lines alone will something else break (i.e if that file is there, is it supposed to contain something else?). I switched to kdm in a different (simple) way (as in lesser editing and lesser time to implement) i.e There is a 3rd way :P. If there is no /etc/sysconfig/desktop file there is a catch-all fallback scheme at the end of the /etc/X11/prefdm script which originally read as follows.

# Fallbacks, in order
exec gdm “$@” >/dev/null 2>&1 </dev/null
exec kdm “$@” >/dev/null 2>&1 </dev/null
exec wdm “$@” >/dev/null 2>&1 </dev/null
exec xdm “$@” >/dev/null 2>&1 </dev/null

Which I changed to….

# Fallbacks, in order
exec kdm “$@” >/dev/null 2>&1 </dev/null
exec gdm “$@” >/dev/null 2>&1 </dev/null
exec wdm “$@” >/dev/null 2>&1 </dev/null
exec xdm “$@” >/dev/null 2>&1 </dev/null

And it worked. Please note this is a fix only if you do not have a /etc/sysconfig/desktop file. If you have that file the fix with the file (manual fix) suggested by the fedora KDE wiki — Link is the way to go.

P.S: Only now am I checking out what the etc/sysconfig/desktop file does. God says here that.

If some of the files listed here are not present in the /etc/sysconfig/ directory, the corresponding program may not be installed….

4.1.5. /etc/sysconfig/desktop

The /etc/sysconfig/desktop file specifies the desktop for new users and the display manager to be run when entering runlevel 5.

Correct values are:

  • DISPLAY=<value>, where <value> is one of the following:
    • GNOME — Selects the GNOME desktop environment.
    • KDE — Selects the KDE desktop environment.
  • DISPLAYMANAGER=<value>, where <value> is one of the following:
    • GDM — Selects the GNOME display manager.
    • KDM — Selects the KDE display manager.
    • XDM — Selects the XFree86 display manager.

For more about the X Window System under Red Hat Enterprise Linux, refer to Chapter 7 The X Window System…..

So you sure can edit /etc/sysconfig/desktop on your own. But if you do that you are locking the new user logins to default to kde.

Anyways hope that was useful…..

Written by deepak

January 11, 2009 at 10:14 am

Posted in linux

Tagged with ,