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

WRITE (LINE) vs. MESSAGE (REPORT)


Both WRITE (LINE) and ME (REPORT) are useful for writing text files. You can use either one or both to output one or more lines of text to a file.

For example:

ME (REPORT) COW166.TXT
ME "leaves the file open, which means a line of text is
ME "appended to the file by any subsequent ME command until
ME (REPORT) OFF
ME (REPORT) COW166.TXT /APPEND
ME "closes the file.
ME (REPORT) OFF


WRITE (LINE) COW166.TXT
\does not leave the file open: it adds one or more
\lines of text and then closes the file.


MESSAGE (REPORT) COW166.TXT /APPEND
ME "can be used that way too: use
ME (REPORT) OFF
WRITE (LINE) COW166.TXT
\before doing anything else.
ME (REPORT) COW166.TXT /APPEND
ME "But the file can be left open, which is a
ME "convenience and a limitation.
ME "The convenience is obvious. The limitation
ME "is that when this file is open
ME "you cannot use the MESSAGE command for
ME "anything else, which is obvious too,
ME "but knowing whether ME (REPORT) filename
ME "is in effect or not may not be obvious.
IF FEXIST COW166A.TXT THEN ERASE COW166A.TXT
WRITE (LINE) COW166A.TXT
\Note: this WRITE (LINE) method never leaves
\the file open, and it always appends to the file.
\It's simple and straightforward and quite safe.
ME "So would good practice be to issue
ME "ME (REPORT) OFF just before the
ME "ME (REPORT) filename command?
ME "Whether it is a good thing or not, GHS does it
ME "for you. Any file left open by
ME "ME (REPORT) filename is closed automatically
ME "if not closed by ME (REPORT) OFF before the
ME "next ME (REPORT) filename. That's fine, but it's
ME "possible that the code that had left the file
ME "open is assuming that it is still open.
WRITE (LINE) COW166A.TXT
\allows two files to be open simultaneously.
\This is the bottom line.
ME (REPORT) OFF
COPY COW166A.TXT COW166.TXT /APPEND

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