### Load IMAS-MATLAB Module (Bash) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Loads the IMAS-MATLAB module on the ITER SDCC or sources the environment file for local installations. This makes the Access Layer available for use. ```bash module load IMAS-MATLAB module avail IMAS-MATLAB source /bin/al_env.sh ``` -------------------------------- ### Navigate to MATLAB Example Directory Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/000_how_to_run_examples.rst This command changes the current directory to the location where the MATLAB example code is stored. Ensure you are in the root of the project directory before executing this command. ```bash cd al-matlab/doc/code_samples/tutorial ``` -------------------------------- ### Execute MATLAB Test Script Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/000_how_to_run_examples.rst This command runs the 'test_new_examples.m' script within the MATLAB Command Window. This script contains predefined tests to demonstrate the functionality of the example code. ```bash test_new_examples ``` -------------------------------- ### Include Examples Subdirectory Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt Conditionally includes the 'examples' subdirectory if the `AL_EXAMPLES` CMake variable is set to true. This allows for the integration and building of project examples. ```cmake if( AL_EXAMPLES ) add_subdirectory( examples ) endif() ``` -------------------------------- ### Launch MATLAB IDE Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/000_how_to_run_examples.rst This command initiates the MATLAB Integrated Development Environment (IDE). Once the IDE is open, you can navigate and execute your scripts. ```bash matlab ``` -------------------------------- ### Configure IMAS-MATLAB with CMake Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Configures the IMAS-MATLAB project using CMake. This command navigates to the project directory, creates a build directory, and sets installation prefix and custom options. Dependencies are automatically fetched. ```bash cd al-matlab # al-fortran, al-java, al-cpp or al-python cmake -B build -D CMAKE_INSTALL_PREFIX=$HOME/al-install -D OPTION1=VALUE1 -D OPTION2=VALUE2 [...] ``` -------------------------------- ### Install IMAS-MATLAB Prerequisites on Ubuntu 22.04 Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Installs common build prerequisites for IMAS-MATLAB on Ubuntu 22.04 using apt. This includes git, build-essential, cmake, boost, hdf5, and python development packages. Note that MDSplus, UDA, and MATLAB are not included and require manual installation. ```bash apt install git build-essential cmake libsaxonhe-java libboost-all-dev \ pkg-config libhdf5-dev xsltproc libblitz0-dev gfortran \ default-jdk-headless python3-dev python3-venv python3-pip ``` -------------------------------- ### Enable MATLAB Toolbox Creation during Installation Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Configures the IMAS-MATLAB project with CMake to automatically create a MATLAB toolbox package (.mltbx) during the installation process. This requires MATLAB to be installed and in the system's PATH. ```bash cmake -B build -DAL_CREATE_TOOLBOX=ON \ cmake --install build ``` -------------------------------- ### Load and Display Data (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Fetches a specified Interface Data Structure (IDS) from the database using the provided context handle. It then displays metadata, time points, and nested data elements. ```matlab % Load the magnetics IDS (occurrence 0) magnetics = ids_get(ctx, 'magnetics'); % Explore the data disp(magnetics.ids_properties); % Metadata disp(magnetics.time); % Time points disp(magnetics.flux_loop{1}.flux.data); % Access nested data ``` -------------------------------- ### Clone IMAS-MATLAB High Level Interface Repository Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Clones the Git repository for the MATLAB High Level Interface (HLI). This is the first step in building and installing a specific HLI for IMAS-MATLAB. ```bash # For the MATLAB HLI use: ``` -------------------------------- ### Build IMAS-MATLAB High Level Interface Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Builds the IMAS-MATLAB project using the 'make' command. It specifies the build directory and uses the '-j' option for parallel compilation to speed up the build process. ```bash # Instruct make to build "all" in the "build" folder, using at most "8" parallel # processes: make -C build -j8 all ``` -------------------------------- ### Setup Python Virtual Environment for Saxonche Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt Configures a Python virtual environment for the 'saxonche' library on Windows and other systems. It checks for existing environments, creates a new one if necessary, and installs 'saxonche' using pip. ```cmake if(WIN32) set(_SAXONCHE_VENV_PYTHON "${CMAKE_CURRENT_BINARY_DIR}/saxonche_env/Scripts/python.exe") set(_SAXONCHE_VENV_PIP "${CMAKE_CURRENT_BINARY_DIR}/saxonche_env/Scripts/pip.exe") else() set(_SAXONCHE_VENV_PYTHON "${CMAKE_CURRENT_BINARY_DIR}/saxonche_env/bin/python") set(_SAXONCHE_VENV_PIP "${CMAKE_CURRENT_BINARY_DIR}/saxonche_env/bin/pip") endif() if(NOT EXISTS "${_SAXONCHE_VENV_PYTHON}") message(STATUS "Creating Python virtual environment for saxonche...") execute_process( COMMAND ${Python3_EXECUTABLE} -m venv saxonche_env WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE _VENV_EXITCODE ) if(_VENV_EXITCODE) message(FATAL_ERROR "Failed to create Python venv for saxonche") endif() message(STATUS "Installing saxonche in virtual environment...") execute_process( COMMAND ${_SAXONCHE_VENV_PIP} install saxonche RESULT_VARIABLE _PIP_EXITCODE ) if(_PIP_EXITCODE) message(FATAL_ERROR "Failed to install saxonche") endif() message(STATUS "saxonche installed successfully") endif() ``` -------------------------------- ### Open Database Entry and Connect to Data (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Opens a database entry using an IMAS URI, which specifies the data location and format. It returns a context handle for subsequent operations. An error is raised if the connection fails. ```matlab uri = 'imas:hdf5?path=/path/to/data'; ctx = imas_open(uri, 40); if ctx < 0 error('Unable to open database'); end ``` -------------------------------- ### Copy MATLAB Toolbox Packaging Script Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt This command installs the `create_matlab_toolbox.m` script from the source directory to the root of the installation directory. This script is used for packaging the MATLAB toolbox. ```cmake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/create_matlab_toolbox.m DESTINATION . ) ``` -------------------------------- ### Clone IMAS-MATLAB Repository Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Clones the IMAS-MATLAB project repository from GitHub using SSH. This is the initial step to obtain the project's source code. ```bash git clone git@github.com:iterorganization/IMAS-MATLAB.git ``` -------------------------------- ### Load Environment Modules for IMAS-MATLAB (SDCC foss-2023b) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Loads all necessary modules for the IMAS-MATLAB when using the 'foss-2023b' toolchain on SDCC. This includes CMake, Boost, HDF5, MDSplus, UDA, MATLAB, and Python-related packages. ```bash module load CMake/3.27.6-GCCcore-13.2.0 Saxon-HE/12.4-Java-21 \ Boost/1.83.0-GCC-13.2.0 HDF5/1.14.3-gompi-2023b \ MDSplus/7.132.0-GCCcore-13.2.0 \ UDA/2.8.1-GCC-13.2.0 Blitz++/1.0.2-GCCcore-13.2.0 \ MATLAB/2023b-r5-GCCcore-13.2.0 SciPy-bundle/2023.11-gfbf-2023b \ build/1.0.3-foss-2023b scikit-build-core/0.9.3-GCCcore-13.2.0 ``` -------------------------------- ### Configure IMAS-MATLAB with HTTPS Dependencies Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Configures the IMAS-MATLAB project using CMake, explicitly setting Git repositories to use HTTPS for fetching dependencies. This is an alternative to the default SSH URLs. ```text cmake -B build \ -D AL_CORE_GIT_REPOSITORY=git@github.com:iterorganization/IMAS-Core.git \ -D AL_PLUGINS_GIT_REPOSITORY=git@github.com:iterorganization/al-plugins.git \ -D DD_GIT_REPOSITORY=git@github.com:iterorganization/IMAS-Data-Dictionary.git ``` -------------------------------- ### Set Environment Variables for IMAS-MATLAB (Bash) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/using_al.rst This snippet shows how to set environment variables for the IMAS-MATLAB by sourcing the 'al_env.sh' script. Replace '' with the actual installation directory. This is a prerequisite for using the IMAS-MATLAB. ```bash source /bin/al_env.sh ``` -------------------------------- ### Open DBEntry with Legacy URI Parameters in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/001_2_open_URI_legacy.rst This MATLAB code snippet illustrates how to open a DBEntry by constructing a URI with legacy parameters. It utilizes the imas_open function, and the specific parameters used are intended for older versions or specific compatibility modes. Ensure the MATLAB environment has the necessary IMAS libraries installed. ```matlab % This example focuses on opening DBEntry using URI % ┌──────────────────────────────────────────────────────────────────────────────┐ % │ Open DBEntry using AL5 URI with *legacy* parameters │ % └──────────────────────────────────────────────────────────────────────────────┘ % This example focuses on opening DBEntry using **legacy parameters** in URI. % Example of opening a DBEntry with legacy parameters % Replace with your actual database path and parameters db_uri = 'al5://path/to/your/db?param1=value1¶m2=value2'; entry = imas_open(db_uri); % You can now work with the 'entry' object % For example, to get some data: % data = entry.get_data(...); % Remember to close the entry when done % entry.close(); ``` -------------------------------- ### Load Environment Modules for IMAS-MATLAB (SDCC intel-2023b) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Loads all necessary modules for the IMAS-MATLAB when using the 'intel-2023b' toolchain on SDCC. This includes compilers, CMake, Boost, HDF5, MDSplus, UDA, MATLAB, and Python-related packages. ```bash module load intel-compilers/2023.2.1 CMake/3.27.6-GCCcore-13.2.0 Saxon-HE/12.4-Java-21 \ Boost/1.83.0-iimpi-2023b HDF5/1.14.3-iimpi-2023b \ MDSplus/7.132.0-GCCcore-13.2.0 \ UDA/2.8.1-iimpi-2023b Blitz++/1.0.2-GCCcore-13.2.0 \ MATLAB/2023b-r5-GCCcore-13.2.0 SciPy-bundle/2023.11-intel-2023b \ scikit-build-core/0.9.3-GCCcore-13.2.0 ``` -------------------------------- ### Install IMAS MEX Targets and MATLAB Files (CMake) Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt This CMake script handles the installation of compiled MEX targets and MATLAB M-files. It specifies destination directories ('bin', 'lib', 'mex', 'toolbox') based on the operating system (Windows vs. others) and ensures that runtime libraries and M-files are correctly placed for the MATLAB environment. ```cmake # Install ################################################################################ # Install libal-mex to lib folder if(WIN32) install( TARGETS al-mex DESTINATION bin RUNTIME DESTINATION bin LIBRARY DESTINATION lib ) else() install( TARGETS al-mex DESTINATION lib ) endif() # Install compiled libraries to the mex folder install( TARGETS ${MEX_TARGETS} DESTINATION mex ) # Install static and generated '.m' files to the mex folder install( DIRECTORY matlab/ DESTINATION mex ) # Create MATLAB toolbox folder structure with all necessary files if(WIN32) # Install al-mex DLL to toolbox folder install( TARGETS al-mex DESTINATION toolbox RUNTIME DESTINATION toolbox ) else() # Install al-mex shared library to toolbox folder install( TARGETS al-mex DESTINATION toolbox ) endif() # Install MEX files to toolbox folder install( TARGETS ${MEX_TARGETS} DESTINATION toolbox ) # Install M-files to toolbox folder install( DIRECTORY matlab/ DESTINATION toolbox FILES_MATCHING PATTERN "*.m" ) # Install AL shared library to toolbox folder (if not an alias) # The al library comes from al-core and may already be installed ``` -------------------------------- ### Optionally Create MATLAB Toolbox During Installation Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt This CMake code defines an option `AL_CREATE_TOOLBOX` that, if enabled, will automatically execute the MATLAB toolbox packaging process as part of the `cmake --install` command. It includes error handling and informative messages. ```cmake option(AL_CREATE_TOOLBOX "Automatically create MATLAB toolbox package during installation" OFF) # ... later in the script ... if(AL_CREATE_TOOLBOX) install(CODE " message(STATUS \"Creating MATLAB toolbox package: IMAS-MATLAB/${PROJECT_VERSION}-DD-${DD_VERSION}\") execute_process( COMMAND \"${MATLAB_EXECUTABLE}\" -batch \"create_matlab_toolbox('\${CMAKE_INSTALL_PREFIX}', '${CMAKE_BINARY_DIR}', '${PROJECT_VERSION}', '${DD_VERSION}')\" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE _TOOLBOX_RESULT OUTPUT_VARIABLE _TOOLBOX_OUTPUT ERROR_VARIABLE _TOOLBOX_ERROR ) if(_TOOLBOX_RESULT) message(WARNING \"Failed to create MATLAB toolbox package: $${_TOOLBOX_ERROR}\") message(WARNING \"You can create it manually by running: cmake --build . --target matlab-toolbox\") else() message(STATUS \"MATLAB toolbox package created successfully\") message(STATUS \"$${_TOOLBOX_OUTPUT}\") endif() ") endif() ``` -------------------------------- ### MATLAB: Get Identifier Information for 'phi' Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/identifiers.rst This MATLAB code snippet demonstrates how to obtain information about a specific identifier, 'phi', using the IMAS identifiers library. It's useful for understanding the properties and values associated with different identifiers within the IMAS data dictionary. ```matlab %% Matlab example 1: obtain identifier information of coordinate identifier ``phi`` % Load the identifiers library ids = imas_identifiers(); % Get information for the 'phi' identifier phi_info = ids.get_identifier('phi'); % Display the information (e.g., name, description, index) disp(phi_info); ``` -------------------------------- ### Print Access Layer Version in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/using_al.rst This MATLAB script loads the Access Layer interface and prints the version information for the access layer, HLI, and data dictionary. It requires the Access Layer to be installed and accessible in the MATLAB environment. ```matlab import sys import os # Add the Access Layer to the Python path sys.path.append(os.path.abspath('../../../src')) from access_layer.access_layer import AccessLayer # Initialize the Access Layer al = AccessLayer() # Print version information print("Hello world!") print("Access Layer version info:") print(f"\t al_version: '{al.get_al_version()}'") print(f"\t hli_version: '{al.get_hli_version()}'") print(f"\t dd_version: '{al.get_dd_version()}'") print(f"\t hli_version_array: {al.get_hli_version_array()}") print(f"\t dd_version_array: {al.get_dd_version_array()}") ``` -------------------------------- ### Configure IMAS-MATLAB with HTTPS Preset Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/building_installing.rst Configures the IMAS-MATLAB project using CMake with the 'https' preset, which is available in CMake 3.21 and newer. This preset is designed to download dependent repositories over HTTPS. ```text cmake -B build --preset=https ``` -------------------------------- ### MATLAB: Fill 'NBI' Label in 'core_sources' IDS Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/identifiers.rst This MATLAB example shows how to use the IMAS identifiers library to set the 'NBI' (Neutral Beam Injection) label within the 'core_sources' identifier set (IDS). This is crucial for correctly populating source information in IMAS data. ```matlab %% Matlab example 2: Use the identifier library to fill the ``NBI`` label in the ``core_sources`` IDS % Load the identifiers library ids = imas_identifiers(); % Access the core_sources identifiers core_sources_ids = ids.get_identifier_set('core_sources'); % Set the NBI label (assuming NBI has a specific index or value) % Replace 'nbi_value' with the actual value or index for NBI core_sources_ids.set_label('NBI', nbi_value); % You can then use this updated identifier set to populate your data % For example, when creating or updating an IMAS structure. ``` -------------------------------- ### Copy Runtime Dependencies to Toolbox (Windows) Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt On Windows systems, this code snippet copies all DLL files from the installation's bin directory to the toolbox directory. This ensures that MEX files have their required runtime libraries available. ```cmake if(WIN32) # On Windows, install runtime DLLs that MEX files depend on install(CODE " file(GLOB AL_RUNTIME_LIBS \"${CMAKE_INSTALL_PREFIX}/bin/*.dll\" ) foreach(lib IN LISTS AL_RUNTIME_LIBS) file(COPY \"${lib}\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/toolbox\") endforeach() message(STATUS \"Copied runtime libraries to toolbox folder\") ") else() # On Linux, install shared libraries that MEX files depend on install(CODE " file(GLOB AL_RUNTIME_LIBS \"${CMAKE_INSTALL_PREFIX}/lib/*.so*\" ) foreach(lib IN LISTS AL_RUNTIME_LIBS) file(COPY \"${lib}\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/toolbox\") endforeach() message(STATUS \"Copied runtime libraries to toolbox folder\") ") endif() ``` -------------------------------- ### Configure MATLAB MEX Tests with HDF5 Backend (CMake) Source: https://github.com/iterorganization/imas-matlab/blob/develop/examples/CMakeLists.txt This snippet configures and adds tests for MATLAB MEX examples that require the HDF5 backend. It iterates through a list of MATLAB files, creates test targets, and conditionally disables them if the HDF5 backend is not found. It also handles test properties, including plugin support. ```cmake # Examples that use HDF5 backend set( M_FILES_HDF5 test_get_sample_magnetics ) # Add tests for HDF5 examples foreach( M_FILE ${M_FILES_HDF5} ) add_test( NAME example-mex-${M_FILE} COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -batch "addpath ${LIB_FOLDER} ${M_FOLDER}; ${M_FILE}; exit()" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set( DISABLED OFF ) if( NOT AL_BACKEND_HDF5 ) set( DISABLED ON ) message(STATUS "Disabling example ${M_FILE}: requires HDF5 backend") endif() set_al_example_properties( example-mex-${M_FILE} ${DISABLED} OFF "ids_path=${MDSPLUS_MODEL_DIR}" ) if( AL_PLUGINS ) add_test( NAME example-mex-${M_FILE}-with-plugins COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -batch "addpath ${LIB_FOLDER} ${M_FOLDER}; ${M_FILE}; exit()" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_al_example_properties( example-mex-${M_FILE}-with-plugins ${DISABLED} ON "ids_path=${MDSPLUS_MODEL_DIR}" ) endif() endforeach() ``` -------------------------------- ### Get IDS Sample in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/use_ids.rst Demonstrates how to retrieve a sample data point from an IDS object in MATLAB using the `ids_get_sample` function. This function is useful for inspecting data or for use in algorithms that require individual data points. The specific sample retrieved may depend on the function's internal logic. ```matlab sample_data = ids_get_sample(ids_object, index); ``` -------------------------------- ### MATLAB: Fill Coordinate System Type in 'equilibrium' IDS Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/identifiers.rst This MATLAB code snippet illustrates how to utilize the IMAS identifiers library to specify the type of coordinate system used within the 'equilibrium' IDS. This ensures consistency and correctness when defining the geometry of the plasma. ```matlab %% Matlab example 3: Use the identifier library to fill the type of coordinate system used in the ``equilibrium`` IDS % Load the identifiers library ids = imas_identifiers(); % Access the equilibrium identifiers equilibrium_ids = ids.get_identifier_set('equilibrium'); % Set the coordinate system type (e.g., 'cartesian', 'toroidal') % Replace 'coordinate_system_type' with the desired type string or its identifier value equilibrium_ids.set_label('coordinate_system_type', coordinate_system_type); % This updated identifier set can then be used when working with equilibrium data. ``` -------------------------------- ### Configure MATLAB MEX Tests with MDSplus Backend (CMake) Source: https://github.com/iterorganization/imas-matlab/blob/develop/examples/CMakeLists.txt This snippet configures and adds tests for MATLAB MEX examples that require the MDSplus backend. It iterates through a list of MATLAB files, creates test targets, and conditionally disables them if the MDSplus backend is not found. It also handles test properties, including plugin support. ```cmake project( mexinterface-ex ) find_package( Matlab COMPONENTS MAIN_PROGRAM ) include( ALExampleUtilities ) get_target_property( LIB_FOLDER al-mex BINARY_DIR ) get_target_property( M_FOLDER al-mex SOURCE_DIR ) set( M_FOLDER ${M_FOLDER}/matlab ) if( AL_BACKEND_MDSPLUS ) get_target_property( MDSPLUS_MODEL_DIR al-mdsplus-model BINARY_DIR ) endif() # Examples that use MDSplus backend set( M_FILES_MDSPLUS test_amns_data_validate test_distributions_validate test_get test_isdefined test_put test_serialize test_waves_validate ) # Add tests for MDSplus examples foreach( M_FILE ${M_FILES_MDSPLUS} ) add_test( NAME example-mex-${M_FILE} COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -batch "addpath ${LIB_FOLDER} ${M_FOLDER}; ${M_FILE}; exit()" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set( DISABLED OFF ) if( NOT AL_BACKEND_MDSPLUS ) set( DISABLED ON ) message(STATUS "Disabling example ${M_FILE}: requires MDSplus backend") endif() set_al_example_properties( example-mex-${M_FILE} ${DISABLED} OFF "ids_path=${MDSPLUS_MODEL_DIR}" ) if( AL_PLUGINS ) add_test( NAME example-mex-${M_FILE}-with-plugins COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -batch "addpath ${LIB_FOLDER} ${M_FOLDER}; ${M_FILE}; exit()" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) set_al_example_properties( example-mex-${M_FILE}-with-plugins ${DISABLED} ON "ids_path=${MDSPLUS_MODEL_DIR}" ) endif() endforeach() ``` -------------------------------- ### Close Database Entry (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Closes the database entry associated with the given context handle, releasing resources and ensuring data integrity. ```matlab imas_close(ctx); ``` -------------------------------- ### Modify and Store Data (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Initializes a new IDS or modifies an existing one by setting its properties, such as time and data values. The modified IDS is then stored back to the database. ```matlab % Create a new IDS or modify existing one equilibrium = ids_init('equilibrium'); equilibrium.time = [0, 1, 2, 3]; equilibrium.q_profile.value.data = [1, 2, 3, 4]; % Store it to the database ids_put(ctx, 'equilibrium', equilibrium); ``` -------------------------------- ### Build Documentation with Make (Bash) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/dev_guide.rst This command uses Make to build the documentation after CMake has been configured. The -C build flag specifies that the make command should be run from the 'build' directory. This process generates the project's documentation files. ```bash make -C build al-matlab-docs ``` -------------------------------- ### Check Data Existence (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Checks if a specific data element within an IDS is defined using the `ids_isdefined` function. This is useful for preventing errors when accessing potentially non-existent data. ```matlab if ids_isdefined(magnetics.flux_loop{1}.flux) disp('Flux data is defined'); end ``` -------------------------------- ### Load Specific Time Slice (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/getting_started.rst Loads a specific time slice of an IDS from the database using the provided context handle and time value. It supports different interpolation methods, such as 'CLOSEST'. ```matlab % Use CLOSEST interpolation data = ids_get_slice(ctx, 'equilibrium', 2.5, 'CLOSEST'); ``` -------------------------------- ### GitHub Actions Workflow Configuration (YAML) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/dev_guide.rst This YAML snippet represents a GitHub Actions workflow file. It defines the triggers, platforms, build steps, and artifact checks for the CI/CD pipeline of the IMAS-MATLAB repository. It automates building and testing on various branches and pull requests. ```yaml .github/workflows/build-and-test.yml ``` -------------------------------- ### Create DBEntry with Explicit Path in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/001_3_open_URI_path.rst This MATLAB code demonstrates how to create a DBEntry by providing an explicit path within the AL5 URI. It assumes necessary database connection libraries are available. ```matlab % This example focuses on opening DBEntry using explicit path ``` -------------------------------- ### Configure CMake for Documentation Build (Bash) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/dev_guide.rst This command configures the CMake build system to only generate documentation. It sets the AL_HLI_DOCS and AL_DOCS_ONLY flags. This is typically run from the project's root directory. ```bash cmake -B build -D AL_HLI_DOCS -D AL_DOCS_ONLY ``` -------------------------------- ### Create Database Entry (Legacy) in MATLAB Source: https://context7.com/iterorganization/imas-matlab/llms.txt Creates a new database entry using legacy environment parameters with the `imas_create_env` function. This method is deprecated in favor of URI-based access with `imas_open`. It sets up the database entry with pulse/run numbering. ```matlab % Legacy method to create database entry user = getenv('USER'); db_name = 'test'; pulse = 1; run = 10; refpulse = 0; % not used refrun = 0; % not used dd_major_version = '3'; ctx = imas_create_env(db_name, pulse, run, refpulse, refrun, ... user, db_name, dd_major_version); % Work with data... equilibrium = ids_init('equilibrium'); equilibrium.ids_properties.homogeneous_time = 1; ids_put(ctx, 'equilibrium', equilibrium); imas_close(ctx); ``` -------------------------------- ### CMake: Download and Configure AL-core Dependency Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt This CMake code handles the downloading and configuration of the AL-core library. It supports fetching from a Git repository using FetchContent or manually cloning if FetchContent is not suitable (e.g., with vcpkg). It also handles checking out a specific version or using a local development layout. ```cmake if(WIN32) if( ${AL_DOWNLOAD_DEPENDENCIES} ) # FetchContent_Declare causing reursive call wrapped by vcpkg to _find_package # So manually clone al-core here. Need fix in later release set( al-core_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/al-core-src" ) if( NOT EXISTS "${al-core_SOURCE_DIR}/.git" ) message( STATUS "Cloning al-core from ${AL_CORE_GIT_REPOSITORY}" ) execute_process( COMMAND git clone "${AL_CORE_GIT_REPOSITORY}" "${al-core_SOURCE_DIR}" RESULT_VARIABLE _GIT_CLONE_RESULT ERROR_VARIABLE _GIT_CLONE_ERROR ) if( _GIT_CLONE_RESULT ) message( FATAL_ERROR "Failed to clone al-core: ${_GIT_CLONE_ERROR}" ) endif() endif() # Checkout the specified version execute_process( COMMAND git fetch origin WORKING_DIRECTORY "${al-core_SOURCE_DIR}" RESULT_VARIABLE _GIT_FETCH_RESULT ) execute_process( COMMAND git checkout "${AL_CORE_VERSION}" WORKING_DIRECTORY "${al-core_SOURCE_DIR}" RESULT_VARIABLE _GIT_CHECKOUT_RESULT ERROR_VARIABLE _GIT_CHECKOUT_ERROR ) if( _GIT_CHECKOUT_RESULT ) message( FATAL_ERROR "Failed to checkout ${AL_CORE_VERSION}: ${_GIT_CHECKOUT_ERROR}" ) endif() elseif ( ${AL_DEVELOPMENT_LAYOUT} ) set( al-core_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../al-core" ) endif() else() if( ${AL_DOWNLOAD_DEPENDENCIES} ) # Download common assets from the ITER git: FetchContent_Declare( al-core GIT_REPOSITORY "${AL_CORE_GIT_REPOSITORY}" GIT_TAG "${AL_CORE_VERSION}" ) FetchContent_MakeAvailable( al-core ) elseif ( ${AL_DEVELOPMENT_LAYOUT} ) FetchContent_Declare( al-core SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../al-core" ) FetchContent_MakeAvailable( al-core ) endif() endif() ``` -------------------------------- ### Configure MATLAB Unit Tests with HDF5 Backend and Preload Source: https://github.com/iterorganization/imas-matlab/blob/develop/tests/CMakeLists.txt Extends the MATLAB unit test configuration to include the HDF5 backend. It finds the HDF5 library, prepares it for `LD_PRELOAD` to avoid conflicts, and appends it to the MATLAB environment variables. ```cmake if( AL_BACKEND_HDF5 ) # The HDF5 library built-in with matlab may conflict with the one that the AL # was built against. Preload the AL-linked library: find_package( HDF5 COMPONENTS C HL REQUIRED ) # LD_PRELOAD expects a space-separated list: string( REPLACE ";" " " PRELOAD_LIBS "${HDF5_HL_LIBRARIES}" ) list( APPEND MATLAB_ENV "LD_PRELOAD=${PRELOAD_LIBS}" ) endif() ``` -------------------------------- ### IMAS Versioning API Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/api_dbentry.rst This section provides information on how to retrieve version constants for the IMAS system. ```APIDOC ## IMAS Versioning API ### Description Provides functions to get IMAS version information. ### Functions #### `imas_versions()` ##### Description Returns the available IMAS version constants. ##### Method `imas_versions()` ##### Parameters None ##### Response - **versions** (struct) - A structure containing IMAS version information. ``` -------------------------------- ### Full IDS Read/Write Cycle Workflow (MATLAB) Source: https://context7.com/iterorganization/imas-matlab/llms.txt Demonstrates a complete workflow for creating, populating, storing, and retrieving IDS data using the IMAS MATLAB API. This includes opening connections, initializing IDS, setting time-dependent data, validating, putting data into the database, and reading it back with verification and slicing. ```matlab %% Complete workflow: Create, populate, store, and retrieve IDS data % Setup - Create database mode_write = 43; % FORCE_CREATE_PULSE ctx = imas_open('imas:hdf5?path=./fusion_data', mode_write); % Create equilibrium IDS equilibrium = ids_init('equilibrium'); equilibrium.ids_properties.homogeneous_time = 1; equilibrium.ids_properties.comment = 'Example equilibrium from simulation'; equilibrium.ids_properties.provider = 'MATLAB tutorial'; % Set time-dependent data equilibrium.time = [0.0, 0.5, 1.0, 1.5, 2.0]; equilibrium.vacuum_toroidal_field.b0 = [5.0, 5.1, 5.2, 5.1, 5.0]; equilibrium.vacuum_toroidal_field.r0 = 6.2; % Validate before storing ids_validate('equilibrium', equilibrium); % Store to database ids_put(ctx, 'equilibrium', equilibrium); fprintf('Equilibrium stored successfully\n'); imas_close(ctx); %% Read back and verify mode_read = 40; % OPEN_PULSE ctx = imas_open('imas:hdf5?path=./fusion_data', mode_read); % Check if data exists eq_loaded = ids_get(ctx, 'equilibrium'); if ids_isdefined(eq_loaded) fprintf('Loaded equilibrium:\n'); fprintf(' Comment: %s\n', eq_loaded.ids_properties.comment); fprintf(' Time points: %d\n', length(eq_loaded.time)); fprintf(' B0 range: [%.2f, %.2f]\n', min(eq_loaded.vacuum_toroidal_field.b0), ... max(eq_loaded.vacuum_toroidal_field.b0)); % Get interpolated slice at t=0.75 eq_slice = ids_get_slice(ctx, 'equilibrium', 0.75, 3); % INTERPOLATION fprintf(' B0 at t=0.75 (interpolated): %.3f\n', ... eq_slice.vacuum_toroidal_field.b0); end imas_close(ctx); ``` -------------------------------- ### Get IMAS Library Version in MATLAB Source: https://context7.com/iterorganization/imas-matlab/llms.txt Retrieves version information about the IMAS library using the `imas_versions` function. The returned information includes the data dictionary version, access layer version, and language binding version. ```matlab % Get library version information versions = imas_versions(); disp(versions); ``` -------------------------------- ### Configure MATLAB Unit Tests with Plugins Source: https://github.com/iterorganization/imas-matlab/blob/develop/tests/CMakeLists.txt Adds configuration for running MATLAB unit tests with plugins enabled. This involves defining a separate test ('al-partial-get-test') and setting specific environment variables related to plugin paths and activation. ```cmake if( AL_PLUGINS ) add_test( NAME al-partial-get-test COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -batch "addpath ${LIB_FOLDER} ${M_FOLDER}; res = runtests('imas_partial_get_tests');exit(~all([res.Passed]))" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) get_target_property( PLUGIN_DIR al-plugins BINARY_DIR ) set( ENVIRONMENT_WITH_PLUGINS ${MATLAB_ENV} "IMAS_AL_ENABLE_PLUGINS=TRUE" "IMAS_AL_PLUGINS=${PLUGIN_DIR}" ) set_tests_properties( al-partial-get-test PROPERTIES TIMEOUT 3600 ENVIRONMENT "${ENVIRONMENT_WITH_PLUGINS}" ) endif() ``` -------------------------------- ### Access Child Node of an IDS Structure in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/use_ids.rst Provides an example of how to access a child node within a Structure node of an Interface Data Structure (IDS) in MATLAB. Structure nodes act as containers for other nodes. ```matlab child_node = ids.structure_node.child_attribute; ``` -------------------------------- ### Initialize IDS in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/use_ids.rst Demonstrates how to initialize an IDS object in MATLAB using the `ids_init` function. This is the first step to creating and manipulating IDS data structures within the MATLAB environment. The function takes a string argument specifying the type of core profiles to initialize. ```matlab ids_init('core_profiles'); ``` -------------------------------- ### Get Data from an IDS Data Node in MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/use_ids.rst Illustrates how to retrieve data from a Data node within an Interface Data Structure (IDS) in MATLAB. Data nodes contain the actual numerical or textual information. ```matlab data = ids.data_node.data; ``` -------------------------------- ### Create DBEntry (Legacy Mode) - MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/001_1_create_db_entry_legacy.rst This snippet shows how to create a DBEntry using the legacy mode in IMAS MATLAB. It utilizes functions like imas_create_env and imas_open_env. Note that this legacy method is deprecated from AL>=5.0.0 and the URI approach is recommended. ```matlab % This example focuses on creating DBEntry using legacy mode method ctx = imas_create_env('legacy'); % Open the IMAS database % The database name and path are example values and should be replaced with actual values. % For more details, refer to the IMAS API documentation. data = imas_open_env(ctx, 'example_db', '/path/to/your/imas/database'); % You can now access and modify the data within the 'data' structure. % For example, to set a variable: % data.profile.x = 1.0; % data.profile.y = 2.0; % Save the changes to the database % imas_close(ctx); ``` -------------------------------- ### Create MATLAB Toolbox Package Target Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt Defines a custom CMake target named `matlab-toolbox` that, when executed, calls the MATLAB executable with the `create_matlab_toolbox` script. This allows users to manually build the MATLAB toolbox package after installation. ```cmake add_custom_target( matlab-toolbox COMMAND ${CMAKE_COMMAND} -E echo "NOTE: Ensure 'cmake --install' has been run before creating the toolbox package" COMMAND ${CMAKE_COMMAND} -E echo "Looking for toolbox in: ${CMAKE_INSTALL_PREFIX}/toolbox" COMMAND "${MATLAB_EXECUTABLE}" -batch "create_matlab_toolbox('${CMAKE_INSTALL_PREFIX}', '${CMAKE_BINARY_DIR}', '${PROJECT_VERSION}', '${DD_VERSION}')" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Creating MATLAB toolbox package: IMAS-MATLAB/${PROJECT_VERSION}-DD-${DD_VERSION}" VERBATIM ) ``` -------------------------------- ### Read IDS Slices from Entry using MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/004_2_read_slice.rst This MATLAB code snippet illustrates how to read IDS slices from an entry. It utilizes the `ids_get_slice` function, which is part of the IMAS library. Ensure the IMAS library is correctly installed and configured for this function to work. ```matlab % This example focuses on reading IDS slices from entry ``` -------------------------------- ### Get Time Slice from IMAS Database Entry (|lang|) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/doc_common/load_store_ids.rst Retrieves a specific time slice from an IMAS Database Entry. Handles edge cases for time ranges outside the stored data. Assumes time arrays are stored in increasing order. ```matlab from imas.codetools import dbentry_getslice # Example usage: # entry = dbentry_getslice(uri, time) # print(entry) ``` -------------------------------- ### Put IDS into Non-default Occurrence using MATLAB Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/003_3_put_into_non_default_occurrence.rst This MATLAB script illustrates the process of inserting Interface Data Structures (IDS) into a specified, non-default occurrence. It utilizes functions from the IMAS library to manage data entries and occurrences. Ensure the IMAS library is correctly installed and accessible. ```matlab % This example focuses on putting IDS into another occurrence % (Code content would be here if provided in the literalinclude) ``` -------------------------------- ### CMake: Project Definition and Versioning Source: https://github.com/iterorganization/imas-matlab/blob/develop/CMakeLists.txt This CMake snippet defines the main project 'al-matlab', setting its version, description, homepage URL, and supported languages (C and CXX). It also includes logic to determine the project version from Git tags and messages if a development version is being built. ```cmake # Set VERSION and FULL_VERSION from `git describe`: set( GIT_ARCHIVE_DESCRIBE [[$Format:%(describe)$]] ) include( ALDetermineVersion ) project( al-matlab VERSION ${VERSION} DESCRIPTION "MATLAB High Level Interface of the IMAS Access Layer" HOMEPAGE_URL "https://imas.iter.org/" LANGUAGES C CXX ) if( NOT PROJECT_VERSION_TWEAK EQUAL 0 ) message( "Building a development version of the Access Layer Matlab HLI" ) endif() ``` -------------------------------- ### Put Entire IDS into Entry (MATLAB) Source: https://github.com/iterorganization/imas-matlab/blob/develop/doc/examples/003_1_put_entire_ids.rst This MATLAB code snippet demonstrates how to insert entire IDS into an entry and pass IDS validation. It utilizes the `ids_put` function, which is part of the IMAS MATLAB API. Ensure you have the necessary IMAS environment set up to run this code. ```matlab % This example focuses on putting IDS into entry and passing IDS validation % █══════════════════════════════════════════════════════════════════════════════█ ```