Poor man’s code generator

A short time ago, I wanted to find a simple code generator that would run on Windows for helping me to maintain hand-rolled SPICE models files. I was a bit surprised to find none that were no-brainers to install or use. However, I did figure out that OpenOffice‘s mail merge feature can be used as a poor-man’s code generator. There’s more than one way to do it, but the process described at Worldlabel.com is the most straightforward for my brain. The key is to “print out” to several files or a single file–depending on what you are generating.

SPICE library management

The following post is all geekspeak. You have been warned.

I am trying to keep my SPICE modeling as platform and vendor-neutral as possible. To help with this, I have come up with the following structure for managing libraries. The idea is to have a file system, e.g.:

- models
    - diodes-inc
        - diodes
        - transistors
        - zeners
    - fairchild
        - transistors
    - onsemi
        - transistors

and in each category (i.e., subdirectory) store your individual model files. The file system, in addition to providing a structure to manage different kinds of parts from of different places, also helps to differentiate models for the same part from different sources.

Now here’s the fun part. So that I don’t have to have a million different .inc or .lib commands in the SPICE simulation’s source (one for each part I use, e.g.,

.lib C:\SpiceDev\models_raw\fairchild\transistors\MMBT2907A.lib

), I aggregate all the models in a given subdirectory into a single library file. Thus, C:\SpiceDev\models_raw\fairchild\transistors in addition to having several individual model files also has the file C:\SpiceDev\models_raw\fairchild\transistors\transistors.lib in it that is an aggregation of all the other files ending in .lib, .mod, or .sp3. So now if I want to use a Farchild transistors, I only need to include a single file:

.lib C:\SpiceDev\models_raw\fairchild\transistors\transistors.lib

Of course I don’t maintain the aggregate library file by hand. Instead I have written an AutoHotkey script that does the job. I place the script in a fixed place and then create links (i.e., shortcuts) to it from the directories containing the model files; but it will also work if you drop the script itself into the directory in which you want to make an aggregate library.

The script goes through each file in a directory (non-recursively) and if the file has a .lib, .mod, or .sp extension it appends its contents to a file named {directory-name}.lib . Both the extension of the output file and the list of aggregated input file extensions can be easily changed in the source code.

One important note: If you want to call the script using a shortcut, make sure the SetWorkingDir command in the code is commented out (as it is below) and also make sure the ‘Start In’ field for the shortcut is blank or points to the desired directory. Enjoy.

; AutoHotkey Version: 1.x
; Language:       English
; Platform:       WinXP
; Author:         Copyright (C) 2009 Mithat Konar
; License:        GNU/GPL2
; Script Function:
;	Copies contents of all files with extensions specified below into {directotyname}{outFileExtension}

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
;SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; To use with a shortcut, make sure SetWorkingDir command above is commented out and
; make sure the 'Start In' field for the shortcut is blank or points to the desired dir.

; user-set constants
outFileExtension=.lib	; the extension for the output (with dot!)
inExtList=lib,mod,sp3	; list of valid model file extensions (without dots!)

; "Main"
SplitPath, A_WorkingDir , outFile	; get the name of the active directoty. 

; use %outFile% as working file, then move to %outFile%%outFileExtension%
FileDelete, %outFile%					; just in case, we delete any old version now
FileDelete, %outFile%%outFileExtension%	; just in case, we delete any old version now

