General HydroStatics
Ship Stability Software
Command of the Week
(New or interesting aspects of GHS that you may not know about)

VARIABLE computations
(Requires GHS version 17.30 or later)

GHS has always been a computational powerhouse, providing full calculation features via the SET command (as seen in COW146, COW154, and COW156). For example, to compute the distance between two points (X1,Y1,Z1) and (X2,Y2,Z2), you could use these commands:

SET DISTANCE = {Z2} MINUS {Z1} POWER 2
SET DISTANCE = {Y2} MINUS {Y1} POWER 2 PLUS {DISTANCE}
SET DISTANCE = {X2} MINUS {X1} POWER 2 PLUS {DISTANCE}
SET DISTANCE = SQRT {DISTANCE}

Now in the latest greatest GHS, that computation can be done in a single line:

SET DISTANCE = {((X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2)) ^0.5}

But wait, there's more: these new computations can be performed anywhere in GHS, not just in SET commands!!

So if you only need to do some quick math, like adding Draft1 to DraftInc after collecting these variable values from a TEMPLATE dialog, that's now easy... without having to declare and SET an extra VARIABLE:

GHS {Draft1} {Draft1+DraftInc} ... {DraftEnd}

Likewise, it's easy to subtract 1 from an array index variable using {index-1}. But beware: operators are allowed inside variable names, so it's possible a variable named "index-1" already exists! If so, then {index-1} just fetches its value instead of computing {index} minus 1.

It's probably best practice going forward not to put operators inside variable names, separating words by using underscores ("_") instead of dashes ("-"). Any ambiguity can always be resolved by wrapping braces around an inner variable name, such as {{index}-1} in this case.

Whereas SET commands perform operations from left to right, computations inside braces obey the PEMDAS (Parentheses, Exponent, Multiply and Divide, Add and Subtract) order of operations. So if A=1, B=2, and C=3, then {A+B*C} computes to 7 not 9, since multiplication of B*C takes precedence over addition of A+B. Just remember, "Please Excuse My Dear Aunt Sally!"

Questions, comments, or requests?
Contact Creative Systems, Inc.

support@ghsport.com

USA phone: 360-385-6212 Fax: 360-385-6213
Office hours: 7:00 am - 4:00 pm Pacific Time, Monday - Friday

Mailing address:
PO Box 1910
Port Townsend, WA 98368 USA

www.ghsport.com

Click here for an index to this and previous COWs