OOMMF Home next up previous index
Next: ODT Table Concatenation: odtcat Up: Command Line Utilities Previous: Process Nicknames: nickname


ODT Derived Quantity Calculator: odtcalc

The odtcalc utility reads an ODT file on stdin that contains one or more tables, and prints to stdout an ODT file consisting of the same tables augmented by additional columns as controlled by command line arguments. This utility enables the calculation and recording of new data table columns that can be computed from existing columns.

Launching
The odtcalc launch command is:

tclsh oommf.tcl odtcalc [standard options] [var expr unit ...] \
    <infile >outfile
where
var expr unit ...
Each triplet of command line arguments determines the calculation to make for the production of a new column in the output data table. Each var value becomes the new Columns: entry in the data table header, labeling the new column of data. Each unit value becomes the new Units: entry in the data table header, reporting the measurement unit for the new column of data. Each expr value is a Tcl expression to be evaluated to compute each new data value to be stored in the new column of data. See below for more details.
<infile
odtcalc reads its input from stdin. Use the redirection operator ``<'' to read input from a file.
>outfile
odtcalc writes its output to stdout. Use the redirection operator ``>'' to send output to a file.

The computation of a new data value for each row of each new column of data is performed by passing the corresponding expr command line argument to Tcl's expr command. The standard collection of operators and functions are available. The value of other columns in the same row may be accessed by use of the column label as a variable name. For example, the value of the Iteration column can be used in expr by including the variable substitution $Iteration. When column labels include colons, the expr has the option of using just the portion of the column label after the last colon as the variable name. For example, the value of the Oxs_UZeeman::Bx column can be used in expr by including the variable substitution $Bx. When multiple triples specifying new data columns are provided, the values of earlier new columns may be used to compute the values of later new columns. The order of command line arguments controls the order of the new columns that are added to the right side of the data table.

Example
Suppose ring.odt contains hysteresis loop data from an Oxsii simulation where the field was applied in the xy-plane at an angle of 30o from the x-axis. The data file holds field and average magnetization axis component values Bx, By, mx, and my. We want field and magnetization data projected onto the applied field axis. We can create those values using odtcalc like so:

tclsh oommf.tcl odtcalc B '$Bx*0.86602540378443865+$By*0.5' mT \
   m '$mx*0.86602540378443865+$my*0.5' '' \
   < ring.odt > ring-augmented.odt
Here cos(30o) = 0.8660254037844365 and sin(30o) = 0.5. The ring-augmented.odt file will have all the data in the original ring.odt file, plus two additional columns, labeled B with units of mT and m with empty units. (Note: On Windows replace the single quotes in the above command with double quotes. Also, the Windows command line uses the caret character ^ for line continuation instead of the backslash \.)

To extract just the B and m columns and prepare for import into a spreadsheet program supporting CSV (comma separated value) format, post-process with odtcols:

tclsh oommf.tcl odtcols -t csv B m < ring-augmented.odt > ring-export.dat


OOMMF Home next up previous index

OOMMF Documentation Team
September 30, 2022