TOC PREV NEXT INDEX

Using AVS/Express



7 V and the V Command Processor


This chapter describes the V Command Processor (VCP) and the V language. It includes the following sections:

7.1 Introduction

Like the Network Editor, the V Command Processor (VCP) is an Object Manager interface with which you develop and debug AVS/Express applications. Unlike the Network Editor, the VCP is not a graphical interface, but rather a textual interface. Its medium is a language called the V command language (also called V code or V), a schema definition language with which AVS/Express defines objects and applications.

You write V code to perform tasks such as the following:

The VCP processes your V code, instructing AVS/Express to perform the specified tasks. Note that the VCP is not a compiler; V is an interpreted language rather than a compiled one.

The V command language consists of comments, statements, commands, and functions.

AVS/Express stores the definitions of objects (whether created in the Network Editor or the VCP) in V code in files called V files. Typically, these objects are stored in text V files, whose names, by convention, have the extension .v; for example, my_object.v. However, you can also store object definitions in binary V files, which load into AVS/Express faster. By convention, binary V files have the extension .vo; for example, my_object.vo.

The following section explains how to access the VCP and, through it, navigate your application's AVS/Express object hierarchy. Subsequent sections describe the V language itself: comments, statements, commands, and functions.

7.2 Using the V Command Processor

There are several ways to use V in AVS/Express:

Note: Advanced Visual Systems does not recommend using parse_V module objects, as they are difficult to debug.

This section focuses on the most simple and direct usage of V: the VCP window.

Accessing the VCP Window

The VCP window is the window from which you launch AVS/Express. It looks like the following:

Figure G-1


When you launch AVS/Express, the current object in the VCP window is Root, the top-level object in the current application. To indicate this, the VCP displays the following prompt:

OM(Root)           ->

Before you can use the VCP to create or modify an object, you must navigate to the appropriate location in the AVS/Express object hierarchy: either the object to be modified or the parent of the object to be created. Note that the VCP prompt changes as you navigate through the object hierarchy, and always indicates your current location.

New Functionality for Creating the VCP

A routine exists OMcreate_stream_parser, has been added that allows you to create the VCP window outside of the OMmain_loop. The declaration for this routine is shown below:

int OMcreate_stream_parser(OMobj_id id, FILE *fp, int mode)

To manually create the V parser, make the following call:

OMcreate_stream_parser(OMroot_obj,stdin,0);

The statement above creates a new VCP that takes its input from stdin that is editing the root object (OMroot_obj).

Navigating the AVS/Express Object Hierarchy

The AVS/Express object hierarchy in an application exists in levels, with Root as the top-most level, as noted previously. From Root, you can move only down the object hierarchy; from the bottom level of the application (whatever that may be), you can move only up; from all other levels, you can move either up or down.

Moving Down the Object Hierarchy

