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


GHS is famous for putting programming power in the hands of its users.

It may be said that the loop is the essence of the computer's power; virtually every program makes use of loops. So it would be strange if the GHS command language did not provide for loops. It's true that there is no LOOP command, but there is the EXIT command.

Whenever you find yourself doing something repeatedly, it's time to ask yourself if you would like the computer to do the repeating for you. You are a rare individual if you like writing almost the same thing over and over again and you can do it without making more and more mistakes. It's called boredom. Fortunately for us, computers never get bored. They love repetition. That's why artificial intelligence is artificial. So make your computer happy and feed it loops!

When you write a run file, the way you identify a loop opportunity is by simply developing a distaste for duplication. Wherever there is similarity there is duplication to some degree, and if you can distinguish the differences from the sameness, then you have taken the first step toward designing a loop. If you can rewrite a portion of code in a more general form that depends on variables—and make it serve in place of two or more similar portions of code—you have taken the essential step in making a loop: you have generalized a group of commands. Now wrap them in a macro-command structure and you have something that's easily executed repeatedly and automatically.

Let's observe as a hypothetical GHS user evolves a loop.

She knows about macros, and being a very organized person, she has put together a series of load cases with each one being in a macro, their names being LOAD1, LOAD2, etc. Nine of them altogether. Since the stability calculation to be performed with each loading case is the same, her final commands are a series of macro-command executions:


That's as far as she gets because she realizes that if a macro could only insert the load case number, then one macro could serve all of her nine cases. She checks the GHS manual; and sure enough, you can vary the effective contents of a macro by means of a parameter that can be different each time the macro is executed. She decides to name it CASE:


Now it takes only one command to do each case:

 .CASE 1
 .CASE 2

Again she stops and wonders why she is writing almost the same thing repeatedly. She notices in the MACRO documentation that there is a way to automatically execute a macro repeatedly and at the same time have it run through a series of values for the parameter. So she tries it—nine commands replaced by one—and it works!

 .CASE (9,1) 1

It would have been almost a loop if she had written out the entire series of CASE executions, but this is certainly worthy of being called a loop.

Like some of the other naval architects in her company, she likes rowing and abhors outboard motors; but somehow writing out a series of nine nearly identical commands lacks the romance of pulling the oars a thousand times. She decides that in the future she will use that CASE macro on every job. But now she wonders if there is a way to generalize it even more, so that it will work regardless of how many cases there happen to be without having to tell it how many. Maybe it could sense whether a load macro exists and stop automatically after it has gone through them all.

The CASE macro would have to become a little smarter and decide on its own when to stop. She discovers the EXIT command and thinks it might be useful for this purpose. Also, since EXIT can exit to a macro, why not have it exit to its own macro? After studying the manual, learning about variables, and trying several things, she comes up with the following:

  SET i={i} PLUS 1


It took her awhile; she is the last one to leave the office, which means she missed her rowing opportunity today, and that she regrets. But she has to admit to herself that she feels some exhilaration in having become the computer's master and not its slave.

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

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

Click here for an index to this and previous COWs