mcstasscript.helper.mcstas_objects.DeclareVariable#

class mcstasscript.helper.mcstas_objects.DeclareVariable(type, name=None, **kwargs)#

Class describing a declared variable in McStas instrument

McStas parameters are declared in declare section with c syntax. This class is initialized with type, name. Using keyword arguments, the variable can become an array and have its initial value set. Can also be used as a user variable in uservars (McStas 3.0)

type#

McStas type to declare: Double, Int, String

Type:

str

name#

Name of variable

Type:

str

value#

Initial value of variable, converted to string

Type:

any

comment#

Comment displayed next to the declaration, could contain units

Type:

str

vector#

0 if a single value is given, otherwise contains the length

Type:

int

write_line(fo)#

Writes a line to text file fo declaring the parameter in c

__init__(type, name=None, **kwargs)#

Initializing mcstas declare variable or user variable object

Examples

Creates a variable with name A3 and default value A = DeclareVariable(“double”, “A3”, value=30)

Creates a variable with type integer and name A A = DeclareVariable(“int”)

Creates a variable with type integer and name sample_number A = DeclareVariable(“int”, “sample_number”)

Creates an array variable called m_values A = DeclareVariable(“double”, “m_values”, array=3,

value=[2, 2.5, 2])

Parameters:
  • type (str) – Type of the parameter, double, int or string

  • name (str) – Name of input parameter

  • arguments (Keyword) –

    arrayint

    length of array to be allocated, 0 if single value

    valueany

    sets initial value of parameter, can be a list with length matching array

    commentstr

    sets comment displayed next to declaration

Methods

__init__(type[, name])

Initializing mcstas declare variable or user variable object

write_line(fo)

Writes line declaring variable to file fo

write_line(fo)#

Writes line declaring variable to file fo

Parameters:

fo (file object) – File the line will be written to