# Macro Language: Calculation Commands

`fg <axis> <min> <max> <steps> <expr>`

Generate a function with the given parameters.
`<axis>`: The target axis (1 = X axis, 2 = Y axis)
`<min>`, `<max>`: The range of the new generated function.
`<steps>`: Number of steps for the function.
`<expr>`: Expression which defines the function.

`bcalc <buffer1> <operator> <buffer2>`

Performs basic calculations between two buffers. This work also for buffers with different X axis and different numbers of data points. Only the overlapping area will be processed and missing points will be interpolated.
`<operator>`: + - * /

`calc <data> <expr> <BUFFER>`

Performs a calculation on the data in the buffers.
`<data>`: The target axis (1 = X values, 2 = Y values, 3 = X error, 4 = Y error)
`<expr>`: Expression which defines the calculation.

`swapxy <BUFFER>`

This function swaps the X and Y values. Error values will also be swapped if available.

`sortx <BUFFER>`

This function sorts the data by X values.

`sorty <BUFFER>`

This function sorts the data by Y values.

`normx <ref1> <ref2> <new1> <new2> <BUFFER>`

This function manipulates the buffers by stretching or shrinking along the X axis. The specified reference points in the data are changed in such a way that the `ref1` value becomes the `new1` value and the `ref2` value becomes the `new2` value.

`normy <ref1> <ref2> <new1> <new2> <BUFFER>`

This function manipulates the buffers by stretching or shrinking along the Y axis. The specified reference points in the data are changed in such a way that the `ref1` value becomes the `new1` value and the `ref2` value becomes the `new2` value.

`movex <from> <to> <BUFFER>`

This function moves the buffers on the X axis.

`movey <from> <to> <BUFFER>`

This function moves the buffers on the Y axis.

`cutoutsidex <min> <max> <BUFFER>`

This function delete all data points in the buffers which are not in the X range between `min` and `max`

`cutinsidex <min> <max> <BUFFER>`

This function delete all data points in the buffers which are in the X range between `min` and `max`

`cutoutsidey <min> <max> <BUFFER>`

This function delete all data points in the buffers which are not in the Y range between `min` and `max`

`cutinsidey <min> <max> <BUFFER>`

This function delete all data points in the buffers which are in the Y range between `min` and `max`

`calcint <min> <max> <BUFFER>`

Integrates the buffers and add the result to the comment field. The result of the last integration is stored in the variable `integral`.

`linreg <min> <max> <BUFFER>`

Perform a linear regression between `min` and `max`. The result of the last regression will be stored in the variables `rega`, `regb` and `regr`.

`logreg <min> <max> <BUFFER>`

Perform a logarithmic regression between `min` and `max`. The result of the last regression will be stored in the variables `rega`, `regb` and `regr`.

`expreg <min> <max> <BUFFER>`

Perform a exponential regression between `min` and `max`. The result of the last regression will be stored in the variables `rega`, `regb` and `regr`

`linbg <a> <b> <BUFFER>`

Perform a linear background subtraction (y=y+a+bx)

`smooth <factor> <BUFFER>`

This function uses `factor` as the effective smooth width and performs a least square smooth to reduce the noise on the buffer.

`fftsmooth <factor> <BUFFER>`

This function uses `factor` as the effective smooth width and performs an FFT based smooth to reduce the noise on the buffer.

`datareduction <n> <BUFFER>`

Sometimes it is useful to reduce a large number of data points which consist mainly of noise to a more practical amount of points. This function takes `n` points, builds the average, and replaces the n points with the new one.

`spline <points> <strength> <BUFFER>`

This function calculates a nonparametric cubic spline interpolation.
`<points>`: Defines the number of points which should be calculated for each interval.
`<strength>`: Defines the strength of the interpolation. 2 is in most cases a good choice.

`fft <windowing> <BUFFER>`

Performs a Fast Fourier Transform and generates a new buffer with the result.
`<windowing>`: 1=none, 2=Hanning, 3=Welch, 4=Parzen

`diff <interval> <BUFFER>`

Differentiate the buffers and generate new buffers with the result data.

`integrate <BUFFER>`

Integrates buffers and generate new buffers with the result data.

`setxval <BUFFER> <index> <value>`

Set the X value at the given index of the buffers.

`setyval <BUFFER> <index> <value>`

Set the Y value at the given index of the buffers.

`setxeval <BUFFER> <index> <value>`

Set the X error value at the given index of the buffers.

`setyeval <BUFFER> <index> <value>`

Set the Y error value at the given index of the buffers.