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

Expressions
(Requires GHS version 17.30 or later)

The GHS Command Language is not an accessory or an afterthought. It is essential to the software product and the prime reason for its success.

In fact, some GHS features are written in the Command Language. The Rig Wizard is an example. Much of probabilistic stability is written in the Command Language. The Load Monitor (GLM) is configured by means of the Command Language.

There is a sense in which the GHS Command Language is the "front end" or the native user interface, because after seeing what it can do (either on their own or in a training class), most users are comfortable writing command language Run files even though other means of running the program are available.

Arithmetic expressions are rarely needed, but the capability is there for "power users" who want to add their calculations.

The COW from a couple weeks ago included code for a perpetual calendar copied from the original COW on templates of several years ago. Typical of its arithmetic expressions is the following macro, which determines whether the value in the variable "y" (the year) is divisible by a given number:

 macro isdiv
  set j={y} div %1
  set j=trunc {j}
  set j={j} times %1
  if {j}<>{y} then set j=0
 /

There is a way to write this macro without using the SET command that is more compact:

 macro isdiv
  j:=trunc(y/%1)*%1
  if {j}<>{y} then j:=0 else j:=1
 /

or to reduce it down to one line,

 macro isdiv
  if {trunc(y/%1)*%1}<>{y} then j:=0 else j:=1
 /

But within a TEMPLATE command, the traditional SET must still be used. Although within the scope of a TEMPLATE command there is no provision for arithmetical statements, there may be SET statements within EXPAND macros.

An example of this is in the Calendar code where the template that displays the month uses EXPAND macros.

The EXPAND macro provides additional lines in the template, so it is very unlike regular macros. But it may include a limited amount of arithmetic code similar to what appears in regular macros.

Something else to note about the template in the calendar code is that it is defined within a macro. This is done so that the title shown in the template may be changed. (We want the title to express the year and month.)

Below is a version of the MONTH macro/template along with its expand macros WEEK and DAY. Note the SET commands that manipulate the variables n, c, and s:

 macro month
  template montht "{month}-{y}" /size:large /gap:9 /bg=15
   "S"/r/color=4|"M"/r|"T"/r|"W"/r|"T"/r|"F"/r|"S"/r
   expand week (6,7) {day1}, {days}
   break
  "Prior month" exit priormonth | "Next Month" exit nextmonth
  exit
  //
 exit month
 /
 macro week
  set n=7
  if %1>%2 then set n=0
  set c=4
  expand day ({n},1) %1, %2
  " "
 /
 macro day
  set s="%1"
  if %1<1 then set s=" "
  if %1>%2 then set s=""
  "{s}" /color:{c} /right |
  set c=0
 /

A rewritten calendar code is available here. If you change the filename extension from TXT to WIZ and place it in your GHS program folder, it will appear as one of the wizards in the "All" category.

This wizard is in plain text, and may be edited. For example you may add to the special day list at the beginning. If you want to expand your knowledge of the GHS command language it is worth studying as an example.


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