Tuesday, August 01, 2006

Memory and Variable in Dicom Unit Conversion Calculator

Dicom can store values in memory. In dicom you can also store values in variables.

Named Memory Variable

x = 1
y = 3 ft.

In the above examples values 1 and 3 ft are stored into variables named x and y. You can later reuse these named memory variables in other expressions.

z = x + 10 (result is 11)
wd = y + 6 inch. (result is 1.0668 m.)

Unnamed Memory Variable

In addition to named variables as in the examples above Dicom also internally stores calculation results in memory locations. These are so called unnamed variables and can be recalled in an expression using # operator. Dicom remembers recent 16 results in unnamed memory locations starting with 1. The memory location 0 however always stores the latest calulation result.

1 + 2 + 3 (result is 6, stored in memory location say, m)
#0 + 4 (result is 10, will be stored in memory location m+1)
#0 + 100 (result is 110, will be stored in memory location m+2)
#(m+1) + #(m+2) (result is 120)

In the above example the result of the first expression (i.e. 6) is stored to unnamed memory variable location no. say m. The second expression recalled this result using #0 and add up 4 with it. As you may guess the result of the second expression (which is 10) will be stored into next memory location, m+1, and so on. In the last expression location (m+1) and (m+2) are recalled and added together.

You can define and use as many named variables as you like. However, you should be careful in selecting the name of the variables so that those do not conflict with Dicom's 650+ unit symbols, 150+ functions and other reserved words. A recommended convention is use m_ as a prefix to name your variables.


m_width = 3 m.
m_height = 12 m.
m_area = m_width * m_height

Note that you can assign values to a named variable but you can't do the same to unnamed memory location.

m_width = 3.5 m. (is valid)
#0 = 3.5 m. (is invalid)

You can store both dimensionless values and units to variables but during calculation don't mix things up. The exression you want to evaluate always need to be homogeneous in terms of dimensions.

m_width + 6 (is invalid)
m_width + 6 inch. (is valid)

Length of a Dicom variable name can be a maximum of 31 characters.

You can display all used named and unnamed memory variables from Dicom explorer. Click on View > Explorer and then click on Memory tab. The nodes Numbered memory and Named Memory will display the unnamed and named variables you have used in current the session.

You can use RECLAIM command to refresh dicom memory. Alternaetly, you can right click on Memory node on the dicom explorer Memory tab and select Reclaim Memory.

This will erase all the named and unnamed memory variables and reclaim the memory for reuse. However, to reflect the refresh in Dicom explorer you need to right click on the root node Memory and select Refresh Memory.