Advanced Octave A18 — Output files and managed publishing

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

Advanced GNU Octave with GX-TXT · Module 03

In addition to numerical series, an analysis can produce a short textual report. A temporary file created by the script becomes a persistent resource of the Session only through the appropriate publication service.

Objectives and prerequisites

After the introductory course and previous lectures on publishing, we use gxtxt_context().output_dir and DATASET_FILE_PUBLICATION_API_v1 to publish a full file. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.

The report describes a synthetic model and does not contain measures. The octave_advanced_report ID is created-only: it uses a teaching session where it is free or changes the ID for a repetition.

Create and close the file

Import pubblica_rapporto.m, register it and run it in the Runner.

The program gets the Job output directory from context and creates the file using Octave functions:

ctx = gxtxt_context();
path = fullfile(ctx.output_dir, 'synthetic_report.txt');
fid = fopen(path, 'w');
assert(fid >= 0, 'Cannot open the output report.');
fprintf(fid, 'Synthetic study: no laboratory measurements.\n');
fprintf(fid, 'Model: voltage = 1 + 0.2 * time; time in s, voltage in V.\n');
assert(fclose(fid) == 0, 'Cannot close the output report.');

The closing completes the file before the publication. The output directory belongs to the execution: a temporary path, alone, is not the persistent identity of the result.

Publish the document

The request declares a Dataset ID, the document.text contract, txt format, type of storage and media type. The source file is the one just completed in the Job output:

req = struct('dataset_id','octave_advanced_report','contract','document.text', ...
             'format','txt','source_file',path,'storage_kind','text', ...
             'media_type','text/plain');
receipt = gxtxt_api_call('DATASET_FILE_PUBLICATION_API_v1','publish',{req});
disp(receipt);

The actual receipt contains ID, contract, format, type of support and SHA-256 footprint calculated by the service. The footprint identifies the published content: it does not guarantee that the statements of the report are scientifically correct.

The publication through the Bridge requires a complete file in the output directory managed by the framework; no arbitrary paths are passed to directly modify the session storage. The service manages the registration of the result according to the contract and ownership policies.

Exercise

  1. Why does the script close the file before you publish it?
  2. What is the difference between path and dataset_id?
  3. Does a receipt with SHA-256 verify that the scientific model is valid?

Worked solution

  1. To deliver a full file to the service.
  2. The first identifies the temporary file produced by the Job; the second identifies the resource published in the Session.
  3. No. The footprint concerns the content; validity and interpretation require separate controls.

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 *