ARTS  2.3.1285(git:92a29ea9-dirty)
InteractiveWorkspace Class Reference

Interactive ARTS workspace. More...

#include <interactive_workspace.h>

Inheritance diagram for InteractiveWorkspace:
Workspace

Public Member Functions

 InteractiveWorkspace (const Index verbosity=1, const Index agenda_verbosity=0)
 
const char * execute_agenda (const Agenda *a)
 Execute agenda. More...
 
const char * execute_workspace_method (long id, const ArrayOfIndex &output, const ArrayOfIndex &input)
 Execute workspace method. More...
 
void set_agenda_variable (Index id, const Agenda &src)
 Set agenda variable into workspace. More...
 
void set_index_variable (Index id, const Index &src)
 Deep-copy of Index variable into workspace. More...
 
void set_array_of_index_variable (Index id, size_t n, const Index *src)
 Deep-copy of ArrayOfIndex variable into workspace. More...
 
void set_numeric_variable (Index id, const Numeric &src)
 Deep-copy of Numeric variable into workspace. More...
 
void set_string_variable (Index id, const char *src)
 Deep-copy of String variable into workspace. More...
 
void set_array_of_string_variable (Index id, size_t n, const char *const *src)
 Deep-copy of ArrayOfString variable into workspace. More...
 
void set_vector_variable (Index id, size_t n, const Numeric *src)
 Deep-copy of Vector variable into workspace. More...
 
void set_matrix_variable (Index id, size_t m, size_t n, const Numeric *src)
 Deep-copy of Matrix variable into workspace. More...
 
void set_tensor3_variable (Index id, size_t l, size_t m, size_t n, const Numeric *src)
 Deep-copy of Tensor3 variable into workspace. More...
 
void set_tensor4_variable (Index id, size_t k, size_t l, size_t m, size_t n, const Numeric *src)
 Deep-copy of Tensor4 variable into workspace. More...
 
void set_tensor5_variable (Index id, size_t k, size_t l, size_t m, size_t n, size_t o, const Numeric *src)
 Deep-copy of Tensor5 variable into workspace. More...
 
void set_tensor6_variable (Index id, size_t k, size_t l, size_t m, size_t n, size_t o, size_t p, const Numeric *src)
 Deep-copy of Tensor6 variable into workspace. More...
 
void set_tensor7_variable (Index id, size_t k, size_t l, size_t m, size_t n, size_t o, size_t p, size_t q, const Numeric *src)
 Deep-copy of Tensor5 variable into workspace. More...
 
void set_sparse_variable (Index id, Index m, Index n, Index nnz, const Numeric *src, const int *row_indices, const int *column_indices)
 Deep-copy of Sparse matrix into workspace. More...
 
void execute_callback (Index callback_id)
 
void initialize_variable (Index id)
 Initialize workspace variable. More...
 
Index add_variable (Index group_id, const char *name)
 Push a stack for a new variable to the workspace. More...
 
void erase_variable (Index i, Index group_id)
 Remove a variable stack from the workspace. More...
 
void swap (Index i, Index j)
 Remove a variable stack from the workspace. More...
 

Static Public Member Functions

static void initialize ()
 Workspace intialization. More...
 
static Index add_callback (Callback *cb)
 Add callback to workspace. More...
 

Private Member Functions

void resize ()
 Resize workspace stack. More...
 
- Private Member Functions inherited from Workspace
 Workspace ()
 Construct a new workspace. More...
 
 Workspace (const Workspace &workspace)
 Workspace copy constructor. More...
 
virtual ~Workspace ()
 Destruct the workspace and free all WSVs. More...
 
void del (Index i)
 Delete WSV. More...
 
void duplicate (Index i)
 Duplicate WSV. More...
 
void initialize ()
 Reset the size of the workspace. More...
 
bool is_initialized (Index i)
 Checks existence of the given WSV. More...
 
Index depth (Index i)
 Return scoping level of the given WSV. More...
 
void * pop (Index i)
 Remove the topmost WSV from its stack. More...
 
void pop_free (Index i)
 Remove the topmost WSV from its stack and free its memory. More...
 
void push (Index i, void *wsv)
 Push a new WSV onto its stack. More...
 
void push_uninitialized (Index i, void *wsv)
 Put a new WSV onto its stack. More...
 
Index nelem ()
 Get the number of workspace variables. More...
 
Index add_wsv_inplace (const WsvRecord &wsv)
 Add a new variable to existing workspace and to the static maps. More...
 