FileAppend, *======================================================================*`n, %outFile%
FileAppend, * Generated by %A_ScriptName% on %A_NowUTC% UTC from`n, %outFile%
FileAppend, * %A_WorkingDir%`n, %outFile%
FileAppend, *======================================================================*`n`n, %outFile%
Loop, *.*
	if A_LoopFileExt in %inExtList%
		FileAppend, *** File: %A_LoopFileFullPath% ***`n, %outFile%
		Loop, Read, %A_LoopFileFullPath% , %outFile%
			FileAppend, %A_LoopReadLine%`n
		FileAppend, `n`n, %outFile%
FileMove, %outFile%, %outFile%%outFileExtension%, 1
FileDelete, %outFile%

LTspice and tube models

Linear Technology’s LTspice is becoming quite popular among audio circuit designers, both professional and amateur. There is a lot to recommend it, but there is at least one issue that is crucial to be aware of if you are planning to use vacuum tube or other third-party models based on arbitrary behavioral voltage or current sources. And that is: LTspice’s implementation of arbitrary behavioral voltage or current sources is not completely SPICE 3 compatible.

In particular (from the LTspice help files),

LTspice uses the caret character, ^, for Boolean XOR and “**” for exponentiation. … This means that when you import a 3rd party model that was targeted at a 3rd party simulator, you may need to translate the syntax such as x^y to x**y or even pwr(x,y).

I ran into exactly this issue when experimenting with SPICE 3 versions of my own tube models.

Google Sites banned

As of 24 June 2009, access to Google Sites has been blocked in Turkey.

Just for giggles, here’s the official English explanation: “The decision no 2009/392 dated 24/06/2009, which is given about this web site (sites.google.com) within the context of protection measure, of Denizli 2. Sulh Ceza Mahkemesi has been implemented by ‘Telekomünikasyon İletişim Başkanlığı’.”

Lest you think that the above is a Google translation, here it is again translated by Google from the official announcement in Turkish: “Denizli 2nd Magistrates of the Criminal Court, dated 24/06/2009 and 2009/392 in the context of this web site nolu PROTECTION MEASURES (sites.google.com) the decision about the Telecommunications Communication Başkanlığı’nca apply.”

Home Cloud

If the recent rash of netbooks is any indication, cloud computing may actually be gaining traction.

The aspect of cloud computing that’s the most attractive for me is being able to access all your stuff no matter where you are–provided you have a computer with a decent Internet connection and a fairly standard browser. However, there are two very bothersome aspects of cloud computing. First, if you cannot connect to the provider of your cloud service (e.g., your ISP is flaky, the service’s servers are ill, the site has been banned in the country you are in, etc.), you are screwed. Second, no matter what guarantees the provider gives you, your stuff is in someone else’s hands–meaning the provider can legally sniff your stuff for more effective marketing (Google) or it may be illegally hacked into.

However, there is a fairly easy approach to ameliorating both these problems, especially now that capable server hardware has become so profoundly cheap. The idea is simple: instead of having Google, Google Apps, Zoho or whomever host your Cloud apps, host them in your own home on a dedicated computer. As long as you don’t plan to open your Home Cloud to tons of users, the performance demands on the hardware will be pretty small.

When you host your Cloud apps from home, if your ISP goes nuts you will still be able to access your stuff from within your home LAN. While this won’t help you if you need to access your stuff from Starbucks, it is better than not being able to access it from anywhere. Also, when you host your Cloud apps from home, your data stays at home. It still may be open to hacking, but it won’t be available for other purposes. In addition, a would-be hacker would have to specifically target your server, whereas in a hosted situation one breach of the server may make all users’ data available to the hacker.

One downside to the Home Cloud concept is that it places the burden of backing up data on the home user. But this can be greatly simplified by appropriate Home Cloud software.

A bigger problem with the Home Cloud is what all the cool people are now calling “monetization”. In other words, how do you make money off it? End users are becoming increasingly accustomed to getting services for free. Google makes money feeding you ads. Zoho makes money by selling premium services mostly to businesses. Are users willing to pay for Home Cloud software? One possible way forward is to adopt the media server model: dedicated server hardware that’s preloaded with everything needed to make it go and that requires a minimum of user configuration. We may be living in a time where it may actually be easier to sell hardware that encapsulates a task than software.

I’m aware of only a few projects that have a Home Cloud spirit. eyeOS and Lucid Desktop are OSS home-hostable apps that give the user a virtual Web-based desktop. Another project to keep an eye on is Tiny Tiny RSS–essentially a home hostable replacement for Google Reader. All three of these projects are open source software, and it will be interesting to see where all three of these projects go.

A rare moment of accountability

On my way to the office today, a white van barreling down a road that joined mine at a T junction nearly removed my car, and possibly me, from service. Fortunately, disaster was averted by some heavy breaking and staccato tire squealing on my part (no ABS on the 1997 Fiat-TOFAS Tipo).

This in itself is not news. Near-misses in traffic are a million a day here. What made this event special was that the driver pulled over at a suitable spot some 300 meters on, rolled down his window, and poking both arms and his head out of the window gestured toward me for forgiveness.

And it all happened so quickly that I didn’t have a chance to give him a warm huggie to let him know that while I was annoyed at his carelessness I still appreciated his accountability.

P.S. For those of you who thought this entry might have something to do with audio, I have no reason to think that the white van had anything to do with speaker sales.