To move down a single level in the object hierarchy, enter the name of a subobject of the current object followed by the left brace character ({). For example, you might enter the following commands to navigate from the top-most Root object to the Read_Geom object in the applications workspace area one level at a time:

OM(Root)           -> Applications{
OM(Applications)    ->     SingleWindowApp{
OM(SingleWindowApp)->         Read_Geom{
OM(Read_Geom)      ->

To move several levels down the object hierarchy in a single step, specify a compound target name consisting of the subobjects to be traversed separated by periods, followed by the left brace character. For example, you can use the following command to move directly from Root to Read_Geom:

OM(Root)           -> Applications.SingleWindowApp.Read_Geom{
OM(Read_Geom)      ->

Observe that the VCP indents the starting position of the commands you enter, to further indicate your current level in the object hierarchy.

Moving Up the Object Hierarchy

To move up the object hierarchy, type the move-up command: a right brace character following by a semicolon ({). This command returns you to your previous location in the object hierarchy. For example, if you moved from the Root object down to the Read_Geom object one level at a time as illustrated in the first example in the previous section, you move back up to Root as follows:

OM(Read_Geom)      ->             };
OM(SingleWindowApp)->         };
OM(Applications)   ->     };
OM(Root)->

Note that if you moved from Root down to Read_Geom in a single single step, as illustrated in the second example, entering the move-up command (};) moves you immediately up to Root, because this was your previous location:

OM(Read_Geom)      ->      };
OM(Root)           ->
Bypassing Global Objects

Many AVS/Express objects, for example the Applications object, have their global attribute set to indicate that they are available to all AVS/Express applications. You can simplify navigating the AVS/Express object hierarchy by bypassing global objects when moving to objects beneath them. When you do this, AVS/Express prints a warning message to inform you that it is skipping levels.

For example, because Applications is a global object, you can navigate directly from the Root object to the SingleWindowApp object as follows:

OM(Root)           -> SingleWindowApp{
warning: jumping from: Root to Root.Applications.SingleWindowApp
OM(SingleWindowApp)->

Starting again at Root, you can navigate directly from Root to Read_Geom in a single step by skipping the Applications portion of the compound target name as follows:

OM(Root)           -> SingleWindowApp.Read_Geom{
warning: jumping from: Root to Root.Applications.SingleWindowApp.
Read_Geom
OM(SingleWindowApp)->

You can determine whether an object is global by examining its base type in the Object Info dialog window and observing whether its global attribute is set. To open this dialog window, right-mouse-click on the object in the Network Editor, then select the Info... command from the pop-up menu that appears.

For example, here is the Object Info window for the Applications object:

Figure G-2


Many AVS/Express libraries of template objects are also global, in order to allow you to instantiate an object in the VCP without specifying its full path. Because you can bypass these libraries, you must be sure to assign unique names to the objects that you create: if you do not, and you bypass a global library object, you may inadvertently use the wrong template object without receiving a warning from AVS/Express.

For more information on global libraries, see Global Libraries on page 5-13.

Accessing Array Elements

A nonprimitive array object has elements that can consist of multiple values. In the VCP, you specify the name of an array element using the following syntax:

!array_obj[index]

In this syntax:

Suppose, for example, that you create an array object named grp_array that contains three elements, each of which consists of two objects.

Note: Nonprimitive arrays are limited to one dimension, so this array object is defined as a three-element, one-dimensional array.

In the Network Editor, the definition of this array object in the Object Editor is as follows:

Figure G-3


The following sequence of V code, issued in the VCP window, accesses and sets various of the array elements as noted in the comment text (that is, text between a pair of forward slash characters (//) and the end of a line):

OM(SingleWindowApp)-> !grp_array[1]{ //Access element 2 of grp_array
OM(grp_array[1])       -> int = 11; //Set int subobject
OM(grp_array[1])       -> float = 11.1; //Set float subobject
OM(grp_array[1])       -> }; //Move from element 2 to SingleWindowApp
OM(SingleWindowApp)-> !grp_array[2]{ //Access element 3 of grp_array
OM(grp_array[2])       -> int = 22; //Set one subobject
OM(grp_array[2])       -> float = 22.2; //Set other subobject
OM(grp_array[2])       -> }; //Move from element 3 to SingleWindowApp
7.3 V Comments

You include V comments in a V file to document the contents of the file. There are three types of comments, each with its own syntax:

C-Style Comments

A C-style comment has this format:

/* comment_text */

The /* and */ delimiters define the beginning and end of the comment; the comment text includes all characters between the delimiters. A C-style comment can appear anywhere in your V code and can span multiple lines.

Here are some examples:

/* This comment is completely contained on a single line. */
/* This is line 1 of a multiline comment.
   This is line 2 of the comment.
/* The following line contains both a V statement and a comment.
int var1;     /* This is a comment. */

AVS/Express ignores C-style comments.

C++-Style Comments

A C++-style comment has this format:

// comment_text

The // delimiter defines the beginning of the comment; the comment text includes all characters from the right of the delimiter to the end of the current line. A C++-style comment can appear anywhere in your V code but it cannot span multiple lines.

Here are some examples:

// This comment is completely contained on a single line.
// This is a comment line
// This is a second comment line. It starts with a new delimiter.
// The following line contains both a V statement and a comment.
int var1;     // This is a comment.

AVS/Express ignores C++-style comments.

Special Comments

A special comment is a comment that AVS/Express tracks, rather than ignoring it as it does C-style and C++-style comments. AVS/Express defines this type of comment as an object (specifically, the child of the current object) and keeps track of it, displaying it in the Network Editor and saving and restoring it along with the current object.

The simplest version of a special comment has this format:

/*= comment_text */

The /*= and */ delimiters define the beginning and end of the comment; the comment text includes all characters between the delimiters. For example:

/*= This is a comment. */

You can specify a size and offset for a special comment by using the following more detailed format:

/*= widthxheight+xoffset+yoffset comment_text */

The parameters specify the width and height of the comment and its x and y offsets. The units for all four parameters are in the same coordinate system as the NEx, NEy, NEwidth, and NEheight properties (pixels on most systems). For example:

/*= 100x50+30+30 This is the comment text. */

In this example, the parameters specify a comment that is 100x50 units in size and is offset 30 units in both the X and Y directions.

AVS/Express assigns unique names to the special comments that it creates. To list your special comments, use the $list command; for example:

OM(grp1)           -> $list;
comment _comment
comment _comment#1

To delete a comment, use the delete (-) operator; for example:

OM(grp1)           -> -_comment;

For more information on the $list command and the delete operator, see V Statements on page 7-11.

7.4 V Statements

You use V statements to create, modify, and delete objects, first navigating to the appropriate location. A V statement consists of one or more clauses, separated by separator characters and terminated by a semicolon.

When using V statements, observe the following general rules:

Except for attributes, properties, and reference mode, the syntax of V statements is very similar to C-language syntax. The syntax varies depending on whether you are using the statement to create, modify, or delete an object.

Note: The syntax of V statements also varies slightly depending on whether you use them in the VCP or in a V file.
The V Create Statement

The V create statement creates a new object. It has the following syntax:

type+type...+attribute+attribute...
[ref_mode ]
object_name
[properties]
[array_decl]
[subobject_decls]
[value_expr]

For descriptions of create statement clauses, see Clauses on page 7-12.

Description

When you use a V statement to create an object, you create an object that is an immediate subobject of the current object. For example, the following V statement creates x as an immediate subobject of grp1:

group grp1 {
int x;
}

You must assign at least one type to an object. The object inherits the characteristics of its type, including attributes, mode, properties, array declaration, subobjects, and value expression. Any characteristics that you specify in a create statement override any inherited characteristics.

You can create multiple objects of the same type at the same time using a single V statement. To do this, separate the object definitions with commas and place the terminating semicolon at the end of the last object's definition. For example, the following V statement creates the three integer objects x, y, and z:

int x; y=>3; &z[10];

You can create an object that inherits from multiple object types, by specifying all of the types, preceding all but the first with the merge + (merge-plus) operator. In this example, the two_groups object contains copies of the grp1 and grp2 subobjects.

grp1+grp2 two_groups;

You can use the V create statement to replace an existing object with a new object. Simply navigate to the parent object of the object to be replaced, then specify its name in the V create statement. AVS/Express replaces the existing object with the new object. If you want only to modify the object's definition, use the V modify statement instead (see The V Modify Statement on page 7-15.)

Clauses

The following table describes clauses in the V create statement syntax.

Table G-1
Component
Description
type
A previously defined object type. The type can be either a base type (either an AVS/Express or a user defined) or a template. When specifying multiple types (in multiple inheritance), precede subsequent types with the merge + (merge-plus) operator.
+attribute
The object's attributes, preceded by the attribute + (attribute-plus) operator. Do not confuse the attribute + operator with the merge + (merge-plus) operator.
This example assigns the nosave attribute to the int object x:
int+nosave x;
ref_mode
The object's reference mode. It must be one of the following:
    ^: By value
    &: By reference
    *: By pointer
This example creates an object named parent of UIpanel type in by-pointer reference mode:
UIpanel *parent;
object_name
The name of the object to be created. A name can consist of:
-- Alphanumeric characters (but a name cannot start with a digit)
-- The pound character (#)
-- The underline character (_) (displayed in the Network Editor as a space)
Note that names are case sensitive.
properties
The object's properties. Place the specified properties in angle brackets (<>) and separate multiple properties with commas. The properties clause begins and ends with opening and closing angle brackets (<>) and contains one entry for each property, with entries separated by commas. You can use either of the following formats for an entry:
prop_name = value
prop_name
={value1, ...}
This example sets the NEx, NEy, and NEportLevels properties of the int object x to specific values:
int x<NEx=100, NEy=100, NEportLevels={2,0}>;
Note that property values can also be scalar expressions.
An object's properties include not only those specified with the <properties> syntax component but also any inherited properties.
array_decl
A C-style array declaration, in one of the following forms:
    [size]: declares a one-dimensional array of size elements
    []: declares a one-dimensional array with an unspecified number of elements
    [size0][size1]...: declares a multi-dimensional array with the specified sizes in         each dimension
Note that sizes can be scalar expressions.
subobject_decls
The object's subobjects. Macro, group, and library objects can have subobjects, but primitive objects cannot. The subobject clause, following, begins and ends with opening and closing braces and contains one declaration for each subobject, with declarations separated by semicolons:
{type subobject_name value_expr;
...
};

For descriptions of these clauses, see the descriptions of the corresponding object clauses elsewhere in this table.
An object's subobjects include not only those defined with the subobject clause but also those inherited from its type.
value_expr
An expression that assigns a value or creates a connection. For details and examples, see Value Expressions on page 7-20.

Examples

Creating a primitive object. This example illustrates a series of V commands and statements, issued in a VCP window, that perform the following tasks:

1. Navigate to the SingleWindowApp parent object.
2. Create test_obj as an array of two integers in the "by reference" reference mode.
3. Set the values of my_obj.

Here are the required V commands and statements:

OM(Root)           -> Applications{
OM(Applications)   ->     SingleWindowApp{
OM(SingleWindowApp)->         int &my_obj [2];  // creates my_obj
OM(SingleWindowApp)->         my_obj = {10,20}; // sets its values

Creating a group object. This example illustrates a V-code definition of a group, stored in a V file. The definition creates a group object named grp1, which contains three float objects and an int object.

group grp1 {
float x, y, z;
int a;
};

Creating an object that inherits subobjects. This example illustrates a V-code definition of a group, stored in a V file. The definition creates a group object named grp2 whose type is grp1 (defined in the previous example). The grp2 group object inherits grp1's subobjects (x, y, z, and a). In addition, the definition creates an additional subobject named w and modifies the inherited subobjects x and y:

grp1 grp2{
float w;               // create w
x<NEportLevels=2> = 1; // modify NEportLevels property of x
y => varx;             // create a reference from y to varx
};
Note: In the example above, varx need not exist yet. When you create varx and set it to a value, y is set to the same value automatically because of the connection.
The V Modify Statement

The V modify statement modifies an existing object. It has the following syntax:

[ref_mode ]
object_name
[type+type...+attribute+attribute...]
[delete_atts]
[properties]
[array_decl]
[subobjec_decls]
[value_expr]

For descriptions of modify statement clauses, see Clauses on page 7-16.

Description

When you use a V statement to modify an object, you change the definition of the object. Only those clauses that you specify in the statement are modified; all others are unchanged. You can use a V modify statement on any of the following objects:

Suppose, for example, that you create the object c1, then change its (inherited) subobject x as follows:

group coordinates {
int x, y;
};
coordinates c1 {
    x = 3;
};

Now suppose that you are in the VCP window and want to modify subobject x. You can do this in either of two ways:

c1 {
x = 3;
c1.x = 3;

Note that you cannot use a V modify statement to change the name of an object. Instead, you must use the V command $set_obj_name; for example:

$set_obj_name x int1

You cannot use the V modify statement to replace an existing object with a new object. If this is what you want do do, use the V create statement instead (see The V Create Statement on page 7-11.)

Clauses

The following table describes clauses in the V modify statement syntax.

Table G-2
Component
Description
ref_mode
The object's reference mode. It must be one of the following:
    ^: By value
    &: By reference
    *: By pointer
This example changes the reference mode of the object x from its previous setting to by-value mode:
^x;
object_name
The name of the object to be modified, either the current object, one of its immediate subobjects, or (using a compound path name) any lower-level subobject. Note that object names are case sensitive.
+type
Additional types to be assigned to the object. Precede each type with the merge + (merge-plus) operator. This example adds the int type to x:
x+int
You cannot remove previously assigned types.
Note that you can mix type additions, attribute additions, and attribute deletions in the same statement. For an example, see the description of delete_attrs.
+attribute
Additional attributes to be assigned to the object. Precede each attribute with the attribute + (attribute-plus) operator. This example adds the req and notify attributes to x:
x+req+notify;
Do not confuse the attribute + operator with the merge + (merge-plus) operator.
To remove previously assigned attributes, use the delete_attrs clause.
Note that you can mix type additions, attribute additions, and attribute deletions in the same statement. For an example, see the description of delete_attrs.
delete_attrs
Previously assigned attributes to be removed from the object. Precede each attribute with the attribute - (attribute-minus) operator. This example removes the notify attribute from x:
x-notify;
You can mix type additions, attribute additions, and attribute deletions in the same statement, as shown in the following example (note that the OM command prompt is shown only as -> for readability):
->     int x;
->     int+notify x;
->     x-notify+write;
->     $print x;
int+write x;

properties
Additional properties to be set or modified for the object. Place the specified properties in angle brackets (<>) and separate multiple properties with commas. The properties clause begins and ends with opening and closing angle brackets (<>) and contains one entry for each property, with entries separated by commas. You can use either of the following formats for an entry:
prop_name = value
prop_name
={value1, ...}
This example sets the NEx properties of the object x the value 100, regardless of whether it was previously set or unset:
int x<NEx=100>;
array_decl
A C-style array declaration, in one of the following forms:
    [size]: declares a one-dimensional array of size elements
    []: declares a one-dimensional array with an unspecified number of elements
    [size0][size1]...: declares a multi-dimensional array with the specified sizes in         each dimension
If the object is currently a single entity, it changes into an array of the specified dimensions. It if is already an array, its dimensions change to those specified. You cannot change an array into a single entity, although you can change it to an array of size 1.
subobject_decls
Subobjects to be added to, modified for, or deleted from the object. Macro, group, and library objects can have subobjects, but primitive objects cannot. The subobject clause, following, begins and ends with opening and closing braces and contains one declaration for each subobject, with declarations separated by semicolons:
{type subobject_name value_expr;
...
};

For descriptions of these clauses, see the descriptions of the corresponding object clauses elsewhere in this table.
The following example might modify the subobject x and add the subobject z:
my_coordinates {
    x = 100;
    int z;
};

Caution: Deleting an inherited subobject breaks an object's template hierarchy.
value_expr
A new value expression for the module. It replaces the value expression previously assigned to the module. For details and examples, see Value Expressions on page 7-20.

The V Delete Statement

The V create statement deletes an existing object. It has the following syntax:

-object_name
CAUTION: Deleting an inherited subobject breaks an object's template hierarchy.
Clause

The object_name argument specifies the name of the object to be deleted. You can delete either the current object, one of its immediate subobjects, or (using a compound path name) any lower-level subobject. Note that object names are case sensitive.

Examples

Creating an object and deleting its subobject. Suppose that you create the macro mymacro, which contains three subobjects, as follows:

macro mymacro {
    Read_Geom geom_1;
    Read_Geom geom_2;
    Viewer3D Viewer;
};

The following V code deletes the geom_1 subobject:

mymacro {
    -geom_1;
};

Navigating to and deleting an object. This example illustrates a series of V commands and statements, issued in a VCP window, that perform the following tasks:

1. Navigate to the SingleWindowApp parent object.
2. Delete a previously created object called my_obj object.

Here are the required V commands and statements:

OM(Root)           -> Applications{
OM(Applications)   ->     SingleWindowApp{
OM(SingleWindowApp)->         -my_obj; //deletes my_obj
Value Expressions

A value expression is a C-style expression that assigns a value or creates a connection. Each value expression begins with an assignment operator (=) or a connection operator (=>), to specify the type of operation. Value expressions are categorized as either scalar value expressions or array value expressions.

Assignment and Connection Operators

A value expression always begins with either an assignment operator (=) or a connection operator (=>).

= value;
Using the assignment operator, assigns the object's value.
=> value;
Using the connection operator, references the object.

Both assignment and connection operators can accept either constant values (for example, the integer value 32) or multioperand values (for example, the expression 3 * val1).

The following simple example illustrates the assignment and connection operators. Suppose that you enter the following V statements in the VCP window:

int int1 = 36;
int int2 => int1;

The first statement uses the assignment operator; the second statement uses the connection operator. Because e int1 and int2 are primitive objects, you can assign values to them directly. After the VCP processes these statements, these results appear in the Network Editor:

Figure G-1


Suppose that you now change the value of int2 using the following statement:

int2 = 45;

After the VCP processes this statement, these results appear in the Network Editor:

Figure G-2


Observe that changing the value of int1 also changed the value of int1 (the connection is a read-write connection).

Scalar Value Expressions

Scalar value expressions (also called scalar expressions) return a scalar value, either constant (for example, the integer value 32) or multioperand (for example, 3 * int1). Here are some simple examples of scalar value expressions:

int x = 4; // Assigns a constant value
int y
=> x; // Connects to an object

Scalar value expressions can include any of the tokens described in this table.

Table G-3
Scalar Token
Description
Examples
Constant
A C-style numeric or string constant.
= 345;
= 3.45;
= 3.45e1;
= "AVS";

Unescaped string literal
A string constant that does not need quote characters to be escaped with the \ character. It begins with the sequence <" and ends with the sequence ">.
= <""hi world"">;
Object name
The name of an object whose value is to be assigned or referenced.
= object1;
=> object1;

Array object element
An element of an array object, in the following format:
array_obj[index]
In this format:
-- array_obj is the name of the array     containing the element
-- index is the index number of the     specific array element
Recall that in AVS/Express, index numbering in arrays begins at 0.
= array_obj[0];
=> array_obj[0];
=> array_obj[int1+2];

Operator
An arithmetic, bitwise, logical, or comparison operator. For details, see Operators on page 7-28.
= my_int*(a+b);
=> b <+> 3;

V function
An AVS/Express V function. For details, see Chapter 7.6, V Functions.
= abs(-90)
Null
A null value, specified by typing nothing after the assignment or connection operator.
The value of a primitive data object that has been instanced but not initialized is unset. Assigning a null value to the object returns it to the unset state.
Using a connection operator with a null value is useful for breaking a connection.
=
=>


Note that scalar value expressions can appear in contexts other than V statements; for example, in the declaration of an array's dimension or the definition of a connection for a group with reference mode set to by-reference or by-pointer. The following V statement specifies that camera_in references (connects to) the view.picked_camera object:

GDcamera_templ &camera_in => view.picked_camera
Array Value Expressions

Array value expressions (also called array expressions) return an array value of a particular dimensionality, either constant (for example, {32, 34, 34}) or multioperand (for example, 3*array_1). Here are some simple examples of array value expressions:

int z => 4*max(a,b,c); // Connects to a multioperand expression
int w[] => {x,y,z}; // Connects to an array of objects

An array value is a sequence of scalar values, each corresponding to an element in an array object. (This section assumes that array objects are arrays of scalar values and not arrays of groups.) For example, the following are equivalent:

The following commands have a somwhat surprising effect; the second command redimensions array_obj to be a 1 by 2 array and sets all the array elements to 5.

-> int array_obj[2][3];
-> array_obj[1][2] = 5;
-> $get_array array_obj
{{5,5}}

To set array elements one by one, a different method must be used.

-> int array_obj[2][3] = 0; // Initialize all elements to zero.
-> $get_array array_obj
{{0,0,0},{0,0,0}}
-> int tmp => array_obj[0][0];
-> tmp = 1;
-> $get_array array_obj
{{1,0,0},{0,0,0}}

An array expression can be in the form of a mathematical expression that uses array names, if the specified arrays have the same number of elements. The following example uses array multiplication in an array expression:

OM(DefaultApplication)-> int a1[2][3] = {1,2,3,4,5,6};
OM(DefaultApplication)-> int a2[3][2] = {10,20,30,40,50,60};
OM(DefaultApplication)-> int a3[2][3] = {a1*a2*2};
OM(DefaultApplication)-> $get_array a3
{{20,80,180},{320,500,720}}
OM(DefaultApplication)-> $array_dims a3
ndim=2 [2][3]

The third command contains the array multiplication: {a1*a2*a3}. Note the use of the $get_array V command to print array values and the $array_dims V command to print dimensions and size.

Array value expressions can include any of the tokens described in this table.

Table G-4
Array Token
Description
Examples
Array literal
A comma-separated set of scalar or array values.
int1 = 2;
array1[] = {1,2};
array2[] = {3,int1+2};
array3[] = {array1, array2, {5, 6}};

Scalar value
Any value that is valid in a scalar expression. AVS/Express assigns the scalar value to every element of the array object.
// Makes an assignment
int int1;
int my_array[2] = int1+2;
// These statements are equivalent to:
// int my_array[2] = {int1+2, int1+2};

// Creates a connection:
my_array[2] => int1 + 2;

Full array object
The name of a compatible array object. Such an assignment or reference accesses all elements of the specified array object.
int one_d_array[2];
int any_array[] = one_d_array;
any_array => one_d_array;

Array object section
A subset of elements of a compatible array object, in the following format:
array_obj[start:end]...
In this format:
-- array_obj is the name of the     array object
-- start and end are scalar values     that specify the array     section's starting and ending     subscripts in a given     dimension
int a1[4][3] = {0,1,2,3,4,5,6,7,8,9,10,11};
int a2[3][2] = a1[0:2][1:2];

// The last statement is equivalent to:
// int a2[3][2] = {a1[0][1], a2[0][2],
// a[1][1],a[1][2], a[2][1], a[2][2]}

Reduced dimensionality array
A multidimensional array object with a single dimension specified, in the following format:
array_obj[index][]
In this format:
-- array_obj is the name of the     array object
-- index is the index number of     the the dimension that you     want to preserve
If you specify fewer dimensions than defined in the array, AVS/Express automatically fills in the remaining dimensions with [].
int a1[4][3] = {0,1,2,3,4,5,6,7,8,9,10,11};
int a2[] = a1[][0];
// The last statement is equivalent to:
// int a2[] = {a1[0][0], a1[1][0],
// a1[2][0], a1[3][0]};

int a3[] = a1[0];
// This statement is equivalent to:
// int a3[] = a1[0][];
// It is also equivalent to:
// int a3[] = {a1[0][0], a1[0][1],
// a1[0][2]};

Mix of scalar and array operands
Operations that AVS/Express performs on each element of each array.
int a1[3] = {1,2,3};
int a2[] = a1*3;
// These statements are equivalent to:
// int a2[] = {a1[0]*3, a1[1]*3, a1[2]*3};

V function
Functions whose operations AVS/Express performs on the array.
int a1[2] = {5,6};
int a2[2] = {3,4};
int a3[] = pow(a1, a2);
// This is equivalent to:
// int a3[] = {pow(a1[0],a2[0]),
// pow(a1[1],a2[2])};
// Therefore, it is also equivalent to:
// int a3[] = {pow(5,3), pow(6,4)};


When you create an array expression, you assign or connect values to an array object. Values can take the form of either a sequence of values (for example, {0, 25, 99, 33*my_int}) or a compatible array object. A set of rules define whether two array objects are compatible. If array_obj_A is compatible with array_obj_B according to these rules, you can make the following assignment or connection:

array_obj_B = array_obj_A;
array_obj_B => array_obj_A;
Note: This section addresses primitive array objects only. Nonprimitive array objects can have only one dimension.

Following are the array compatibility rules. They assume that array_obj_A and array_obj_B have the same number of elements.

OM(SingleWindowApp)-> int array_obj_A[6] = {0,1,2,3,4,5};
OM(SingleWindowApp)-> int array_obj_B[2][3];
OM(SingleWindowApp)-> array_obj_B = array_obj_A; // allowed
OM(SingleWindowApp)-> int array_obj_A[2][3] = {{0,1,2},{3,4,5}};
OM(SingleWindowApp)-> int array_obj_B[6];
OM(SingleWindowApp)-> array_obj_B = array_obj_A; //allowed
OM(SingleWindowApp)-> int array_obj_A[2][3] = {0,1,2,3,4,5};
OM(SingleWindowApp)-> int array_obj_B[3][2];
OM(SingleWindowApp)-> array_obj_B = array_obj_A; // not allowed
--- Error detected in: module: OMmatch_dims ---
unable to match: 2D array with 2D array, [3] doesn't match [6]
--------------------------------------------------
--- Error detected in: module: OMprim ---
object: `array_obj_A' has invalid value or type for assignment to:
Root.Applications.SingleWindowApp.array_obj_B
OM(SingleWindowApp)-> int array_obj_A [2][3][2] =
{1,2,3,4,5,6,7,8,9,10,11,12}; // define 3-dim array with 12 elems
OM(SingleWindowApp)-> int array_obj_B [][][2]; // define
                                               // 3-dim array
OM(SingleWindowApp)-> array_obj_B = array_obj_A; //make assignment
OM(SingleWindowApp)-> $get_array array_obj_B // get array elems
{
1,2,3,4,5,6,7,8,9,10,11,12
}
OM(SingleWindowApp)-> $array_dims array_obj_B // get array dims
ndim=1 [12] // converted to 1-dim array with 12 elements
OM(SingleWindowApp)-> int scalar_obj_A = 8;
OM(SingleWindowApp)-> int array_obj_B[6];
OM(SingleWindowApp)-> array_obj_B = scalar_obj_A; // allowed
OM(SingleWindowApp)-> $print array_obj_B // check value of
                                         // array_obj_B
int array_obj_B[6] = {8,8,8,8,8,8}; // AVS/Express promotes
                                       scalar to array
OM(SingleWindowApp)-> int array_obj_A[2][3] = {0,1,2,3,4,5};
OM(SingleWindowApp)-> int scalar_obj = 77;
OM(SingleWindowApp)-> int array_obj_B[][];
OM(SingleWindowApp)-> array_obj_B = scalar_obj * array_obj_A;
OM(SingleWindowApp)-> $print array_obj_B
int array_obj_B[][] = {0,77,154,231,308,385};
Operators

AVS/Express supports the use of the following types of operators in V code:

The following table describes the AVS/Express operators, grouped by type. Note that all operators follow the C language order of precedence; use parentheses to override the default order.

Table G-5
Operator Type
Operator
Operation
Arithmetic
+
-
*
/
%
-
+

Addition
Subtraction
Multiplication
Division
Modulo
Unary minus
String concatenation
Note: Floats or other primitive data objects can be converted directly to strings, so you can use the + operator on them as well.
Bitwise
&
|
^
~

Bitwise and
Bitwise inclusive or
Bitwise exclusive or
One's complement
Logical
&&
||

Logical and
Logical or
Comparison
==
!=
<
>
<=
>=

Equality
Inequality
Less than
Greater than
Less than or equal to
Greater than or equal to
Note: Comparison operators also work on array operands. When you specify array operands, a comparison operator returns an array of integers that indicate the value of an item-by-item comparison of the objects.
Read-write
<+>
<*>
!

Read-write addition
Read-write multiplication
Read-write modification (read-write negation)
Note: For details on read-write operators, see the next section, Read-Write Operators.
Miscellaneous
+
Merge + (multiple inheritance)
Syntax: mesh+node_data my_field;

Read-Write Operators

The AVS/Express read-write operators-<+>, <*>, and !-perform read-write operations. All other operators perform read-only operations. For example, if you use a read-only operator in a connection value expression and then change the one of the operands' values, the other operands do not change their values to maintain the connection. Instead, the operator breaks the connection to maintain the operands' values.

Suppose that you create two objects and connect them using a read-only operator:

int b = 2; // create b and assign it a value
int a => b + 3; // create and connect a
                // using a read-only operator

The results appear in the Network Editor as follows:

Figure G-3


Now, suppose that you reassign the value of a (the $print statement displays the value of b):

a = 8; // reassign a the value 8
$print b // check the value of b

The results appear in the Network Editor as follows:

Figure G-4


Observe that b retains its value of 2, but its connection with a is broken. The read-only operator does not allow b to be overwritten.

By comparison, read-write operators change the values of operands in order to maintain a connection. For example, suppose that you create the same two objects but connect them using a read-write operator:

int b = 2; // create b and assign it a value
int a => b <+> 3; // create and connect a
                  // using a read-write operator

The results appear in the Network Editor as follows:

Figure G-5


Now, suppose that you reassign the value of a (again, the $print statement displays the value of b):

a = 8; // reassign a the value 8
$print b // check the value of b

The results appear in the Network Editor as follows:

Figure G-6


Observe that in this case, b changes its value to 5 and maintains its connection with a.

Multiple Read-Write Operators

If you use more than one read-write operator in a connection, the operators change the value of the leftmost operand to maintain the connection. Suppose, for example, that you use the following statements to create two objects and connect them using multiple read-write operators:

int b = 2; c = 3; d = 4; // create b, c, and d and
                         // and assign values to them
int a => b <*> c <*> d; // create and connect a using
                        // two read-write operators

The results appear in the Network Editor as follows:

Figure G-7


Now, suppose that you reassign the value of a (the $print statement displays the values of b, c, and d):

a = 37; // reassign a the value 37
$print b // check the value of b
$print c // check the value of c
$print d // check the value of d

The results appear in the Network Editor as follows:

Figure G-8


Observe that only b changes its value to maintain the connection.

Read-Write Modification Operator

The ! operator is the read-write modification operator, which always represents a read-write operation. It is so named because it maintains a connection by modifying its operands.

The Read-Write Operator versus the rdonly Property

The read-only operators take precedence over the rdonly property of a referenced object. For example, suppose that you create two objects and connect them using a read-only operator:

int int1 = 35; // create int1 and assign it a value
int int2 => int1 +5; // create and connect int2
                     // using a read-only operator

The results appear in the Network Editor as follows:

Figure G-9


Now, suppose that you reassign the value of int2:

int2 = 44; // reassign int2 the value 44

The results appear in the Network Editor as follows:

Figure G-10


Observe that the read-only operator breaks the connection in order to maintain the value of int1. However, a different result occurs when you create the same two objects and connect them using a read-write operator, but then set the rdonly property:

int int1 = 35; // create int1 and assign it a value
int int2 => int1 <+> 5; // create and connect int2
                        // using a read-write operator
int1<rdonly=1>; // set the rdonly property of int1
$print int1 // check the value of int1 and
            // verify that rdonly is set to 1

The output of the $print command, following, confirms that the rdonly property is set.

int int1<NEdisplayMode="open",NEx=143.,NEy=44.,rdonly=1> = 35;

The results appear in the Network Editor as follows:

Figure G-11


Now, suppose that you reassign the value of int2:

int2 = 44; // reassign int2 the value 44
$print int1 // recheck the value of int1

The output of the $print command, following, shows that the value of int2 has been changed to 39.

int int1<NEdisplayMode="open",NEx=143.,NEy=44.,rdonly=1> = 39; //new value

The results in the Network Editor confirm the change in value and show that the connection has been maintained:

Figure G-12


You typically create a read-only connection to a mathematical expression so that the connection breaks when you attempt to change the value of the object. This is appropriate because most mathematical expressions are not generally defined in the reverse direction. For example, if you set c to the value of the expression a + b, you cannot then change c because you do not know whether you must change a, b, or both to maintain the expression.

Alternatively, you can construct a dummy mathematical expression such as a + 0. This technique is sometimes useful for making transient one-way connections.

7.5 V Commands

You use V commands to perform special operations such as obtaining information on objects (including V files), setting various types of values, saving and loading projects, testing and debugging, and defining conditional code.

Syntax

A V command has the following syntax:

$command_name_string arg1 ...

In this syntax, command_name_string identifies a particular command and arg1 ... specifies one or more command arguments. Not all V commands require arguments: a few take none, most take one, and some take more than one (for details, see Command Summary on page 7-36). Note that unlike a V statement, a V command is not terminated by a semicolon.

When using V commands, observe the following general rules:

The following sections discuss two special topics relevant to V command usage.

Option-Name Argument

Most V commands take at least one argument, and those that do typically take an object name as one of their arguments. An object-name argument is usually optional and defaults to the current object. In the command descriptions later in this section (see Command Summary on page 7-36), optional arguments are enclosed in brackets; for example:

$print [object].

If you specify a simple object name, the specified object must be a subobject of the current object. However, you can specify a lower-level subobject in one of the following ways:

OM(Root)           -> Applications{
OM(Applications)   ->     SingleWindowApp{
OM(SingleWindowApp)->         higher_group{
OM(higher_group)   ->         $print my_group
group my_group<NEdisplayMode="open",NEx=319.,NEy=55.> {
    int int<NEportLevels=1> = 22;
    float float<NEportLevels=1> = 98.2;
};
In this example, you navigate from the SingleWindowApp object to its higher_group subobject (the parent of my_group), then specify the $print my_group command.
OM(Root)           -> Applications{
OM(Applications)   ->     SingleWindowApp{
OM(SingleWindowApp)-> $print higher_group.my_group
group my_group<NEdisplayMode="open",NEx=319.,NEy=55.> {
    int int<NEportLevels=1> = 22;
    float float<NEportLevels=1> = 98.2;
};
In this example, you remain at the SingleWindowApp object, but specify the command as $print higher_group.my_group.
Redirecting Command Output to a File

You can redirect the output of any command to a file by specifying UNIX-style redirection at the end of the command. The default directory is the directory in which AVS/Express started; however, you specify a different directory using a more explicit path name. For example, the following V command redirects the output of the $save command to the specified file:

$save myapp > myV_dir/myapp.v

The $save command prints an object's V definition; therefore, using $save with redirection saves an object's V definition to a file. This technique is equivalent to selecting Object->Save Objects... in the Network Editor.

Note: This technique works on both UNIX and Windows systems.
Command Summary

This section summarizes V commands. Each of the following sections contains a specific group of commands, as follows:

For reference descriptions of these commands, see the AVS/Express online help.

Command arguments appear in italic type and, if optional, are enclosed in brackets.

Printing Object Definitions
Table G-1
V Command
Description
$print [object]
Prints the definition of the specified object and the changed values, if any, of its subobjects. A subobject's value is considered to be changed if it differs from that of its template.
$dprint [object]
Prints the definition of the specified object and the values of all its subobjects. Unlike $print, $dprint is not restricted to changed values only.
$save [object]
Prints the program state definition of the specified subobject.
$save_usr [object]
Prints the program state and user state definitions of the specified subobject.
$list [object]
Prints the types and names of the specified object's immediate subobjects.
$count_objs [object]
Prints the number of objects defined in the specified object that were created to support its instance. The count includes the object itself but does not include objects inherited from base classes. This count can be less than the number of objects displayed by the $list command.
$array_dims [array_object]
Prints the number of dimensions in the specified array object and the size of each dimension.
$array_size [array_object]
Prints the total number of elements in the specified array object.

Printing Object Values
Table G-2
V Command
Description
$int [object]
Prints the integer value of the specified scalar object.
$float [object]
Prints the value of the specified float-based object.
$double [object]
Prints the value of the specified double-based object.
$real [object]
Prints the value of the specified double- or float-based object.
$str [object]
Prints the string value of the specified object.
$ptr [object]
Prints the hexadecimal version of the specified object's pointer value.
$get_array [array_obj]
Prints the value of the specified array object. The array cannot be an array of group objects.
$get_str_array [array_obj]
Prints the value of the specified string array object.
$get_str_array_val array_obj index
Prints a particular element of the specified string array object, where:
-- array_obj is the name of the array containing the element
-- index is the index number of the array element
Recall that in AVS/Express, index numbering in arrays begins at 0.
$sub_array [array_obj]
Prints the values of a subarray of elements of the specified array object. The array cannot be an array of group objects.
When prompted, enter:
1. The starting and ending indexes of the last (nth) dimension,     separated by a space; for example, 1 1.
2. The starting and ending indexes of the n-1th dimension,     separated by a space; for example, 0 3.
Continue this sequence as required.

Printing and Setting Miscellaneous Object Characteristics
Table G-3
V Command
Description
$get_data_type [object]
Prints the type of the specified primitive data object.
$obj_path [object]
Prints the full path name of the specified object.
$get_obj_att attribute [object]
Prints the setting of a particular attribute of the specified object.
$get_obj_prop property [object]
Prints the setting of a particular property of the specified object.
$user_template [object]
Prints the template name of the specified object.
$set_data_type new_type [object]
Resets the data type of a primitive object to another primitive type.
$set_obj_name [object] new_name
Renames the specified object.
$move [object] new_parent_obj
Moves the specified object to a new location within the object hierarchy. You specify the target parent object.

Printing and Setting Object References
Table G-4
V Command
Description
$link [object1] object2
Creates a connection in the object specified as object1 so that it references the object specified as object2.
$obj_pval [object]
Prints the name and relative path of the (upstream) object that the specified object references.
$obj_val [object]
Prints the name and full path (starting at Root.Applications) of the (upstream) object that the specified object references.
$obj_ref [object]
Prints the full path name of the object at the end of a chain of references to which the specified object is connected. This command skips over intermediate name-link objects.
$get_array_ref [object]
For an array of references, prints the full path names of objects connected to the specified array object. If object is connected to a multioperand expression, this command returns nothing.
$refcnt [object]
Prints the number of references to the specified object, including the object itself; that is, the count is equal to num_of_refs+1.
$refs_to [object]
Prints the names of objects that reference the specified object.

Saving and Loading Projects
Table G-5
V Command
Description
$save_project [proj_dir]
Saves the current project to the specified (or default) project directory. This command is equivalent to the Project->Save command in the Network Editor.
Note: Avoid using this method to save your template objects. Instead, save the libraries that contain them. For more information, see Templates and Library Objects on page 5-11.
$save_project_as proj_dir
Saves the current project to the specified new project directory. This command is equivalent to the Project->Save As... command in the Network Editor.
$save_compiled_project [-option] [proj_dir][object1] ... [objectn]
Saves a compiled project to a particular project directory, using the specified object(s) and one or more of the following options:
    -build: save and compile the project.
    -no_inst: do not instance the object when it is restored.
    -ne: include the Network Editor in the project.
    -into_exec: build the binary V definition file into the         executable.
    -save_usr: save the current user interface settings.
This command is equivalent to the Project->Save Compiled Project... command in the Network Editor.

Testing and Debugging Applications
Table G-6
V Command
Description
$cur_seq
Prints the current sequence number.
$obj_seq [object]
Prints the highest sequence number from those for the following:
-- the specified object
-- objects connected to the specified object
-- subobjects of the specified object
-- objects connected to subobjects of the specified object
If a connection is to a chain of references, $obj_seq traces the chain of references and determines the highest sequence number in the chain.
$obj_seq_base [object]
Prints the sequence number of the specified object. This command does not consider connections or subobjects.
$obj_seq_ptrs [object]
Prints the highest sequence number from those for the following:
-- the specified object
-- objects connected to the specified object
This command does not consider subobjects.
$obj_id [object]
Prints the specified object's ID and the ID of the process in which it executes.
$obj_proc [object]
Prints the ID of the process in which the specified object executes.
$echo string
Prints the specified string. The string does not have enclosing quotes.
$match [downstream_obj] upstream_obj
Tests whether the specified upstream object is a possible match in order for the specified downstream object to reference it.
$ematch [downstream_obj] upstream_obj
Tests whether the specified upstream object is an exact match in order for the specified downstream object to reference it.
$notify [object]
Lists notifications on the specified object. A notification contains a list of events that a method requested on an object.
$deps [method_obj]
Lists dependencies for the specified method object.
$resolve [object]
Resolves object references to the specified object by verifying if forward references have been defined.
$set_trace ops_list
Sets the trace option for the specified Object Manager operations.
$unset_trace ops_list
Clears the trace option for the specified Object Manager operations.
$set_arr_trace ops_list
Sets the trace option for the specified Object Manager array operations.
$set_verbose ops_list
Sets the verbose option for the specified Object Manager operations.
$unset_verbose ops_list
Clears the verbose option for the specified Object Manager operations.
$valid [object]
Determines whether the specified object has a valid value.
$timer_start
Sets or resets the timer to 0.
$timer_get
Prints the number of seconds that have elapsed since the timer was last reset by $timer_start.

Controlling Method Execution Order
Table G-7
V Command
Description
$pause
Suspends execution until the user presses the Enter key.
$push [-exe_state]
Delays delivery of events until the $pop command is invoked. The -exe_state argument specifies the execution state for the scope of the command. The allowed values are as follows:
-- prog: program state (the default)
-- usr: user state
-- trn: transient state
$pop
Ends the most recent $push command and delivers the delayed events.
$include v_file
Includes the specified V file in the current object. The v_file argument can be a full or relative path name.

Making Code Conditional
Table G-8
V Command
Description
#define symbol
Defines a symbol that can be used in a #ifdef statement. The symbol argument is an unquoted string.
#undef symbol
Undefines a previously defined symbol.
#ifdef symbol
Begins a conditional block of V code. The symbol argument specifies a symbol that AVS/Express uses to determine whether whether it should recognize the code in the #ifdef block when it parses the ifdef block.
-- If the symbol was previously defined using #define,     AVS/Express recognizes the code.
-- If the symbol was not defined, AVS/Express ignores the code.
#else
Switches the state of a previous #ifdef command.
#endif
Ends a conditional block of V code.

Miscellaneous V Commands
Table G-9
V Command
Description
$help [format]
Prints help information as specified by the format argument. The allowed values are as follows:
-- all: print help on all V commands
-- v_cmd: print help on all commands that contain the v_cmd     string
-- summary: print summarized help on all V commands
-- summary v_cmd: print summarized help on all commands     that contain the v_cmd string
$open [object]
Parses the V code for the specified buffered object. You use this command on an object whose buffered attribute is set (this attribute causes AVS/Express to defer parsing the object's V code).
In the Network Editor, a buffered object name appears in parentheses; select the object to cause AVS/Express to parse its V code.
For information on using the buffered attribute, see Defining a Buffered Library on page 5-18.
$quit
Exits AVS/Express. This command causes the main AVS/Express process to exit even if the VCP is running in a different process.
$local_quit
Exits only the process that is running the VCP.
$compile [object]
Compiles the specified object's process. You must specify either a template object or one of the process objects in the ProcTemplates object (which is defined in the proc.v file). This command is equivalent to the Project -> Compile command in the Network Editor.
$generate [object]
Generates code for the specified object. This command is the same as the $compile command except that it only generates any required source for the object. It does not perform a make on the resulting makefile.
$type [type]
Prints the AVS/Express base types.
$server_info
Prints information about the Object Manager's server. This information enables you to allow another process to connect to this server process in either of the following ways:
-- Set the following environment variables:
    -- OM_BOSS: the local socket id for the server process
    -- OM_BOSS_2: the socket id to use for remote connections
    -- OM_ROOT_OBJ: the id of the root object to use
-- Use the -client command line option
$shell shell_cmd
Executes the specified shell command (the shell command can include arguments).
$set_file_env env_var
Makes an environment variable accessible as an AVS/Express file variable. AVS/Express resolves the definition of file variables whenever it opens a V file or a data file.
$setenv ENV_VAR [value]
Assigns the specified value to a particular environment variable. By convention, you must specify ENV_VAR in uppercase letters.
The value argument can be a single word or a string. If you do not specify a value, the command assigns the null value.

7.6 V Functions

This section describes V functions (also called built-in functions). Each of the following sections contains a specific group of commands, as follows:

Each V function takes one or more arguments (shown in italics) and returns a value. You can use V functions in either the VCP window or a V file.

Note: In the examples that appear in some function descriptions, the OM prompt is shown as -> and intevening spaces between the prompt and V code have been removed, in order to improve readability. However, relative levels of indentation have been maintained.
Mathematical Functions

Mathematical functions operate on any numeric data type. They return the appropriate data type, performing any necessary data-type conversion. When using a mathematical function in a value expression, note the following:

AVS/Express supports the following mathematical functions in V code:

Table G-1
Mathematical Function
Description
abs(num)
Returns the absolute value of num, where num is any valid numeric expression.
acos(angle)
Returns the arc cosine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
add(addend1,addend2,...)
Returns sum, where sum is calculated as:
     sum = addend1 + addend2 + ...
In this function, addend1, addend2, ... are any valid numeric expressions.
asin(angle)
Returns the arc sine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
atan(angle)
Returns the arc tangent of angle, where angle is any valid numeric expression representing an angle measurement in radians.
cos(angle)
Returns the cosine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
cosh(angle)
Returns the hyperbolic cosine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
deviation(array)
Returns the standard deviation of the elements of the the specified array. The array elements must be numeric types.
divide(dividend,divisor1,divisor2,...)
Returns quotient, where quotient is calculated as:
     quotient =  dividend / divisor / divisor2 / ...
In this function, dividend, divisor1, divisor2, ... are any valid numeric expressions.
exp(x)
Returns ex; that is, e (the natural logarithmic base) raised to the xth power.
log(x)
Returns the natural (base e) logarithm of x.
log10(x)
Returns the common (base 10) logarithm of x.
modulo(num1,num2,...)
Returns the result of the modulus operation, calculated as follows:
     result =  num1 % num2 % ...
In this function, arg1, arg2, ... are any valid numeric expressions.
multiply(factor1,factor2,...)
Returns product, where product is calculated as follows:
     product =  factor1 * factor2 * ...
In this function, factor1, factor2, ... are any valid numeric expressions.
pow(x, y)
Returns x y; that is, x raised to the yth power.
rand(range, seed)
Returns a random scalar value or an array of values between 0 and range. If you do not specify a seed argument, the function uses the object ID of the rand object as its seed.
sin(angle)
Returns the sine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
sinh(angle)
Returns the hyperbolic sine of angle, where angle is any valid numeric expression representing an angle measurement in radians.
sqrt(x)
Returns the square root of x, where x is any valid numeric expressions.
strcmp(str1,str2)
Returns a value that indicates the result comparing str1 and str2, where str1, str2 are any string values:
-- Returns 0 if the strings are equivalent.
-- Returns a nonzero value f the strings are not     equivalent.
strlen(str)
Returns the length of str, where str is any string value.
sub(minuend,subtrahend1,subtrahend2,...)
Returns diff, where diff is calculated as follows:
     diff =  minuend - subtrahend1 - subtrahend2 - ...
In this function, minuend, subtrahend1, subtrahend2, ... are any valid numeric expressions.
tan(angle)
Returns the tangent of angle, where angle is any valid numeric expression representing an angle measurement in radians.
tanh(angle)
Returns the hyperbolic tangent of angle, where angle is any valid numeric expression representing an angle measurement in radians.

Logical Functions

AVS/Express supports these logical functions in V code:

Table G-2
Logical Function
Description
and(arg1,arg2,...)
Returns the result of the logical and operation, calculated in C notation as follows:
      arg1 && arg2 && ...
or(arg1,arg2,...)
Returns the result of the logical or operation, calculated in C notation as follows:
    arg1 || arg2| | ..
xor(arg1,arg2,...)
Returns the result of the exclusive or operation, calculated as follows:
    ((arg1 ^ arg2) ^ ...)

Array Functions

When using an array function, note the following:

AVS/Express supports the following array functions in V code:

Table G-3
Array Function
Description
array_size(array)
Returns the total number of elements in the specified array object.
array_dims(array)
Returns a one-dimensional array containing the dimensions of the specified array object.
For example, suppose that you define an array as follows:
int my_arr[2][3][4];
The value of array_dims(my_arr) is {2,3,4}.
combine_array(array1,array2,...)
Combines the specified array objects into a single array and returns that array. For details and examples, see The combine_array Function on page 7-52.
concat_array(array1,array2, ...)
Concatenates the specified array objects into a single array whose dimensions are equal to the sum of the dimensions of all of the source arrays, and returns that array.
index_of(array)
Returns the index of the current object in the array of groups specified by the input array object. The current object must be in a group in the array of groups specified by arr. This function is useful for connecting objects in two parallel arrays of groups.
init_array(size,start,end)
Returns a one-dimensional array of size elements whose values range from start to end, in ascending order. The size argument must be an integer.
magnitude(array)
Returns an array containing the magnitude of each column in the specified array object. (The magnitude is the square root of the sum of squares.) The returned array is an n-1 dimension array, where n is the number of dimensions in arr.
max_array(array, flag, null_val)
Returns a one-dimensional array of the maximum value in each column in the specified array object. You specify the optional flag and null_val arguments only if the array contains null values. In this case:
-- Set flag to 1 to indicate that the function should ignore null     values.
-- Set null_val to the number that represents a null value.
By default, the value of the flag argument is 0, to indicate that the function operates on all array values.
min_array(array, flag, null_val)
Returns a one-dimensional array of the minimum value in each column in the specified array object. You specify the optional flag and null_val arguments only if the array contains null values. In this case:
-- Set flag to 1 to indicate that the function should ignore null     values.
-- Set null_val to the number that represents a null value.
By default, the value of the flag argument is 0, to indicate that the function operates on all array values.
prod(array1,array2,...)
Returns the product of all of the elements in the specified array objects.
str_array(string_obj,delimiter)
Returns an array of strings that are obtained by splitting the specified string object into pieces delimited by the first character of the string value of the delimiter argument.
For example:
-> string a = "One;Two;Three";
-> string b[3] = str_array(a, ";");
-> $print b
string b[3] = {"One","Two","Three"};

sum(array1, ..., arrayn)
Returns the sum of all of the elements in all of the specified array objects, calculated as follows:
    array1[0] + ... + array1[m] + ... + arrayn[0] + ... arrayn[m]
The array objects must have numerical elements. You cannot use sum() for string arrays.
sum_array(array)
Returns an array defined as follows:
-- It has the same number of elements as the specified array     object.
-- Each of the array elements is the sum of the preceeding     elements in the specified array object.
Each element in the result array is calculated as follows:
    result_array[n] = array[0]+array[1]+...array[n]
This produces the following result array:
    result_array[] = {array[0],
                                 array[0]+array[1],
                                 ... ,
                                 array[0]+array[1]+...array[n-1]+array[n]}

The combine_array Function

The combine_array(arr1,arr2,...) function performs a complex operation that requires some special discussion and examples. It combines the elements of the specified array objects into a single array object. In order to accomplish this:

This function returns an n-dimensional array, where the size of the first n-1 dimensions is the same as the source arrays and the size of the nth dimension is the sum of the sizes of the source arrays' nth dimensions.

For example, suppose that you have two arrays defined as follows:

int arr1[n][m][x];
int arr2[n][m][y];

Invoking combine_array(arr1,arr2) returns an array having the following size:

int result_arr[n][m][x+y];

The following more specific example uses V code in a VCP window to create two arrays, combine them, and then display the result (note that the OM command prompt is shown only as -> for readability):

-> int arr1[1][2][3] = {1,2,3,4,5,6};
-> int arr2[1][2][4] = {11,22,33,44,55,66,77,88};
-> int combined[1][2][7] = combine_array(arr1,arr2);
-> $get_array combined
{
{{1,2,3,11,22,33,44},{4,5,6,55,66,77,88}}
}

Miscellaneous Functions

AVS/Express supports the following miscellaneous functions in V code.

Table G-4
Miscellaneous Function
Description
cache(expr)
Caches the result of the enclosed expression so that AVS/Express recomputes it only if objects referenced in the expression change. By default, if an object is connected to an expression, AVS/Express recomputes the expression whenever the object's value is requested. Caching involves a tradeoff between the time required to recompute the expression and the space required to cache the result.
Suppose, for example, that you use the following V code to define a group whose method creates a large array of float data (stored in a subobject called out) and an object called max that you connect to the maximum value of out:
-> group create_data {
->     float+write out[];
->     method_upd func = "create_data";
->     };
-> float max => max_array(out);

By default, AVS/Express recomputes the expression max_array(out) every time you request the value of max, even if the value of out has not changed. To prevent recomputing, use the cache function as follows:
-> float max => cache(max_array(out));
data_type_of(object)
Returns the text-string name of the specified object; for example, the string float.
getenv(env_var_name)
Returns the value of the specified environment variable.
index_of(grp_array)
Returns the current index of an array of groups. This function is useful in the value expression for a subobject of the array of groups; for example:
-> group foo[3] {
->     int a=> index_of(foo);
->     };
-> !foo[0] {
->     $int a
0
->     };
-> !foo[1] {
->     $int a
1
->     };

is_valid(object)
Returns 1 to indicate that the specified object has a valid value and 0 to indicate that it is unset.
merge(grp1, grp2, ...)
Returns a group object consisting of the merged subobjects of grp1, grp2, .... Unlike the merge + (merge-plus) operator, which performs a static merge, the merge() function maintains a reference to grp1 and grp2 so that any changes to these objects are reflected in the newly defined group object. You can only reference the result of merge(); you cannot assign it to a group object.
If subobjects of the same name exist in more than one object argument, merge() uses the subobject found in the first object in the argument list; for example:
-> group a {
->     int sub1 = 10, sub2 = 20;
->     };
-> group b {
->     int sub2 = 30, sub3 = 40;
->     };
-> group &c => merge(a,b);
-> c {
->     $print sub1
int sub1 = 10;
->     $print sub2
int sub2 = 20;
->     $print sub3
int sub3 = 40
->     };

name_of(object)
Returns a string that contains the name of the object. For example:
-> group grp1 {
->     string str1 => name_of(<-);
->     $str str1
grp1
->     };

num_subobjs(object)
Returns the number of subobjects in the specified object.
str_format(printf_fmt)
Provides string formatting functionality like that of the standard C routine printf. The printf_fmt argument, a string defined in the same way as the format parameter to printf, contains the following:
"[string] %[field1].[prec1][conv1] %[field2].[prec2][conv2]",[value1],[value2]
In this syntax, field is the field width, prec is the precision, conv is the conversion character, and the nth value corresponds to the nth conversion character. The data type of the value is determined by the following conversion characters:
-- Integer data type: d, i, o, u, x, X
-- Real data type: e, E, f, g, G
-- String data type: s
-- Pointer data type: p
If any value is an array, str_format() provides an array of strings and applies the format string to each value in the array individually. Otherwise, this function returns a scalar string value.
This function does not interpret the %n$ syntax of the printf function.
Here are some examples:
-> string str1 = str_format("print this: %5d ",3);
-> $print str1
string str1 = "print this:    3 ";

-> string arr1[] => str_format("%10.3f",{1.2345,2.34,4.56});
-> string arr2[3] = arr1;
-> $print arr2
string arr2[3] = {"     1.234",
   "     2.340","     4.560"};

switch(index, arg1, arg2,...)
Returns the argument specified by the value of the index argument; that is, if index is 1, switch() returns arg1, if index is 2, switch returns arg2, and so on. If index is either 0 or greater than the total number of arguments, the function returns a null value.
Use the specified format to call this function inline. Alternatively, you can use switch() as a primitive, in which case its first subobject specifies the index and subsequent subobjects specify the arguments. For example:
-> int i;
-> switch x {
->     int index => i;
->     int val1 = 10;
->     int val2 = 20;
->     };
-> int result => x;

In this format, the value of the switch function is available for use later in the application.


TOC PREV NEXT INDEX