void * operator[] (Index i)
 Retrieve a pointer to the given WSV. More...
 

Static Private Attributes

static size_t n_anonymous_variables_ = 0
 
static std::vector< Callback * > callbacks_ {}
 
- Static Private Attributes inherited from Workspace
static Array< WsvRecordwsv_data
 Global WSV data. More...
 
static map< String, IndexWsvMap
 Global map associated with wsv_data. More...
 

Additional Inherited Members

- Static Private Member Functions inherited from Workspace
static void define_wsv_data ()
 Define workspace variables. More...
 
static void define_wsv_map ()
 Map WSV names to indices. More...
 
static Index add_wsv (const WsvRecord &wsv)
 Append a new WSV to the workspace. More...
 
- Private Attributes inherited from Workspace
String context
 Debugging context. More...
 
Array< stack< WsvStruct * > > ws
 Workspace variable container. More...
 

Detailed Description

Interactive ARTS workspace.

The InteractiveWorkspace class extends the ARTS Workspace class with features that are required to allow an interactive simulation session.

Definition at line 84 of file interactive_workspace.h.

Constructor & Destructor Documentation

◆ InteractiveWorkspace()

Member Function Documentation

◆ add_callback()

static Index InteractiveWorkspace::add_callback ( Callback cb)
inlinestatic

Add callback to workspace.

So that a callback can be executed from within an agenda it must be stored within the workspace. This is done with this method. The returned index can then be inserted as a WSM call into a agenda, which will then trigger execution of the workspace when ARTS executes the given agenda.

Parameters
[in]cbThe callback to add to the workspace.
Returns
The WSM index representing the newly added callback.

Definition at line 280 of file interactive_workspace.h.

References add_variable(), erase_variable(), i, and swap().

Referenced by agenda_insert_callback().

◆ add_variable()

Index InteractiveWorkspace::add_variable ( Index  group_id,
const char *  name 
)

Push a stack for a new variable to the workspace.

Registers a new variable with and adds a new stack to the given workspace. If name is nullptr, a unique name is created.

Parameters
group_idIndex of the group of the variable to add to the workspace.
nameChar pointer to the name of the variable.
Returns
Index of the newly pushed stack

Definition at line 323 of file interactive_workspace.cc.

References WorkspaceMemoryHandler::allocate(), n_anonymous_variables_, Workspace::push(), resize(), global_data::workspace_memory_handler, Workspace::ws, Workspace::wsv_data, and Workspace::WsvMap.

Referenced by add_variable().

◆ erase_variable()

void InteractiveWorkspace::erase_variable ( Index  i,
Index  group_id 
)

Remove a variable stack from the workspace.

Remove the stack given by index id from the workspace. This is used by the C API to control the workspace size.

Parameters
iIndex of the stack to erase.
group_idIndex of the group of the variable.

Definition at line 353 of file interactive_workspace.cc.

References Workspace::WsvStruct::auto_allocated, WorkspaceMemoryHandler::deallocate(), i, n_anonymous_variables_, global_data::workspace_memory_handler, Workspace::ws, Workspace::WsvStruct::wsv, Workspace::wsv_data, and Workspace::WsvMap.

Referenced by erase_variable().

◆ execute_agenda()

const char * InteractiveWorkspace::execute_agenda ( const Agenda a)

Execute agenda.

Executes the given agenda on this workspace.

Parameters
[in]aPointer to the agenda to execute.
Returns
0 if execution was successful, otherwise c-string pointer to the generated error message.

Definition at line 100 of file interactive_workspace.cc.

References Agenda::execute(), resize(), Workspace::ws, and Workspace::wsv_data.

Referenced by execute_agenda().

◆ execute_callback()

void InteractiveWorkspace::execute_callback ( Index  callback_id)
inline

Definition at line 265 of file interactive_workspace.h.

Referenced by callback_getaway().

◆ execute_workspace_method()

const char * InteractiveWorkspace::execute_workspace_method ( long  id,
const ArrayOfIndex output,
const ArrayOfIndex input 
)

Execute workspace method.

Executes the WSM with given id on this workspace.

Parameters
[in]idWorkspace id of the workspace method to execute.
[in]outputArray containing the indices of the output variables in which to store the results.
[in]inputArray containing the indices of the input variables to the function calls.
Returns
0 if execution was successful, otherwise c-string pointer to the generated error message.

Definition at line 115 of file interactive_workspace.cc.

