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

EXPAND


Last week's COW demonstrated that the END command can execute a macro. The macro it used in its example simply listed a series of macros, each one presumably representing a load case or condition. If you want to run a subset of the cases, you simply delete the unwanted ones from the list. Very simple and straightforward. But you do have to edit the run file every time you want to change the case selection.

Can we make an arrangement that allows for changing the case selection without having to edit the run file? Yes, of course. It's always fun to tinker with automation, and GHS encourages it.

We would like the run file to pop up a list of the cases that lets us select the ones we want. Like this:



You will recognize these as the same case macro names that were in last week's example.

EXPAND is a special command that can appear within the scope of a TEMPLATE command. It refers to a macro whose purpose is to deposit something into the template. Here is such a macro:


 MACRO CASE
  CHECK C%1 | "{CMAC%1}"
 /
 
Note that MACRO CASE contains what you would normally expect to find in a TEMPLATE. The CHECK element makes a check box, and the rest takes whatever text is in the CMAC variable and puts it on the same line. The %1 stands for an integer number that gets passed to the macro by the template:

 TEMPLATE CASES
  EXPAND CASE (%1,1) 1
  "GO" EXIT CALC (%1,1) 1
 /
 
(%1,1) 1 means to execute the macro a given number of times, passing a parameter which starts at one and is increased by one each time.

Now this presupposes that we have defined variables Cn and CMACn (n=1 ... ). It can be done simply by a list of VARIABLE commands, but using a macro makes it slightly easier if you have a lot of cases.


 
 MACRO DEF
  SET NCASES={NCASES} PLUS 1
  VARIABLE (STR) CMAC{NCASES}="%1"
  VARIABLE C{NCASES}=1
 /
 VARIABLE NCASES=0
 .DEF "CASE1"
 .DEF "CASE2"
 .DEF "CASE3C"
 .DEF "FLOOD1"
 .DEF "FLOOD6"
 

The "GO" button in the template executes MACRO CALC which in turn executes a case macro only if the check box was checked:

 MACRO CALC
  IF {C%1}<>0 THEN  .{CMAC%1}
 /
 

Finally we get to the END:

 END CASES {NCASES}
 

Here it is all together:

 MACRO CASE1
  ME "Doing Case 1
 /
 
 MACRO CASE3C
  ME "Doing Case 3C
 /
 
 MACRO FLOOD1
  ME "Doing Flooded Case 1
 /
 
 `etc.
 
 `-----------------------
 
 MACRO CALC
  IF {C%1}<>0 THEN IF EXIST {CMAC%1} THEN .{CMAC%1}
 /
 
 MACRO DEF
  SET NCASES={NCASES} PLUS 1
  VARIABLE (STR) CMAC{NCASES}="%1"
  VARIABLE C{NCASES}=1
 /
 VARIABLE NCASES=0
 .DEF "CASE1"
 .DEF "CASE2"
 .DEF "CASE3C"
 .DEF "FLOOD1"
 .DEF "FLOOD6"
 
 `-----------------------
 
 MACRO CASE
  CHECK C%1 | "{CMAC%1}"
 /
 
 TEMPLATE CASES
 EXPAND CASE (%1,1) 1
 "GO" EXIT CALC (%1,1) 1
 /
 
 `-----------------------
 
 END CASES {NCASES}
 
What we have now has taken almost three times the number of GHS commands that were in last week's simple example. But since we have to add only one line for each new case, the 14 extra lines in this method becomes less significant with more cases.

Whether or not it's practical depends on how much fun you want to have.


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