File conventions

From OPS
Jump to: navigation, search

All CReSIS Toolbox Development Guides

This page describes the conventions for writing to output files.

Contents

Directory

Check for the existence of the output directory and create if it does not exist. Example:

fn_dir = fileparts(fn);
if ~exist(fn_dir,'dir')
  mkdir(fn_dir);
end

Filenames

Please follow the conventions described in the following three sections:

Negative numbers and decimals

Use "-" and "+" in front of the number if it is signed.

Use "p" for the radix point.

Generally fix the number of significant figures so if a number's range of possible values requires a maximum of N digits to represent where N >= 0, then N decimals should always be used and zeros should be used to pad.

For example:

  • an unsigned number 34.5 with a maximum of 3 digits including 1 decimal would be: "_34p5_".
  • a signed number 34.5 with a maximum of 3 digits including 1 decimal would be: "_+34p5_".
  • a signed number 34.5 with a maximum of 5 digits including 2 decimals would be: "_+034p50_".
  • an unsigned integer 34 with a maximum of 4 digits would be: "_0034_".
  • a signed integer 34 with a maximum of 4 digits would be: "_+0034_".
  • a signed integer -34 with a maximum of 4 digits would be: "_-0034_".

Figures

Generally, figures that are saved should follow the conventions at: Debug Plots.

fopen

The following error checking should always be done when a file is opened for writing. The "b" option should always be specified, even for text files.

[fid,msg] = fopen(txt_fn,'wb');
if fid < 0
  error('Could not open file:\n  %s\nError message: %s.', txt_fn, msg);
end
fclose(fid);

Saving files (fopen, save, saveas, ct_save, ct_saveas)

When saving a file (assuming output filename is out_fn), always print out the filename to stdout before calling the appropriate save function (e.g. fopen, ct_save, ct_saveas, save, saveas), in this form:

fprintf('Save %s (%s)\n', out_fn, datestr(now));

mat files

Use the "ct_save" command to save mat files instead of "save". This checks for sufficient disk space before starting the save operation and also always saves in v7.3 (HFD5) format.

Mat files that contain results that are dependent on the standard param structure, should always save the relevant param structures. For example:

out.(['param_' mfilename]) = param;
ct_save(fn,'-struct','out');

If the function is dependent on the records file or other previous operations that stored the param structure, then those param structures should be stored in the file as well. For example:

out.param_records = records.param_records;
ct_save(fn,'-struct','out');
Personal tools
Namespaces

Variants
Actions
Navigation
Tools