References CREATE_OUTS, get_wsv_id(), getaways, i, Workspace::is_initialized(), MRecord::isInternal(), global_data::md_data, MdRecord::Name(), resize(), Verbosity::set_main_agenda(), MdRecord::SetMethod(), string_buffer, swap(), Workspace::ws, and Workspace::wsv_data.

Referenced by execute_workspace_method().

◆ initialize()

void InteractiveWorkspace::initialize ( )
static

◆ initialize_variable()

void InteractiveWorkspace::initialize_variable ( Index  id)

Initialize workspace variable.

If unitialized, initializes the workspace variable. If variable exists it is reinitialized to be empty.

Parameters
idWorkspace variable index of the variable to (re)initialize.

Definition at line 317 of file interactive_workspace.cc.

References Workspace::operator[](), and Workspace::pop_free().

Referenced by set_variable_value().

◆ resize()

void InteractiveWorkspace::resize ( )
private

Resize workspace stack.

This method resizes the array of stacks that manages the runtime memory of ARTS to match the number of WSV variables.

Definition at line 311 of file interactive_workspace.cc.

References copy(), Array< base >::nelem(), swap(), Workspace::ws, and Workspace::wsv_data.

Referenced by add_variable(), execute_agenda(), and execute_workspace_method().

◆ set_agenda_variable()

void InteractiveWorkspace::set_agenda_variable ( Index  id,
const Agenda src 
)

Set agenda variable into workspace.

Copies the given agenda object into the Agenda variable with the given id in this workspace.

Note: This triggers checking of the agenda which can result in an exception being thrown from the call.

Parameters
[in]idWorkspace id of the agenda to set
[in]agendaThe agenda to copy into the workspace

Definition at line 163 of file interactive_workspace.cc.

References global_data::AgendaMap, Agenda::check(), Agenda::name(), Workspace::operator[](), and Agenda::set_name().

Referenced by set_variable_value().

◆ set_array_of_index_variable()

void InteractiveWorkspace::set_array_of_index_variable ( Index  id,
size_t  n,
const Index src 
)

Deep-copy of ArrayOfIndex variable into workspace.

Parameters
[in]idWorkspace id of the Index variable to set
[in]srcPointer to the c-style index array to copy.

Definition at line 195 of file interactive_workspace.cc.

References i, n, and Workspace::operator[]().

◆ set_array_of_string_variable()

void InteractiveWorkspace::set_array_of_string_variable ( Index  id,
size_t  n,
const char *const *  src 
)

Deep-copy of ArrayOfString variable into workspace.

Parameters
[in]idWorkspace id of the ArrayOfString variable to set
[in]srcPointer to the null-terminated c-string to copy into the workspace.

Definition at line 186 of file interactive_workspace.cc.

References i, n, and Workspace::operator[]().

◆ set_index_variable()

void InteractiveWorkspace::set_index_variable ( Index  id,
const Index src 
)

Deep-copy of Index variable into workspace.

Parameters
[in]idWorkspace id of the Index variable to set
[in]srcThe index value to copy into the workspace.

Definition at line 174 of file interactive_workspace.cc.

References Workspace::operator[]().

◆ set_matrix_variable()

void InteractiveWorkspace::set_matrix_variable ( Index  id,
size_t  m,
size_t  n,
const Numeric src 
)

Deep-copy of Matrix variable into workspace.

Parameters
[in]idWorkspace id of the Vector variable to set
[in]srcPointer to the two-dimensional c-array of Numeric containing the matrix elements in column-major order.

Definition at line 215 of file interactive_workspace.cc.

References MatrixView::get_c_array(), i, Workspace::operator[](), and Matrix::resize().

◆ set_numeric_variable()

void InteractiveWorkspace::set_numeric_variable ( Index  id,
const Numeric src 
)

Deep-copy of Numeric variable into workspace.

Parameters
[in]idWorkspace id of the Numeric variable to set
[in]srcThe index value to copy into the workspace.

Definition at line 178 of file interactive_workspace.cc.

References Workspace::operator[]().

◆ set_sparse_variable()

void InteractiveWorkspace::set_sparse_variable ( Index  id,
Index  m,
Index  n,
Index  nnz,
const Numeric src,
const int *  row_indices,
const int *  column_indices 
)

Deep-copy of Sparse matrix into workspace.

Copies a sparse matrix in coordinate format into the workspace.

Parameters
[in]idWorkspace id of the Sparse variable to set
[in]mNumber of rows of the matrix
[in]nNumber of column of the matrix
[in]nnzNumber of non-zeros of the matrix
[in]srcPointer to the one-dimensional c-array containing the matrix elements.
[in]inner_ptrPointer to the c-array of Index containing the row indices of the elements in src.
[in]outer_ptrPointer to the c-array of Index containing the column indices of the elements in src.

