SELECT

\label{chap:files}

Some \madxcommands can perform specific operations on selected elements or ranges of elements and can produce specific output for selected elements or ranges of elements.

The selection is made through the SELECT command and applies to subsequent commands.

\madbox

SELECT, F̄LAG=string, RANGE=string, CLASS=string, PATTERN=string,
SEQUENCE=string, FULL=logical, CLEAR=logical,
COLUMN=string{,string}, SLICE=integer, THICK=logical;

The attributes to the SELECT command are:

{madlist}\ttitem

FLAG determines the applicability of the SELECT statement and the attribute value can be one of the following: {madlist} \ttitemSEQEDIT selection of elements for the SEQEDIT module.

\ttitem

ERROR selection of elements for the error assignment module.

\ttitem

MAKETHIN selection of elements for the MAKETHIN command that converts the sequence into one with thin elements.

\ttitem

SECTORMAP selection of elements for the SECTORMAP output file from the TWISS module.

\ttitem

SAVE selection of elements for the SAVE command.

\ttitem

tablename is a table name such as twiss, track etc., and the rows and columns to be written are selected.

\ttitem

RANGE the range of elements to be selected as defined in section \ref{sec:range} on range selection.

\ttitem

CLASS the class of elements to be selected as defined in section \ref{sec:class} on class selection.

\ttitem

PATTERN the regular expression pattern for the element names to be selected as defined in section \ref{sec:regex} on selection via regular expressions.

\ttitem

SEQUENCE the name of a sequence to which the selection is applied.

\ttitem

FULL a logical falg to select ALL positions in the sequence for the named flag.
For the flag TWISS, this attribute includes all standard columns for a TWISS table, and therefore the following two statements are equivalent: \madxmp SELECT, FLAG=twiss, COLUMN= name, s, betx, …, var1;
SELECT, FLAG=twiss, FULL, COLUMN= var1; FULL=true is the default for the MAKETHIN flag and for tables: eg SELECT, FLAG=makethin; is equivalent to SELECT, FLAG=makethin, FULL;

\ttitem

CLEAR deselects ALL positions in the sequence for the flag ”name”. This is the default for ERROR and SEQEDIT flags.
eg SELECT, FLAG=error; is equivalent to SELECT, FLAG=error, CLEAR;

\ttitem

COLUMN is only valid for tables and takes as attribute value a list of columns to be written into the TFS file. The special ”_name” argument refers to the actual name of the element.

\ttitem

SLICE is the number of slices into which the selected elements have to be cut and is only used by MAKETHIN. (Default = 1).

\ttitem

THICK is a logical flag to indicate whether the selected elements are treated as thick elements by the MAKETHIN command.
This only applies up to now to QUADRUPOLEs and BENDs for which thick maps have been explicitely derived.


Composition of SELECT statements:
The selection criteria provided on a single SELECT statement are logically ANDed,
ie selected elements have to fulfill all provided criteria in the single SELECT statement.

The selection criteria on different SELECT statements are logically ORed, ie selected elements have to fulfill any of the selection criteria provided by the different SELECT statements.

All selections for a given flag remain valid until a SELECT statement with the CLEAR argument is specified for the same flag.

Note that because of these composition rules, it is considered good practice to start by clearing the selection for a given flag before making a new selection, eg: \madxmp SELECT, FLAG=twiss, CLEAR;
SELECT, FLAG=twiss, CLASS=MQ;
SELECT, FLAG=twiss, RANGE=MQ[5]/MQ[7];
...


Examples: \madxmp SELECT, FLAG = ERROR, CLASS = quadrupole, RANGE = mb[1]/mb[5];
SELECT, FLAG = ERROR, PATTERN = "^mqw.*"; selects all quadrupoles in the range mb[1] to mb[5], as well as all elements (in the whole sequence) with name starting with "mqw", for treatment by the ERROR module.


\madxmp

SELECT, FLAG=SAVE, CLASS=variable, PATTERN="abc.*";
SAVE, FILE=mysave; saves all variables (and sequences) containing "abc" in their name, but does not save elements with names containing "abc" since the class "variable" does not exist.


\madxmp

sig1 := sqrt(beam->ex*table(twiss,betx));
SELECT, FLAG=twiss, COLUMN= _name, s, betx, ..., sig1; ! or equivalently
SELECT, FLAG=twiss, FULL, COLUMN= sig1; ! default columns + new writes the current value of ``sig1'' into the TWISS table each time a new line is added; Note that the values from the same (current) line can be are accessed by the variable ``sig1''. The PLOT command also accepts the new variable in the table.

Note that the filenames given as attribute values in File Handling statements must be explicit names and should not contain wildcard characters since the filename strings are not passed to the underlying Operating System for evaluation.