sampsapursiainen / zeffiro_interface

Interface for using finite elements in inverse problems with complex domains
GNU General Public License v3.0
24 stars 15 forks source link

zeffiro_interface: add argument validation with name–value arguments #152

Closed SeSodesa closed 1 year ago

SeSodesa commented 1 year ago

The main function now utilizes Matlab's built-in name–value argument parsing mechanism. This changes how arguments are to be passed to the functions, and the actions are always performed in a certain order, which cannot be modified by the user.

This is a squashed version of the branch

141-simplify-main-function-zeffiro_interface-argument-parsin

and closes #141. Individual commit messages are below.


zeffiro_interface: added a few TODO notes

Removed varargin and started adding actions based on input name–value arguments

Added handling of open_project and import_segmentation

Rewrote more actions from the old code to conform to the new key–value argument syntax

Also changed character arrays to strings.

Added comments and moved GPU initialization earlier in the routine

zeffiro_interface: improved documentation comment

zeffiro_interface: added line breaks and changed more character arrays into strings

Added a note about eval and arbitrary code execution, and simplified how input script is run

Move existing zef detection to function start

Moved calls to zef_{start,load} to a new position

zeffiro_interface: do not unnecessarily save irrelevant function inputs into zef

Change char arrays to proper strings in different files

Now the program starts again. The problem was with the function zeffiro_interface now using strings instead of char arrays in the paths it sets, which were then propagated to different initialization functions and scripts that expected char arrays.

zeffiro_interface: remove old commented implementation

zeffiro_interface: more ' → "

We use proper strings, not char arrays.

zeffiro_interface: importing → import in comment

zeffiro_interface: add one more note about the dangers of eval

zeffiro_interface: run_script validated as a string array and handled accoringly

zef_start_new_project: call zeffiro_interface with restart=true

zef_remove_system_fields: change a char array into a string

… for compatibility with the modified zeffiro_interface.

zeffiro_interface: if args.restart, then close all before reloading

zef_load: load profile name as string instead of char array

Again, for compatibility reasons with modified zeffiro_interface.

zef_{load,save,…}: change char arrays to strings and use + to construct strings from parts

zeffiro_interface: make sure program_path is a string and unconditionally close existing windows, if zef does not exist

zeffiro_interface: replace one more char array catenation with string addition

zeffiro_interface: change how args.run_script is executed

No longer assumed to consist of multiple file paths, but the string is interpreted as the script itself and evaluated as-is.

NOTE: This is still a security hole, by the way. Using eval like this is unsafe.

zef_start_log: remove leftover ]

zeffiro_interface: add missing "args." prefix

Make sure file names are strings and not character arrays in a few places related to opening a project

zeffiro_interface: add m/ folder to path before calling zef_close_all

Also updated documentation comment and fixed a few typos in the existing zef error message.

zeffiro_interface: fix typos in documentation comment

zeffiro_interface: further improved documentation comment

zeffiro_interface: one more documentation comment fix

zef_load: more character arrays into proper strings

zeffiro_interface: add missing .args prefix and the save_project block

zeffiro_interface: use fullfile to construct paths and == to check for string emptiness

zeffiro_interface: reformulate start of comment

zeffiro_interface: move FE mesh exporting after all imports and script execution

zeffiro_interface: do not return "ans" if output was not requested

zeffiro_interface: improve zef-already-open error message

zeffiro_interface: rename file_1 and file_2 → fname and fsuffix, respectively

Also remove calls to fullfile when combining fname and fsuffix.

zef_export_fem_mesh_as: construct file path with a call to fullfile

zef_load: construct paths properly with fullfile and convert some char vectors to strings

zef_start: construct path properly with fullfile

zef_mesh_tool: construct paths with fullfile instead of string or char concatenation

zef_load: construct more file paths properly with fullfile

zeffiro_interface: add missing references to function args

zeffiro_interface: reference to zef_data → zef and change directory name to string

zef_import_figure: construct path properly with fullfile and change char array to a proper string

zeffiro_interface: construct more paths with fullfile

zef_save: construct a path properly with fullfile

zeffiro_interface: zef file paths to char vectors, but also checkout files that use these from main_development_branch

It turns out the paths are further manipulated in the checked out files in a way that is not compatible with proper strings. It is better to manipulate the paths as strings in zeffiro_interface and then convert them to char vectors before calling legacy code, as many changes would be required otherwise.

zeffiro_interface: fix a typo: 9 → )

plugins/Kalman/…/run_cluster_job: use the new name–value arguments when running the script given to Zeffiro