SETVARS_LIN

\label{sec:setvars_lin}

The SETVARS_LIN command sets the variables with values calculated by linear interpolation, or extrapolation, between two rows of a table.

\madbox

SETVARS_LIN, TABLE=tabname, ROW1=integer, ROW2=integer, PARAM=string;

The attributes of SETVARS_LIN are:

{madlist}\ttitem

TABLE the name of the table. (Default: none) \ttitemROW1 a first row number with values for interpolation. (Default: 0) \ttitemROW2 a second row number with values for interpolation. (Default: 0) \ttitemPARAM a string containing the linear interpolation factor or the name of a variable or expression containing the interpolation factor. If the resulting value of PARAM is outside the \([0,1]\) interval, the result is a linear extrapolation.
(Default: ”interp”, itself defaulting to a value of 0.0 when evaluated)

SETVARS_LIN sets the variables with values calculated through the following formula that \madxconstructs internally as a deferred expression which is immediately evaluated: \madxmpvalue := value(row1)*(1-param) + value(row2)*param; Both the expression and the value of the expression are available to the user through respectively the commands SHOW and VALUE.

When the values are represented as strings, e.g. the name or keyword of elements, the resulting value is the string in ROW1.

Negative ROWi values are allowed and count the row numbers from the last row, allowing access to the table in reverse order of rows: ROWi = -1 accesses the last row of the table, ROWi = -2 accesses the penultimate (one before last) row, etc…

Trying to access the table forward beyond the last row, i.e. ROWi strictly greater than nrow the number of rows in the table, or trying to access the table backwards before the first row, i.e. ROWi strictly lower than -nrow, or trying to access the illegal ROWi=0, all result in a ``row out of bound'' message and the expression is not constructed or evaluated.

Example: \madxmp ! extracts the position of the centre of each element from a standard
! TWISS table giving positions at end of elements:
len = table(twiss,tablelength);
interpolate = 0.5;
i = 2;
WHILE (̄i < len) {
SETVARS_LIN, TABLE=twiss, ROW1=i-1, ROW2=i, PARAM=interpolate;
! now variables are interpolated at the center of the elements.
! in particular S holds the position of the center of the element.
SHOW, s; VALUE, s;

i = i + 1; };