Documentation:Users:TDI - MdsWiki
Personal tools

From MdsWiki

Jump to: navigation, search

Understanding TDI Expressions

Justin Burruss


This guide is intended to help the user with understanding TDI, the language used for expressions stored in MDSplus nodes. The complete TDI reference is available here.

The Basics

TDI expressions are what you store in an MDSplus node. A TDI expression can be a number, a variable, simple text, or a complex function. That expression is evaluated by MDSplus.

TDI is a programming language; it contains the sequential, repetition, and decision structures fundamental to any structured programming language. This means that you can put programs into MDSplus nodes (although for tree design reasons you would probably not want to put everything into a single node).

You can put multiple expressions into a node, with each expression separated by a comma. In this case the node will be evaluated by the last expression in the comma delimited list.

Use the TCL command put to put a TDI expression into a node. The syntax is put nodename "expression" .

The TDI expressions in a node can be viewed using the TCL command decomp. The syntax is decomp nodename .

Numbers, variables, and arrays

Numbers are straightforward: just put the number into the node. Remember to use decimal points with floating point numbers (10.0 or 10. rather than 10, for example).

TDI variables always start with an underscore. For example:

  _alpha = 32.678

Arrays are enclosed in brackets, with elements of an array separated by commas. Example:

  [12.1, 33.3, 0.003, 1.67]


TDI generally uses C style operators. An exception is the string concatenation operator, which in TDI is two slashes (//). Example:

  WRITE(*, "Hello," // " World!");


There are two types of TDI functions: intrinsic TDI functions that are part of the TDI language, and user TDI functions that are written by users. Both have exactly the same syntax: use the name of the function followed by the argument list enclosed within parentheses. Example:

  ABS( -32.9 )

Function arguments are delimited by commas. If you omit a function argument, use * as a placeholder. Example:

  BUILD_SIGNAL( [1., 2., 3., 4.], *, [0.1, 0.2, 0.3, 0.4] )

Sequence, repetition, and decision

You can build a sequence of TDI expressions using commas to delimit the TDI statements. As mentioned above, if multiple TDI expressions appear in a node, then the node is evaluated by the last TDI expression in the comma delimited list.

You can repeat statements using the TDI intrinsic FOR(). The syntax is FOR( [init]; [test]; [update];) statement. For example:

  FOR( _i=0; _i <= 5; _i++ ) WRITE(*,"Hi");

You can also do compound statements using curly braces:

  FOR( _i=0; _i <= 5; _i++ )
    WRITE( *, _i );
    WRITE( *, "Hi" );

You can use the TDI intrinsic IF() to make decisions. The syntax is IF( test, statement [,else] ). For example:

  IF( _i < 10., _i = 10. )

Surprisingly, when you put an IF() into a node, then decompile the node, you will get back a different statement. The above example would come back as

If ( _i < 10. )
  _i = 10;

The above statement doesn't work if you enter it directly--you must use IF() to build the statement.

This behavior may lead to confusion, so consider using the ternary operator in lieu of an if-then-else block. For example, the expression

  (_i < 10) ? (_i = 10) : --_i

says "if i is less than ten, then set i equal to 10, otherwise decrement i by 1."