Definition at line 289 of file interactive_workspace.cc.

References i, Sparse::insert_elements(), and Workspace::operator[]().

◆ set_string_variable()

void InteractiveWorkspace::set_string_variable ( Index  id,
const char *  src 
)

Deep-copy of String variable into workspace.

Parameters
[in]idWorkspace id of the String variable to set
[in]srcPointer to the null-terminated c-tring to copy into the workspace.

Definition at line 182 of file interactive_workspace.cc.

References Workspace::operator[]().

◆ set_tensor3_variable()

void InteractiveWorkspace::set_tensor3_variable ( Index  id,
size_t  l,
size_t  m,
size_t  n,
const Numeric src 
)

Deep-copy of Tensor3 variable into workspace.

Parameters
[in]idWorkspace id of the Tensor3 variable to set
[in]srcPointer to the three-dimensional c-array of Numeric containing the tensor elements.

Definition at line 226 of file interactive_workspace.cc.

References Tensor3View::get_c_array(), i, Workspace::operator[](), and Tensor3::resize().

◆ set_tensor4_variable()

void InteractiveWorkspace::set_tensor4_variable ( Index  id,
size_t  k,
size_t  l,
size_t  m,
size_t  n,
const Numeric src 
)

Deep-copy of Tensor4 variable into workspace.

Parameters
[in]idWorkspace id of the Tensor4 variable to set
[in]srcPointer to the four-dimensional c-array of Numeric containing the tensor elements.

Definition at line 235 of file interactive_workspace.cc.

◆ set_tensor5_variable()

void InteractiveWorkspace::set_tensor5_variable ( Index  id,
size_t  k,
size_t  l,
size_t  m,
size_t  n,
size_t  o,
const Numeric src 
)

Deep-copy of Tensor5 variable into workspace.

Parameters
[in]idWorkspace id of the Tensor5 variable to set
[in]srcPointer to the five-dimensional c-array of Numeric containing the tensor elements.

Definition at line 244 of file interactive_workspace.cc.

◆ set_tensor6_variable()

void InteractiveWorkspace::set_tensor6_variable ( Index  id,
size_t  k,
size_t  l,
size_t  m,
size_t  n,
size_t  o,
size_t  p,
const Numeric src 
)

Deep-copy of Tensor6 variable into workspace.

Parameters
[in]idWorkspace id of the Tensor5 variable to set
[in]srcPointer to the six-dimensional c-array of Numeric containing the tensor elements.

Definition at line 258 of file interactive_workspace.cc.

◆ set_tensor7_variable()

void InteractiveWorkspace::set_tensor7_variable ( Index  id,
size_t  k,
size_t  l,
size_t  m,
size_t  n,
size_t  o,
size_t  p,
size_t  q,
const Numeric src 
)

Deep-copy of Tensor5 variable into workspace.

Parameters
[in]idWorkspace id of the Tensor4 variable to set
[in]srcPointer to the four-dimensional c-array of Numeric containing the tensor elements.

Definition at line 273 of file interactive_workspace.cc.

◆ set_vector_variable()

void InteractiveWorkspace::set_vector_variable ( Index  id,
size_t  n,
const Numeric src 
)

Deep-copy of Vector variable into workspace.

Parameters
[in]idWorkspace id of the ArrayOfString variable to set
[in]srcPointer to the c-array of Numeric containing the vector elements.

Definition at line 205 of file interactive_workspace.cc.

References i, n, Workspace::operator[](), and Vector::resize().

◆ swap()

void InteractiveWorkspace::swap ( Index  i,
Index  j 
)

Remove a variable stack from the workspace.

Remove the stack given by index id from the workspace. This is used by the C API to control the workspace size.

Parameters
iIndex of the stack to erase.

Definition at line 370 of file interactive_workspace.cc.

References i, Workspace::is_initialized(), swap(), and Workspace::ws.

Referenced by execute_workspace_method().

Member Data Documentation

◆ callbacks_

std::vector< Callback * > InteractiveWorkspace::callbacks_ {}
staticprivate

Definition at line 335 of file interactive_workspace.h.

◆ n_anonymous_variables_

size_t InteractiveWorkspace::n_anonymous_variables_ = 0
staticprivate

Definition at line 334 of file interactive_workspace.h.

Referenced by add_variable(), and erase_variable().


The documentation for this class was generated from the following files: