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

ROUTINE
(Requires GHS version 18.50 or later)

New in GHS 18.50, the ROUTINE command is a major addition to the command language. ROUTINE is like SUBROUTINE, FUNCTION, and PROCEDURE in other languages.

GHS/BHS users with current maintenance/support will be receiving version 18.50 starting next week.

Advantages to using the ROUTINE structure include:
  • Macro and variable definitions within the scope of a ROUTINE are local, meaning there is no conflict with like-named variables and macros outside of the ROUTINE.

  • Variables and macros outside of a ROUTINE are accessible by a suitable prefix, which makes the reference unambiguous.

  • Unlike the MACRO, when defining a ROUTINE you name its parameters, and the names are recognized within the ROUTINE.

  • The IF statements within a ROUTINE are expressed in block format, which facilitates nested IFs and improves readability.

  • Similarly, LOOP is a blocked structure facilitating nested loops. The loop continues to cycle until the EXIT statement is encountered.

  • ROUTINES may be called as subroutines or functions.

  • Variables may be passed to a ROUTINE as a value or as a variable reference.
Below is an example of a ROUTINE which demonstrates the nested LOOP feature.

ROUTINE WindReport (AxisRange; AxisIncrement; HeelRange; HeelIncrement)
 
  VARIABLE h=0, a=0
  VARIABLE (STR) plotlabel, plotline
 
  MACRO plotline
   plotline:="{plotline},%1"
  /
  MACRO plotlabel
   plotlabel:=""{plotlabel}",""heel=%1"""
  /
  plotlabel:="Axis"
  .plotlabel (HeelRange/HeelIncrement+1,HeelIncrement) 0
   ME PLOTSTART "Rig Heeling Moments" /POLAR
   ME PLOTLABEL {plotlabel}
 
   LOOP
     HEEL 0
     AXIS {a}
     h:=0
     plotline:="{a}"
     LOOP
       HEEL {h}
       TRIM 0
       SOLVE DEPTH
       .plotline {.HMMT}
       h:=h+HeelIncrement
       IF h>HeelRange THEN
         EXIT
       END
     END
     ME {plotline}
     a:=a+AxisIncrement
     IF a>AxisRange THEN
       EXIT
     END
   END
 
   ME PLOTEND
END WindReport
 
WindReport(360,15, 90,15)




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