This is a subroutine for doing calculations. While the routine can be used as a calculator from the user interface (entered with command MA), its utility is in use within macros. The following definitions may make more sense if you examine the Math screen by typing MA.
There are 10 REGISTER, 10 MEMORY and 10 INTEGRAL locations. The REGISTERs act like a stack, similar to an RPN calculator. When a math operation is done, it is performed between REGISTER_0 and REGISTER_1 and the answer is put in REGISTER_0 and REGISTERs 2 thru 9 roll down one level. There is one comment field which can be placed into a Note, along with the contents of Register 0, so results are displayed on the screen. An example of a macro is shown below.
Related commands: Multiply and Divide data by a specified constant.
Macro commands
Use of the ENTER function puts the value in REGISTER_0 and rolls the stack up. For
example,
DO MATH ENTER 1
Any location can be set to a specific value, such as
SET MATH REGISTER x value
Set Reg x to
"value"
Clear all Registers, Memory and Integral values using
DO MATH CLEAR
The line below specifies the number of decimal places to show in calculations
SET MATH DECPLACES x
The math operations possible are:
add
subtract
multiply
divide
reciprocal
natural log
log base 10
exponential
power
The following operations are performed on Registers 0 and 1, and the result is then placed into Register 0.
DO MATH +
DO MATH - Register 1 - Register 0
DO MATH *
DO MATH / Register 1 / Register 0
DO MATH POWER Reg0**Reg1
These operations are performed on the contents of Register 0:
DO MATH RECIPROCAL 1/Reg0
DO MATH EXP
DO MATH LN Natural Log
DO MATH LOG Log Base 10
The value of Register and Memory locations can be set from another location, using
DO MATH REGISTER x REGISTER y
copy contents of
Reg x to Reg y
DO MATH REGISTER x MEMORY y
copy contents of
Reg x to Mem y
DO MATH MEMORY x REGISTER y
copy contents of
Mem x to Reg y
DO MATH INTEGRAL x REGISTER y
copy contents of
Integral x to Reg y
DO MATH INTEGRAL x MEMORY y
copy contents of Integral x to Mem y
Acquisition parameters can be set from Register 0, using
DO MATH SF1
Set
SF1 to the value in Register 0
DO MATH SF2
Set
SF2 to the value in Register 0
DO MATH SW1
Set
SW1 to the value in Register 0
DO MATH SW2
Set
SW2 to the value in Register 0
DO MATH OF1
Set OF1 to the value in Register 0
DO MATH OF2
Set OF2 to the value in Register 0
Acquisition parameters can be placed into Registers or Memory locations, using
DO MATH REGISTER x SF1 Put
SF1 into Register x
DO MATH REGISTER x SF2 Put
SF2 into Register x
DO MATH MEMORY x SF1
Put SF1 into Memory x
DO MATH MEMORY x SF2
Put SF2 into Memory x
DO MATH REGISTER x SW1
Put 1st Dimension sweep width into
Register x
DO MATH REGISTER x SW2
Put 2nd Dimension sweep width into
Register x
DO MATH MEMORY x SW1
Put 1st Dimension sweep width into
Memory x
DO MATH MEMORY x SW2
Put 2nd Dimension sweep width into
Memory x
DO MATH REGISTER x OF1
Put 1st Dim O1 into Reg
x
DO MATH REGISTER x OF2
Put 2nd Dim O2 into Reg
x
DO MATH MEMORY x OF1
Put 1st Dim
O1 into Memory x
DO MATH MEMORY x OF2
Put
2nd Dim O2 into Memory x
The Zoom regions (Z0 - Z9) can be set from values in the
Registers. The line below sets Zoom Region i. The value in register x becomes the
left end of Zoom Region i (in ppm), and the value in register y becomes the right end (in
ppm).
DO MATH ZOOM_REGION i x y
The following creates a Note (text annotation) consisting of the COMMENT and the contents of Register 0, and displays it at specified screen position (x_pos, y_pos) (in percent of display, a number between 0 and 100). The font used is the default Notes font, set in the nuts.ini file.
SET MATH COMMENT string
Make
"string" a comment for output
DO MATH NOTE x_pos y_pos
To automatically measure pre-defined integrals, the integral limits must first be defined using the Set Zoom Region command. (Do not confuse this with the Set Integral macro commands.) After all regions are defined, a single command, DO MATH GET_INT, measures all values and places them into the corresponding INTEGRAL locations. For example, The following sequence defines 2 integrals (7.4 - 7 ppm and 6.2 - 6.0 ppm), named as regions 1 and 2, and then the Get_Int command puts the integrals of those regions into Integral locations 1 and 2. It is important to understand that the DO MATH GET_INT command measures the integrals of all defined zoom regions.
set zoom_region 1 7.4 7
set zoom_region 2 6.2 6.0
do math get_int
It is also possible to load areas resulting from a line fit in the LF routine. The command
Do Math get_lf_areas
will insert the area values of peaks 1-10 from the LF calculation into the corresponding INTEGRAL locations.
These commands are used to request user to enter values at runtime. The entered value is placed in the specified location.
ASK MATH REGISTER x Ask for a value for Reg x
ASK MATH MEMORY x Ask for a value for Mem x
Example: The following is a macro which measures the mole% of 2 impurities, relative to the major component.
NutsMacro math test ; ask name of file to open ask filea ga ; clear any old Notes no c ^m ; integrals of 1 proton each from major component set zoom_region 1 7.17 7.04 set zoom_region 2 7.27 7.18 ; integral of impurity #1 set zoom_region 3 6.02 5.96 ; integral of impurity #2 set zoom_region 4 2.72 2.68 ; now get the integrals and place into Integral locations in Math routine do math get_int ; average integrals of 2 protons from major component. Move integrals from major component ; into registers 0 and 1, add them, divide by 2. do math integral 1 register 0 do math enter 1 do math integral 2 register 0 do math + do math enter 2 do math / ; Put result into memory location for later retrieval do math register 0 memory 7 ; impurity peak #1 is from 2 protons, so move it to register 0, enter value of 2, divide, then move to memory location do math enter 1 do math integral 3 register 0 do math enter 2 do math / do math register 0 memory 1 ; calc mole % imp 1. Divide previous result by integral of main component, mult by 100 do math enter 1 do math memory 7 register 0 do math / do math enter 100 do math * ; Set comment, output result at specified screen location set math comment Mole % Impurity #1 do math note 35 10 ; now do same for impurity #2 do math integral 4 register 1 do math memory 7 register 0 do math / do math enter 100 do math * set math comment Mole % Impurity #2 do math note 35 20 end
See also: sample macro for X-nucleus chemical shift referencing based on the proton TMS frequency.
Multiply the current 1D data set or the currently displayed slice by a constant. This takes one argument, the factor by which the data is to be multiplied. In Arrayed Mode, only the current slice is multiplied, not the entire data set.
Divide the current 1D data set or the currently displayed slice by a constant. This takes one argument, the factor by which the data is to be divided. This can be helpful in cleaning up 2D data which has t1 noise "stripes", which consist of a few data slices with high noise level. Display each slice and divide it to reduce the noise amplitude. This command is not array-aware, meaning that even in arrayed mode, it acts only on the displayed slice.
Last updated: 1/5/05