Tcl

From Flooxs
Jump to navigation Jump to search

All of FLOODS/FLOOPS is built using tcl. A familiarity with tcl commands is essential for understanding how to do anything complex in FLOOXS. You can find many great tcl reference books. We suggest Practical Programming in Tcl and Tk by Brent Welch and Ken Jones. tcl command documentation is also available. Below are some common tcl commands and how to use them.

Common Tcl Commands

set

The "set" command is used to set variables. The syntax is

set variable_name value

All of the variables in tcl are strings. Thus, in the example below, all the variables var1-var5 are strings.

set var1 bunchofletters
set var2 1e5
set var3 1.0e5
set var4 1.0
set var5 1+2

If you type these on the flooxs command line, you'll see that you get back exactly the string of characters you gave. Notice that "1+2" is not evaluated; it is simply a string of 3 characters, the first of which is the character "1", the second of which is the character "+", and the third of which is the character "2". So let's not confuse ourselves, shall we? Let's make a more descriptive variable name, and let's use double-quotes "" around the string:

set eqn1 "1+2"

Now everybody knows this is a string. If you have a good text editor, then it should even make you strings in quotes a different color, for easy recognition.

Now that you have some nice variables defined, you might want to access them. Do this by using the "$" symbol:

$var1

Wherever you use the "$var", floods will immediately replace "$var" with the value stored in "var". For example:

set var6 $var1

puts

The puts command puts the string after "puts" to standard input/output (in the case of flooxs, this means to your terminal), unless you specify another channel to put the string to (we'll cover that later). So, if you want to test what's in your variables, no problem:

puts $var1
puts "var 1 is $var1"

expr

Since all variables in tcl are strings, we need a way of doing math. This is the "expr" command, which stands for "mathematical expression". The format is:

expr {math_expression}

but usually you want to save the answer, so a more common format is to set a new variable to the result of the expr command. For example:

set var6 [expr {$eqn1}]

The square brackets "[ ]" mean "evaluate this right now and put the answer here," to tcl. Here's an attempt to show how tcl reads the previous command:

set var6 [expr {$eqn1}]
set var6 [expr {1+2}]
set var6 3

foreach

Sometimes you want to run splits on your deck. For example, how does the IV characteristic of a MOSFET change when you change the oxide thickness? Let's say you have some FLOODS lines specifying the oxide thickness (these are NOT tcl commands):

line x -0.002 spac=0.001
line x 0.0 spac=0.001

Well, you can use a tcl var, and a foreach loop around your whole floods deck to change the variable for you automatically. This pseudo-code explains how the whole deck will be run three times with the oxide thicknesses of 1nm, 2nm and 3nm:

foreach tox {0.001 0.002 0.003} {
    #floods code here
    line x -$tox spac=0.001
    line x 0.0 spac=0.001
    #floods code here
 }

string

list

file

exec

Stuff to Watch out For

brackets in comments

eval set