Script Operators

Top  Previous  Next

The operators available in FreeFlyer can be broken up into assignment operators, mathematical operators, logical operators, and String operators. For more information, be sure to see the Matrix, Array, and Variable Math and Flow Control pages.

 

 

Assignment Operators


The assignment and increment operators can be used with Variables, Arrays, and Matrices. The examples in the table below use the following objects:

 

Variable v1;

Variable v2;

 

The following assignment and increment operators are available in FreeFlyer:

 

Operator

Description

Examples

Meaning

=

Assignment

v1 = v2;

v1 = v2;

:=

Reference Assignment

v1 := v2;

v1 now references the same object as v2

++

Increment

v1++;

v1 = v1 + 1;

--

Decrement

v1--;

v1 = v1 - 1;

+=

Addition Assignment

v1 += v2;

v1 = v1 + v2;

-=

Subtraction Assignment

v1 -= v2;

v1 = v1 - v2;

*=

Multiplication Assignment

v1 *= v2;

v1 = v1 * v2;

/=

Division Assignment

v1 /= v2;

v1 = v1 / v2;

^=

Exponent Assignment

v1 ^= v2;

v1 = v1 ^ v2;

%=

Modulus Assignment

v1 %= v2;

v1 = v1 % v2;

 

Reference Assignment

When something like a Variable declaration is presented elsewhere in the FreeFlyer help documentation, the discussion is specifically referring to the object itself. In this section, there will be a clear delineation between something being an object and something being a reference. Given the advanced nature of this topic, it's recommended that you completely understand Working with Objects before trying to understand references and reference assignments.

 

When you declare an object, such as a Variable, you're also declaring a reference. Consider the following script.

 

Variable v1;

 

In the above script, you're declaring a Variable object as well as configuring a reference to that object by the name of 'v1'. Whenever you use 'v1' elsewhere in your script after this point, you're telling FreeFlyer that you want to use the Variable object referred to by the 'v1' reference. You might think on the surface that there's no difference between the reference and the object, but once you get into reference assignments you will realize that you need to treat them differently. Now consider the following script that uses a reference assignment.

 

Variable v1;

Variable v2;

v1 := v2; // v1 now refers to the same object as v2

 

In this example, you've declared two objects and configured two references, but then you set the reference v1 to point to the same object as the reference v2. If this were the only script in your Mission Plan, you'd no longer have any references pointing to the object initially declared alongside v1 and that object will get garbage collected as nothing refers to it any longer. This should help clarify the difference between a reference and an object, and alongside reference assignments allows you to achieve some powerful results in your Mission Plans.

 

Note: The Object.ReferenceEquals() method can be used to check whether two references refer to the same object.

 

Further Examples

 

 

Mathematical Operators


The examples in the table below use the following objects:

 

Variable v1;

Variable v2;

Array a1;

Array a2;

Array a3;

Matrix m1;

Matrix m2;

Matrix m3;

Spacecraft Spacecraft1;

 

The following mathematical operators are available in FreeFlyer:

 

Operator

Description

Examples

+

Addition

v1 = Spacecraft1.A + v2;

Element-by-scalar addition

a1 = v1 + a2;

m1 = v1 + m2;

Element-by-element addition

a1 = a2 + a3;

m1 = m2 + m3;

-

Subtraction

v1 = Spacecraft1.A – v2;

Element-by-scalar subtraction

a1 = v1 - a2;

m1 = v1 - m2;

Element-by-element subtraction

a1 = a2 - a3;

m1 = m2 - m3;

*

Multiplication

v1 = Spacecraft1.A * v2;

Element-by-scalar multiplication

a1 = v1 * a2;

m1 = v1 * m2;

Matrix multiplication

m1 = m2 * m3;

Element-by-element multiplication

a1 = a2 * a3;

**

Element-by-element multiplication

m1 = m2 ** m3;

/

Division

v1 = Spacecraft1.A / v2;

Element-by-scalar division

a1 = v1 / a2;

m1 = m2 / v1;

Element-by-element division

a1 = a2 / a3;

Matrix division (equivalent to multiplying by the matrix inverse)

m1 = m2 / m3;

m1 = v1 / m2;

\\

Element-by-element division

m1 = m2 \\ m3;

^

Exponent

v1 = Spacecraft1.A^v2;

m1 = m2 ^ v1;

Element-by-scalar exponent

a1 = a2 ^ v1;

Element-by-element exponent

a1 = a2 ^ a3;

m1 = m2 ^ m3;

^^

Element-by-scalar exponent

m1 = m2 ^^ v1;

%

Modulus

v1 = (Spacecraft1.W + Spacecraft1.TA)%360;

Element-by-scalar modulus

a1 = a2 % v1;

m1 = m2 % v1;

Element-by-element modulus

a1 = a2 % a3;

m1 = m2 % m3;

 

 

Literal Operators


The literal operators described below can be used to conveniently create literal Array or Matrix objects in FreeFlyer script. See the Matrix, Array, and Variable Math page for more information. The examples in the table below use the following objects:

 

Array arr1;

Matrix m1;

Vector vec1;

CoordinateSystem cs1;

Spacecraft Spacecraft1;

 

FreeFlyer supports the following literal operators:

 

Operator

Description

Examples

{ }

Converts the specified argument to an Array

arr1 = {vec1};

arr1 = {m1};

[ ]

Converts the specified argument to a Matrix

m1 = [arr1];

m1 = [vec1];

m1 = [cs1];

 

 

Logical Operators


The logical operators described below can be used in conjunction with the While and If statements. Nested Flow Control loops can be used to test and handle complex decisions. It is possible to test for multiple logical conditions in a single Flow Control statement by using the logical operators “and” or "or”. The examples in the table below use the following objects.

 

Variable v1;

Variable v2;

Array a1;

Array a2;

Array a3;

Matrix m1;

Matrix m2;

Matrix m3;

Spacecraft Spacecraft1;

 

FreeFlyer supports the following logical operators.

 

Operator

Description

Examples

()

Parentheses

Used to group logical statements

==

Equal

If (Spacecraft1.ElapsedTime == TIMESPAN(1 days));

  Report Spacecraft1.ElapsedTime.ToDays();

End;

Element-by-element comparison

a1 = a2 == a3;

m1 = m2 == m3;

a1 = a2 == v1;

m1 = m2 == v1;

a1.IsEqualTo(a2);

m1.IsEqualTo(m2);

Object.ReferenceEquals()

Checks whether the calling object refers to the argument object

v1.ReferenceEquals(v2);

<

Less than

If (Spacecraft1.ElapsedTime < TIMESPAN(1 days));

  Step Spacecraft1;

End;

Element-by-element comparison

a1 = a2 < a3;

m1 = m2 < m3;

a1 = a2 < v1;

m1 = m2 < v1;

>

Greater than

If (Spacecraft1.ElapsedTime > TIMESPAN(1 days));

  Step Spacecraft1 to (Spacecraft1.AscendingNode);

End;

Element-by-element comparison

a1 = a2 > a3;

m1 = m2 > m3;

a1 = a2 > v1;

m1 = m2 > v1;

<=

Less than or equal to

If (Spacecraft1.ElapsedTime <= TIMESPAN(1 days));

  Step Spacecraft1;

End;

Element-by-element comparison

a1 = a2 <= a3;

m1 = m2 <= m3;

a1 = a2 <= v1;

m1 = m2 <= v1;

>=

Greater than or equal to

If (Spacecraft1.ElapsedTime >= TIMESPAN(1 days));

  Report Spacecraft1.Height;

End;

Element-by-element comparison

a1 = a2 >= a3;

m1 = m2 >= m3;

a1 = a2 >= v1;

m1 = m2 >= v1;

and

Logical AND

If (Spacecraft1.ElapsedTime < TIMESPAN(5 days) and Spacecraft1.ElapsedTime > TIMESPAN(3 days));

  Step Spacecraft1;

End;

Element-by-element Boolean AND

a1 = a2 and a3;

m1 = m2 and m3;

a1 = a2 and v1;

m1 = m2 and v1;

!=

Logical NOT

If (Spacecraft1.ElapsedTime != TIMESPAN(1 days));

  Stop;

End;

Element-by-element comparison

a1 = a2 != a3;

m1 = m2 != m3;

a1 = a2 != v1;

m1 = m2 != v1;

!

Boolean NOT

If v1 is 0, this conditional statement evaluates to true, otherwise this conditional statement evaluates to false.

If(!v1 == 1);

   Stop;

End;

Element-by-element Boolean NOT

v1 = !v2;

a1 = !a2;

m1 = !m2;

or

Logical OR

If (Spacecraft1.ElapsedTime < TIMESPAN(5 days) or Spacecraft1.A > 6800);

  Step Spacecraft1;

End;

Element-by-element Boolean OR

a1 = a2 or a3;

m1 = m2 or m3;

a1 = a2 or v1;

m1 = m2 or v1;

IsType

Is of the specified object type

If (Spacecraft1.Propagator IsType RK89);
    (Spacecraft1.Propagator AsType RK89).Tolerance = 1e-9;
End;

 

Compound Boolean Statements

Compound Boolean statements containing multiple operators are often used in If and While commands. Boolean expressions now follow standard order of operations. Consider the following script:
 

Create Variable v = 0;
 
If(v == 0 or v == 0 and v == 1);
  Watch v;
End;

 

Previous to FreeFlyer 6.5, Boolean expressions evaluated left to right. In the script above, this leads to a grouping like:

(v == 0 or v == 0) and v == 1

 

In FreeFlyer 6.5 and higher, the and operator takes precedence over the or operator leading to a grouping like:

v == 0 or (v == 0 and v == 1)

 

In the example given, the expression evaluates to true in FreeFlyer 6.5, but false in previous versions. In FreeFlyer 6.5 and higher, you can also use parentheses to group expressions and explicitly specify the order of evaluation you desire.

 

 

String Operators


There are a number of String-specific operators that are unique in how they are evaluated. None of the boolean-returning operators below can be used in-line in conditional statements as they all return an Array of boolean values. The examples in the table use the following objects.

 

Array ar1;

String s1;

StringArray sa1;

StringArray sa2;

StringArray sa3;

 

FreeFlyer supports the following String operators.

 

Operator

Description

Examples

+

Concatenation

sa2 = sa1 + s1

Element-by-element concatenation

sa3 = sa1 + sa2

==

Equals

ar1 = sa1 == s1

Element-by-element equals

ar1 = sa1 == sa2

!=

Not equals

ar1 = sa1 != s1

Element-by-element not equals

ar1 = sa1 != sa2

 

 

See Also


Matrix, Array, and Variable Math

Flow Control

Parsing Arbitrary String Data