General HydroStatics
Ship Stability Software |
Command of the Week
(New or interesting aspects of GHS that you may not know about) |
TEMPLATE
|
Template code and the dialog boxes that result from template execution
have appeared in previous COWs
without offering an explanation of how templates work in GHS.
So here is a gentle introduction to the TEMPLATE command as well as an attempt to show that templates can improve almost any GHS run file. If parameters appear in your run file (drafts, for example) which depend on the particulars of the vessel, a dialog box can be used to collect the parameter values. Here is an example: |
variable (string) gf1
variable (length) d1=1.0, d2=7.0, dd=1.0
if fexist stuff.sav then run stuff.sav /call
TEMPLATE getstuff "Parameters"
"GF: {GF}"
break
"Read new GF" file gf1 /ext:"GF*" /apply:read /persist:refresh |,
"Units are {LUNIT}"
"First draft" | "Last draft" | "Increment"
d1 /dec:3 | d2 /dec:3 | dd /dec:3
"Try it" .doghs
/
macro read
read {gf1}
/
macro doghs
variable d1a
set d1a={d1} plus {dd}
cls
ghs {d1}, {d1a}, ..., {d2}
/
.getstuff
save stuff.sav
|
Note that it provides a means of remembering the parameters
so there is no need to enter them anew the next time the run file is exercised:
After the dialog is closed it saves the parameters in a file. At the
beginning of the next run it checks to see if the saved file is there,
and if so it picks up all your settings before executing the template.
By adding more fields to the template, this simple technique can serve to collect all of the parameters involved in the run. It seems that templates are limited only by one's imagination. Need a calendar? The following example may be of interest if you are already into templates. Even if you are not familiar with templates, you can see what it does by copying and pasting it to the GHS command line or into a run file. |
macro day
set s="%1"
if %1<1 then set s=" "
if %1>%2 then set s=""
"{s}" /color:{c} /right |
set c=0
/
macro daybox
<BOX>" "</BOX> |
/
macro week
set n=7
if %1>%2 then set n=0
set c=4
expand day ({n},1) %1, %2
" "
%3 expand daybox ({n})
%3 " "
/
macro month
template t "{month}-{y}%4" /size:%1 /gap:9 /bg=15 %5
%2 "{month} {y}" /cen /bold
%2 " "
"S"/r/color=4|"M"/r|"T"/r|"W"/r|"T"/r|"F"/r|"S"/r
expand week (6,7) {day1}, {days}, "%2"
break
%3 "Make html" check dohtml
%2 exit
%3 "Ok" exit /start
//
.t
/
macro domonth
.month "large", "REM"
set more={templok}
if {more}=0 then exit
set mo={mo} plus 1 | if {mo}>12 then set mo=1, imo=0, yr={yr} plus 1 | set y={yr}
if {dohtml}=0 then exit
.month -40, "", "REM", ".jpg", "/FILE"
.html "{month}-{y}"
/
macro skipyear
set day1={day1} minus 1 minus {leap}
set y={y} plus 1
/
macro doyear
set month=item {imo}, "{months}"
set imo={imo} plus 1
set days=item {imo}, "{months}"
set m={imo} div 2
if {m}=2 then set days={days} plus {leap}
set more=1
if {m}={mo} then .domonth | if {more}=0 then exit
set day1={day1} plus 28 minus {days}
set imo={imo} plus 1
/
macro isdiv
set j={y} div %1
set j=trunc {j}
set j={j} times %1
if {j}<>{y} then set j=0
/
macro maybleap
.isdiv 4
set leap=0
if {j}=0 then exit
.isdiv 100 | if {j}<>0 then .isdiv 400 | if {j}=0 then exit
set leap=1
/
macro html
me (report) "%1.html"
me "<HTML><BODY><TABLE BORDER=1><TR><TD>
me "<IMG SRC="%1.jpg">
me "</TD></TR></TABLE></BODY></HTML>
me (report) off
me "Handing %1.html to the browser
shell start %1.html
/
macro calendar1
.maybleap
if {y}<{yr} then .skipyear else .doyear | if {more}=0 then exit
if {day1}<-5 then set day1={day1} plus 7
exit calendar1
/
macro calendar0
variable j, m, n, days, leap, c, more
variable (str) s, month, months
set months="January 31, February 28, March 31,
April 30, May 31, June 30,
July 31, August 31, September 30,
October 31, November 30, December 31"
.calendar 1
variable yr:{y}:9999, mo:1:12
/
macro calendar
variable imo=1, y=1583, day1=-5
if "%1"="" then exit calendar1
/
variable dohtml=1
.calendar0
template ask "Perpetual Calendar" /size:large
"Year" yr /dec:0
"Month" mo /dec:0
/
set yr=2017, mo=1
.ask | if {templok}<>0 then .calendar
|
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 |