Handling AoS & Default ValuesΒΆ

This example focuses on handling arrays of structures and default values.

See also

API documentation for ids_allocate()

    % create empty edge_profiles
    edge_profiles = ids_init('edge_profiles');

    % set mandatory field
    edge_profiles.ids_properties.homogeneous_time = 1;

    % edge_profiles/grid_ggd is array of structures and must be resized before accessing any of it's elements
    edge_profiles.grid_ggd = ids_allocate('edge_profiles', 'grid_ggd', 1);
    edge_profiles.grid_ggd{1}.identifier.name = 'First test struct';

    % single element can be added to AoS the following way
    % in this example we will create copy of edge_profiles.grid_ggd{1} and modify it's values
    aos_element = edge_profiles.grid_ggd{1};
    aos_element.identifier.name = 'Second test struct';

    % append aos_element to edge_profiles.grid_ggd AoS
    edge_profiles.grid_ggd{2} = aos_element;

    % common action would be merging two different AoS
    % edge_profiles2/grid_ggd will be merged with edge_profiles/grid_ggd
    % first, we have to create new AoS and fill it with data
    edge_profiles2 = ids_init('edge_profiles');
    edge_profiles2.grid_ggd = ids_allocate('edge_profiles', 'grid_ggd', 1);
    edge_profiles2.grid_ggd{1}.identifier.name = 'Third test struct';

    % once data are in place, we can merge two AoS objects
    for idx = length(edge_profiles2.grid_ggd)
        next_position = length(edge_profiles.grid_ggd) +1;
        edge_profiles.grid_ggd{next_position} = edge_profiles2.grid_ggd{idx};
    end

    fprintf('edge_profiles/grid_ggd after merge:\n');
    for struct_to_display = edge_profiles.grid_ggd
       fprintf('\tstruct_to_display{1}.identifier.name: %s\n', struct_to_display{1}.identifier.name);
    end
    fprintf('\n');

    % ids fields have default values different for every data type
    fprintf('Default value for "INT"          %i (edge_profiles/midplane/index) \n', edge_profiles.midplane.index);
    fprintf('Default value for "FLOAT"        %s (edge_profiles/vacuum_toroidal_field/vacuum_toroidal_field/r0) \n', edge_profiles.vacuum_toroidal_field.r0);
    fprintf('Default value for 1+ dimensional [%s]  (Empty array)\n', edge_profiles.vacuum_toroidal_field.b0);
    fprintf('\n');

    % IDSs can be printed using fprintf() method.
    fprintf('edge_profiles.ids_properties.homogeneous_time: %i\n', edge_profiles.ids_properties.homogeneous_time);
    fprintf('\tedge_profiles.grid_ggd{1}.identifier.name:     %s\n', edge_profiles.grid_ggd{1}.identifier.name);
    fprintf('\tedge_profiles.grid_ggd{2}.identifier.name:     %s\n', edge_profiles.grid_ggd{2}.identifier.name);
    fprintf('\tedge_profiles.grid_ggd{3}.identifier.name:     %s\n', edge_profiles.grid_ggd{3}.identifier.name);
    fprintf('\n');

    clear edge_profiles;
    clear edge_profiles2;