G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
GREYC CNRS ENSICAEN UNICAEN

A Full-Featured Open-Source Framework for Image Processing



Latest stable version: 3.4.3        Current pre-release: 3.4.4 (2024/11/20)

Tutorial

check (+)


frontimage
Curtis L. Brown Jr., STS-95 commander,
checks over notes with Houston ground controllers. October 31, 1998           NASA
check throws exceptions if the given math expression argument resolves to False, otherwise it takes no action. It is the tool of choice for checking command arguments, taking math expressions that resolve to True with arguments that possess must-have features.

If any calling scope encompasses a localdone block with an onfail section, the exception is caught and further processing resumes in the -onfail section. Otherwise -check uses its argument for the exception message and exits G'MIC.

Since 2.6, -check no longer directly tests for file system objects; use math expressions isfile() or isdir() instead.

Consider using error if a custom message is desired. Since -error unconditionally throws exceptions, combine it with conditional commands to emulate -check, but in (probably) a less compact way.

Examples

$ gmic check 0 echo 'Done!'
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ *** Error *** Command 'check': Expression '0' evaluated to false.

$ gmic check 1 echo 'Fooooo!'
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Fooooo!
[gmic]-0./ End G'MIC interpreter.
-check throws an exception immediately if its argument reduces to False; G'MIC does not operate on the remainder of a pipeline. Instead, it commences to exit all the scopes encompassing the offending pipeline. Should any of those scopes reside in an onfail section of a localdone block, then G'MIC resumes processing at that specific -onfail section — the exception being caught. Otherwise, upon the exit from all scopes, -check echoes its argument in the shell log and G'MIC quits. -check performs no operation if its argument is True.
display_graph : check "${1=0}>=0 && ${2=0}>=0" …
dg : check "${1=0}>=0 && ${2=0}>=0" skip ${3=1},${4=0},${5=0},${6=0},${7=0},${8=0},"${9=x-axis}","${10=y-axis}"…
Very frequently, -check constitutes the first line in custom command definitions, its argument a sanity-checking math expression. These test for properties among arguments upon which the custom command depends. In these examples, -check takes one argument, a string, which G'MIC processes as a math expression, substituting the results of the math expression for the string. -check interprets non-zero results as True, allowing G'MIC to proceed with the rest of the pipeline. Zero-results are interpreted as False; -check throws an exception, using its argument string as the exception message.
Combine skip with check to set custom command arguments to default values, but exclude such from -check processing. Effectively, this creates an optional argument that has a default value.
onfail.gmic
sameas :
   left=$1
   right=$2
   -local
      -testit $left,$right
      -echo $left" is the same as "$right"."
      -onfail
         -echo $left" differs from "$right"."
         -quit
   -done

testit : -check "${1}==${2}"

        §§§

$ gmic onfail.gmic sameas 3,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 3 is the same as 3.
[gmic]-0./ End G'MIC interpreter.

 $ gmic onfail.gmic sameas 4,3
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input custom command file 'onfail.gmic' (2 new, total: 4447).
[gmic]-0./sameas/*local/ 4 differs from 3.
Wrapping -check within an onfail section of a localdone block may lead to a more adroit handling of thrown exceptions, not the least of which being posting purpose-specific error messages or saving of already-generated images from the effects of an inopportune exception. This approach is not peculiar to -check but to any circumstance where an exception is possible.

Command reference

$ gmic -h check

check (+):
condition

Evaluate specified condition and display an error message if evaluated to false.
Updated: 07-March-2023 13:47 UTC Commit: 220bd6b91cf3556158551b6ca6d8f6e242b72850
G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing

G'MIC is an open-source software distributed under the CeCILL free software licenses (LGPL-like and/or
GPL-compatible). Copyrights (C) Since July 2008, David Tschumperlé - GREYC UMR CNRS 6072, Image Team.