Advanced Octave A13 — Controlled incremental publishing

by Giux GX-TXT, octave-en, scripts-en 2 min read

Advanced GNU Octave with GX-TXT · Module 03

When a series is produced progressively, it is not always necessary to accumulate it all before publishing it. A writer managed by GX-TXT allows to declare the structure and add blocks, completing the publication only at the end.

Objectives and prerequisites

After the introductory course and Dataset lessons, we deepen the begin cycle, statement, append, finalize and abort DATASET_PUBLICATION_API_v2. The example generates a synthetic series segnale = 1 + 0,2 tempo V, with time from 0 to 10 s; they are not measures. Test performed with GX-TXT dev112-P011-bis and GNU Octave 9.4.0.

Import pubblica_blocchi.m, register it and run it in the Runner at a teaching session. The Dataset octave_advanced_chunks is created with a fixed ID: to repeat the script, use a new Session or choose a free ID consistently in the code. Do not overwrite an existing result.

Open, declare, add

The writer is a matte reference managed by the framework. The definition requires a table.generic Dataset with HDF5 storage; the program declares a sample dimension initially empty and extendable and two numerical variables, time and signal, with units and roles.

The central cycle adds three blocks:

for start = 0:4:8
  x = (start:min(start+3,10))';
  y = 1 + 0.2*x;
  chunk = struct('time_s',x,'signal_v',y);
  gxtxt_api_call('DATASET_PUBLICATION_API_v2', 'append', {w,'sample',chunk});
  fprintf('Appended rows: %d\n', numel(x));
endfor
gxtxt_api_call('DATASET_PUBLICATION_API_v2', 'finalize', {w});

The blocks contain 4, 4 and 3 rows respectively. Each chunk associates variable names to block vectors: time and signal must remain aligned. The last block is shorter because the range ends at 10.

Close and check

finalize concludes the publication. If an operation in the try block fails, the example calls abort and raises the error, instead of presenting an incomplete Dataset as concluded. Once finalized, the writer should not be finalized a second time. The program then reads the 11 rows using the canonical API.

In the test, 11 lines were published and the last signal is 3,00 V. It is a control over the result obtained, not an experimental measure. The HDF5 choice supports the required incremental writing; other providers can have different capabilities and must be verified before use.

Exercise

  1. Why is the initial size sample declared extensible?
  2. What happens in the program if adding a block fails?
  3. What would you control besides the number of rows to validate a real production?

Worked solution

  1. Because it has to grow as the blocks are added.
  2. The code attempts to interrupt the writer with abort and raises the error.
  3. Identity and order of variables, values, units, origin and consistency between the series, as well as the provider’s limit cases.

Download the Module 03 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *