next up previous contents index
Next: Macro Command Reference Up: Summary of macro commands Previous: Summary of macro commands   Contents   Index

Variable Types

There are only three data types: numbers, strings, and function variables. Variable names are changed from one type to the other if an expression of the appropriate type is assigned to it. Since the data type is determined automatically, there is no need to declare variables or distinguish them with special characters (such as '$' or '@').

Numeric variables

All numeric expressions are evaluated to double-precision floating point numbers. There is no need to specify a data type. For example, the following macro sets 'a' and 'b' to 123.456 and 42, respectively, checks their values, then adds 81.456 to each pixel between (100,100) and (200,200).

       set(a=123.456);
       set(b=sqrt(1764));
       whatis(a);
       whatis(b);
       select(100,100,200,200);
       i+=a-b;

If you want to change a variable outside of a loop, use set() to prevent automatic looping over the pixels:

       set(a=123);
       set(a+=exp(2.34));
       set(a=a-sqrt(8350.5));
       whatis(a);

For large macros, it may be necessary to increase the number of symbols in calculator.h (default=1000).

String variables

Strings are useful for file names, image titles, and for output formatting. To set a string variable, put the string in quotes:

       set(bimage="gray.tif");
       whatis(bimage);
       open(bimage);

You cannot have macros like

       set(bimage="gray.tif");
       open(bimage);
       set(a=123);
       bimage += a;          /* Wrong */

The last line in the above macro would simply set all the pixels to 0 because a string always has a value of 013.1. Use i+=a instead. Caution: Don't use predefined variables such as i,r,g,b,re,im, or w as string variables. This would cause your variable to be changed back to a numeric variable when a math command is executed.

Assignment of string variables (e.g., a=bimage ) is not yet supported.

Set should not be used in loops.

Function variables

Another useful feature is the ability to interchange names of functions with string variables. For example, suppose you defined string a with the name of macro command left:

   set(a="left");
   a(100);

From then on, executing a(100); would execute the function ``left'', which moves the image to the left by the specified number of pixels. Now if a is redefined to be ``right'', executing a(100); would move the image to the right by 100 pixels. There are many situations where this makes the macro more compact.

In future versions, this will be used to permit the creation of new user-defined functions in macros.


next up previous contents index
Next: Macro Command Reference Up: Summary of macro commands Previous: Summary of macro commands   Contents   Index
root 2006-11-13