Input and Output

Simgua defines a number of useful functions for input and output during model simulation. These functions are summarized in the following table:

Table of Available input and output functions

Function

Description

Output

Beep

Plays a short “beep” sound.

Speak(“s”, b)

Speaks the text s using the system’s speech synthesizer. The Boolean b is optional. If True, a new speak command will interrupt any ongoing speak commands. If False, speak commands will be queued and spoken one after another. False is the default.

Write(“s”)

Writes the string s to the console.

WriteLn(“s”)

Writes the string s to the console and appends the new line character to it.

MsgBox(“s”)

Displays the string s in a separate window.

EOL

A constant that represents a new line character.

OperatingSystem

A string containing the operating system Simgua is currently running on. “Macintosh,” “Windows,” or “Linux.” Can be combined with the Execute function for implementing shell commands.

Input

Read(“msg”, “s”)

Asks the user to input a string. Msg is displayed as a prompt and returns the results. The default value is set to s.

Read(“msg”, d)

Asks the user to input a double. Msg is displayed as a prompt and returns the results. The default value is set to d.

Read(“msg”, b)

Asks the user to input a boolean. Msg is displayed as a prompt and returns the results. The default value is set to b.

Execute(“cmd”)

Executes the shell command cmd and returns the results as a string. Can be used to determine general variables such as the current date or to execute auxiliary analysis programs. The shell commands on different operating systems are very different so using this function naively could limit your model portability.

 

The following image shows an example of using the read function to obtain a numeric value.

Sample invocation of the read function