Put Multiple SlicesΒΆ

This example focuses on putting multiple slices of IDS into entry.

See also

API documentation for:
    ctx = imas_open('imas:mdsplus?path=./testdb_mdsplus', mode);

    summary = ids_init('summary');

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

    summary.heating_current_drive.nbi = ids_allocate('summary', 'heating_current_drive/nbi', 1);

    for x = 1:5
        % NOTE: time-independent data is being put only if it is empty in entry
        % In this case summary/stationary_phase_flag/source will be put only at first iteration.
        % Suggested way to fill this type of fields is to do this outside loop
        summary.stationary_phase_flag.source = strcat('Name saved by example code iteration: ', num2str(x));
 
        % Fill example data
        summary.stationary_phase_flag.value = [10.0 .* x];

        % Fill 2D data
        summary.heating_current_drive.nbi{1}.beam_current_fraction.value = [ x*100, x*100, x*100 ]'; 

        % NOTE: it is user's responsibility to organize <ids>/time field in ascending manner
        % breaking this rule will make get_slice() command to fail
        % slice time is being appended to <ids>/time stored in entry
        summary.time = double(x);
        ids_put_slice(ctx, 'summary', summary);
    end

    % multiple slices can be put into entry as well
    summary.stationary_phase_flag.value = [11.0, 12.0, 13.0];
    summary.heating_current_drive.nbi{1}.beam_current_fraction.value = [[1000.0, 2000.0, 3000.0]; [1000.0, 2000.0, 3000.0]; [1000.0, 2000.0, 3000.0]]; 
    summary.time = [50.0, 60.0, 70.0];

    ids_validate('summary', summary);
    ids_put_slice(ctx, 'summary', summary);
    clear summary;

    % IDSs can be printed using fprintf() and disp() methods.
    fprintf('Dumping summary from fprintf() and disp() functions\n');
    summary_check = ids_get(ctx, 'summary');
    fprintf('\tsummary.ids_properties.homogeneous_time: %i\n', summary_check.ids_properties.homogeneous_time);
    fprintf('\tsummary.time: \n');
    disp(summary_check.time');
    fprintf('\tsummary.stationary_phase_flag.value:     %s\n');
    disp(summary_check.stationary_phase_flag.value');
    fprintf('\tsummary.stationary_phase_flag.source:    %s\n', summary_check.stationary_phase_flag.source);
    fprintf('\tsummary.heating_current_drive.nbi{0}.beam_current_fraction.value: \n'); 
    disp(summary_check.heating_current_drive.nbi{1}.beam_current_fraction.value); 
    fprintf('\n');
    clear summary_check;

    imas_close(ctx);