next up previous contents index
Next: Loops and control structures Up: Mathematical pixel operations (Image Previous: Evaluating expressions   Contents   Index

Input and output

Printing to stdout

You can print a value to the standard output with the command:

print(stuff, more stuff, numbers, etc);

For example:

          
    print("The answers were: ", x, " ", y+z," yep, those were the answers\n");

The syntax is similar to C's printf() statement, including the usual `backslash' characters (tab, newline, etc), except that no formatting characters (e.g., %d, %g, etc.) are needed, and all strings (including single characters) must be enclosed in double quotes. There can be any number of parameters in the print statement. The output is flushed after each print. The output can be directed to a file by starting tnimage with

          
   tnimage > filename .

If your locale uses commas as decimal separators, it may be necessary to add a space between two numbers to avoid ambiguities like:

          
    print("The 2 numbers were: ", 42,567, "\n");

Printing messages

A simple message can be displayed with the command

          
    message("your message here");

This will open a small information box that will display your message. Note that it will not wait for the user to click OK before continuing.

File output

File syntax is slightly different from C. Files are always accessed by their filename, not by pointers. There can be any number of files open simultaneously. A file must be opened before executing a 'write' statement. The filename is the first parameter, and literal filenames should be in quotes. For example:

          
       fopen("data");
       write("data", "The answer was", wavelet[x][y] "\n");
       fclose("data");

As with print, there can be any number of parameters in the write statement. The output is flushed after each write and the file will be closed when tnimage exits. Even so, it is good practice to close files. A string variable can also be used as the filename (see below).

Input

The input command gets a number from the user and returns it to some numeric variable:

          
    a = input("prompt string");

Similarly, getstring gets a string (such as filename or a function name) from the user and returns it to some string variable:

          
    a = getstring("prompt string");

For both cases, the value can be examined with whatis():

          
    whatis(a);


next up previous contents index
Next: Loops and control structures Up: Mathematical pixel operations (Image Previous: Evaluating expressions   Contents   Index
root 2006-11-13