EVALUATED EXPRESSIONS
Expressions can be evaluated in the Gifa program. Expressions
should be enclosed in parentheses. Expressions can use most of the entries
found in the paragraph SYNTAX, at the exception of the special entries :
%% ; <from_file and the pseudo variable $_ .
( 2*(5-1)) (cos($i)) are examples of expressions. Expressions can be used
whenever a Gifa input is needed (command as well as parameters). Expressions
must fit on one line (i.e. 256 characters long), continuation mark cannot be
used within expressions.
Values can be numeric, string or logical. Strings should be enclosed within
'..' or "..". Logicals are stored as 0 for false and 1 for true (or any
non-zero value).
The following operators and functions are implemented :
- the regular 4 operations : + - / * e.g. : (2*3 - 1)
- the modulo function : % (12 % 5)
- the power ^ operator (3^2.1)
- the regular mathematical functions : sqrt(x) cos(x) sin (x) atan(x) log(x)
exp(x) abs(x) int(x) max(x,y) min(x,y)
- the special function power2(n) will have the value of the closest power of
2 below or equal to the number n : power2(130) will be 128 (=27)
- the concatenation operator : ( 'string1' // "string2" )
- the formatting operator : ; equivalent to // ' ' //
- ("Value is:" ; $a) is equivalent to ("Value is:" ; // ' ' // $a)
- the alphanumeric operators :
toupper(st) put string in upper
case
tolower(st) put string in lower case
sp(i) generates a string of i
blanks
len(st) is the length of the string
index(st1,st2) is the position
of st2 located in st1, 0 if not present
subst(st,i,j) is the substring from
st, starting at i, ending at j
head(st) will be the first word in string st
(blank separated)
tail(st) will be the string st but the first
word.
headx(st,c) and tailx(st,c) are equivalent to head and tail but the
character c is used rather than blank.
- the numeral comparison operators : == != < > <= and >= for
comparing numbers : ($x<=0.5)
- the string comparison s= (equal) and s! (different) for comparing strings
: ($s s= 'name')
- the logical operators : | (or) and & (and) : (($x<=0.5)&($s s=
'name'))
- the not operation : ! : (!($i==1)) (!$arg)
- the function eof(file_name) will be true if the last input from file
file_name (with <file_name) had reached the end of the file, will be false
otherwise.
- the function dbm(array_name) is true if array_name is bound to a dbm file
with the DBOPEN command
- the function exist(var_name) will be true if var_name is a user variable
either local or global. e.g.
if (exist("i")) set j = ($i+1)
j is computed only if $i exists as a variable.
The special syntax (exist("foo[]")) checks wheter the array foo
exists with at least one index. It works both for regular and dbm arrays.
- the functions va1d(i), val2d(i,j) and val3d(i,j,k) returns the value of
the content of the main Gifa working buffers. In 2D i and j are the index in F1
and F2 respectively, in 3D in F1, F2 and F3. This replaces the old $VAL[]
construct.
- the function itoh(index,dim,axis), htoi(hertz,dim,axis),
itop(index,dim,axis), ptoi(ppm,dim,axis), htop(hertz dim, axis) and
ptoh(ppm,dim,axis) perform unit conversion. Respectively : index to hertz and
back; index to ppm and back; hertz to ppm and back.
For each function,
index, ppm or hertz is the value to be converted, dim is the dimension to use
(1, 2 or 3) and axis is the axis to use, depending on which spectral widths and
frequencies you want to use for the conversion.
- the next element function : nextlm. If i is an entry in the associative
array $array, the construction nextlm(array,i) will have the value of the next
available entry. The end of the array is notified with an empty string. The
series is also initialised with an empty string. The series is gone through in
the internal order which is not related neither to the input order nor the
sequential order. For instance the following macro will print all the entries
of the array $table :
set $index = (nextlm('table',' '))
while ($index s! ' ')
print ($index // ' : ' // $table[$index])
set $index = (nextlm('table',$index))
endwhile
However the command FOREACH is much simpler to use for the same
purpose.
Check also the macro tunset, which permits to remove all the entries of an
array.
When evaluating expressions, all the internal computations are not typed and
performed on strings. This permits to mix integer and string freely. Thus the
following expressions are perfectly valid :
( cos(1) // 'a string' // ($i==1))
( toupper($file // ($i+1)) )
( log ('0.1') )